Changeset 59 in tmcsimulator for trunk/src/tmcsim/client/cadclientgui/screens/ScreenManager.java
- Timestamp:
- 03/15/2017 10:20:21 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/client/cadclientgui/screens/ScreenManager.java
r3 r59 1 1 package tmcsim.client.cadclientgui.screens; 2 3 import javax.swing.InputMap;4 import javax.swing.JComponent;5 import javax.swing.Timer;6 import javax.swing.table.DefaultTableModel;7 8 import tmcsim.cadsimulator.Coordinator;9 import tmcsim.client.cadclientgui.data.CADData;10 import tmcsim.client.cadclientgui.data.Unit;11 import tmcsim.interfaces.CoordinatorInterface;12 2 13 3 import java.awt.KeyEventDispatcher; … … 19 9 import java.awt.event.WindowEvent; 20 10 import java.awt.event.WindowListener; 21 import java.rmi.RemoteException; 22 import java.util.Vector; 11 import java.util.HashMap; 12 import javax.swing.Timer; 13 import tmcsim.interfaces.CoordinatorInterface; 23 14 24 15 /** 25 * This class contains a reference to every single view-able component as well as a reference to the coordinator(which serves as the database). 26 * All commands to access data or manipulate a screen outside of the individual screen should be done through this ScreenManager. 27 * 16 * This class contains a reference to every single view-able component as well 17 * as a reference to the coordinator(which serves as the database). All commands 18 * to access data or manipulate a screen outside of the individual screen should 19 * be done through this ScreenManager. 20 * 28 21 * @author Stuart 29 22 */ 30 31 public class ScreenManager { 32 23 public class ScreenManager 24 { 33 25 private final static int ONE_SECOND = 1000; 34 26 private final static int FIVE_SECONDS = 5000; 35 27 private static ActivityLogViewer activityLogViewer; 36 28 private static AssignedIncidents assignedIncidents; … … 41 33 private static IncidentInfo incidentInfo; 42 34 //private static IncidentSupplementPersonForm incidentSupplementPersonForm; 43 private static IncidentViewer incidentViewer;35 private static HashMap<Integer, IncidentViewer> incidentViewMap = new HashMap<Integer, IncidentViewer>(); //JD 44 36 private static Login login; 45 37 private static PendingIncidents pendingIncidents; … … 54 46 private static UnitStatus unitStatus; 55 47 //private static VehicleInformationEntry vehicleInformationEntry; 56 57 48 //Reference to the Coordinator to use RMI methods 58 49 protected static CoordinatorInterface theCoordinator; 59 60 public ScreenManager(CoordinatorInterface theCoor){ 50 51 private String username; // The login name entered by the trainee 52 53 public ScreenManager(CoordinatorInterface theCoor) 54 { 61 55 theCoordinator = theCoor; 62 56 activityLogViewer = new ActivityLogViewer(); 63 57 64 58 assignedIncidents = new AssignedIncidents(); 65 59 assignedIncidents.addWindowListener(createWindowListener()); … … 67 61 //boloEntry = new BOLOEntry(); 68 62 //boloEntry.addWindowListener(createWindowListener()); 69 63 70 64 cadMenu = new CADMenu(); 71 65 cadMenu.addWindowListener(createWindowListener()); 72 66 73 67 cardfile = new Cardfile(); 74 68 cardfile.addWindowListener(createWindowListener()); 75 69 76 70 incidentEditor = new IncidentEditor(); 77 71 incidentEditor.addWindowListener(createWindowListener()); 78 72 79 73 incidentInfo = new IncidentInfo(); 80 74 incidentInfo.addWindowListener(createWindowListener()); 81 75 82 76 //incidentSupplementPersonForm = new IncidentSupplementPersonForm(); 83 77 //incidentSupplementPersonForm.addWindowListener(createWindowListener()); 84 85 incidentViewer = new IncidentViewer(); 86 incidentViewer.addWindowListener(createWindowListener()); 87 78 79 incidentViewMap = new HashMap<Integer, IncidentViewer>(); //JD 80 88 81 pendingIncidents = new PendingIncidents(); 89 82 pendingIncidents.addWindowListener(createWindowListener()); … … 91 84 powerlineUI1 = new PowerlineUI(false, 1); 92 85 powerlineUI1.addWindowListener(createWindowListener()); 93 86 94 87 powerlineUI2 = new PowerlineUI(false, 2); 95 88 powerlineUI2.addWindowListener(createWindowListener()); 96 89 97 90 powerlineUI3 = new PowerlineUI(false, 3); 98 91 powerlineUI3.addWindowListener(createWindowListener()); 99 92 100 93 powerlineUI4 = new PowerlineUI(false, 4); 101 94 powerlineUI4.addWindowListener(createWindowListener()); 102 95 103 96 powerlineUI5 = new PowerlineUI(false, 5); 104 97 powerlineUI5.addWindowListener(createWindowListener()); 105 98 106 99 //rotationServiceRequest = new RotationServiceRequest(); 107 100 //rotationServiceRequest.addWindowListener(createWindowListener()); 108 101 109 102 search = new Search(); 110 103 search.addWindowListener(createWindowListener()); 111 104 unitStatus = new UnitStatus(); 112 105 unitStatus.addWindowListener(createWindowListener()); 113 106 114 107 //vehicleInformationEntry = new VehicleInformationEntry(); 115 108 //vehicleInformationEntry.addWindowListener(createWindowListener()); 116 109 117 110 KeyboardFocusManager.getCurrentKeyboardFocusManager() 118 .addKeyEventDispatcher(new KeyEventDispatcher(){ 119 public boolean dispatchKeyEvent(KeyEvent e) { 120 if(e.getKeyCode() == KeyEvent.VK_F2 && e.getID() == KeyEvent.KEY_PRESSED 121 && e.getModifiers() == InputEvent.SHIFT_MASK){ 111 .addKeyEventDispatcher(new KeyEventDispatcher() 112 { 113 public boolean dispatchKeyEvent(KeyEvent e) 114 { 115 if (e.getKeyCode() == KeyEvent.VK_F2 && e.getID() == KeyEvent.KEY_PRESSED 116 && e.getModifiers() == InputEvent.SHIFT_MASK) 117 { 122 118 openPendingIncidents(); 123 119 return true; 124 120 } 125 if(e.getKeyCode() == KeyEvent.VK_F3 && e.getID() == KeyEvent.KEY_PRESSED 126 && e.getModifiers() == InputEvent.SHIFT_MASK){ 121 if (e.getKeyCode() == KeyEvent.VK_F3 && e.getID() == KeyEvent.KEY_PRESSED 122 && e.getModifiers() == InputEvent.SHIFT_MASK) 123 { 127 124 openAssignedIncidents(); 128 125 return true; 129 126 } 130 if(e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED 131 && e.getModifiers() == InputEvent.SHIFT_MASK){ 127 if (e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED 128 && e.getModifiers() == InputEvent.SHIFT_MASK) 129 { 132 130 openUnitStatus(); 133 131 return true; 134 132 } 135 if(e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED){ 133 if (e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED) 134 { 136 135 cyclePowerlineUI(); 137 136 return true; 138 137 } 139 if(e.getKeyCode() == KeyEvent.VK_F5 && e.getID() == KeyEvent.KEY_PRESSED){ 138 if (e.getKeyCode() == KeyEvent.VK_F5 && e.getID() == KeyEvent.KEY_PRESSED) 139 { 140 140 openPowerlineUI(); 141 141 return true; 142 142 } 143 if(e.getKeyCode() == KeyEvent.VK_F9 && e.getID() == KeyEvent.KEY_PRESSED){ 143 if (e.getKeyCode() == KeyEvent.VK_F9 && e.getID() == KeyEvent.KEY_PRESSED) 144 { 144 145 openCardfile(); 145 146 return true; 146 147 } 147 if(e.getKeyCode() == KeyEvent.VK_F10 && e.getID() == KeyEvent.KEY_PRESSED){ 148 if (e.getKeyCode() == KeyEvent.VK_F10 && e.getID() == KeyEvent.KEY_PRESSED) 149 { 148 150 putRCARDinPL(); 149 151 return true; … … 152 154 } 153 155 }); 154 155 handleUpdateTimes(); 156 } 157 158 public WindowListener createWindowListener(){ 159 return new WindowListener(){ 160 public void windowActivated(WindowEvent e) { 156 157 launchUpdateTimers(); 158 } 159 160 public WindowListener createWindowListener() 161 { 162 return new WindowListener() 163 { 164 public void windowActivated(WindowEvent e) 165 { 161 166 closeDropDownMenus(); 162 167 } 163 public void windowClosed(WindowEvent e) { 168 169 public void windowClosed(WindowEvent e) 170 { 164 171 closeDropDownMenus(); 165 172 } 166 public void windowClosing(WindowEvent e) { 173 174 public void windowClosing(WindowEvent e) 175 { 167 176 closeDropDownMenus(); 168 177 } 169 public void windowDeactivated(WindowEvent e) {} 170 public void windowDeiconified(WindowEvent e) {} 171 public void windowIconified(WindowEvent e) { 178 179 public void windowDeactivated(WindowEvent e) 180 { 181 } 182 183 public void windowDeiconified(WindowEvent e) 184 { 185 } 186 187 public void windowIconified(WindowEvent e) 188 { 172 189 closeDropDownMenus(); 173 190 } 174 public void windowOpened(WindowEvent e) {} 191 192 public void windowOpened(WindowEvent e) 193 { 194 } 175 195 }; 176 196 } 177 178 public static void openActivityLogViewer(){ activityLogViewer.open(); } 179 public static void closeActivityLogViewer(){ activityLogViewer.close(); } 180 181 public static void openAssignedIncidents(){ assignedIncidents.open(); } 182 public static void closeAssignedIncidents(){ assignedIncidents.close(); } 183 197 198 public static void openActivityLogViewer() 199 { 200 activityLogViewer.open(); 201 } 202 203 public static void closeActivityLogViewer() 204 { 205 activityLogViewer.close(); 206 } 207 208 public static void openAssignedIncidents() 209 { 210 assignedIncidents.open(); 211 } 212 213 public static void closeAssignedIncidents() 214 { 215 assignedIncidents.close(); 216 } 217 184 218 //public static void openBOLOEntry(){ boloEntry.open(); } 185 219 //public static void closeBOLOEntry(){ boloEntry.close(); } 186 187 public static void openCADMenu(){ cadMenu.open(); } 188 public static void closeCADMenu(){ cadMenu.close(); } 189 190 public static void openCardfile(){ cardfile.open(); } 191 public static void closeCardfile(){ cardfile.close(); } 192 193 public static void openIncidentEditor(){ incidentEditor.open(); } 194 public static void closeIncidentEditor(){ incidentEditor.close(); } 195 public static void refreshIncidentEditor(){ incidentEditor.refreshInformation(); } 196 197 public static void openIncidentInfo(int incidentId){ incidentInfo.open(incidentId); } 198 public static void closeIncidentInfo(){ incidentInfo.close(); } 199 220 public static void openCADMenu() 221 { 222 cadMenu.open(); 223 } 224 225 public static void closeCADMenu() 226 { 227 cadMenu.close(); 228 } 229 230 public static void openCardfile() 231 { 232 cardfile.open(); 233 } 234 235 public static void closeCardfile() 236 { 237 cardfile.close(); 238 } 239 240 public static void openIncidentEditor() 241 { 242 incidentEditor.open(); 243 } 244 245 public static void closeIncidentEditor() 246 { 247 incidentEditor.close(); 248 } 249 250 public static void refreshIncidentEditor() 251 { 252 incidentEditor.refreshInformation(); 253 } 254 255 public static void openIncidentInfo(int incidentId) 256 { 257 incidentInfo.open(incidentId); 258 } 259 260 public static void closeIncidentInfo() 261 { 262 incidentInfo.close(); 263 } 264 200 265 //public static void openIncidentSupplementPersonForm(){ incidentSupplementPersonForm.open(); } 201 266 //public static void closeIncidentSupplementPersonForm(){ incidentSupplementPersonForm.close(); } 202 203 public static void openIncidentViewer(int incidentId){ incidentViewer.open(incidentId); } 204 public static void closeIncidentViewer(){ incidentViewer.close(); } 205 206 public static void openPendingIncidents(){ pendingIncidents.open(); } 207 public static void closePendingIncidents(){ pendingIncidents.close(); } 208 209 public static void openPowerlineUI(){ 210 if(!powerlineUI1.isVisible()){ 267 //JD public static void openIncidentViewer(int incidentId){ incidentViewer.open(incidentId); } 268 public static void openIncidentViewer(int incidentId) 269 { 270 if (incidentViewMap.containsKey(new Integer(incidentId))) 271 { 272 // if incident viewer already open for this incident ... 273 // make it visible 274 incidentViewMap.get(new Integer(incidentId)).setVisible(true); 275 } 276 else // there's no viewer open for this incident, so create it 277 { 278 // Just pass the incident ID to the constructor, not open() 279 IncidentViewer currIV = new IncidentViewer(incidentId); 280 currIV.open(); 281 // Don't put the item in the map until AFTER we've opened it, 282 // to avoid the possibility that the refresh timer happens to fire 283 // before we've opened the viewer. 284 incidentViewMap.put(new Integer(incidentId), currIV); 285 // Doesn't seem necessary, as this viewer has no drop down menus 286 // currIV.addWindowListener(createWindowListener()); 287 } 288 } 289 290 // JD Seems obsolete, never used. 291 // public static void closeIncidentViewer() 292 // { 293 // incidentViewer.close(); 294 // } 295 public static void openPendingIncidents() 296 { 297 pendingIncidents.open(); 298 } 299 300 public static void closePendingIncidents() 301 { 302 pendingIncidents.close(); 303 } 304 305 public static void openPowerlineUI() 306 { 307 if (!powerlineUI1.isVisible()) 308 { 211 309 powerlineUI1.open(); 212 }else if(!powerlineUI2.isVisible()){ 310 } 311 else if (!powerlineUI2.isVisible()) 312 { 213 313 powerlineUI2.open(); 214 }else if(!powerlineUI3.isVisible()){ 314 } 315 else if (!powerlineUI3.isVisible()) 316 { 215 317 powerlineUI3.open(); 216 }else if(!powerlineUI4.isVisible()){ 318 } 319 else if (!powerlineUI4.isVisible()) 320 { 217 321 powerlineUI4.open(); 218 }else if(!powerlineUI5.isVisible()){ 322 } 323 else if (!powerlineUI5.isVisible()) 324 { 219 325 powerlineUI5.open(); 220 } 221 } 222 223 public static void cyclePowerlineUI(){ 224 if(currPowerlineFocus == 1){ 326 } 327 } 328 329 public static void cyclePowerlineUI() 330 { 331 if (currPowerlineFocus == 1) 332 { 225 333 currPowerlineFocus = 2; 226 334 powerlineUI1.setVisible(true); … … 228 336 powerlineUI1.clearText(); 229 337 } 230 else if(currPowerlineFocus == 2){ 338 else if (currPowerlineFocus == 2) 339 { 231 340 currPowerlineFocus = 3; 232 341 powerlineUI2.setVisible(true); … … 234 343 powerlineUI2.clearText(); 235 344 } 236 else if(currPowerlineFocus == 3){ 345 else if (currPowerlineFocus == 3) 346 { 237 347 currPowerlineFocus = 4; 238 348 powerlineUI3.setVisible(true); … … 240 350 powerlineUI3.clearText(); 241 351 } 242 else if(currPowerlineFocus == 4){ 352 else if (currPowerlineFocus == 4) 353 { 243 354 currPowerlineFocus = 5; 244 355 powerlineUI4.setVisible(true); … … 246 357 powerlineUI4.clearText(); 247 358 } 248 else if(currPowerlineFocus == 5){ 359 else if (currPowerlineFocus == 5) 360 { 249 361 currPowerlineFocus = 1; 250 362 powerlineUI5.setVisible(true); … … 253 365 } 254 366 } 255 256 public static void putRCARDinPL(){ 257 if(powerlineUI2.hasFocus()){ 367 368 public static void putRCARDinPL() 369 { 370 if (powerlineUI2.hasFocus()) 371 { 258 372 powerlineUI2.putRCARD(); 259 373 } 260 else if(powerlineUI3.hasFocus()){ 374 else if (powerlineUI3.hasFocus()) 375 { 261 376 powerlineUI3.putRCARD(); 262 377 } 263 else if(powerlineUI4.hasFocus()){ 378 else if (powerlineUI4.hasFocus()) 379 { 264 380 powerlineUI4.putRCARD(); 265 381 } 266 else if(powerlineUI5.hasFocus()){ 382 else if (powerlineUI5.hasFocus()) 383 { 267 384 powerlineUI5.putRCARD(); 268 385 } 269 else{ 386 else 387 { 270 388 powerlineUI1.setVisible(true); 271 389 powerlineUI1.putRCARD(); 272 390 } 273 391 } 274 392 275 393 //public static void openRotationServiceRequest(){ rotationServiceRequest.open(); } 276 394 //public static void closeRotationServiceRequest(){ rotationServiceRequest.close(); } 277 278 public static void openSearch(){ search.open(); } 279 public static void closeSearch(){ search.close(); } 280 281 public static void openUnitStatus(){ unitStatus.open(); } 282 public static void closeUnitStatus(){ unitStatus.close(); } 283 395 public static void openSearch() 396 { 397 search.open(); 398 } 399 400 public static void closeSearch() 401 { 402 search.close(); 403 } 404 405 public static void openUnitStatus() 406 { 407 unitStatus.open(); 408 } 409 410 public static void closeUnitStatus() 411 { 412 unitStatus.close(); 413 } 414 284 415 //public static void openVehicleInformationEntry(){ vehicleInformationEntry.open(); } 285 416 //public static void closeVehicleInformationEntry(){ vehicleInformationEntry.close(); } 286 287 public static void createPowerlineSearch(String search){417 public static void createPowerlineSearch(String search) 418 { 288 419 new PowerlineSearch(search); 289 420 } 290 291 public static void closeDropDownMenus(){ 421 422 public static void closeDropDownMenus() 423 { 292 424 cadMenu.closeMoreMenu(); 293 425 cadMenu.closeToolMenu(); … … 297 429 pendingIncidents.closeDropDownMenu(); 298 430 } 299 300 public static void refreshScreens(){ 431 432 public static void refreshScreens() 433 { 301 434 assignedIncidents.refreshTable(); 302 435 unitStatus.refreshTable(); 303 436 pendingIncidents.refreshTable(); 304 437 } 305 306 public static void setUserName(String username){ 438 439 public static void setUserName(String username) 440 { 307 441 cadMenu.setName(username); 308 442 } 309 443 public static String getUserName() 444 { 445 return cadMenu.getName(); 446 } 447 310 448 /** 311 449 * This method calls CADMenu's and UnitStatus's update time method. 312 450 */ 313 public static void handleUpdateTimes(){ 314 Timer timer = new Timer(ONE_SECOND, new ActionListener(){ 315 public void actionPerformed(ActionEvent e) { 451 public static void launchUpdateTimers() 452 { 453 Timer timer = new Timer(ONE_SECOND, new ActionListener() 454 { 455 public void actionPerformed(ActionEvent e) 456 { 316 457 refreshScreens(); 317 458 cadMenu.handleUpdateTime(); 318 unitStatus.handleUpdateTime(); 459 // Don't need this? Because refreshScreens already does it JD 460 //unitStatus.handleUpdateTime(); 319 461 } 320 462 }); 321 463 timer.start(); 322 } 323 464 465 //JD refresh the info in all the incident viewers 466 Timer timer2 = new Timer(FIVE_SECONDS, new ActionListener() 467 { 468 public void actionPerformed(ActionEvent e) 469 { 470 // for each incident viewer that we've created 471 for (Integer key : incidentViewMap.keySet()) 472 { 473 // Fetch the viewer 474 IncidentViewer viewer = incidentViewMap.get(key); 475 // is the viewer visible? 476 if (viewer.isVisible()) 477 { 478 // refresh the comments 479 viewer.refreshCommentsNotesTable(); 480 } 481 } 482 } 483 }); 484 timer2.start(); 485 } 486 324 487 /** 325 * Removes drag and drop/button clicking in unitStatus panel if bool is false.326 * This method should only be called from Login.java488 * Removes drag and drop/button clicking in unitStatus panel if bool is 489 * false. This method should only be called from Login.java 327 490 */ 328 public static void setDispatcherAuthority(boolean bool){ 329 if (!bool){ 491 public static void setDispatcherAuthority(boolean bool) 492 { 493 if (!bool) 494 { 330 495 unitStatus.removeDispatcherAuthority(); 331 496 cadMenu.removeDispatcherStatus();
Note: See TracChangeset
for help on using the changeset viewer.
