Changeset 147 for trunk/src/org/expeditee/gui/Browser.java
- Timestamp:
- 07/18/08 14:28:41 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/Browser.java
r145 r147 50 50 51 51 public static Browser _theBrowser = null; 52 52 53 53 // A flag which is set once the application is exiting. 54 54 private boolean _isExiting = false; … … 60 60 */ 61 61 public static void main(String[] args) { 62 62 63 63 // Prepare all expeditee and swing data on the AWT event thread. 64 64 SwingUtilities.invokeLater(new Runnable() { 65 65 public void run() { 66 // MessageBay.supressMessages(true);67 68 // MessageBay.supressMessages(false);69 66 // MessageBay.supressMessages(true); 67 68 // MessageBay.supressMessages(false); 69 70 70 _theBrowser = new Browser(); 71 71 _theBrowser.requestFocus(); 72 FrameMouseActions.MouseX = MouseInfo.getPointerInfo().getLocation().x - _theBrowser.getOrigin().x; 73 FrameMouseActions.MouseY = MouseInfo.getPointerInfo().getLocation().y - _theBrowser.getOrigin().y; 72 FrameMouseActions.MouseX = MouseInfo.getPointerInfo() 73 .getLocation().x 74 - _theBrowser.getOrigin().x; 75 FrameMouseActions.MouseY = MouseInfo.getPointerInfo() 76 .getLocation().y 77 - _theBrowser.getOrigin().y; 74 78 } 75 79 }); 76 80 77 81 } 78 82 79 83 public Point getOrigin() { 80 84 return getContentPane().getLocationOnScreen(); 81 85 } 82 83 /** 84 * @return 85 * 86 * True if the application is about to exit. False if not. Not that this is only set once the87 * window is in its closed state (not closing) or if the application has explicity being requested88 * 86 87 /** 88 * @return 89 * 90 * True if the application is about to exit. False if not. Not that this is 91 * only set once the window is in its closed state (not closing) or if the 92 * application has explicity being requested to exit. 89 93 * 90 94 * @see Browser#exit() … … 131 135 } 132 136 } 133 137 134 138 FrameUtils.ParseProfile(profile); 135 136 // Now reset the size of the windows to the size specified in the users137 // profile138 setSizes(new Dimension(UserSettings.InitialWidth,139 UserSettings.InitialHeight));140 139 141 140 // set the layout to absolute layout for widgets … … 151 150 addComponentListener(this); 152 151 pack(); 153 154 155 // See java bug ID 4016934. They say that window closed events are called once the 152 153 // Reset windows to user specified size 154 // Must be done after initialising the content pane above! 155 setSizes(new Dimension(UserSettings.InitialWidth, 156 UserSettings.InitialHeight)); 157 158 // See java bug ID 4016934. They say that window closed events are 159 // called once the 156 160 // jframe is disposed. 157 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 158 161 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 162 159 163 // Expeditee handles its own repainting of AWT/Swing components 160 164 RepaintManager.setCurrentManager(ExpediteeRepaintManager.getInstance()); 161 165 162 166 // Listen for save status to display during and after runtime 163 167 EntitySaveManager.getInstance().addSaveStateChangedEventListener(this); 164 168 165 169 // Set the drag and drop handler 166 170 setTransferHandler(FrameDNDTransferHandler.getInstance()); 167 171 168 172 try { 169 173 Collection<String> warningMessages = Actions.Init(); 170 174 171 175 DisplayIO.Init(this); 172 // Set visible must be just after DisplayIO.Init for the message box to 176 // Set visible must be just after DisplayIO.Init for the message box 177 // to 173 178 // be the right size 174 179 setVisible(true); … … 178 183 // required to accept TAB key 179 184 setFocusTraversalKeysEnabled(false); 180 181 // Must be loaded after setupGraphics if images are on the frame182 // Turn off XRay mode and load the first frame185 186 // Must be loaded after setupGraphics if images are on the frame 187 // Turn off XRay mode and load the first frame 183 188 FrameUtils.loadFirstFrame(profile); 184 189 FrameGraphics.setMode(FrameGraphics.MODE_NORMAL, false); 185 190 DisplayIO.UpdateTitle(); 186 187 //I think this can be moved back up to the top of the Go method now... 188 //It used to crash the program trying to print error messages up the top 191 192 // I think this can be moved back up to the top of the Go method 193 // now... 194 // It used to crash the program trying to print error messages up 195 // the top 189 196 for (String message : warningMessages) 190 197 MessageBay.warningMessage(message); … … 193 200 this.getContentPane().addKeyListener(keyboardListner); 194 201 this.addKeyListener(keyboardListner); 195 202 196 203 FrameKeyboardActions.Refresh(); 197 // setVisible(true);204 // setVisible(true); 198 205 } catch (Exception e) { 199 206 e.printStackTrace(); … … 292 299 293 300 public void saveCompleted(SaveStateChangedEvent event) { 294 // if (isExisting()) {295 296 // } else {297 298 // }301 // if (isExisting()) { 302 303 // } else { 304 MessageBay.displayMessage("Save finished!", Color.BLUE); 305 // } 299 306 } 300 307 301 308 public void saveStarted(SaveStateChangedEvent event) { 302 // if (isExisting()) {303 304 // } else {305 306 if (name == null) name = "data";307 MessageBay.displayMessage("Saving " + name + "...", Color.BLUE);308 //}309 }310 311 /** 312 * Closes the browser and ends the application.313 * Performs saving operations - halting until saves have completed.314 * Feedback is given to the user while the application is exiting.315 * Must call on the swing thread.309 // if (isExisting()) { 310 311 // } else { 312 String name = event.getEntity().getSaveName(); 313 if (name == null) 314 name = "data"; 315 MessageBay.displayMessage("Saving " + name + "...", Color.BLUE); 316 // } 317 } 318 319 /** 320 * Closes the browser and ends the application. Performs saving operations - 321 * halting until saves have completed. Feedback is given to the user while 322 * the application is exiting. Must call on the swing thread. 316 323 */ 317 324 public void exit() { 318 325 319 326 // Set exiting flag 320 327 _isExiting = true; 321 328 322 329 MessageBay.displayMessage("System exiting..."); 323 330 324 331 /** 325 332 * TODO: Prompt the user etc. 326 333 */ 327 328 // TODO: Should we should a popup with a progress bar for user feedback? this would be nice and easy to do.329 334 335 // TODO: Should we should a popup with a progress bar for user feedback? 336 // this would be nice and easy to do. 330 337 // Exit on a dedicated thread so that feedback can be obtained 331 338 new Exiter().start(); // this will exit the application 332 339 } 333 334 /** 335 * The system must exit on a different thread other than the swing thread 336 * sothat the save threads can fire save-feedback to the swing thread and thus340 341 /** 342 * The system must exit on a different thread other than the swing thread so 343 * that the save threads can fire save-feedback to the swing thread and thus 337 344 * provide user feedback on asynchronous save operations. 338 345 * 339 346 * @author Brook Novak 340 * 347 * 341 348 */ 342 349 private class Exiter extends Thread { … … 344 351 @Override 345 352 public void run() { 346 353 347 354 // The final save point for saveable entities 348 355 EntitySaveManager.getInstance().saveAll(); … … 353 360 } 354 361 355 // The final phase must save on the wing thread since dealing with the expeditee 362 // The final phase must save on the wing thread since dealing with 363 // the expeditee 356 364 // data model 357 365 SwingUtilities.invokeLater(new Runnable() { 358 366 public void run() { 359 367 360 // Stop any agents or simple programs368 // Stop any agents or simple programs 361 369 Simple.stop(); 362 370 Actions.stopAgent(); 363 //Wait for them to stop 364 try{ 365 MessageBay.displayMessage("Stopping Simple programs..."); // TODO: Only stop if need to... 366 while(Simple.isProgramRunning()){ 367 Thread.sleep(100); // Brook: What purpose does this serve? 371 // Wait for them to stop 372 try { 373 MessageBay 374 .displayMessage("Stopping Simple programs..."); // TODO: 375 // Only 376 // stop 377 // if 378 // need 379 // to... 380 while (Simple.isProgramRunning()) { 381 Thread.sleep(100); // Brook: What purpose does this 382 // serve? 368 383 } 369 MessageBay.displayMessage("Stopping Agents..."); // TODO: Only stop if need to... 370 while(Actions.isAgentRunning()){ 371 Thread.sleep(100); // Brook: What purpose does this serve? 384 MessageBay.displayMessage("Stopping Agents..."); // TODO: 385 // Only 386 // stop 387 // if 388 // need 389 // to... 390 while (Actions.isAgentRunning()) { 391 Thread.sleep(100); // Brook: What purpose does this 392 // serve? 372 393 } 373 } catch(Exception e){374 394 } catch (Exception e) { 395 375 396 } 376 377 MessageBay.displayMessage("Saving current frame..."); 397 398 MessageBay.displayMessage("Saving current frame..."); 378 399 FrameIO.SaveFrame(DisplayIO.getCurrentFrame()); 379 400 380 while (FrameIO.DeleteFrameset("messages")); 381 382 MessageBay.displayMessage("Saving stats..."); 401 while (FrameIO.DeleteFrameset("messages")) 402 ; 403 404 MessageBay.displayMessage("Saving stats..."); 383 405 StatsLogger.WriteStatsFile(); 384 385 MessageBay.displayMessage("System exited"); 406 407 MessageBay.displayMessage("System exited"); 386 408 System.exit(0); 387 409 388 410 } 389 411 }); 390 412 391 413 } 392 393 } 394 395 396 414 415 } 416 397 417 }
Note:
See TracChangeset
for help on using the changeset viewer.