1 | package org.expeditee.actions;
|
---|
2 |
|
---|
3 | import org.expeditee.gui.Browser;
|
---|
4 | import org.expeditee.gui.DisplayIO;
|
---|
5 | import org.expeditee.gui.Frame;
|
---|
6 | import org.expeditee.gui.FrameIO;
|
---|
7 | import org.expeditee.gui.FrameMouseActions;
|
---|
8 | import org.expeditee.gui.FreeItems;
|
---|
9 | import org.expeditee.gui.MessageBay;
|
---|
10 | import org.expeditee.io.WebParser;
|
---|
11 | import org.expeditee.items.Item;
|
---|
12 | import org.expeditee.items.Text;
|
---|
13 | import org.expeditee.items.widgets.InteractiveWidget;
|
---|
14 | import org.expeditee.items.widgets.JfxBrowser;
|
---|
15 | import org.expeditee.settings.network.NetworkSettings;
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * A list of Actions used with the JFX Browser widget
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public 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 |
|
---|
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 | * @param text Text item which passes contents as URL for browser and becomes link to the browser's new frame.
|
---|
62 | * @throws Exception
|
---|
63 | */
|
---|
64 | public static void startBrowserNewFrame(Item text) throws Exception {
|
---|
65 | if (!(text instanceof Text)) {
|
---|
66 | MessageBay.errorMessage("Must be a text item.");
|
---|
67 | return;
|
---|
68 | }
|
---|
69 | if(text.getLink() != null) { // text item can't already have a link
|
---|
70 | MessageBay.errorMessage("Text item already has link.");
|
---|
71 | return;
|
---|
72 | }
|
---|
73 |
|
---|
74 | // If no text with url is passed to action create a new text item with http://www.waikato.ac.nz for a default url
|
---|
75 | if(!FreeItems.textOnlyAttachedToCursor()) {
|
---|
76 | text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),
|
---|
77 | NetworkSettings.HomePage.get(), null);
|
---|
78 | text.setParent(DisplayIO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()
|
---|
79 | FrameMouseActions.pickup(text); // Attach new text link to cursor
|
---|
80 | }
|
---|
81 |
|
---|
82 | // Create JfxBrowser widget on a new frame
|
---|
83 | Frame frame = FrameIO.CreateNewFrame(text); // create new frame for browser
|
---|
84 | frame.removeAllItems(frame.getItems());
|
---|
85 | text.setLink("" + frame.getNumber()); // link this text item to new frame
|
---|
86 |
|
---|
87 | // Create widget via text annotation
|
---|
88 | Text wt = frame.addText(0, 0, "@iw: org.expeditee.items.widgets.JfxBrowser "
|
---|
89 | + Browser._theBrowser.getContentPane().getWidth() + " " + Browser._theBrowser.getContentPane().getHeight()
|
---|
90 | + " : " + text.getText(), null);
|
---|
91 |
|
---|
92 | InteractiveWidget.createWidget(wt);
|
---|
93 |
|
---|
94 | FrameIO.SaveFrame(frame); // save frame to disk
|
---|
95 | }
|
---|
96 |
|
---|
97 | public static void parsePage(Item text) throws Exception {
|
---|
98 | if (!(text instanceof Text) || !FreeItems.textOnlyAttachedToCursor()) {
|
---|
99 | MessageBay.errorMessage("Must provide a text item.");
|
---|
100 | return;
|
---|
101 | }
|
---|
102 | if(text.getLink() != null) { // text item can't already have a link
|
---|
103 | MessageBay.errorMessage("Text item already has link.");
|
---|
104 | return;
|
---|
105 | }
|
---|
106 |
|
---|
107 | // Create JfxBrowser widget on a new frame
|
---|
108 | Frame frame = FrameIO.CreateNewFrame(text); // create new frame for browser
|
---|
109 | text.setLink("" + frame.getNumber()); // link this text item to new frame
|
---|
110 | frame.addText(100, 100, "test", null);
|
---|
111 |
|
---|
112 | WebParser.parseURL(text.getText(), frame);
|
---|
113 | System.out.println(text.getText());
|
---|
114 | }
|
---|
115 |
|
---|
116 | public static void gotoURL(Text link, String URL) {
|
---|
117 | Frame frame = FrameIO.CreateNewFrame(link);
|
---|
118 | link.setAction(null);
|
---|
119 | link.setLink("" + frame.getNumber());
|
---|
120 |
|
---|
121 | WebParser.parseURL(URL, frame);
|
---|
122 |
|
---|
123 | frame.change();
|
---|
124 |
|
---|
125 | FrameIO.SaveFrame(frame);
|
---|
126 | }
|
---|
127 | }
|
---|