Ignore:
Timestamp:
03/15/2017 10:20:21 AM (9 years ago)
Author:
jdalbey
Message:

Merge CAD Client updates for multiple incident view windows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/cadclientgui/screens/ScreenManager.java

    r3 r59  
    11package 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; 
    122 
    133import java.awt.KeyEventDispatcher; 
     
    199import java.awt.event.WindowEvent; 
    2010import java.awt.event.WindowListener; 
    21 import java.rmi.RemoteException; 
    22 import java.util.Vector; 
     11import java.util.HashMap; 
     12import javax.swing.Timer; 
     13import tmcsim.interfaces.CoordinatorInterface; 
    2314 
    2415/** 
    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 * 
    2821 * @author Stuart 
    2922 */ 
    30  
    31 public class ScreenManager { 
    32      
     23public class ScreenManager 
     24{ 
    3325    private final static int ONE_SECOND = 1000; 
    34      
     26    private final static int FIVE_SECONDS = 5000; 
    3527    private static ActivityLogViewer activityLogViewer; 
    3628    private static AssignedIncidents assignedIncidents; 
     
    4133    private static IncidentInfo incidentInfo; 
    4234    //private static IncidentSupplementPersonForm incidentSupplementPersonForm; 
    43     private static IncidentViewer incidentViewer; 
     35    private static HashMap<Integer, IncidentViewer> incidentViewMap = new HashMap<Integer, IncidentViewer>(); //JD 
    4436    private static Login login; 
    4537    private static PendingIncidents pendingIncidents; 
     
    5446    private static UnitStatus unitStatus; 
    5547    //private static VehicleInformationEntry vehicleInformationEntry; 
    56      
    5748    //Reference to the Coordinator to use RMI methods 
    5849    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    { 
    6155        theCoordinator = theCoor; 
    6256        activityLogViewer = new ActivityLogViewer(); 
    63          
     57 
    6458        assignedIncidents = new AssignedIncidents(); 
    6559        assignedIncidents.addWindowListener(createWindowListener()); 
     
    6761        //boloEntry = new BOLOEntry(); 
    6862        //boloEntry.addWindowListener(createWindowListener()); 
    69          
     63 
    7064        cadMenu = new CADMenu(); 
    7165        cadMenu.addWindowListener(createWindowListener()); 
    72          
     66 
    7367        cardfile = new Cardfile(); 
    7468        cardfile.addWindowListener(createWindowListener()); 
    75          
     69 
    7670        incidentEditor = new IncidentEditor(); 
    7771        incidentEditor.addWindowListener(createWindowListener()); 
    78          
     72 
    7973        incidentInfo = new IncidentInfo(); 
    8074        incidentInfo.addWindowListener(createWindowListener()); 
    81          
     75 
    8276        //incidentSupplementPersonForm = new IncidentSupplementPersonForm(); 
    8377        //incidentSupplementPersonForm.addWindowListener(createWindowListener()); 
    84          
    85         incidentViewer = new IncidentViewer(); 
    86         incidentViewer.addWindowListener(createWindowListener()); 
    87          
     78 
     79        incidentViewMap = new HashMap<Integer, IncidentViewer>(); //JD 
     80 
    8881        pendingIncidents = new PendingIncidents(); 
    8982        pendingIncidents.addWindowListener(createWindowListener()); 
     
    9184        powerlineUI1 = new PowerlineUI(false, 1); 
    9285        powerlineUI1.addWindowListener(createWindowListener()); 
    93          
     86 
    9487        powerlineUI2 = new PowerlineUI(false, 2); 
    9588        powerlineUI2.addWindowListener(createWindowListener()); 
    96          
     89 
    9790        powerlineUI3 = new PowerlineUI(false, 3); 
    9891        powerlineUI3.addWindowListener(createWindowListener()); 
    99          
     92 
    10093        powerlineUI4 = new PowerlineUI(false, 4); 
    10194        powerlineUI4.addWindowListener(createWindowListener()); 
    102          
     95 
    10396        powerlineUI5 = new PowerlineUI(false, 5); 
    10497        powerlineUI5.addWindowListener(createWindowListener()); 
    105          
     98 
    10699        //rotationServiceRequest = new RotationServiceRequest(); 
    107100        //rotationServiceRequest.addWindowListener(createWindowListener()); 
    108          
     101 
    109102        search = new Search(); 
    110103        search.addWindowListener(createWindowListener()); 
    111104        unitStatus = new UnitStatus(); 
    112105        unitStatus.addWindowListener(createWindowListener()); 
    113          
     106 
    114107        //vehicleInformationEntry = new VehicleInformationEntry(); 
    115108        //vehicleInformationEntry.addWindowListener(createWindowListener()); 
    116          
     109 
    117110        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                { 
    122118                    openPendingIncidents(); 
    123119                    return true; 
    124120                } 
    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                { 
    127124                    openAssignedIncidents(); 
    128125                    return true; 
    129126                } 
    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                { 
    132130                    openUnitStatus(); 
    133131                    return true; 
    134132                } 
    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                { 
    136135                    cyclePowerlineUI(); 
    137136                    return true; 
    138137                } 
    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                { 
    140140                    openPowerlineUI(); 
    141141                    return true; 
    142142                } 
    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                { 
    144145                    openCardfile(); 
    145146                    return true; 
    146147                } 
    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                { 
    148150                    putRCARDinPL(); 
    149151                    return true; 
     
    152154            } 
    153155        }); 
    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            { 
    161166                closeDropDownMenus(); 
    162167            } 
    163             public void windowClosed(WindowEvent e) { 
     168 
     169            public void windowClosed(WindowEvent e) 
     170            { 
    164171                closeDropDownMenus(); 
    165172            } 
    166             public void windowClosing(WindowEvent e) { 
     173 
     174            public void windowClosing(WindowEvent e) 
     175            { 
    167176                closeDropDownMenus(); 
    168177            } 
    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            { 
    172189                closeDropDownMenus(); 
    173190            } 
    174             public void windowOpened(WindowEvent e) {} 
     191 
     192            public void windowOpened(WindowEvent e) 
     193            { 
     194            } 
    175195        }; 
    176196    } 
    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 
    184218    //public static void openBOLOEntry(){ boloEntry.open(); } 
    185219    //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 
    200265    //public static void openIncidentSupplementPersonForm(){ incidentSupplementPersonForm.open(); } 
    201266    //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        { 
    211309            powerlineUI1.open(); 
    212         }else if(!powerlineUI2.isVisible()){ 
     310        } 
     311        else if (!powerlineUI2.isVisible()) 
     312        { 
    213313            powerlineUI2.open(); 
    214         }else if(!powerlineUI3.isVisible()){ 
     314        } 
     315        else if (!powerlineUI3.isVisible()) 
     316        { 
    215317            powerlineUI3.open(); 
    216         }else if(!powerlineUI4.isVisible()){ 
     318        } 
     319        else if (!powerlineUI4.isVisible()) 
     320        { 
    217321            powerlineUI4.open(); 
    218         }else if(!powerlineUI5.isVisible()){ 
     322        } 
     323        else if (!powerlineUI5.isVisible()) 
     324        { 
    219325            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        { 
    225333            currPowerlineFocus = 2; 
    226334            powerlineUI1.setVisible(true); 
     
    228336            powerlineUI1.clearText(); 
    229337        } 
    230         else if(currPowerlineFocus == 2){ 
     338        else if (currPowerlineFocus == 2) 
     339        { 
    231340            currPowerlineFocus = 3; 
    232341            powerlineUI2.setVisible(true); 
     
    234343            powerlineUI2.clearText(); 
    235344        } 
    236         else if(currPowerlineFocus == 3){ 
     345        else if (currPowerlineFocus == 3) 
     346        { 
    237347            currPowerlineFocus = 4; 
    238348            powerlineUI3.setVisible(true); 
     
    240350            powerlineUI3.clearText(); 
    241351        } 
    242         else if(currPowerlineFocus == 4){ 
     352        else if (currPowerlineFocus == 4) 
     353        { 
    243354            currPowerlineFocus = 5; 
    244355            powerlineUI4.setVisible(true); 
     
    246357            powerlineUI4.clearText(); 
    247358        } 
    248         else if(currPowerlineFocus == 5){ 
     359        else if (currPowerlineFocus == 5) 
     360        { 
    249361            currPowerlineFocus = 1; 
    250362            powerlineUI5.setVisible(true); 
     
    253365        } 
    254366    } 
    255      
    256     public static void putRCARDinPL(){ 
    257         if(powerlineUI2.hasFocus()){ 
     367 
     368    public static void putRCARDinPL() 
     369    { 
     370        if (powerlineUI2.hasFocus()) 
     371        { 
    258372            powerlineUI2.putRCARD(); 
    259373        } 
    260         else if(powerlineUI3.hasFocus()){ 
     374        else if (powerlineUI3.hasFocus()) 
     375        { 
    261376            powerlineUI3.putRCARD(); 
    262377        } 
    263         else if(powerlineUI4.hasFocus()){ 
     378        else if (powerlineUI4.hasFocus()) 
     379        { 
    264380            powerlineUI4.putRCARD(); 
    265381        } 
    266         else if(powerlineUI5.hasFocus()){ 
     382        else if (powerlineUI5.hasFocus()) 
     383        { 
    267384            powerlineUI5.putRCARD(); 
    268385        } 
    269         else{ 
     386        else 
     387        { 
    270388            powerlineUI1.setVisible(true); 
    271389            powerlineUI1.putRCARD(); 
    272390        } 
    273391    } 
    274      
     392 
    275393    //public static void openRotationServiceRequest(){ rotationServiceRequest.open(); } 
    276394    //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 
    284415    //public static void openVehicleInformationEntry(){ vehicleInformationEntry.open(); } 
    285416    //public static void closeVehicleInformationEntry(){ vehicleInformationEntry.close(); } 
    286      
    287     public static void createPowerlineSearch(String search){ 
     417    public static void createPowerlineSearch(String search) 
     418    { 
    288419        new PowerlineSearch(search); 
    289420    } 
    290      
    291     public static void closeDropDownMenus(){ 
     421 
     422    public static void closeDropDownMenus() 
     423    { 
    292424        cadMenu.closeMoreMenu(); 
    293425        cadMenu.closeToolMenu(); 
     
    297429        pendingIncidents.closeDropDownMenu(); 
    298430    } 
    299      
    300     public static void refreshScreens(){ 
     431 
     432    public static void refreshScreens() 
     433    { 
    301434        assignedIncidents.refreshTable(); 
    302435        unitStatus.refreshTable(); 
    303436        pendingIncidents.refreshTable(); 
    304437    } 
    305      
    306     public static void setUserName(String username){ 
     438 
     439    public static void setUserName(String username) 
     440    { 
    307441        cadMenu.setName(username); 
    308442    } 
    309      
     443    public static String getUserName() 
     444    { 
     445        return cadMenu.getName(); 
     446    } 
     447 
    310448    /** 
    311449     * This method calls CADMenu's and UnitStatus's update time method. 
    312450     */ 
    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            { 
    316457                refreshScreens(); 
    317458                cadMenu.handleUpdateTime(); 
    318                 unitStatus.handleUpdateTime(); 
     459                // Don't need this? Because refreshScreens already does it JD 
     460                //unitStatus.handleUpdateTime(); 
    319461            } 
    320462        }); 
    321463        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 
    324487    /** 
    325      * Removes drag and drop/button clicking in unitStatus panel if bool is false. 
    326      * This method should only be called from Login.java 
     488     * Removes drag and drop/button clicking in unitStatus panel if bool is 
     489     * false. This method should only be called from Login.java 
    327490     */ 
    328     public static void setDispatcherAuthority(boolean bool){ 
    329         if (!bool){ 
     491    public static void setDispatcherAuthority(boolean bool) 
     492    { 
     493        if (!bool) 
     494        { 
    330495            unitStatus.removeDispatcherAuthority(); 
    331496            cadMenu.removeDispatcherStatus(); 
Note: See TracChangeset for help on using the changeset viewer.