source: trunk/src/org/expeditee/actions/ExploratorySearchActions.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

  • Property svn:executable set to *
File size: 9.4 KB
Line 
1/**
2 * ExploratorySearchActions.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.actions;
20
21import org.expeditee.core.Point;
22import org.expeditee.gio.EcosystemManager;
23import org.expeditee.gio.gesture.StandardGestureActions;
24import org.expeditee.gui.Browser;
25import org.expeditee.gui.DisplayController;
26import org.expeditee.gui.Frame;
27import org.expeditee.gui.FrameIO;
28import org.expeditee.gui.FreeItems;
29import org.expeditee.items.Item;
30import org.expeditee.items.Justification;
31import org.expeditee.items.Text;
32import org.expeditee.settings.exploratorysearch.ExploratorySearchSettings;
33import org.expeditee.settings.network.NetworkSettings;
34
35/**
36 * List of actions which Exploratory Search uses.
37 * @author csl14
38 */
39public class ExploratorySearchActions {
40
41 /**
42 * Adds a text item to the cursor which is linked to a new frame with the web browser active overlay and a JavaFX browser.
43 * @param caller The item that the action is called from
44 */
45 public static void startBrowserSession(Item caller) {
46 try {
47 String url;
48
49 Text urlItem = FreeItems.getTextAttachedToCursor();
50
51 // If there is a text item attached to the cursor, use it as the URL to load
52 if (urlItem != null) {
53 url = urlItem.getText();
54
55 // Remove the item, since the link to the browser session will added to the cursor
56 urlItem.delete();
57 } else {
58 // Otherwise use the home page specified in the settings
59 url = NetworkSettings.HomePage.get();
60 }
61
62 Text linkToBrowserSession = DisplayController.getCurrentFrame().addText(DisplayController.getMouseX(), DisplayController.getMouseY(), " - Web Browser Session", null);
63 linkToBrowserSession.setParent(DisplayController.getCurrentFrame());
64 Text.AddDate(linkToBrowserSession);
65 StandardGestureActions.pickup(linkToBrowserSession);
66
67 // Create new frame
68 Frame frame = FrameIO.CreateNewFrame(linkToBrowserSession);
69
70 // link this text item to new frame
71 linkToBrowserSession.setLink("" + frame.getNumber());
72
73 // Remove everything from new frame
74 frame.removeAllItems(frame.getItems());
75
76 // Add web browser active overlay and @old
77 Text t = (Text) frame.addText(-150, 50, "@ao: 2", null, "overlayset2");
78 t.setAnchorRight(-100);
79 t.setAnchorTop(50);
80 t = (Text) frame.addText(-150, 50, "@old", null);
81 t.setFamily("Roboto Condensed");
82 t.setSize(15.0f);
83 t.setColor(null);
84 t.setWidth(116);
85 t.setJustification(Justification.right);
86 t.setLinkMark(false);
87 t.setAnchorLeft(9);
88 t.setAnchorBottom(114);
89
90 Text wt;
91
92 // Extract marigns from settings
93 int lm = ExploratorySearchSettings.BrowserLeftMargin.get();
94 int rm = ExploratorySearchSettings.BrowserRightMargin.get();
95 int tm = ExploratorySearchSettings.BrowserTopMargin.get();
96 int bm = ExploratorySearchSettings.BrowserBottomMargin.get();
97
98 // Start Browser in fullscreen or default, depending on settings
99 if(ExploratorySearchSettings.BrowserFullScreen.get()) {
100 wt = frame.addText(ExploratorySearchSettings.BROWSER_HORZ_OFFSET + lm, ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm,
101 "@iw: org.expeditee.items.widgets.JfxBrowser "
102 + ("--anchorLeft " + (lm + ExploratorySearchSettings.BROWSER_HORZ_OFFSET) + " --anchorRight " + rm + " --anchorTop "
103 + (ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm) + " --anchorBottom " + bm + " ")
104 + (EcosystemManager.getGraphicsManager().getWindowSize().getWidth() - ExploratorySearchSettings.BROWSER_HORZ_OFFSET - lm - rm) + " "
105 + (EcosystemManager.getGraphicsManager().getWindowSize().getHeight() - ExploratorySearchSettings.BROWSER_VERT_OFFSET - tm - bm) + " : " + url, null);
106 } else {
107 wt = frame.addText(ExploratorySearchSettings.BROWSER_HORZ_OFFSET + lm, ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm,
108 "@iw: org.expeditee.items.widgets.JfxBrowser " +
109 (ExploratorySearchSettings.BrowserDefaultWidth.get() - lm - rm) + " " +
110 (ExploratorySearchSettings.BrowserDefaultHeight.get() - tm - bm) + " : " + url, null);
111 }
112
113 FrameIO.SaveFrame(frame); // save frame to disk
114 } catch(Exception e) {
115 e.printStackTrace();
116 }
117 }
118
119 /**
120 * Adds a text item to the cursor which is linked to a new frame with the mindmap active overlay.
121 */
122 public static void startMindmapSession() {
123 // Replace any text item on cursor with link to a new mindmap
124 FreeItems.getInstance().clear();
125 Point cursorPos = DisplayController.getMousePosition();
126 Text text = DisplayController.getCurrentFrame().addText(cursorPos.getX(), cursorPos.getY(), " - Mindmap Session", null);
127 text.setParent(DisplayController.getCurrentFrame());
128 Text.AddDate(text);
129 StandardGestureActions.pickup(text);
130 Frame frame = FrameIO.CreateNewFrame(text);
131 text.setLink("" + frame.getNumber());
132
133 // Clear new frame and add active overlay and @old
134 frame.removeAllItems(frame.getItems());
135 Text t = (Text) frame.addText(-150, 50, "@ao: 2", null, "overlayset3");
136 t.setAnchorLeft(-150);
137 t.setAnchorTop(50);
138 t = (Text) frame.addText(-150, 50, "@old", null);
139 t.setFamily("Roboto Condensed");
140 t.setSize(15.0f);
141 t.setColor(null);
142 t.setWidth(116);
143 t.setJustification(Justification.right);
144 t.setLinkMark(false);
145 t.setAnchorLeft(9);
146 t.setAnchorBottom(114);
147
148 FrameIO.SaveFrame(frame);
149 }
150
151 /**
152 * Adds a text item to the cursor which is linked to a new frame with the web browser active overlay and a JavaFX browser.
153 * @param caller The item that the action is called from
154 */
155 public static void startBrowserWithOverlay(Item caller) {
156 try {
157 String url;
158
159 Text urlItem = FreeItems.getTextAttachedToCursor();
160
161 // If there is a text item attached to the cursor, use it as the URL to load
162 if (urlItem != null) {
163 url = urlItem.getText();
164
165 // Remove the item, since the link to the browser session will added to the cursor
166 urlItem.delete();
167 } else {
168 // Otherwise use the home page specified in the settings
169 url = NetworkSettings.HomePage.get();
170 }
171
172 Point cursorPos = DisplayController.getMousePosition();
173 Text linkToBrowserSession = DisplayController.getCurrentFrame().addText(cursorPos.getX(), cursorPos.getY(), url, null);
174 linkToBrowserSession.setParent(DisplayController.getCurrentFrame());
175 StandardGestureActions.pickup(linkToBrowserSession);
176
177 // Create new frame
178 Frame frame = FrameIO.CreateNewFrame(linkToBrowserSession);
179
180 // link this text item to new frame
181 linkToBrowserSession.setLink("" + frame.getNumber());
182
183 // Remove everything from new frame
184 frame.removeAllItems(frame.getItems());
185
186 // Add web browser active overlay and @old
187 Text t = (Text) frame.addText(-150, 50, "@ao: 2", null, "overlayset2");
188 t.setAnchorLeft(-150);
189 t.setAnchorTop(50);
190 t = (Text) frame.addText(-150, 50, "@old", null);
191 t.setFamily("Roboto Condensed");
192 t.setSize(15.0f);
193 t.setColor(null);
194 t.setWidth(116);
195 t.setJustification(Justification.right);
196 t.setLinkMark(false);
197 t.setAnchorLeft(9);
198 t.setAnchorBottom(114);
199
200 Text wt;
201
202 // Extract marigns from settings
203 int lm = ExploratorySearchSettings.BrowserLeftMargin.get();
204 int rm = ExploratorySearchSettings.BrowserRightMargin.get();
205 int tm = ExploratorySearchSettings.BrowserTopMargin.get();
206 int bm = ExploratorySearchSettings.BrowserBottomMargin.get();
207
208 // Start Browser in fullscreen or default, depending on settings
209 if(ExploratorySearchSettings.BrowserFullScreen.get()) {
210 wt = frame.addText(ExploratorySearchSettings.BROWSER_HORZ_OFFSET + lm, ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm,
211 "@iw: org.expeditee.items.widgets.JfxBrowser "
212 + ("--anchorLeft " + (lm + ExploratorySearchSettings.BROWSER_HORZ_OFFSET) + " --anchorRight " + rm + " --anchorTop "
213 + (ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm) + " --anchorBottom " + bm + " ")
214 + (EcosystemManager.getGraphicsManager().getWindowSize().getWidth() - ExploratorySearchSettings.BROWSER_HORZ_OFFSET - lm - rm) + " "
215 + (EcosystemManager.getGraphicsManager().getWindowSize().getHeight() - ExploratorySearchSettings.BROWSER_VERT_OFFSET - tm - bm) + " : " + url, null);
216 } else {
217 wt = frame.addText(ExploratorySearchSettings.BROWSER_HORZ_OFFSET + lm, ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm,
218 "@iw: org.expeditee.items.widgets.JfxBrowser " +
219 (ExploratorySearchSettings.BrowserDefaultWidth.get() - lm - rm) + " " +
220 (ExploratorySearchSettings.BrowserDefaultHeight.get() - tm - bm) + " : " + url, null);
221 }
222
223 FrameIO.SaveFrame(frame); // save frame to disk
224 } catch(Exception e) {
225 e.printStackTrace();
226 }
227 }
228
229}
Note: See TracBrowser for help on using the repository browser.