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.items.Item;
|
---|
11 | import org.expeditee.items.Text;
|
---|
12 | import org.expeditee.items.widgets.InteractiveWidget;
|
---|
13 | import org.expeditee.items.widgets.JfxBrowser;
|
---|
14 | import org.expeditee.settings.exploratorysearch.ExploratorySearchSettings;
|
---|
15 | import org.expeditee.settings.network.NetworkSettings;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * List of actions which Exploratory Search uses.
|
---|
19 | * @author csl14
|
---|
20 | */
|
---|
21 | public class ExploratorySearchActions {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Adds a text item to the cursor which is linked to a new frame with the web browser active overlay and a JavaFX browser.
|
---|
25 | * @param text The text item attached to the cursor.
|
---|
26 | */
|
---|
27 | public static void startBrowserSession(Text text) {
|
---|
28 | try {
|
---|
29 | if (!(text instanceof Text)) {
|
---|
30 | MessageBay.errorMessage("Must be a text item.");
|
---|
31 | return;
|
---|
32 | }
|
---|
33 |
|
---|
34 | if(text.getLink() != null) { // text item can't already have a link
|
---|
35 | MessageBay.errorMessage("Text item already has link.");
|
---|
36 | return;
|
---|
37 | }
|
---|
38 |
|
---|
39 | String url = "";
|
---|
40 |
|
---|
41 | // If no text with url is passed to action create a new text item
|
---|
42 | if(!FreeItems.textOnlyAttachedToCursor()) {
|
---|
43 | url = NetworkSettings.HomePage.get(); // use home page specified by settings
|
---|
44 | text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),
|
---|
45 | "Web Browser Session", null);
|
---|
46 | text.setParent(DisplayIO.getCurrentFrame());
|
---|
47 | FrameMouseActions.pickup(text);
|
---|
48 | } else {
|
---|
49 | url = text.getText(); // get url from text attached to cursor if possible
|
---|
50 | }
|
---|
51 |
|
---|
52 | // Set text to session id. TODO: set session id.
|
---|
53 | text.setText("Web Browser Session");
|
---|
54 |
|
---|
55 | // Create new frame
|
---|
56 | Frame frame = FrameIO.CreateNewFrame(text);
|
---|
57 | text.setLink("" + frame.getNumber()); // link this text item to new frame
|
---|
58 |
|
---|
59 | // Remove everything from new page
|
---|
60 | frame.removeAllItems(frame.getItems());
|
---|
61 |
|
---|
62 | // Add web browser active overlay and @old
|
---|
63 | //frame.addText(1100, 50, "@ao: 2", null, "overlayset2");
|
---|
64 | //frame.addText(1100, 20, "@old", null);
|
---|
65 |
|
---|
66 | Text t = (Text) frame.addText(1100, 50, "@ao: 2", null, "overlayset2");
|
---|
67 | t.setAnchorLeft(1087.0f);
|
---|
68 | t = (Text) frame.addText(1100, 20, "@old", null);
|
---|
69 | t.setAnchorLeft(1087.0f);
|
---|
70 |
|
---|
71 | Text wt;
|
---|
72 |
|
---|
73 | // Extract marigns from settings
|
---|
74 | int lm = ExploratorySearchSettings.BrowserLeftMargin.get();
|
---|
75 | int rm = ExploratorySearchSettings.BrowserRightMargin.get();
|
---|
76 | int tm = ExploratorySearchSettings.BrowserTopMargin.get();
|
---|
77 | int bm = ExploratorySearchSettings.BrowserBottomMargin.get();
|
---|
78 |
|
---|
79 | // Start Browser in fullscreen or default, depending on settings
|
---|
80 | if(ExploratorySearchSettings.BrowserFullScreen.get()) {
|
---|
81 | wt = frame.addText(0 + lm, 70 + tm, "@iw: org.expeditee.items.widgets.JfxBrowser "+ (Browser._theBrowser.getWidth() -
|
---|
82 | JfxBrowser.HORZ_CROP - lm - rm) + " " + (Browser._theBrowser.getHeight() - JfxBrowser.VERT_CROP -
|
---|
83 | JfxBrowser.VERT_OFFSET - tm - bm) + " : " + url, null);
|
---|
84 | } else {
|
---|
85 | wt = frame.addText(0 + lm, 70 + tm, "@iw: org.expeditee.items.widgets.JfxBrowser " +
|
---|
86 | (ExploratorySearchSettings.BrowserDefaultWidth.get() - lm - rm) + " " +
|
---|
87 | (ExploratorySearchSettings.BrowserDefaultHeight.get() - tm - bm) + " : " + url, null);
|
---|
88 | }
|
---|
89 |
|
---|
90 | // Create widget via text annotation
|
---|
91 | InteractiveWidget.createWidget(wt);
|
---|
92 |
|
---|
93 | FrameIO.SaveFrame(frame); // save frame to disk
|
---|
94 | } catch(Exception e) {
|
---|
95 | e.printStackTrace();
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Adds a text item to the cursor which is linked to a new frame with the mindmap active overlay.
|
---|
101 | */
|
---|
102 | public static void startMindmapSession() {
|
---|
103 | // Replace any text item on cursor with link to a new mindmap
|
---|
104 | FreeItems.getInstance().clear();
|
---|
105 | Text text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(), "Mindmap Session", null);
|
---|
106 | text.setParent(DisplayIO.getCurrentFrame());
|
---|
107 | FrameMouseActions.pickup(text);
|
---|
108 | Frame frame = FrameIO.CreateNewFrame(text);
|
---|
109 | text.setLink("" + frame.getNumber());
|
---|
110 |
|
---|
111 | // Clear new frame and add active overlay and @old
|
---|
112 | frame.removeAllItems(frame.getItems());
|
---|
113 | Text t = (Text) frame.addText(1100, 50, "@ao: 2", null, "overlayset3");
|
---|
114 | t.setAnchorLeft(1087.0f);
|
---|
115 | t = (Text) frame.addText(1100, 20, "@old", null);
|
---|
116 | t.setAnchorLeft(1087.0f);
|
---|
117 |
|
---|
118 | FrameIO.SaveFrame(frame);
|
---|
119 | }
|
---|
120 |
|
---|
121 | }
|
---|