source: trunk/src/org/expeditee/actions/JfxBrowserActions.java@ 748

Last change on this file since 748 was 748, checked in by ngw8, 10 years ago

Changed JFX files to no longer use reflection (as some new features were impossible via reflection) and just import javafx instead. This will probably cause Eclipse to complain if you're using a Java version <= 7, but building/running Expeditee will still work (using Eclipse or Ant).
Have also added an Ant target that builds without ant JFX stuff. See the comments near the top of JfxBrowser.java or WebParser.java for details

File size: 6.4 KB
Line 
1package org.expeditee.actions;
2
3import org.expeditee.gui.Browser;
4import org.expeditee.gui.DisplayIO;
5import org.expeditee.gui.Frame;
6import org.expeditee.gui.FrameIO;
7import org.expeditee.gui.FrameMouseActions;
8import org.expeditee.gui.FreeItems;
9import org.expeditee.gui.MessageBay;
10import org.expeditee.io.WebParser;
11import org.expeditee.items.Item;
12import org.expeditee.items.Text;
13import org.expeditee.items.widgets.InteractiveWidget;
14import org.expeditee.items.widgets.JfxBrowser;
15import org.expeditee.settings.network.NetworkSettings;
16
17
18
19/**
20 * A list of Actions used with the JFX Browser widget
21 *
22 */
23public class JfxBrowserActions {
24
25 /**
26 * Launches items.widgets.JfxBrowser and uses Text item as URL.
27 * Note: currently doesn't work
28 * @param text Text item which passes contents as URL for browser.
29 * @throws Exception
30 */
31 public static void startBrowser(Item text) throws Exception {
32 if (!(text instanceof Text)) {
33 MessageBay.errorMessage("Must be a text item.");
34 return;
35 }
36 if(text.getLink() != null) {
37 MessageBay.errorMessage("Text item cannot have link.");
38 return;
39 }
40
41 Text wt = new Text("@iw:org.expeditee.items.widgets.JfxBrowser"); // create new text item for browser widget
42
43 if(FreeItems.textOnlyAttachedToCursor()) { // navigates to url specified by the text item
44 wt.appendText(":" + text.getText());
45 } else {
46 wt.appendText(":http://www.waikato.ac.nz");
47 }
48
49 FreeItems.getInstance().clear(); // remove url text from cursor
50
51 wt.setParent(DisplayIO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()
52 wt.setXY(FrameMouseActions.getX(), FrameMouseActions.getY());
53 // create widget from text item
54 JfxBrowser browser = (JfxBrowser) InteractiveWidget.createWidget(wt);
55
56 FrameMouseActions.pickup(browser.getItems()); // attach browser widget to mouse
57 }
58
59 /**
60 * Text item becomes link to new frame containing items.widgets.JfxBrowser and uses Text item as URL for browser.
61 * Note: currently doesn't work
62 * @param text Text item which passes contents as URL for browser and becomes link to the browser's new frame.
63 * @throws Exception
64 */
65 public static void startBrowserNewFrame(Item text) throws Exception {
66 if (!(text instanceof Text)) {
67 MessageBay.errorMessage("Must be a text item.");
68 return;
69 }
70 if(text.getLink() != null) { // text item can't already have a link
71 MessageBay.errorMessage("Text item already has link.");
72 return;
73 }
74
75 // If no text with url is passed to action create a new text item with http://www.waikato.ac.nz for a default url
76 if(!FreeItems.textOnlyAttachedToCursor()) {
77 text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),
78 NetworkSettings.HomePage.get(), null);
79 text.setParent(DisplayIO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()
80 FrameMouseActions.pickup(text); // Attach new text link to cursor
81 }
82
83 // Create JfxBrowser widget on a new frame
84 Frame frame = FrameIO.CreateNewFrame(text); // create new frame for browser
85 text.setLink("" + frame.getNumber()); // link this text item to new frame
86 // Create widget via text annotation
87 Text wt = frame.addText(0, JfxBrowser.VERT_OFFSET, "@iw: org.expeditee.items.widgets.JfxBrowser "+ (Browser._theBrowser.getWidth() - JfxBrowser.HORZ_CROP)+
88 " " + (Browser._theBrowser.getHeight() - JfxBrowser.VERT_CROP) + " : ".concat(text.getText()), null);
89 InteractiveWidget.createWidget(wt);
90
91 FrameIO.SaveFrame(frame); // save frame to disk
92 }
93
94 public static void parsePage(Item text) throws Exception {
95 if (!(text instanceof Text) || !FreeItems.textOnlyAttachedToCursor()) {
96 MessageBay.errorMessage("Must provide a text item.");
97 return;
98 }
99 if(text.getLink() != null) { // text item can't already have a link
100 MessageBay.errorMessage("Text item already has link.");
101 return;
102 }
103
104 // Create JfxBrowser widget on a new frame
105 Frame frame = FrameIO.CreateNewFrame(text); // create new frame for browser
106 text.setLink("" + frame.getNumber()); // link this text item to new frame
107 frame.addText(100, 100, "test", null);
108
109 WebParser.parseURL(text.getText(), frame);
110 System.out.println(text.getText());
111 }
112
113 /**
114 * Adds a text item to the cursor which is linked to a new frame with the web browser active overlay and a JavaFX browser.
115 * @param text The text item attached to the cursor.
116 */
117 public static void startBrowserSession(Text text) {
118 try {
119 if (!(text instanceof Text)) {
120 MessageBay.errorMessage("Must be a text item.");
121 return;
122 }
123
124 if(text.getLink() != null) { // text item can't already have a link
125 MessageBay.errorMessage("Text item already has link.");
126 return;
127 }
128
129 String url = "";
130
131 // If no text with url is passed to action create a new text item
132 if(!FreeItems.textOnlyAttachedToCursor()) {
133 url = NetworkSettings.HomePage.get(); // use home page specified by settings
134 text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),
135 "Web Browser Session", null);
136 text.setParent(DisplayIO.getCurrentFrame());
137 FrameMouseActions.pickup(text);
138 } else {
139 url = text.getText(); // get url from text attached to cursor if possible
140 }
141
142 // Set text to session id. TODO: set session id.
143 text.setText("Web Browser Session");
144
145 // Create new frame
146 Frame frame = FrameIO.CreateNewFrame(text);
147 text.setLink("" + frame.getNumber()); // link this text item to new frame
148
149 // Remove everything from new page
150 frame.removeAllItems(frame.getItems());
151
152 // Add web browser active overlay
153 frame.addText(1100, 50, "@ao: 2", null, "overlayset2");
154 // Add @old
155 frame.addText(1100, 20, "@old", null);
156
157 // Create widget via text annotation
158 Text wt = frame.addText(0, 80, "@iw: org.expeditee.items.widgets.JfxBrowser "+ (Browser._theBrowser.getWidth() - JfxBrowser.HORZ_CROP)+
159 " " + (Browser._theBrowser.getHeight() - JfxBrowser.VERT_CROP) + " : ".concat(url), null);
160 InteractiveWidget.createWidget(wt);
161
162 FrameIO.SaveFrame(frame); // save frame to disk
163 } catch(Exception e) {
164 e.printStackTrace();
165 }
166 }
167
168 public static void gotoURL(Text link, String URL) {
169 Frame frame = FrameIO.CreateNewFrame(link);
170 link.setAction(null);
171 link.setLink("" + frame.getNumber());
172
173 WebParser.parseURL(URL, frame);
174
175 frame.change();
176
177 FrameIO.SaveFrame(frame);
178 }
179}
Note: See TracBrowser for help on using the repository browser.