[919] | 1 | /**
|
---|
| 2 | * Browser.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 |
|
---|
[4] | 19 | package org.expeditee.gui;
|
---|
| 20 |
|
---|
[348] | 21 | import java.io.File;
|
---|
[1215] | 22 | import java.io.IOException;
|
---|
[535] | 23 | import java.net.Authenticator;
|
---|
[1215] | 24 | import java.security.KeyStoreException;
|
---|
| 25 | import java.security.NoSuchAlgorithmException;
|
---|
| 26 | import java.security.cert.CertificateException;
|
---|
| 27 | import java.sql.SQLException;
|
---|
[427] | 28 | import java.util.ArrayList;
|
---|
[80] | 29 | import java.util.Collection;
|
---|
[4] | 30 |
|
---|
| 31 | import org.expeditee.actions.Actions;
|
---|
[139] | 32 | import org.expeditee.actions.Simple;
|
---|
[238] | 33 | import org.expeditee.agents.mail.MailSession;
|
---|
[1282] | 34 | import org.expeditee.auth.AuthenticatorBrowser;
|
---|
[1102] | 35 | import org.expeditee.core.BlockingRunnable;
|
---|
| 36 | import org.expeditee.core.Colour;
|
---|
| 37 | import org.expeditee.core.Dimension;
|
---|
| 38 | import org.expeditee.core.Point;
|
---|
| 39 | import org.expeditee.gio.EcosystemManager;
|
---|
| 40 | import org.expeditee.gio.EcosystemManager.Ecosystem;
|
---|
| 41 | import org.expeditee.gio.GraphicsManager;
|
---|
| 42 | import org.expeditee.gio.InputManager;
|
---|
| 43 | import org.expeditee.gio.InputManager.WindowEventListener;
|
---|
| 44 | import org.expeditee.gio.InputManager.WindowEventType;
|
---|
| 45 | import org.expeditee.gio.gesture.StandardGestureActions;
|
---|
[535] | 46 | import org.expeditee.io.ProxyAuth;
|
---|
[427] | 47 | import org.expeditee.items.Item;
|
---|
[1102] | 48 | import org.expeditee.items.ItemUtils;
|
---|
[777] | 49 | import org.expeditee.items.Text;
|
---|
[219] | 50 | import org.expeditee.items.widgets.WidgetCacheManager;
|
---|
[298] | 51 | import org.expeditee.network.FrameShare;
|
---|
[570] | 52 | import org.expeditee.settings.Settings;
|
---|
| 53 | import org.expeditee.settings.UserSettings;
|
---|
[419] | 54 | import org.expeditee.stats.Logger;
|
---|
[139] | 55 | import org.expeditee.stats.StatsLogger;
|
---|
| 56 | import org.expeditee.taskmanagement.EntitySaveManager;
|
---|
| 57 | import org.expeditee.taskmanagement.SaveStateChangedEvent;
|
---|
| 58 | import org.expeditee.taskmanagement.SaveStateChangedEventListener;
|
---|
[4] | 59 |
|
---|
| 60 | /**
|
---|
| 61 | * The Main GUI class, comprises what people will see on the screen.<br>
|
---|
| 62 | * Note: Each Object (Item) is responsible for drawing itself on the screen.<br>
|
---|
| 63 | * Note2: The Frame is registered as a MouseListener and KeyListener, and
|
---|
| 64 | * processes any Events.
|
---|
| 65 | *
|
---|
[1102] | 66 | * TODO List:
|
---|
| 67 | *
|
---|
| 68 | * Back to standard:
|
---|
| 69 | * - JavaFX Text-hitting (requires JFX1.9)
|
---|
| 70 | * - Overlays and Vectors review
|
---|
| 71 | * - Pop-ups (unused in base Expeditee, only in Apollo)
|
---|
| 72 | * - Apollo input (test)
|
---|
| 73 | * - The rest of Apollo
|
---|
| 74 | * - Make sure clipping/invalidation takes twin-frames into account
|
---|
| 75 | * - Reinstate Simple input commands
|
---|
| 76 | * - Test LinkedTrack.paintInFreeSpace()
|
---|
| 77 | * - Test EmulatedTextItem.onMouseReleased(MouseEvent) (removed emulatedSource mouse button check)
|
---|
| 78 | * - Constrained placement of items
|
---|
| 79 | *
|
---|
| 80 | * Extra:
|
---|
| 81 | * - Self-describing input
|
---|
| 82 | * - Thread safety (most stuff on GIO event thread but Agents can start new threads)
|
---|
| 83 | * - Touch input
|
---|
| 84 | * - Better reflection??? (currently changes to the code break reflection as it relies on names)
|
---|
| 85 | * - JavaFX lag (always rendering to images doesn't gel well with JavaFX)
|
---|
| 86 | * - Swing widgets in JFX
|
---|
| 87 | * - JavaFX Widgets (exception on drawing?)
|
---|
| 88 | * - Reduce reliance on into-image rendering to improve JavaFX performance (utilise enforced-clip)
|
---|
| 89 | * - Block Swing ecosystem setup until window is available, or...
|
---|
| 90 | * - Reconfigure window-resized code so things are properly resized (PREFERRED).
|
---|
| 91 | * - Swing alpha-compositing of colours (currently alpha is ignored e.g. drop-shadow in transition).
|
---|
| 92 | * - Overly-thick extrusion lines (seems to depend on number of connected lines...)
|
---|
| 93 | * - Make FreeItems control pickup etc.
|
---|
| 94 | * - Remove MouseEventRouter
|
---|
| 95 | * - Highlighting (should be controlled by the items themselves)
|
---|
| 96 | * - Make Widgets into fully-fledged items (maybe???)
|
---|
| 97 | * - Merge Widget and HeavyDutyWidget
|
---|
| 98 | * - Redefine TextLayouts (relative/absolute layouts)
|
---|
| 99 | * - Settings exceptions (Password widget in JFX) (currently fixed with hack)
|
---|
| 100 | * - MessageBay (what did I mean by this specifically?)
|
---|
| 101 | * - Order-dependency of start-up code
|
---|
| 102 | * - MessageBay not refreshing at start-up
|
---|
| 103 | * - Invalidation hierarchy (item => frame => display controller area => window)
|
---|
| 104 | * - Add gesture data type checking
|
---|
| 105 | * - Paintable interface
|
---|
| 106 | * - EcosystemSpecific interface (utilise to enable/disable features based on ecosystem)
|
---|
| 107 | * - Remove/modify Mutable class (in Apollo.util, change to InOutReference)
|
---|
| 108 | * - Convert BlockingRunnable to interface
|
---|
| 109 | * - Modify Metronome to utilise Timeouts
|
---|
| 110 | * - Need AWT in FastAlphaEffect???
|
---|
| 111 | *
|
---|
| 112 | * General:
|
---|
| 113 | * - Tidy FrameGraphics
|
---|
| 114 | * - Comment
|
---|
| 115 | * - UserSettings.DEFAULT_PROFILE_NAME not actually a user setting
|
---|
| 116 | *
|
---|
| 117 | * Done:
|
---|
| 118 | * - Timers
|
---|
| 119 | * - Timer input animations
|
---|
| 120 | * - Finish DisplayController/FrameGraphics separation
|
---|
| 121 | * - Anchor constraints (create class)
|
---|
| 122 | * - Make MessageBay take lead from DisplayController
|
---|
| 123 | * - Make message bay display again (to do with above)
|
---|
| 124 | * - Tooltips (layout broken in Swing as window size not correct when tooltips laid out)
|
---|
| 125 | * - Frame transitions
|
---|
| 126 | * - Frame transitions in twin-frames mode drawing over each other
|
---|
| 127 | * - JFX DnD manager
|
---|
| 128 | * - Reinstate Simple
|
---|
| 129 | * - Reinstate exclude source
|
---|
| 130 | * - Reinstate commented code
|
---|
| 131 | * - Twin-frames division 0 at startup
|
---|
| 132 | * - Twin frames off-by-one frame size (draws a line of erroneous pixels)
|
---|
| 133 | * - MessageBay delays showing messages on start-up
|
---|
| 134 | * - JFX Antialiasing done on theScene??? Doesn't apply for our situation
|
---|
| 135 | * - Incorporate Clip class into code
|
---|
| 136 | * - Enforced clip
|
---|
| 137 | *
|
---|
| 138 | * @author cts16
|
---|
[4] | 139 | * @author jdm18
|
---|
| 140 | */
|
---|
[1102] | 141 | public class Browser implements SaveStateChangedEventListener {
|
---|
| 142 |
|
---|
| 143 | public static final Ecosystem ECOSYSTEM_TYPE = Ecosystem.Swing;
|
---|
[67] | 144 |
|
---|
[139] | 145 | public static Browser _theBrowser = null;
|
---|
[535] | 146 |
|
---|
| 147 | public static ProxyAuth proxyAuth = new ProxyAuth();
|
---|
[348] | 148 |
|
---|
[763] | 149 | public static boolean _hasExited = false;
|
---|
[147] | 150 |
|
---|
[1102] | 151 | /** A flag which is set once the application is exiting. */
|
---|
[1075] | 152 | protected boolean _isExiting = false;
|
---|
[67] | 153 |
|
---|
[1075] | 154 | protected static boolean _initComplete = false;
|
---|
[667] | 155 |
|
---|
[1215] | 156 | private static String _startFrame = null;
|
---|
[154] | 157 |
|
---|
[1244] | 158 |
|
---|
[4] | 159 | /**
|
---|
| 160 | * Constructs a new Browser object, then launches it
|
---|
| 161 | *
|
---|
| 162 | * @param args
|
---|
| 163 | */
|
---|
[1264] | 164 | public static void main(String[] args) {
|
---|
[1327] | 165 | if (AuthenticatorBrowser.isAuthenticationRequired()) {
|
---|
[1244] | 166 | String starting_user_name = System.getProperty("user.name");
|
---|
| 167 | System.setProperty("startinguser.name", starting_user_name);
|
---|
[1303] | 168 | System.setProperty("user.name", AuthenticatorBrowser.USER_NOBODY);
|
---|
[1244] | 169 | }
|
---|
| 170 |
|
---|
[1102] | 171 | // Parse the starting frame command-line argument
|
---|
[667] | 172 | if(args.length > 0) {
|
---|
[1215] | 173 | setStartFrame(args[0]);
|
---|
| 174 | if(!Character.isDigit(getStartFrame().charAt(getStartFrame().length() - 1))) {
|
---|
| 175 | setStartFrame(getStartFrame() + "1");
|
---|
[1170] | 176 | }
|
---|
[1102] | 177 | } else {
|
---|
[1215] | 178 | setStartFrame("home1");
|
---|
[1013] | 179 | }
|
---|
[1039] | 180 |
|
---|
[1102] | 181 | // Window icon must be set before initialisation
|
---|
| 182 | GraphicsManager.setWindowIcon(DisplayController.ICON_IMAGE);
|
---|
| 183 |
|
---|
| 184 | // Setup the GIO ecosystem so it is ready when we need it
|
---|
| 185 | EcosystemManager.createEcosystem(ECOSYSTEM_TYPE);
|
---|
| 186 |
|
---|
| 187 | try {
|
---|
| 188 | EcosystemManager.getMiscManager().runOnGIOThread(new BlockingRunnable() {
|
---|
| 189 | @Override
|
---|
| 190 | public void execute() {
|
---|
| 191 | init();
|
---|
| 192 | }
|
---|
| 193 | });
|
---|
| 194 | } catch (Throwable e) {
|
---|
| 195 | e.printStackTrace(System.err);
|
---|
| 196 | System.exit(1);
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[1182] | 199 | DisplayController.requestRefresh(false, () -> { MessageBay.showDelayedMessages(false); return true; });
|
---|
[4] | 200 | }
|
---|
[1102] | 201 |
|
---|
[1215] | 202 | public static void init() {
|
---|
[1327] | 203 | if (AuthenticatorBrowser.isAuthenticationRequired()) {
|
---|
[1215] | 204 | try {
|
---|
[1282] | 205 | _theBrowser = AuthenticatorBrowser.getInstance();
|
---|
[1215] | 206 | } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | ClassNotFoundException | SQLException e) {
|
---|
| 207 | e.printStackTrace();
|
---|
| 208 | }
|
---|
[1282] | 209 | } else {
|
---|
| 210 | _theBrowser = new Browser();
|
---|
| 211 | }
|
---|
[147] | 212 |
|
---|
[1102] | 213 | EcosystemManager.getGraphicsManager().requestFocus();
|
---|
| 214 |
|
---|
[1282] | 215 | // Java's way of getting access to internet. Authenticating the user with their proxy username and password.
|
---|
[1102] | 216 | Authenticator.setDefault(proxyAuth);
|
---|
| 217 |
|
---|
| 218 | _initComplete = true;
|
---|
[145] | 219 | }
|
---|
[348] | 220 |
|
---|
[320] | 221 | /**
|
---|
[147] | 222 | * @return
|
---|
[139] | 223 | *
|
---|
[1215] | 224 | * True if the application is about to exit. False if not. Note that this is
|
---|
[147] | 225 | * only set once the window is in its closed state (not closing) or if the
|
---|
[1215] | 226 | * application has explicitly being requested to exit.
|
---|
[139] | 227 | *
|
---|
| 228 | * @see Browser#exit()
|
---|
| 229 | *
|
---|
| 230 | */
|
---|
[1102] | 231 | public boolean isExiting() {
|
---|
[139] | 232 | return _isExiting;
|
---|
| 233 | }
|
---|
[67] | 234 |
|
---|
[763] | 235 | public static boolean isInitComplete() {
|
---|
[154] | 236 | return _initComplete;
|
---|
| 237 | }
|
---|
[1281] | 238 |
|
---|
| 239 | protected Browser(String mode) {
|
---|
| 240 | System.out.println("Running Expeditee in " + mode + " mode.");
|
---|
| 241 | }
|
---|
[154] | 242 |
|
---|
[1215] | 243 | protected Browser() {
|
---|
[67] | 244 | // center the frame on the screen
|
---|
[1102] | 245 | GraphicsManager g = EcosystemManager.getGraphicsManager();
|
---|
| 246 | Dimension screen = g.getScreenSize();
|
---|
| 247 | double xpos = (screen.width - UserSettings.InitialWidth.get()) / 2.0;
|
---|
| 248 | double ypos = (screen.height - UserSettings.InitialHeight.get()) / 2.0;
|
---|
| 249 | g.setWindowLocation(new Point((int) xpos, (int) ypos));
|
---|
[4] | 250 |
|
---|
[1102] | 251 | DisplayController.Init();
|
---|
[1215] | 252 |
|
---|
[1102] | 253 | DisplayController.addDisplayObserver(WidgetCacheManager.getInstance());
|
---|
| 254 | if (ECOSYSTEM_TYPE == Ecosystem.Swing) {
|
---|
| 255 | DisplayController.addDisplayObserver(PopupManager.getInstance());
|
---|
| 256 | }
|
---|
[233] | 257 |
|
---|
[1102] | 258 | setInputManagerWindowRoutines();
|
---|
[1215] | 259 |
|
---|
[699] | 260 | // Reset windows to user specified size
|
---|
[1102] | 261 | Dimension initialWindowSize = new Dimension(UserSettings.InitialWidth.get(), UserSettings.InitialHeight.get());
|
---|
| 262 | g.setWindowSize(initialWindowSize);
|
---|
[1215] | 263 |
|
---|
[781] | 264 | // Load documentation and start pages
|
---|
| 265 | FrameUtils.extractResources(false);
|
---|
[1215] | 266 |
|
---|
| 267 | // Load fonts before loading any frames so the items on the frames will be able
|
---|
| 268 | // to access their fonts
|
---|
[781] | 269 | Text.InitFonts();
|
---|
[1215] | 270 |
|
---|
[1141] | 271 | Settings.Init();
|
---|
[1140] | 272 | Frame userProfile = loadProfiles();
|
---|
[147] | 273 |
|
---|
[1329] | 274 | if (!AuthenticatorBrowser.isAuthenticationRequired() && UserSettings.PublicAndPrivateResources) {
|
---|
[1244] | 275 | String userName = UserSettings.ProfileName.get();
|
---|
[1415] | 276 | if (!FrameIO.personalResourcesExist(userName)) {
|
---|
| 277 | FrameIO.setupPersonalResources(userName);
|
---|
| 278 | }
|
---|
[1244] | 279 | }
|
---|
[139] | 280 | // Listen for save status to display during and after runtime
|
---|
| 281 | EntitySaveManager.getInstance().addSaveStateChangedEventListener(this);
|
---|
[1215] | 282 |
|
---|
[4] | 283 | try {
|
---|
[1102] | 284 | MessageBay.warningMessages(Actions.Init());
|
---|
[570] | 285 |
|
---|
[667] | 286 | // Go to the start frame if specified, otherwise go to the profile frame
|
---|
| 287 | Frame start = null;
|
---|
[1215] | 288 | if (getStartFrame() == null) {
|
---|
| 289 | setStartFrame(UserSettings.StartFrame.get());
|
---|
| 290 | if (getStartFrame() != null && !Character.isDigit(getStartFrame().charAt(getStartFrame().length() - 1))) {
|
---|
| 291 | setStartFrame(getStartFrame() + "1");
|
---|
[1102] | 292 | }
|
---|
[732] | 293 | }
|
---|
[1215] | 294 |
|
---|
| 295 | if ((start = FrameIO.LoadFrame(getStartFrame())) != null) {
|
---|
| 296 | // Make sure HomeFrame gets set
|
---|
| 297 | UserSettings.HomeFrame.set(start.getName());
|
---|
| 298 |
|
---|
| 299 | // Go to the start frame
|
---|
| 300 | DisplayController.setCurrentFrame(start, true);
|
---|
| 301 | } else {
|
---|
| 302 | // If an invalid start frame was specified, show a warning
|
---|
| 303 | if (getStartFrame() != null) {
|
---|
| 304 | MessageBay.warningMessage("Unknown frame: " + getStartFrame());
|
---|
[1170] | 305 | }
|
---|
[1215] | 306 |
|
---|
| 307 | // Go to the profile frame
|
---|
| 308 | FrameUtils.loadFirstFrame(userProfile);
|
---|
| 309 | }
|
---|
| 310 |
|
---|
[1102] | 311 | DisplayController.updateTitle();
|
---|
[147] | 312 |
|
---|
[1102] | 313 | // Don't refresh for the profile frame otherwise error messages are shown twice
|
---|
| 314 | if (!DisplayController.getCurrentFrame().equals(userProfile)) {
|
---|
| 315 | StandardGestureActions.Refresh();
|
---|
[1215] | 316 | // If it's the profile frame just reparse it in order to display
|
---|
| 317 | // images/circles/widgets correctly
|
---|
[513] | 318 | } else {
|
---|
[1102] | 319 | FrameUtils.Parse(userProfile);
|
---|
[513] | 320 | }
|
---|
[108] | 321 | } catch (Exception e) {
|
---|
| 322 | e.printStackTrace();
|
---|
| 323 | Logger.Log(e);
|
---|
| 324 | }
|
---|
| 325 | }
|
---|
[4] | 326 |
|
---|
[1170] | 327 | @Override
|
---|
[1102] | 328 | public void saveCompleted(SaveStateChangedEvent event)
|
---|
| 329 | {
|
---|
| 330 | MessageBay.displayMessage("Save finished!", Colour.BLUE);
|
---|
[348] | 331 | }
|
---|
| 332 |
|
---|
[1170] | 333 | @Override
|
---|
[1102] | 334 | public void saveStarted(SaveStateChangedEvent event)
|
---|
| 335 | {
|
---|
[147] | 336 | String name = event.getEntity().getSaveName();
|
---|
[1170] | 337 | if (name == null) {
|
---|
| 338 | name = "data";
|
---|
| 339 | }
|
---|
[1102] | 340 | MessageBay.displayMessage("Saving " + name + "...", Colour.BLUE);
|
---|
[139] | 341 | }
|
---|
[147] | 342 |
|
---|
[139] | 343 | /**
|
---|
[147] | 344 | * Closes the browser and ends the application. Performs saving operations -
|
---|
| 345 | * halting until saves have completed. Feedback is given to the user while
|
---|
| 346 | * the application is exiting. Must call on the swing thread.
|
---|
[139] | 347 | */
|
---|
| 348 | public void exit() {
|
---|
[147] | 349 |
|
---|
[139] | 350 | // Set exiting flag
|
---|
| 351 | _isExiting = true;
|
---|
[147] | 352 |
|
---|
[139] | 353 | MessageBay.displayMessage("System exiting...");
|
---|
[147] | 354 |
|
---|
[139] | 355 | /**
|
---|
| 356 | * TODO: Prompt the user etc.
|
---|
| 357 | */
|
---|
| 358 |
|
---|
[147] | 359 | // TODO: Should we should a popup with a progress bar for user feedback?
|
---|
| 360 | // this would be nice and easy to do.
|
---|
[139] | 361 | // Exit on a dedicated thread so that feedback can be obtained
|
---|
| 362 | new Exiter().start(); // this will exit the application
|
---|
| 363 | }
|
---|
[147] | 364 |
|
---|
[139] | 365 | /**
|
---|
[147] | 366 | * The system must exit on a different thread other than the swing thread so
|
---|
| 367 | * that the save threads can fire save-feedback to the swing thread and thus
|
---|
[139] | 368 | * provide user feedback on asynchronous save operations.
|
---|
| 369 | *
|
---|
| 370 | * @author Brook Novak
|
---|
[147] | 371 | *
|
---|
[139] | 372 | */
|
---|
| 373 | private class Exiter extends Thread {
|
---|
| 374 |
|
---|
| 375 | @Override
|
---|
| 376 | public void run() {
|
---|
[147] | 377 |
|
---|
[139] | 378 | // The final save point for saveable entities
|
---|
| 379 | EntitySaveManager.getInstance().saveAll();
|
---|
| 380 | try {
|
---|
| 381 | EntitySaveManager.getInstance().waitUntilAllSavingFinished();
|
---|
| 382 | } catch (InterruptedException e) {
|
---|
| 383 | e.printStackTrace();
|
---|
| 384 | }
|
---|
[1102] | 385 |
|
---|
| 386 | // Stop any agents or simple programs
|
---|
| 387 | Simple.stop();
|
---|
| 388 | Actions.stopAgent();
|
---|
| 389 | // Wait for them to stop
|
---|
| 390 | try {
|
---|
| 391 | // Only stop if need to...
|
---|
| 392 | // Brook: What purpose does this serve?
|
---|
| 393 | MessageBay.displayMessage("Stopping Simple programs...");
|
---|
| 394 | while (Simple.isProgramRunning()) {
|
---|
| 395 | Thread.sleep(100);
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | MessageBay.displayMessage("Stopping Agents...");
|
---|
| 399 | /* TODO: Only stop if need to... */
|
---|
| 400 | while (Actions.isAgentRunning()) {
|
---|
| 401 | Thread.sleep(100); // Brook: What purpose does this serve?
|
---|
| 402 | }
|
---|
| 403 | } catch (Exception e) {
|
---|
[139] | 404 |
|
---|
[1102] | 405 | }
|
---|
[139] | 406 |
|
---|
[1102] | 407 | MessageBay.displayMessage("Saving current frame...");
|
---|
| 408 | FrameIO.SaveFrame(DisplayController.getCurrentFrame());
|
---|
[147] | 409 |
|
---|
[1102] | 410 | MessageBay.displayMessage("Saving stats...");
|
---|
| 411 | StatsLogger.WriteStatsFile();
|
---|
[147] | 412 |
|
---|
[1102] | 413 | if (MailSession.getInstance() != null) {
|
---|
| 414 | if (MailSession.getInstance().finalise()) {
|
---|
| 415 | // TODO display this message before the finalising
|
---|
| 416 | // is done but only if the mail needs closing
|
---|
| 417 | MessageBay.displayMessage("Closed ExpMail...");
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
[139] | 420 |
|
---|
[1102] | 421 | if (FrameShare.getInstance() != null) {
|
---|
| 422 | MessageBay.displayMessage("Stopping FrameServer...");
|
---|
| 423 | FrameShare.getInstance().finalise();
|
---|
| 424 | }
|
---|
[242] | 425 |
|
---|
[1102] | 426 | MessageBay.displayMessage("System exited");
|
---|
[147] | 427 |
|
---|
[1102] | 428 | // Finally remove the messages frameset
|
---|
[1293] | 429 | FrameIO.moveFrameset("messages", FrameIO.MESSAGES_PATH, false);
|
---|
[298] | 430 |
|
---|
[1102] | 431 | /*
|
---|
| 432 | * Create a new messages folder so that it doesn't throw
|
---|
| 433 | * Exceptions when two Expeditee's open at once and the
|
---|
| 434 | * second tries to save its messages
|
---|
| 435 | */
|
---|
| 436 | File file = new File(FrameIO.MESSAGES_PATH + "messages");
|
---|
| 437 | file.mkdirs();
|
---|
[311] | 438 |
|
---|
[1102] | 439 | Browser._hasExited = true;
|
---|
| 440 |
|
---|
| 441 | System.exit(0);
|
---|
[139] | 442 | }
|
---|
| 443 | }
|
---|
| 444 |
|
---|
[242] | 445 | /**
|
---|
| 446 | * Used to set up the the browser for use in testing.
|
---|
| 447 | *
|
---|
| 448 | * @return
|
---|
| 449 | */
|
---|
[1102] | 450 | public static Browser initializeForTesting()
|
---|
| 451 | {
|
---|
[156] | 452 | if (Browser._theBrowser == null) {
|
---|
[311] | 453 | FrameShare.disableNetworking = true;
|
---|
[242] | 454 | MailSession._autoConnect = false;
|
---|
[311] | 455 |
|
---|
[926] | 456 | Browser.main(new String[]{});
|
---|
[156] | 457 | try {
|
---|
| 458 | while (!isInitComplete()) {
|
---|
| 459 | Thread.sleep(10);
|
---|
| 460 | }
|
---|
| 461 | } catch (Exception e) {
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
| 464 | return _theBrowser;
|
---|
| 465 | }
|
---|
[1102] | 466 |
|
---|
[1215] | 467 | private static void setInputManagerWindowRoutines() {
|
---|
[1102] | 468 | InputManager manager = EcosystemManager.getInputManager();
|
---|
| 469 |
|
---|
| 470 | // Refresh the layout when the window resizes
|
---|
| 471 | manager.addWindowEventListener(new WindowEventListener() {
|
---|
| 472 | @Override
|
---|
| 473 | public void onWindowEvent(WindowEventType type)
|
---|
| 474 | {
|
---|
[1170] | 475 | if (type != WindowEventType.WINDOW_RESIZED) {
|
---|
| 476 | return;
|
---|
| 477 | }
|
---|
[1102] | 478 | DisplayController.refreshWindowSize();
|
---|
| 479 | FrameIO.RefreshCacheImages();
|
---|
| 480 | for (Frame frame : DisplayController.getFrames()) {
|
---|
| 481 | if (frame != null) {
|
---|
| 482 | ItemUtils.Justify(frame);
|
---|
| 483 | frame.refreshSize();
|
---|
| 484 | }
|
---|
| 485 | }
|
---|
| 486 | DisplayController.requestRefresh(false);
|
---|
| 487 | }
|
---|
| 488 | });
|
---|
| 489 |
|
---|
| 490 | manager.addWindowEventListener(new WindowEventListener() {
|
---|
| 491 | @Override
|
---|
| 492 | public void onWindowEvent(WindowEventType type)
|
---|
| 493 | {
|
---|
[1170] | 494 | if (type != WindowEventType.MOUSE_EXITED_WINDOW) {
|
---|
| 495 | return;
|
---|
| 496 | }
|
---|
[1102] | 497 | StandardGestureActions.mouseExitedWindow();
|
---|
| 498 | }
|
---|
| 499 | });
|
---|
| 500 |
|
---|
| 501 | manager.addWindowEventListener(new WindowEventListener() {
|
---|
| 502 | @Override
|
---|
| 503 | public void onWindowEvent(WindowEventType type)
|
---|
| 504 | {
|
---|
[1170] | 505 | if (type != WindowEventType.MOUSE_ENTERED_WINDOW) {
|
---|
| 506 | return;
|
---|
| 507 | }
|
---|
[1102] | 508 | StandardGestureActions.mouseEnteredWindow();
|
---|
| 509 | }
|
---|
| 510 | });
|
---|
| 511 |
|
---|
| 512 | manager.addWindowEventListener(new WindowEventListener() {
|
---|
| 513 | @Override
|
---|
| 514 | public void onWindowEvent(WindowEventType type)
|
---|
| 515 | {
|
---|
[1170] | 516 | if (type != WindowEventType.WINDOW_CLOSED) {
|
---|
| 517 | return;
|
---|
| 518 | }
|
---|
| 519 | if (Browser._theBrowser != null) {
|
---|
| 520 | Browser._theBrowser.exit();
|
---|
| 521 | }
|
---|
[1102] | 522 | }
|
---|
| 523 | });
|
---|
| 524 | }
|
---|
[156] | 525 |
|
---|
[1102] | 526 | /**
|
---|
| 527 | * @return The user's profile frame.
|
---|
| 528 | */
|
---|
[1215] | 529 | public static Frame loadProfiles()
|
---|
[1102] | 530 | {
|
---|
| 531 | String defaultProfileName = UserSettings.DEFAULT_PROFILE_NAME;
|
---|
| 532 | String userName = UserSettings.ProfileName.get();
|
---|
| 533 |
|
---|
[1141] | 534 | Frame userProfile = loadProfile(userName);
|
---|
[1102] | 535 | Frame defaultProfile = loadProfile(defaultProfileName);
|
---|
[1141] | 536 |
|
---|
[1102] | 537 | MessageBay.warningMessages(FrameUtils.ParseProfile(defaultProfile));
|
---|
| 538 |
|
---|
| 539 | // Save the cursor if the defaultProfile had a custom cursor
|
---|
| 540 | Collection<Item> cursor = null;
|
---|
| 541 | if(FreeItems.hasCursor()) {
|
---|
| 542 | cursor = new ArrayList<Item>();
|
---|
| 543 | cursor.addAll(FreeItems.getCursor());
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | MessageBay.warningMessages(FrameUtils.ParseProfile(userProfile));
|
---|
| 547 |
|
---|
[1170] | 548 | if (cursor != null && !FreeItems.hasCursor()) {
|
---|
| 549 | FreeItems.setCursor(cursor);
|
---|
| 550 | }
|
---|
[1102] | 551 |
|
---|
| 552 | return userProfile;
|
---|
| 553 | }
|
---|
| 554 |
|
---|
[1242] | 555 | protected static Frame loadProfile(String userName) {
|
---|
[1102] | 556 | Frame profile = FrameIO.LoadProfile(userName);
|
---|
| 557 |
|
---|
| 558 | if (profile == null) {
|
---|
| 559 | try {
|
---|
[1270] | 560 | profile = FrameIO.CreateNewProfile(userName, null, null);
|
---|
[1102] | 561 | } catch (Exception e) {
|
---|
| 562 | // TODO tell the user that there was a problem creating the
|
---|
| 563 | // profile frame and close nicely
|
---|
| 564 | e.printStackTrace();
|
---|
| 565 | assert (false);
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 | return profile;
|
---|
| 569 | }
|
---|
[1215] | 570 |
|
---|
| 571 | public static String getStartFrame() {
|
---|
| 572 | return _startFrame;
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 | public static void setStartFrame(String _startFrame) {
|
---|
| 576 | Browser._startFrame = _startFrame;
|
---|
| 577 | }
|
---|
[4] | 578 | }
|
---|