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

Revision 3, 12.5 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files - cadclientgui

Line 
1package tmcsim.client.cadclientgui.screens;
2
3import javax.swing.InputMap;
4import javax.swing.JComponent;
5import javax.swing.Timer;
6import javax.swing.table.DefaultTableModel;
7
8import tmcsim.cadsimulator.Coordinator;
9import tmcsim.client.cadclientgui.data.CADData;
10import tmcsim.client.cadclientgui.data.Unit;
11import tmcsim.interfaces.CoordinatorInterface;
12
13import java.awt.KeyEventDispatcher;
14import java.awt.KeyboardFocusManager;
15import java.awt.event.ActionEvent;
16import java.awt.event.ActionListener;
17import java.awt.event.InputEvent;
18import java.awt.event.KeyEvent;
19import java.awt.event.WindowEvent;
20import java.awt.event.WindowListener;
21import java.rmi.RemoteException;
22import java.util.Vector;
23
24/**
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 *
28 * @author Stuart
29 */
30
31public class ScreenManager {
32   
33    private final static int ONE_SECOND = 1000;
34   
35    private static ActivityLogViewer activityLogViewer;
36    private static AssignedIncidents assignedIncidents;
37    //private static BOLOEntry boloEntry;
38    private static CADMenu cadMenu;
39    private static Cardfile cardfile;
40    private static IncidentEditor incidentEditor;
41    private static IncidentInfo incidentInfo;
42    //private static IncidentSupplementPersonForm incidentSupplementPersonForm;
43    private static IncidentViewer incidentViewer;
44    private static Login login;
45    private static PendingIncidents pendingIncidents;
46    private static PowerlineUI powerlineUI1;
47    private static PowerlineUI powerlineUI2;
48    private static PowerlineUI powerlineUI3;
49    private static PowerlineUI powerlineUI4;
50    private static PowerlineUI powerlineUI5;
51    private static int currPowerlineFocus = 1;
52    //private static RotationServiceRequest rotationServiceRequest;
53    private static Search search;
54    private static UnitStatus unitStatus;
55    //private static VehicleInformationEntry vehicleInformationEntry;
56   
57    //Reference to the Coordinator to use RMI methods
58    protected static CoordinatorInterface theCoordinator;
59   
60    public ScreenManager(CoordinatorInterface theCoor){
61        theCoordinator = theCoor;
62        activityLogViewer = new ActivityLogViewer();
63       
64        assignedIncidents = new AssignedIncidents();
65        assignedIncidents.addWindowListener(createWindowListener());
66
67        //boloEntry = new BOLOEntry();
68        //boloEntry.addWindowListener(createWindowListener());
69       
70        cadMenu = new CADMenu();
71        cadMenu.addWindowListener(createWindowListener());
72       
73        cardfile = new Cardfile();
74        cardfile.addWindowListener(createWindowListener());
75       
76        incidentEditor = new IncidentEditor();
77        incidentEditor.addWindowListener(createWindowListener());
78       
79        incidentInfo = new IncidentInfo();
80        incidentInfo.addWindowListener(createWindowListener());
81       
82        //incidentSupplementPersonForm = new IncidentSupplementPersonForm();
83        //incidentSupplementPersonForm.addWindowListener(createWindowListener());
84       
85        incidentViewer = new IncidentViewer();
86        incidentViewer.addWindowListener(createWindowListener());
87       
88        pendingIncidents = new PendingIncidents();
89        pendingIncidents.addWindowListener(createWindowListener());
90
91        powerlineUI1 = new PowerlineUI(false, 1);
92        powerlineUI1.addWindowListener(createWindowListener());
93       
94        powerlineUI2 = new PowerlineUI(false, 2);
95        powerlineUI2.addWindowListener(createWindowListener());
96       
97        powerlineUI3 = new PowerlineUI(false, 3);
98        powerlineUI3.addWindowListener(createWindowListener());
99       
100        powerlineUI4 = new PowerlineUI(false, 4);
101        powerlineUI4.addWindowListener(createWindowListener());
102       
103        powerlineUI5 = new PowerlineUI(false, 5);
104        powerlineUI5.addWindowListener(createWindowListener());
105       
106        //rotationServiceRequest = new RotationServiceRequest();
107        //rotationServiceRequest.addWindowListener(createWindowListener());
108       
109        search = new Search();
110        search.addWindowListener(createWindowListener());
111        unitStatus = new UnitStatus();
112        unitStatus.addWindowListener(createWindowListener());
113       
114        //vehicleInformationEntry = new VehicleInformationEntry();
115        //vehicleInformationEntry.addWindowListener(createWindowListener());
116       
117        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){
122                    openPendingIncidents();
123                    return true;
124                }
125                if(e.getKeyCode() == KeyEvent.VK_F3 && e.getID() == KeyEvent.KEY_PRESSED
126                        && e.getModifiers() == InputEvent.SHIFT_MASK){
127                    openAssignedIncidents();
128                    return true;
129                }
130                if(e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED
131                        && e.getModifiers() == InputEvent.SHIFT_MASK){
132                    openUnitStatus();
133                    return true;
134                }
135                if(e.getKeyCode() == KeyEvent.VK_F4 && e.getID() == KeyEvent.KEY_PRESSED){
136                    cyclePowerlineUI();
137                    return true;
138                }
139                if(e.getKeyCode() == KeyEvent.VK_F5 && e.getID() == KeyEvent.KEY_PRESSED){
140                    openPowerlineUI();
141                    return true;
142                }
143                if(e.getKeyCode() == KeyEvent.VK_F9 && e.getID() == KeyEvent.KEY_PRESSED){
144                    openCardfile();
145                    return true;
146                }
147                if(e.getKeyCode() == KeyEvent.VK_F10 && e.getID() == KeyEvent.KEY_PRESSED){
148                    putRCARDinPL();
149                    return true;
150                }
151                return false;
152            }
153        });
154       
155        handleUpdateTimes();
156    }
157   
158    public WindowListener createWindowListener(){
159        return new WindowListener(){
160            public void windowActivated(WindowEvent e) {
161                closeDropDownMenus();
162            }
163            public void windowClosed(WindowEvent e) {
164                closeDropDownMenus();
165            }
166            public void windowClosing(WindowEvent e) {
167                closeDropDownMenus();
168            }
169            public void windowDeactivated(WindowEvent e) {}
170            public void windowDeiconified(WindowEvent e) {}
171            public void windowIconified(WindowEvent e) {
172                closeDropDownMenus();
173            }
174            public void windowOpened(WindowEvent e) {}
175        };
176    }
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   
184    //public static void openBOLOEntry(){ boloEntry.open(); }
185    //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   
200    //public static void openIncidentSupplementPersonForm(){ incidentSupplementPersonForm.open(); }
201    //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()){
211            powerlineUI1.open();
212        }else if(!powerlineUI2.isVisible()){
213            powerlineUI2.open();
214        }else if(!powerlineUI3.isVisible()){
215            powerlineUI3.open();
216        }else if(!powerlineUI4.isVisible()){
217            powerlineUI4.open();
218        }else if(!powerlineUI5.isVisible()){
219            powerlineUI5.open();
220        }   
221    }
222   
223    public static void cyclePowerlineUI(){
224        if(currPowerlineFocus == 1){
225            currPowerlineFocus = 2;
226            powerlineUI1.setVisible(true);
227            powerlineUI1.requestFocus();
228            powerlineUI1.clearText();
229        }
230        else if(currPowerlineFocus == 2){
231            currPowerlineFocus = 3;
232            powerlineUI2.setVisible(true);
233            powerlineUI2.requestFocus();
234            powerlineUI2.clearText();
235        }
236        else if(currPowerlineFocus == 3){
237            currPowerlineFocus = 4;
238            powerlineUI3.setVisible(true);
239            powerlineUI3.requestFocus();
240            powerlineUI3.clearText();
241        }
242        else if(currPowerlineFocus == 4){
243            currPowerlineFocus = 5;
244            powerlineUI4.setVisible(true);
245            powerlineUI4.requestFocus();
246            powerlineUI4.clearText();
247        }
248        else if(currPowerlineFocus == 5){
249            currPowerlineFocus = 1;
250            powerlineUI5.setVisible(true);
251            powerlineUI5.requestFocus();
252            powerlineUI5.clearText();
253        }
254    }
255   
256    public static void putRCARDinPL(){
257        if(powerlineUI2.hasFocus()){
258            powerlineUI2.putRCARD();
259        }
260        else if(powerlineUI3.hasFocus()){
261            powerlineUI3.putRCARD();
262        }
263        else if(powerlineUI4.hasFocus()){
264            powerlineUI4.putRCARD();
265        }
266        else if(powerlineUI5.hasFocus()){
267            powerlineUI5.putRCARD();
268        }
269        else{
270            powerlineUI1.setVisible(true);
271            powerlineUI1.putRCARD();
272        }
273    }
274   
275    //public static void openRotationServiceRequest(){ rotationServiceRequest.open(); }
276    //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   
284    //public static void openVehicleInformationEntry(){ vehicleInformationEntry.open(); }
285    //public static void closeVehicleInformationEntry(){ vehicleInformationEntry.close(); }
286   
287    public static void createPowerlineSearch(String search){
288        new PowerlineSearch(search);
289    }
290   
291    public static void closeDropDownMenus(){
292        cadMenu.closeMoreMenu();
293        cadMenu.closeToolMenu();
294        assignedIncidents.closeDropDownMenu();
295        unitStatus.closeDropDownMenu();
296        unitStatus.closeDropDownWithAssignedIncMenu();
297        pendingIncidents.closeDropDownMenu();
298    }
299   
300    public static void refreshScreens(){
301        assignedIncidents.refreshTable();
302        unitStatus.refreshTable();
303        pendingIncidents.refreshTable();
304    }
305   
306    public static void setUserName(String username){
307        cadMenu.setName(username);
308    }
309   
310    /**
311     * This method calls CADMenu's and UnitStatus's update time method.
312     */
313    public static void handleUpdateTimes(){
314        Timer timer = new Timer(ONE_SECOND, new ActionListener(){
315            public void actionPerformed(ActionEvent e) {
316                refreshScreens();
317                cadMenu.handleUpdateTime();
318                unitStatus.handleUpdateTime();
319            }
320        });
321        timer.start();
322    }
323   
324    /**
325     * Removes drag and drop/button clicking in unitStatus panel if bool is false.
326     * This method should only be called from Login.java
327     */
328    public static void setDispatcherAuthority(boolean bool){
329        if (!bool){
330            unitStatus.removeDispatcherAuthority();
331            cadMenu.removeDispatcherStatus();
332        }
333    }
334}
Note: See TracBrowser for help on using the repository browser.