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

Last change on this file since 766 was 766, checked in by csl14, 10 years ago

Added Exploratory Search settings package; can now specify height and width or fullscreen mode for JfxBrowser and specify whitespace margins

File size: 4.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 * @param text Text item which passes contents as URL for browser.
28 * @throws Exception
29 */
30 public static void startBrowser(Item text) throws Exception {
31 if (!(text instanceof Text)) {
32 MessageBay.errorMessage("Must be a text item.");
33 return;
34 }
35 if(text.getLink() != null) {
36 MessageBay.errorMessage("Text item cannot have link.");
37 return;
38 }
39
40 Text wt = new Text("@iw:org.expeditee.items.widgets.JfxBrowser"); // create new text item for browser widget
41
42 if(FreeItems.textOnlyAttachedToCursor()) { // navigates to url specified by the text item
43 wt.appendText(":" + text.getText());
44 } else {
45 wt.appendText(":http://www.waikato.ac.nz");
46 }
47
48 FreeItems.getInstance().clear(); // remove url text from cursor
49
50 wt.setParent(DisplayIO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()
51 wt.setXY(FrameMouseActions.getX(), FrameMouseActions.getY());
52 // create widget from text item
53 JfxBrowser browser = (JfxBrowser) InteractiveWidget.createWidget(wt);
54
55 FrameMouseActions.pickup(browser.getItems()); // attach browser widget to mouse
56 }
57
58 /**
59 * Text item becomes link to new frame containing items.widgets.JfxBrowser and uses Text item as URL for browser.
60 * @param text Text item which passes contents as URL for browser and becomes link to the browser's new frame.
61 * @throws Exception
62 */
63 public static void startBrowserNewFrame(Item text) throws Exception {
64 if (!(text instanceof Text)) {
65 MessageBay.errorMessage("Must be a text item.");
66 return;
67 }
68 if(text.getLink() != null) { // text item can't already have a link
69 MessageBay.errorMessage("Text item already has link.");
70 return;
71 }
72
73 // If no text with url is passed to action create a new text item with http://www.waikato.ac.nz for a default url
74 if(!FreeItems.textOnlyAttachedToCursor()) {
75 text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),
76 NetworkSettings.HomePage.get(), null);
77 text.setParent(DisplayIO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()
78 FrameMouseActions.pickup(text); // Attach new text link to cursor
79 }
80
81 // Create JfxBrowser widget on a new frame
82 Frame frame = FrameIO.CreateNewFrame(text); // create new frame for browser
83 text.setLink("" + frame.getNumber()); // link this text item to new frame
84 // Create widget via text annotation
85 Text wt = frame.addText(0, JfxBrowser.VERT_OFFSET, "@iw: org.expeditee.items.widgets.JfxBrowser "+ (Browser._theBrowser.getWidth() - JfxBrowser.HORZ_CROP)+
86 " " + (Browser._theBrowser.getHeight() - JfxBrowser.VERT_CROP - JfxBrowser.VERT_OFFSET) + " : ".concat(text.getText()), null);
87 InteractiveWidget.createWidget(wt);
88
89 FrameIO.SaveFrame(frame); // save frame to disk
90 }
91
92 public static void parsePage(Item text) throws Exception {
93 if (!(text instanceof Text) || !FreeItems.textOnlyAttachedToCursor()) {
94 MessageBay.errorMessage("Must provide a text item.");
95 return;
96 }
97 if(text.getLink() != null) { // text item can't already have a link
98 MessageBay.errorMessage("Text item already has link.");
99 return;
100 }
101
102 // Create JfxBrowser widget on a new frame
103 Frame frame = FrameIO.CreateNewFrame(text); // create new frame for browser
104 text.setLink("" + frame.getNumber()); // link this text item to new frame
105 frame.addText(100, 100, "test", null);
106
107 WebParser.parseURL(text.getText(), frame);
108 System.out.println(text.getText());
109 }
110
111 public static void gotoURL(Text link, String URL) {
112 Frame frame = FrameIO.CreateNewFrame(link);
113 link.setAction(null);
114 link.setLink("" + frame.getNumber());
115
116 WebParser.parseURL(URL, frame);
117
118 frame.change();
119
120 FrameIO.SaveFrame(frame);
121 }
122}
Note: See TracBrowser for help on using the repository browser.