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