source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/screens/ScreenManager.java @ 59

Revision 59, 15.0 KB checked in by jdalbey, 9 years ago (diff)

Merge CAD Client updates for multiple incident view windows.

Line 
1package tmcsim.client.cadclientgui.screens;
2
3import java.awt.KeyEventDispatcher;
4import java.awt.KeyboardFocusManager;
5import java.awt.event.ActionEvent;
6import java.awt.event.ActionListener;
7import java.awt.event.InputEvent;
8import java.awt.event.KeyEvent;
9import java.awt.event.WindowEvent;
10import java.awt.event.WindowListener;
11import java.util.HashMap;
12import javax.swing.Timer;
13import tmcsim.interfaces.CoordinatorInterface;
14
15/**
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 *
21 * @author Stuart
22 */
23public class ScreenManager
24{
25    private final static int ONE_SECOND = 1000;
26    private final static int FIVE_SECONDS = 5000;
27    private static ActivityLogViewer activityLogViewer;
28    private static AssignedIncidents assignedIncidents;
29    //private static BOLOEntry boloEntry;
30    private static CADMenu cadMenu;
31    private static Cardfile cardfile;
32    private static IncidentEditor incidentEditor;
33    private static IncidentInfo incidentInfo;
34    //private static IncidentSupplementPersonForm incidentSupplementPersonForm;
35    private static HashMap<Integer, IncidentViewer> incidentViewMap = new HashMap<Integer, IncidentViewer>(); //JD
36    private static Login login;
37    private static PendingIncidents pendingIncidents;
38    private static PowerlineUI powerlineUI1;
39    private static PowerlineUI powerlineUI2;
40    private static PowerlineUI powerlineUI3;
41    private static PowerlineUI powerlineUI4;
42    private static PowerlineUI powerlineUI5;
43    private static int currPowerlineFocus = 1;
44    //private static RotationServiceRequest rotationServiceRequest;
45    private static Search search;
46    private static UnitStatus unitStatus;
47    //private static VehicleInformationEntry vehicleInformationEntry;
48    //Reference to the Coordinator to use RMI methods
49    protected static CoordinatorInterface theCoordinator;
50
51    private String username; // The login name entered by the trainee
52
53    public ScreenManager(CoordinatorInterface theCoor)
54    {
55        theCoordinator = theCoor;
56        activityLogViewer = new ActivityLogViewer();
57
58        assignedIncidents = new AssignedIncidents();
59        assignedIncidents.addWindowListener(createWindowListener());
60
61        //boloEntry = new BOLOEntry();
62        //boloEntry.addWindowListener(createWindowListener());
63
64        cadMenu = new CADMenu();
65        cadMenu.addWindowListener(createWindowListener());
66
67        cardfile = new Cardfile();
68        cardfile.addWindowListener(createWindowListener());
69
70        incidentEditor = new IncidentEditor();
71        incidentEditor.addWindowListener(createWindowListener());
72
73        incidentInfo = new IncidentInfo();
74        incidentInfo.addWindowListener(createWindowListener());
75
76        //incidentSupplementPersonForm = new IncidentSupplementPersonForm();
77        //incidentSupplementPersonForm.addWindowListener(createWindowListener());
78
79        incidentViewMap = new HashMap<Integer, IncidentViewer>(); //JD
80
81        pendingIncidents = new PendingIncidents();
82        pendingIncidents.addWindowListener(createWindowListener());
83
84        powerlineUI1 = new PowerlineUI(false, 1);
85        powerlineUI1.addWindowListener(createWindowListener());
86
87        powerlineUI2 = new PowerlineUI(false, 2);
88        powerlineUI2.addWindowListener(createWindowListener());
89
90        powerlineUI3 = new PowerlineUI(false, 3);
91        powerlineUI3.addWindowListener(createWindowListener());
92
93        powerlineUI4 = new PowerlineUI(false, 4);
94        powerlineUI4.addWindowListener(createWindowListener());
95
96        powerlineUI5 = new PowerlineUI(false, 5);
97        powerlineUI5.addWindowListener(createWindowListener());
98
99        //rotationServiceRequest = new RotationServiceRequest();
100        //rotationServiceRequest.addWindowListener(createWindowListener());
101
102        search = new Search();
103        search.addWindowListener(createWindowListener());
104        unitStatus = new UnitStatus();
105        unitStatus.addWindowListener(createWindowListener());
106
107        //vehicleInformationEntry = new VehicleInformationEntry();
108        //vehicleInformationEntry.addWindowListener(createWindowListener());
109
110        KeyboardFocusManager.getCurrentKeyboardFocusManager()
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                {
118                    openPendingIncidents();
119                    return true;
120                }
121                if (e.getKeyCode() == KeyEvent.VK_F3 && e.getID() == KeyEvent.KEY_PRESSED
122                        && e.getModifiers() == InputEvent.SHIFT_MASK)
123                {
124                    openAssignedIncidents();
125                    return true;
126                }
127                if (e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED
128                        && e.getModifiers() == InputEvent.SHIFT_MASK)
129                {
130                    openUnitStatus();
131                    return true;
132                }
133                if (e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED)
134                {
135                    cyclePowerlineUI();
136                    return true;
137                }
138                if (e.getKeyCode() == KeyEvent.VK_F5 && e.getID() == KeyEvent.KEY_PRESSED)
139                {
140                    openPowerlineUI();
141                    return true;
142                }
143                if (e.getKeyCode() == KeyEvent.VK_F9 && e.getID() == KeyEvent.KEY_PRESSED)
144                {
145                    openCardfile();
146                    return true;
147                }
148                if (e.getKeyCode() == KeyEvent.VK_F10 && e.getID() == KeyEvent.KEY_PRESSED)
149                {
150                    putRCARDinPL();
151                    return true;
152                }
153                return false;
154            }
155        });
156
157        launchUpdateTimers();
158    }
159
160    public WindowListener createWindowListener()
161    {
162        return new WindowListener()
163        {
164            public void windowActivated(WindowEvent e)
165            {
166                closeDropDownMenus();
167            }
168
169            public void windowClosed(WindowEvent e)
170            {
171                closeDropDownMenus();
172            }
173
174            public void windowClosing(WindowEvent e)
175            {
176                closeDropDownMenus();
177            }
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            {
189                closeDropDownMenus();
190            }
191
192            public void windowOpened(WindowEvent e)
193            {
194            }
195        };
196    }
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
218    //public static void openBOLOEntry(){ boloEntry.open(); }
219    //public static void closeBOLOEntry(){ boloEntry.close(); }
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
265    //public static void openIncidentSupplementPersonForm(){ incidentSupplementPersonForm.open(); }
266    //public static void closeIncidentSupplementPersonForm(){ incidentSupplementPersonForm.close(); }
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        {
309            powerlineUI1.open();
310        }
311        else if (!powerlineUI2.isVisible())
312        {
313            powerlineUI2.open();
314        }
315        else if (!powerlineUI3.isVisible())
316        {
317            powerlineUI3.open();
318        }
319        else if (!powerlineUI4.isVisible())
320        {
321            powerlineUI4.open();
322        }
323        else if (!powerlineUI5.isVisible())
324        {
325            powerlineUI5.open();
326        }
327    }
328
329    public static void cyclePowerlineUI()
330    {
331        if (currPowerlineFocus == 1)
332        {
333            currPowerlineFocus = 2;
334            powerlineUI1.setVisible(true);
335            powerlineUI1.requestFocus();
336            powerlineUI1.clearText();
337        }
338        else if (currPowerlineFocus == 2)
339        {
340            currPowerlineFocus = 3;
341            powerlineUI2.setVisible(true);
342            powerlineUI2.requestFocus();
343            powerlineUI2.clearText();
344        }
345        else if (currPowerlineFocus == 3)
346        {
347            currPowerlineFocus = 4;
348            powerlineUI3.setVisible(true);
349            powerlineUI3.requestFocus();
350            powerlineUI3.clearText();
351        }
352        else if (currPowerlineFocus == 4)
353        {
354            currPowerlineFocus = 5;
355            powerlineUI4.setVisible(true);
356            powerlineUI4.requestFocus();
357            powerlineUI4.clearText();
358        }
359        else if (currPowerlineFocus == 5)
360        {
361            currPowerlineFocus = 1;
362            powerlineUI5.setVisible(true);
363            powerlineUI5.requestFocus();
364            powerlineUI5.clearText();
365        }
366    }
367
368    public static void putRCARDinPL()
369    {
370        if (powerlineUI2.hasFocus())
371        {
372            powerlineUI2.putRCARD();
373        }
374        else if (powerlineUI3.hasFocus())
375        {
376            powerlineUI3.putRCARD();
377        }
378        else if (powerlineUI4.hasFocus())
379        {
380            powerlineUI4.putRCARD();
381        }
382        else if (powerlineUI5.hasFocus())
383        {
384            powerlineUI5.putRCARD();
385        }
386        else
387        {
388            powerlineUI1.setVisible(true);
389            powerlineUI1.putRCARD();
390        }
391    }
392
393    //public static void openRotationServiceRequest(){ rotationServiceRequest.open(); }
394    //public static void closeRotationServiceRequest(){ rotationServiceRequest.close(); }
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
415    //public static void openVehicleInformationEntry(){ vehicleInformationEntry.open(); }
416    //public static void closeVehicleInformationEntry(){ vehicleInformationEntry.close(); }
417    public static void createPowerlineSearch(String search)
418    {
419        new PowerlineSearch(search);
420    }
421
422    public static void closeDropDownMenus()
423    {
424        cadMenu.closeMoreMenu();
425        cadMenu.closeToolMenu();
426        assignedIncidents.closeDropDownMenu();
427        unitStatus.closeDropDownMenu();
428        unitStatus.closeDropDownWithAssignedIncMenu();
429        pendingIncidents.closeDropDownMenu();
430    }
431
432    public static void refreshScreens()
433    {
434        assignedIncidents.refreshTable();
435        unitStatus.refreshTable();
436        pendingIncidents.refreshTable();
437    }
438
439    public static void setUserName(String username)
440    {
441        cadMenu.setName(username);
442    }
443    public static String getUserName()
444    {
445        return cadMenu.getName();
446    }
447
448    /**
449     * This method calls CADMenu's and UnitStatus's update time method.
450     */
451    public static void launchUpdateTimers()
452    {
453        Timer timer = new Timer(ONE_SECOND, new ActionListener()
454        {
455            public void actionPerformed(ActionEvent e)
456            {
457                refreshScreens();
458                cadMenu.handleUpdateTime();
459                // Don't need this? Because refreshScreens already does it JD
460                //unitStatus.handleUpdateTime();
461            }
462        });
463        timer.start();
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
487    /**
488     * Removes drag and drop/button clicking in unitStatus panel if bool is
489     * false. This method should only be called from Login.java
490     */
491    public static void setDispatcherAuthority(boolean bool)
492    {
493        if (!bool)
494        {
495            unitStatus.removeDispatcherAuthority();
496            cadMenu.removeDispatcherStatus();
497        }
498    }
499}
Note: See TracBrowser for help on using the repository browser.