Changeset 61 in tmcsimulator for trunk/src/tmcsim


Ignore:
Timestamp:
03/15/2017 02:25:16 PM (9 years ago)
Author:
jdalbey
Message:

CADClock development.

Location:
trunk/src/tmcsim/client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/CADClockDisplay.java

    r57 r61  
    11package tmcsim.client; 
    22 
    3 import java.awt.event.WindowEvent; 
    4 import java.awt.event.WindowListener; 
    53import java.io.FileInputStream; 
    64import java.io.FileOutputStream; 
     
    97import java.rmi.RemoteException; 
    108import java.rmi.server.UnicastRemoteObject; 
     9import java.text.SimpleDateFormat; 
     10import java.util.Date; 
    1111import java.util.Properties; 
    1212import java.util.Vector; 
     13import java.util.concurrent.TimeUnit; 
    1314import java.util.logging.Level; 
    1415import java.util.logging.Logger; 
    1516 
    16 import javax.swing.JFrame; 
    1717import javax.swing.JOptionPane; 
    1818import javax.swing.JWindow; 
     
    2020 
    2121import tmcsim.client.cadclientgui.CADClientGUI; 
    22 import tmcsim.client.cadclientgui.CardfileReader; 
    23 import tmcsim.client.cadclientgui.GUIScriptReader; 
    24 import tmcsim.client.cadclientgui.data.CADData; 
    25 import tmcsim.client.cadclientgui.screens.Login; 
    26 import tmcsim.client.cadclientgui.screens.ScreenManager; 
    27 import tmcsim.common.CADEnums; 
    2822import tmcsim.common.SimulationException; 
    2923import tmcsim.interfaces.CADClientInterface; 
     
    4337 * <code> 
    4438 * -----------------------------------------------------------------------------<br> 
    45  * Host Name     The host name where the CAD Simulator is located.<br> 
    46  * Port Number   The port number that the CAD Simulator is bound on.<br> 
    47  * CAD Position  The integer (>= 0) position for this CAD Client.<br> 
    48  * CAD User ID   The unique user id for this CAD Client.<br> 
    49  * Error File    Filename of error logging file.<br> 
     39 * Host Name The host name where the CAD Simulator is located.<br> 
     40 * Port Number The port number that the CAD Simulator is bound on.<br> 
     41 * CAD Position The integer (>= 0) position for this CAD Client.<br> 
     42 * CAD User ID The unique user id for this CAD Client.<br> 
     43 * Error File Filename of error logging file.<br> 
    5044 * -----------------------------------------------------------------------------<br> 
    5145 * Example File: <br> 
    52  * CADSimulatorHost       = localhost<br> 
     46 * CADSimulatorHost = localhost<br> 
    5347 * CADSimulatorSocketPort = 4444<br> 
    5448 * CADPosition = 1 <br> 
    55  * CADUserID   = A12345<br> 
    56  * ErrorFile   = cad_client_err.txt<br> 
     49 * CADUserID = A12345<br> 
     50 * ErrorFile = cad_client_err.txt<br> 
    5751 * </code> 
    58  *  
     52 * 
    5953 * @author Matthew Cechini (mcechini@calpoly.edu) 
    6054 * @version $Date: 2009/04/17 16:27:47 $ $Revision: 1.8 $ 
    6155 */ 
    62  
    6356public class CADClockDisplay extends UnicastRemoteObject implements 
    64         CADClientInterface { 
    65  
    66     /** Error logger. */ 
     57        CADClientInterface 
     58{ 
     59 
     60    /** 
     61     * Error logger. 
     62     */ 
    6763    private static Logger cadClientLogger = Logger.getLogger("tmcsim.client"); 
    6864 
     
    7066     * Enumeration containing properties name values. See CADClient class 
    7167     * description for more information. 
    72      *  
     68     * 
    7369     * @author Matthew Cechini 
    7470     * @see CADClient 
    7571     */ 
    76     private static enum PROPERTIES { 
     72    private static enum PROPERTIES 
     73    { 
     74 
    7775        CAD_SIM_HOST("CADSimulatorHost"), CAD_SIM_PORT("CADSimulatorSocketPort"), CAD_RMI_PORT( 
    78                 "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID( 
    79                 "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE( 
    80                 "DisplayType"); 
    81  
     76        "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID( 
     77        "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE( 
     78        "DisplayType"); 
    8279        public String name; 
    8380 
    84         private PROPERTIES(String n) { 
     81        private PROPERTIES(String n) 
     82        { 
    8583            name = n; 
    8684        } 
    8785    } 
    88  
    8986    /** 
    9087     * CADClientSocket Object to handle socket communication between the Client 
     
    9289     */ 
    9390    private CADClientSocket theClientSocket; 
    94  
    95     /** Instance of the CADClientModel. */ 
     91    /** 
     92     * Instance of the CADClientModel. 
     93     */ 
    9694    private CADClientModel theClientScreenModel; 
    97  
    98     /** Instance of the CADClockView. */ 
     95    /** 
     96     * Instance of the CADClockView. 
     97     */ 
    9998    private CADClockView theClientScreenView; 
    100  
    10199    /** 
    102100     * Instance of the CADCLientGUI Replaces CADClockView 
    103101     */ 
    104102    private CADClientGUI theClientGUI; 
    105  
    106     /** Properties object for the CADClient class. */ 
     103    /** 
     104     * Properties object for the CADClient class. 
     105     */ 
    107106    private Properties cadClientProp; 
    108  
    109     /** RMI interface for communication with the remote Coordinator. */ 
     107    /** 
     108     * RMI interface for communication with the remote Coordinator. 
     109     */ 
    110110    private static CoordinatorInterface theCoorInt; 
    111  
    112     /** reference to itself to be used for disconnecting from CADSimulator */ 
     111    /** 
     112     * reference to itself to be used for disconnecting from CADSimulator 
     113     */ 
    113114    private CADClientInterface client = this; 
    114  
    115115    private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 
     116 
     117    private String formatInterval(final long l) 
     118    { 
     119        final long hr = TimeUnit.SECONDS.toHours(l); 
     120        final long min = TimeUnit.SECONDS.toMinutes(l - TimeUnit.HOURS.toSeconds(hr)); 
     121        final long sec = TimeUnit.SECONDS.toSeconds(l - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min)); 
     122        return String.format("%02d:%02d:%02d", hr, min, sec); 
     123    } 
    116124     
    117125    /** 
     
    122130     * and userID read in from the properties file. The ClientScreenView is then 
    123131     * created and initialized and set as an observer of the model. 
    124      *  
     132     * 
    125133     * A thread is created with the runnable ClientScreenModel and is started. 
    126134     * When this thread is no longer alive, or the ClientScrenView and 
    127135     * CADClientSocket are closed. The program then exits. 
    128      *  
    129      * @param propertiesFile 
    130      *            File path (absolute or relative) to the properties file 
    131      *            containing configuration data. 
     136     * 
     137     * @param propertiesFile File path (absolute or relative) to the properties 
     138     * file containing configuration data. 
    132139     */ 
    133140    public CADClockDisplay(String propertiesFile) throws SimulationException, 
    134             RemoteException { 
     141            RemoteException 
     142    { 
    135143        if (!verifyProperties(propertiesFile)) 
     144        { 
    136145            System.exit(0); 
     146        } 
    137147 
    138148        connect(cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), 
    139149                cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim()); 
    140150 
    141         // Instantiate the Socket and Model Objects. 
    142         theClientSocket = new CADClientSocket(cadClientProp.getProperty( 
    143                 PROPERTIES.CAD_SIM_HOST.name).trim(), 
    144                 Integer.parseInt(cadClientProp.getProperty( 
    145                         PROPERTIES.CAD_SIM_PORT.name).trim())); 
    146         theClientScreenModel = new CADClientModel(); 
    147         theClientScreenModel.initializeScreen(theClientSocket.getInputStream(), 
    148                 theClientSocket.getOutputStream()); 
    149  
    150         // Register this CAD Client with the Simulation Manager 
    151         theClientScreenModel.register(Integer.parseInt(cadClientProp 
    152                 .getProperty(PROPERTIES.CLIENT_CAD_POS.name)), cadClientProp 
    153                 .getProperty(PROPERTIES.CLIENT_USER_ID.name)); 
    154  
    155151        // Instantiate the CADScreenView and set up the model-view observer 
    156152        // relationship. 
    157         theClientScreenView = new CADClockView(theClientScreenModel); 
    158         theClientScreenModel.addObserver(theClientScreenView); 
     153        theClientScreenView = new CADClockView(); 
    159154        theClientScreenView.setVisible(true); 
     155 
     156        try 
     157        { 
     158            while (true) 
     159            { 
     160                long simtime = theCoorInt.getCurrentSimulationTime(); 
     161                //System.out.println("" + formatInterval(simtime)); 
     162                theClientScreenView.updateTime("" + formatInterval(simtime)); 
     163                Thread.sleep(1000); 
     164            } 
     165        } catch (InterruptedException ex) 
     166        { 
     167            Logger.getLogger(CADClockDisplay.class.getName()).log(Level.SEVERE, null, ex); 
     168        } 
     169 
    160170        // Create the CAD Client thread to run the CADClientModel Object. 
    161         Thread clientThread = new Thread(theClientScreenModel); 
    162         clientThread.start(); 
    163          
    164         // TODO: set up model-view relationship similar to ClientView and 
    165         // ScreenView 
    166         // Can repurpose the old model, but may be better to copy over and 
    167         // modify in parallel 
    168         // This is required to perform powerline commands on the data 
    169 //        theClientGUI = new CADClientGUI(); 
    170  
    171         // Each screen of the UI should have a reference to either it's parent 
    172         // object or the main client 
    173         // This ensures they all have access to each other and the data model 
    174 //        theClientGUI.screen = new ScreenManager(theCoorInt); 
    175 //        theClientGUI.login = new Login(); 
    176 //        theClientGUI.client = this; 
    177  
    178         // setup keyboard settings for CAD Client 
    179 //        if (cadClientProp.getProperty(PROPERTIES.KEYBOARD_TYPE.name).trim() 
    180 //                .equals("CAD")) { 
    181 //            CADEnums.CAD_KEYS.setupCADKeyboard(); 
    182 //        } 
    183 //        // STD 
    184 //        else { 
    185 //            CADEnums.CAD_KEYS.setupStandardKeyboard(); 
    186 //        } 
    187 // 
    188 //        theClientScreenModel.addObserver(theClientScreenView); 
    189 // 
    190 //        // Initialize the display 
    191 //        if (cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name).equals( 
    192 //                "FULL_SCREEN")) { 
    193 // 
    194 //            theClientScreenView.addWindowListener(new WindowListener() { 
    195 //                public void windowClosed(WindowEvent e) { 
    196 //                } 
    197 // 
    198 //                public void windowOpened(WindowEvent e) { 
    199 //                } 
    200 // 
    201 //                public void windowIconified(WindowEvent e) { 
    202 //                } 
    203 // 
    204 //                public void windowDeiconified(WindowEvent e) { 
    205 //                } 
    206 // 
    207 //                public void windowActivated(WindowEvent e) { 
    208 //                } 
    209 // 
    210 //                public void windowDeactivated(WindowEvent e) { 
    211 //                } 
    212 // 
    213 //                public void windowClosing(WindowEvent e) { 
    214 // 
    215 //                    try { 
    216 //                        theClientSocket.closeSocket(); 
    217 //                    } catch (SimulationException se) { 
    218 //                    } 
    219 // 
    220 //                    System.exit(0); 
    221 //                } 
    222 //            }); 
    223 // 
    224 //            theClientScreenView.initWindow(); 
    225 //            theClientScreenView.setVisible(false); 
    226 //        } else { 
    227 //            JFrame cadFrame = new JFrame("CAD Client"); 
    228 //            cadFrame.add(theClientScreenView.initBox()); 
    229 //            cadFrame.setSize(800, 600); 
    230 // 
    231 //            cadFrame.addWindowListener(new WindowListener() { 
    232 //                public void windowClosed(WindowEvent e) { 
    233 //                } 
    234 // 
    235 //                public void windowOpened(WindowEvent e) { 
    236 //                } 
    237 // 
    238 //                public void windowIconified(WindowEvent e) { 
    239 //                } 
    240 // 
    241 //                public void windowDeiconified(WindowEvent e) { 
    242 //                } 
    243 // 
    244 //                public void windowActivated(WindowEvent e) { 
    245 //                } 
    246 // 
    247 //                public void windowDeactivated(WindowEvent e) { 
    248 //                } 
    249 // 
    250 //                public void windowClosing(WindowEvent e) { 
    251 // 
    252 //                    try { 
    253 //                        theClientSocket.closeSocket(); 
    254 //                    } catch (SimulationException se) { 
    255 //                    } 
    256 // 
    257 //                    System.exit(0); 
    258 //                } 
    259 //            }); 
    260 // 
    261 //            cadFrame.setVisible(true); 
    262 //        } 
    263 // 
    264 //        // Create the CAD Client thread to run the CADClientModel Object. 
    265171//        Thread clientThread = new Thread(theClientScreenModel); 
    266172//        clientThread.start(); 
    267173 
     174 
    268175        ensureProperShutdown(); 
    269176    } 
     
    272179     * Connect to the Coordinator's RMI object, and register this object for 
    273180     * callback with the Coordinator. 
    274      *  
    275      * @param hostname 
    276      *            Host name of the CAD Simulator. 
    277      * @param portNumber 
    278      *            Port number of the CAD Simulator RMI communication. 
    279      * @throws SimulationException 
    280      *             if there is an error creating the RMI connection. 
     181     * 
     182     * @param hostname Host name of the CAD Simulator. 
     183     * @param portNumber Port number of the CAD Simulator RMI communication. 
     184     * @throws SimulationException if there is an error creating the RMI 
     185     * connection. 
    281186     */ 
    282187    protected void connect(String hostname, String portNumber) 
    283             throws SimulationException { 
     188            throws SimulationException 
     189    { 
    284190 
    285191        String coorIntURL = ""; 
    286192 
    287         try { 
     193        try 
     194        { 
    288195            coorIntURL = "rmi://" + hostname + ":" + portNumber 
    289196                    + "/coordinator"; 
    290197            theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); 
    291198            theCoorInt.registerForCallback(this); 
    292         } catch (Exception e) { 
     199        } catch (Exception e) 
     200        { 
    293201            throw new SimulationException(SimulationException.CAD_SIM_CONNECT, 
    294202                    e); 
     
    302210     * the properties file. If the user cancels the process of entering these 
    303211     * values, the verification fails. 
    304      *  
    305      * @param propertiesFile 
    306      *            File path (absolute or relative) to the properties file 
    307      *            containing configuration data. 
     212     * 
     213     * @param propertiesFile File path (absolute or relative) to the properties 
     214     * file containing configuration data. 
    308215     * @return True if the properties file is valid, false if not. 
    309      * @throws SimulationException 
    310      *             if there is an exception in verifying the properties file, or 
    311      *             if the user cancels input. 
     216     * @throws SimulationException if there is an exception in verifying the 
     217     * properties file, or if the user cancels input. 
    312218     */ 
    313219    private boolean verifyProperties(String propertiesFile) 
    314             throws SimulationException { 
     220            throws SimulationException 
     221    { 
    315222 
    316223        // Load the properties file. 
    317         try { 
     224        try 
     225        { 
    318226            cadClientProp = new Properties(); 
    319227            cadClientProp.load(new FileInputStream(propertiesFile)); 
    320         } catch (Exception e) { 
     228        } catch (Exception e) 
     229        { 
    321230            cadClientLogger.logp(Level.SEVERE, "SimulationManager", 
    322231                    "Constructor", "Exception in reading properties file.", e); 
     
    325234                    e); 
    326235        } 
    327          
     236 
    328237 
    329238        // Ensure that the properties file does not have null values for the 
    330239        // CAD Simulator's connection information. 
    331240        if (cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name) == null 
    332                 || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) { 
     241                || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) 
     242        { 
    333243            cadClientLogger.logp(Level.SEVERE, "SimulationManager", 
    334244                    "Constructor", "Null value in properties file."); 
     
    336246        } 
    337247 
    338         try { 
     248        try 
     249        { 
    339250            // If the properties file does not specify a CAD position, prompt 
    340251            // the 
     
    342253            // new properties values to the file. If the user cancels, else 
    343254            // throw an exception. 
    344             if (cadClientProp.getProperty(PROPERTIES.CLIENT_CAD_POS.name) == null) { 
     255            if (cadClientProp.getProperty(PROPERTIES.CLIENT_CAD_POS.name) == null) 
     256            { 
    345257                if (getCADPosition()) 
     258                { 
    346259                    cadClientProp.store(new FileOutputStream(propertiesFile), 
    347260                            ""); 
    348                 else 
     261                } else 
     262                { 
    349263                    throw new SimulationException( 
    350264                            SimulationException.INITIALIZE_ERROR); 
     265                } 
    351266            } 
    352267 
     
    356271            // new properties values to the file. If the user cancels, else 
    357272            // throw an exception. 
    358             if (cadClientProp.getProperty(PROPERTIES.CLIENT_USER_ID.name) == null) { 
     273            if (cadClientProp.getProperty(PROPERTIES.CLIENT_USER_ID.name) == null) 
     274            { 
    359275                if (getUserID()) 
     276                { 
    360277                    cadClientProp.store(new FileOutputStream(propertiesFile), 
    361278                            ""); 
    362                 else 
     279                } else 
     280                { 
    363281                    throw new SimulationException( 
    364282                            SimulationException.INITIALIZE_ERROR); 
    365             } 
    366         } catch (IOException ioe) { 
     283                } 
     284            } 
     285        } catch (IOException ioe) 
     286        { 
    367287            cadClientLogger.logp(Level.SEVERE, "SimulationManager", 
    368288                    "Constructor", 
     
    374294        if (cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name) == null 
    375295                || (!cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name) 
    376                         .equals("FULL_SCREEN") && !cadClientProp.getProperty( 
    377                         PROPERTIES.DISPLAY_TYPE.name).equals("FRAME"))) { 
     296                .equals("FULL_SCREEN") && !cadClientProp.getProperty( 
     297                PROPERTIES.DISPLAY_TYPE.name).equals("FRAME"))) 
     298        { 
    378299            cadClientLogger.logp(Level.SEVERE, "SimulationManager", 
    379300                    "Constructor", "Invalid display type."); 
     
    388309     * the user cancels the method returns false, else the Properties object is 
    389310     * updated and true is returned. 
    390      *  
     311     * 
    391312     * @return True if the user successfully selected a CAD position, false if 
    392      *         not. 
    393      */ 
    394     private boolean getCADPosition() { 
     313     * not. 
     314     */ 
     315    private boolean getCADPosition() 
     316    { 
    395317 
    396318        Vector<Integer> positions = new Vector<Integer>(); 
    397319        for (int i = 0; i < 10; i++) 
     320        { 
    398321            positions.add(i); 
     322        } 
    399323 
    400324        Object cadPos = null; 
    401325 
    402         while (true) { 
     326        while (true) 
     327        { 
    403328            cadPos = JOptionPane.showInputDialog(null, 
    404329                    "Please assign this workstation a CAD position number.", 
     
    407332 
    408333            // If the user pressed cancel, confirm the exit and return false. 
    409             if (cadPos == null) { 
     334            if (cadPos == null) 
     335            { 
    410336                if (JOptionPane 
    411337                        .showConfirmDialog( 
    412                                 null, 
    413                                 "CAD Client cannot load until a valid CAD " 
    414                                         + "position has been selected.  Do you wish to " 
    415                                         + "cancel loading the CAD Client?", 
    416                                 "Confirm Exit", JOptionPane.YES_NO_OPTION, 
    417                                 JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 
     338                        null, 
     339                        "CAD Client cannot load until a valid CAD " 
     340                        + "position has been selected.  Do you wish to " 
     341                        + "cancel loading the CAD Client?", 
     342                        "Confirm Exit", JOptionPane.YES_NO_OPTION, 
     343                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 
     344                { 
    418345                    return false; 
    419             } 
    420             // Else the user selected a CAD position, exit the loop. 
    421             else { 
     346                } 
     347            } // Else the user selected a CAD position, exit the loop. 
     348            else 
     349            { 
    422350                break; 
    423351            } 
     
    433361     * cancels the method returns false, else the Properties object is updated 
    434362     * and true is returned. 
    435      *  
     363     * 
    436364     * @return True if the user successfully selected a CAD position, false if 
    437      *         not. 
    438      */ 
    439     private boolean getUserID() { 
     365     * not. 
     366     */ 
     367    private boolean getUserID() 
     368    { 
    440369        String cadUID = null; 
    441370 
    442         while (true) { 
     371        while (true) 
     372        { 
    443373            cadUID = JOptionPane.showInputDialog(null, 
    444374                    "Please assign this workstation a 6-character CAD " 
    445                             + "User ID.", "CAD User ID Asignment", 
     375                    + "User ID.", "CAD User ID Asignment", 
    446376                    JOptionPane.QUESTION_MESSAGE); 
    447377 
    448378            // /If the user pressed cancel, confirm the exit and return false. 
    449             if (cadUID == null) { 
     379            if (cadUID == null) 
     380            { 
    450381                if (JOptionPane.showConfirmDialog(null, 
    451382                        "CAD Client cannot load until a valid User ID " 
    452                                 + "has been entered.  Do you wish to " 
    453                                 + "cancel loading the CAD Client?", 
     383                        + "has been entered.  Do you wish to " 
     384                        + "cancel loading the CAD Client?", 
    454385                        "Confirm Exit", JOptionPane.YES_NO_OPTION, 
    455386                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 
     387                { 
    456388                    return false; 
    457             } 
    458             // If the user does not enter a valid User ID, notify and reprompt. 
    459             else if (cadUID.length() != 6) { 
     389                } 
     390            } // If the user does not enter a valid User ID, notify and reprompt. 
     391            else if (cadUID.length() != 6) 
     392            { 
    460393                JOptionPane.showMessageDialog(null, 
    461394                        "The User ID must be 6 characters.", "Invalid User ID", 
    462395                        JOptionPane.WARNING_MESSAGE); 
    463             } 
    464             // Else the user entered a valid value, exit the loop. 
    465             else { 
     396            } // Else the user entered a valid value, exit the loop. 
     397            else 
     398            { 
    466399                break; 
    467400            } 
     
    475408     * Construct the CADClient with the properties file path, either from the 
    476409     * command line arguments or default. 
    477      *  
    478      * @param args 
    479      *            Command line arguments. 
    480      */ 
    481     public static void main(String[] args) { 
    482         if(System.getProperty("CONFIG_DIR") == null){ 
    483                 System.setProperty("CONFIG_DIR", "config"); 
    484         } 
    485  
    486         try { 
     410     * 
     411     * @param args Command line arguments. 
     412     */ 
     413    public static void main(String[] args) 
     414    { 
     415        if (System.getProperty("CONFIG_DIR") == null) 
     416        { 
     417            System.setProperty("CONFIG_DIR", "config"); 
     418        } 
     419 
     420        try 
     421        { 
    487422            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    488423            new CADClockDisplay(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
    489           
    490         } catch (Exception e) { 
     424 
     425        } catch (Exception e) 
     426        { 
    491427            cadClientLogger.logp(Level.SEVERE, "SimulationManager", "Main", 
    492428                    "Error initializing application."); 
     
    500436    } 
    501437 
    502     public void refresh() { 
     438    public void refresh() 
     439    { 
    503440        theClientGUI.screen.refreshScreens(); 
    504441    } 
    505442 
    506     public void ensureProperShutdown() { 
    507         Runtime.getRuntime().addShutdownHook(new Thread() { 
    508             public void run() { 
    509                 try { 
     443    public void ensureProperShutdown() 
     444    { 
     445        Runtime.getRuntime().addShutdownHook(new Thread() 
     446        { 
     447            public void run() 
     448            { 
     449                try 
     450                { 
    510451                    theCoorInt.unregisterForCallback(client); 
    511                 } catch (RemoteException e) { 
     452                } catch (RemoteException e) 
     453                { 
    512454                    e.printStackTrace(); 
    513455                } 
     
    515457        }); 
    516458    } 
    517  
    518459} 
  • trunk/src/tmcsim/client/CADClockView.java

    r58 r61  
    11package tmcsim.client; 
    22 
    3 import java.awt.BorderLayout; 
    43import java.awt.Color; 
    54import java.awt.Dimension; 
     
    98import java.util.Observable; 
    109import java.util.Observer; 
    11 import java.util.TreeMap; 
    12 import java.util.logging.Level; 
    1310import java.util.logging.Logger; 
    1411 
     
    2017import javax.swing.JOptionPane; 
    2118import javax.swing.JPanel; 
    22 import javax.swing.JTextPane; 
    2319import javax.swing.WindowConstants; 
    24 import javax.xml.parsers.DocumentBuilderFactory; 
    25  
    26 import org.w3c.dom.Document; 
    27 import org.w3c.dom.Element; 
    28  
    29 import tmcsim.cadmodels.BlankScreenModel; 
    30 import tmcsim.cadmodels.CADScreenModel; 
    31 import tmcsim.cadmodels.IncidentBoardModel; 
    32 import tmcsim.cadmodels.IncidentInquiryModel; 
    33 import tmcsim.cadmodels.IncidentSummaryModel; 
    34 import tmcsim.cadmodels.RoutedMessageModel; 
    35 import tmcsim.client.cadscreens.IB_IncidentBoard; 
    36 import tmcsim.client.cadscreens.II_IncidentInquiry; 
    37 import tmcsim.client.cadscreens.SA_IncidentSummary; 
    38 import tmcsim.client.cadscreens.TO_RoutedMessage; 
    39 import tmcsim.client.cadscreens.view.CADCommandLineView; 
    40 import tmcsim.client.cadscreens.view.CADFooterView; 
    41 import tmcsim.client.cadscreens.view.CADMainView; 
    4220import tmcsim.common.ObserverMessage; 
    43 import tmcsim.common.CADEnums.ARROW; 
    4421import tmcsim.common.CADEnums.CADScreenNum; 
    45 import tmcsim.common.CADEnums.CAD_ERROR; 
    46 import tmcsim.common.CADEnums.CAD_KEYS; 
    47 import tmcsim.common.CADProtocol.CAD_CLIENT_CMD; 
    48 import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus;         
     22import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; 
    4923 
    5024/** 
    5125 * The CADClientView class is the view component to the CAD Client application. 
    5226 * 
    53  * This view class observers the CADClientModel, listening for updates 
    54  * from the CAD Simulator.  Updates includes the current  
    55  * CAD time  */ 
     27 * This view class observers the CADClientModel, listening for updates from the 
     28 * CAD Simulator. Updates includes the current CAD time 
     29 */ 
    5630@SuppressWarnings("serial") 
    57 public class CADClockView extends JFrame implements KeyListener, Observer { 
    58      
    59     /** Error Logger. */ 
     31public class CADClockView extends JFrame 
     32{ 
     33 
     34    /** 
     35     * Error Logger. 
     36     */ 
    6037    private static Logger cadLogger = Logger.getLogger("tmcsim.client"); 
    61      
    62     /** Reference to the CADClient model object. */ 
    63     private CADClientModel theModel = null; 
    64                
    65     /** Current CAD Screen number. */ 
    66     private CADScreenNum currentScreenNum = null; 
    6738    private JPanel mainPane; 
    6839    private JLabel currentTime; 
    69      
     40 
    7041    /** 
    7142     * Constructor. Build panes, add key listeners, and set up observer 
    7243     * relationship between the footer and main panes. 
    73      *  
    74      * @param position 
    75      *            The CAD position for this client terminal. 
     44     * 
     45     * @param position The CAD position for this client terminal. 
    7646     */ 
    77     public CADClockView(CADClientModel mod) { 
     47    public CADClockView() 
     48    { 
    7849        super("CAD Client"); 
    7950        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
    80         theModel = mod; 
    8151        currentTime = new JLabel("0:00:00"); 
    8252        CADSimulatorStatus status = new CADSimulatorStatus(); 
     
    8454        currentTime.setText(simtime); 
    8555        currentTime.setAlignmentX(Box.CENTER_ALIGNMENT); 
    86         currentTime.setFont(new Font("Geneva", Font.BOLD, 70));         
     56        currentTime.setFont(new Font("Geneva", Font.BOLD, 70)); 
    8757        mainPane = new JPanel(); 
    8858        setSize(new Dimension(730, 455)); 
     
    9060        setMinimumSize(new Dimension(730, 455)); 
    9161        mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); 
    92         mainPane.setBorder(BorderFactory.createLineBorder(Color.black));    
     62        mainPane.setBorder(BorderFactory.createLineBorder(Color.black)); 
    9363        mainPane.setBackground(Color.LIGHT_GRAY); 
    9464        mainPane.add(currentTime); 
    95         add(mainPane);  
     65        add(mainPane); 
    9666        pack(); 
    9767    } 
    9868 
    99     /** 
    100      * Observable update method.  The CADClientView class is an observer of the  
    101      * CADClientModel.  If the model sends a null object, it is signifying that 
    102      * it has shut down.  In this case, an error message should be shown to prompt 
    103      * the user to restart the CAD Client.  If the update object is an 
    104      * ObserverMessage object, the following actions are to be taken: 
    105      *  
    106      *<table cellpadding="2" cellspacing="2" border="1" 
    107      * style="text-align: left; width: 250px;"> 
    108      *  <tbody> 
    109      *    <tr> 
    110      *      <th>Message Type</th> 
    111      *      <th>Message Data</th> 
    112      *      <th>Action Taken</th> 
    113      *    </tr> 
    114      *    <tr> 
    115      *      <td>TIME_UPDATE<br></td> 
    116      *      <td>Time String<br></td> 
    117      *      <td>Update the footer pane with the new time.</td> 
    118      *    </tr> 
    119      *  </tbody> 
    120      *</table> 
    121      */ 
    122     public void update(Observable o, Object arg) { 
    123          
    124          
    125         if(arg == null)  
    126         { 
    127             JOptionPane.showMessageDialog(this,  
    128                     "Connection to the CAD Simulator has been lost.  " + 
    129                     "Restart the CAD Client.", "Connection Error",  
    130                     JOptionPane.ERROR_MESSAGE);  
    131             return; 
    132         } 
    133          
    134         ObserverMessage oMessage = (ObserverMessage)arg;     
    135          
    136         switch(oMessage.type) { 
    137             // Time updates occur once a minute 
    138             case TIME_UPDATE: 
    139                 currentTime.setText("" + (String)oMessage.value); 
    140                 break; 
    141         }            
     69    public void updateTime(String msg) 
     70    { 
     71        currentTime.setText(msg); 
    14272    } 
    143  
    144     @Override 
    145     public void keyTyped(KeyEvent e) 
    146     { 
    147         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 
    148     } 
    149  
    150     @Override 
    151     public void keyPressed(KeyEvent e) 
    152     { 
    153         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 
    154     } 
    155  
    156     @Override 
    157     public void keyReleased(KeyEvent e) 
    158     { 
    159         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 
    160     } 
    161      
    162     
    163      
    164 }     
     73} 
Note: See TracChangeset for help on using the changeset viewer.