Changeset 64 in tmcsimulator for trunk/src


Ignore:
Timestamp:
03/16/2017 07:28:12 AM (9 years ago)
Author:
jdalbey
Message:

Renamed to ClockClient?, added build target for it.

Location:
trunk/src/tmcsim
Files:
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/application.properties

    r59 r64  
    1 #Wed, 15 Mar 2017 11:18:58 -0700 
     1#Thu, 16 Mar 2017 08:26:10 -0700 
    22 
    3 Application.revision=58 
     3Application.revision=63 
    44 
    5 Application.buildnumber=33 
     5Application.buildnumber=44 
  • trunk/src/tmcsim/client/ClockClient.java

    r62 r64  
    44import java.awt.event.ActionListener; 
    55import java.io.FileInputStream; 
    6 import java.io.FileOutputStream; 
    7 import java.io.IOException; 
    86import java.rmi.Naming; 
    97import java.rmi.RemoteException; 
    108import java.rmi.server.UnicastRemoteObject; 
    119import java.util.Properties; 
    12 import java.util.Vector; 
    1310import java.util.concurrent.TimeUnit; 
    1411import java.util.logging.Level; 
     
    1815import javax.swing.Timer; 
    1916import javax.swing.UIManager; 
    20 import tmcsim.client.cadclientgui.CADClientGUI; 
    2117import tmcsim.common.SimulationException; 
    2218import tmcsim.interfaces.CADClientInterface; 
     
    2420 
    2521/** 
    26  * CADClockDisplay shows the simulation clock time. It operates as a client of 
    27  * the CAD server, using RMI to poll the server every second for the current 
     22 * ClockClient shows the simulation clock time. It operates as a client of the 
     23 * CAD server, using RMI to poll the server every second for the current 
    2824 * simulation clock time. 
     25 * 
     26 * @author jdalbey 
    2927 */ 
    30 public class CADClockDisplay extends UnicastRemoteObject implements 
     28public class ClockClient extends UnicastRemoteObject implements 
    3129        CADClientInterface 
    3230{ 
     
    3533     */ 
    3634    private static Logger cadClientLogger = Logger.getLogger("tmcsim.client"); 
     35 
     36    @Override 
     37    public void refresh() throws RemoteException 
     38    { 
     39        throw new UnsupportedOperationException("Not supported yet."); 
     40    } 
    3741 
    3842    /** 
     
    6266    private CADClientSocket theClientSocket; 
    6367    /** 
    64      * Instance of the CADClientModel. 
    65      */ 
    66     private CADClientModel theClientScreenModel; 
    67     /** 
    68      * Instance of the CADClockView. 
    69      */ 
    70     private CADClockView theClientScreenView; 
    71     /** 
    72      * Instance of the CADCLientGUI Replaces CADClockView 
    73      */ 
    74     private CADClientGUI theClientGUI; 
     68     * Instance of the ClockView. 
     69     */ 
     70    private ClockView theView; 
    7571    /** 
    7672     * Properties object for the CADClient class. 
     
    9591     * file containing configuration data. 
    9692     */ 
    97     public CADClockDisplay(String propertiesFile) throws SimulationException, 
     93    public ClockClient(String propertiesFile) throws SimulationException, 
    9894            RemoteException 
    9995    { 
     
    106102                cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim()); 
    107103 
    108         theClientScreenView = new CADClockView(); 
    109         theClientScreenView.setVisible(true); 
     104        theView = new ClockView(); 
     105        theView.setVisible(true); 
    110106 
    111107        // Create a timer that fetches the simulation time every second. 
     
    117113                { 
    118114                    long simtime = theCoorInt.getCurrentSimulationTime(); 
    119                     theClientScreenView.updateTime("" + formatInterval(simtime)); 
     115                    theView.updateTime("" + formatInterval(simtime)); 
    120116                } catch (RemoteException ex) 
    121117                { 
    122                     Logger.getLogger(CADClockDisplay.class.getName()).log(Level.SEVERE, null, ex); 
     118                    Logger.getLogger(ClockClient.class.getName()).log(Level.SEVERE, null, ex); 
    123119                } 
    124120            } 
     
    199195        } 
    200196 
    201         try 
    202         { 
    203             // If the properties file does not specify a CAD position, prompt 
    204             // the 
    205             // user to select one. If the user selects a position, write the 
    206             // new properties values to the file. If the user cancels, else 
    207             // throw an exception. 
    208             if (cadClientProp.getProperty(PROPERTIES.CLIENT_CAD_POS.name) == null) 
    209             { 
    210                 if (getCADPosition()) 
    211                 { 
    212                     cadClientProp.store(new FileOutputStream(propertiesFile), 
    213                             ""); 
    214                 } 
    215                 else 
    216                 { 
    217                     throw new SimulationException( 
    218                             SimulationException.INITIALIZE_ERROR); 
    219                 } 
    220             } 
    221  
    222             // If the properties file does not specifiy a CAD User ID, prompt 
    223             // the 
    224             // user to enter a value. If the user enters a valid ID, write the 
    225             // new properties values to the file. If the user cancels, else 
    226             // throw an exception. 
    227             if (cadClientProp.getProperty(PROPERTIES.CLIENT_USER_ID.name) == null) 
    228             { 
    229                 if (getUserID()) 
    230                 { 
    231                     cadClientProp.store(new FileOutputStream(propertiesFile), 
    232                             ""); 
    233                 } 
    234                 else 
    235                 { 
    236                     throw new SimulationException( 
    237                             SimulationException.INITIALIZE_ERROR); 
    238                 } 
    239             } 
    240         } catch (IOException ioe) 
    241         { 
    242             cadClientLogger.logp(Level.SEVERE, "SimulationManager", 
    243                     "Constructor", 
    244                     "Exception in writing to the properties file."); 
    245             throw new SimulationException(SimulationException.INITIALIZE_ERROR); 
    246         } 
    247  
    248         // Ensure that the properties file has a valid display type 
    249         if (cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name) == null 
    250                 || (!cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name) 
    251                 .equals("FULL_SCREEN") && !cadClientProp.getProperty( 
    252                 PROPERTIES.DISPLAY_TYPE.name).equals("FRAME"))) 
    253         { 
    254             cadClientLogger.logp(Level.SEVERE, "SimulationManager", 
    255                     "Constructor", "Invalid display type."); 
    256             throw new SimulationException(SimulationException.INITIALIZE_ERROR); 
    257         } 
    258  
    259197        return true; 
    260198    } 
    261199 
    262200    /** 
    263      * This method prompts the user to select a value for the CAD position. If 
    264      * the user cancels the method returns false, else the Properties object is 
    265      * updated and true is returned. 
    266      * 
    267      * @return True if the user successfully selected a CAD position, false if 
    268      * not. 
    269      */ 
    270     private boolean getCADPosition() 
    271     { 
    272  
    273         Vector<Integer> positions = new Vector<Integer>(); 
    274         for (int i = 0; i < 10; i++) 
    275         { 
    276             positions.add(i); 
    277         } 
    278  
    279         Object cadPos = null; 
    280  
    281         while (true) 
    282         { 
    283             cadPos = JOptionPane.showInputDialog(null, 
    284                     "Please assign this workstation a CAD position number.", 
    285                     "CAD Position Asignment", JOptionPane.QUESTION_MESSAGE, 
    286                     null, positions.toArray(), positions.get(0)); 
    287  
    288             // If the user pressed cancel, confirm the exit and return false. 
    289             if (cadPos == null) 
    290             { 
    291                 if (JOptionPane 
    292                         .showConfirmDialog( 
    293                         null, 
    294                         "CAD Client cannot load until a valid CAD " 
    295                         + "position has been selected.  Do you wish to " 
    296                         + "cancel loading the CAD Client?", 
    297                         "Confirm Exit", JOptionPane.YES_NO_OPTION, 
    298                         JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 
    299                 { 
    300                     return false; 
    301                 } 
    302             } // Else the user selected a CAD position, exit the loop. 
    303             else 
    304             { 
    305                 break; 
    306             } 
    307         } 
    308  
    309         cadClientProp.setProperty(PROPERTIES.CLIENT_CAD_POS.name, 
    310                 cadPos.toString()); 
    311         return true; 
    312     } 
    313  
    314     /** 
    315      * This method prompts the user to enter a 5-character User ID. If the user 
    316      * cancels the method returns false, else the Properties object is updated 
    317      * and true is returned. 
    318      * 
    319      * @return True if the user successfully selected a CAD position, false if 
    320      * not. 
    321      */ 
    322     private boolean getUserID() 
    323     { 
    324         String cadUID = null; 
    325  
    326         while (true) 
    327         { 
    328             cadUID = JOptionPane.showInputDialog(null, 
    329                     "Please assign this workstation a 6-character CAD " 
    330                     + "User ID.", "CAD User ID Asignment", 
    331                     JOptionPane.QUESTION_MESSAGE); 
    332  
    333             // /If the user pressed cancel, confirm the exit and return false. 
    334             if (cadUID == null) 
    335             { 
    336                 if (JOptionPane.showConfirmDialog(null, 
    337                         "CAD Client cannot load until a valid User ID " 
    338                         + "has been entered.  Do you wish to " 
    339                         + "cancel loading the CAD Client?", 
    340                         "Confirm Exit", JOptionPane.YES_NO_OPTION, 
    341                         JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 
    342                 { 
    343                     return false; 
    344                 } 
    345             } // If the user does not enter a valid User ID, notify and reprompt. 
    346             else if (cadUID.length() != 6) 
    347             { 
    348                 JOptionPane.showMessageDialog(null, 
    349                         "The User ID must be 6 characters.", "Invalid User ID", 
    350                         JOptionPane.WARNING_MESSAGE); 
    351             } // Else the user entered a valid value, exit the loop. 
    352             else 
    353             { 
    354                 break; 
    355             } 
    356         } 
    357  
    358         cadClientProp.setProperty(PROPERTIES.CLIENT_USER_ID.name, cadUID); 
    359         return true; 
    360     } 
    361  
    362     /** 
    363      * Construct the CADClient with the properties file path, either from the 
    364      * command line arguments or default. 
    365      * 
    366      * @param args Command line arguments. 
    367      */ 
    368     public static void main(String[] args) 
    369     { 
    370         if (System.getProperty("CONFIG_DIR") == null) 
    371         { 
    372             System.setProperty("CONFIG_DIR", "config"); 
    373         } 
    374  
    375         try 
    376         { 
    377             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    378             new CADClockDisplay(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
    379  
    380         } catch (Exception e) 
    381         { 
    382             cadClientLogger.logp(Level.SEVERE, "SimulationManager", "Main", 
    383                     "Error initializing application."); 
    384  
    385             JOptionPane.showMessageDialog(new JWindow(), e.getMessage(), 
    386                     "Error - Program Exiting", JOptionPane.ERROR_MESSAGE); 
    387  
    388             System.exit(-1); 
    389         } 
    390  
    391     } 
    392  
    393     public void refresh() 
    394     { 
    395         theClientGUI.screen.refreshScreens(); 
     201     * Format a time in seconds as HH:MM:SS 
     202     * 
     203     * @param l 
     204     * @return 
     205     */ 
     206    private String formatInterval(final long l) 
     207    { 
     208        final long hr = TimeUnit.SECONDS.toHours(l); 
     209        final long min = TimeUnit.SECONDS.toMinutes(l - TimeUnit.HOURS.toSeconds(hr)); 
     210        final long sec = TimeUnit.SECONDS.toSeconds(l - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min)); 
     211        return String.format("%02d:%02d:%02d", hr, min, sec); 
    396212    } 
    397213 
     
    414230 
    415231    /** 
    416      * Format a time in seconds as HH:MM:SS 
    417      * 
    418      * @param l 
    419      * @return 
    420      */ 
    421     private String formatInterval(final long l) 
    422     { 
    423         final long hr = TimeUnit.SECONDS.toHours(l); 
    424         final long min = TimeUnit.SECONDS.toMinutes(l - TimeUnit.HOURS.toSeconds(hr)); 
    425         final long sec = TimeUnit.SECONDS.toSeconds(l - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min)); 
    426         return String.format("%02d:%02d:%02d", hr, min, sec); 
     232     * Construct the CADClient with the properties file path, either from the 
     233     * command line arguments or default. 
     234     * 
     235     * @param args Command line arguments. 
     236     */ 
     237    public static void main(String[] args) 
     238    { 
     239        if (System.getProperty("CONFIG_DIR") == null) 
     240        { 
     241            System.setProperty("CONFIG_DIR", "config"); 
     242        } 
     243 
     244        try 
     245        { 
     246            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
     247            new ClockClient(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
     248 
     249        } catch (Exception e) 
     250        { 
     251            cadClientLogger.logp(Level.SEVERE, "SimulationManager", "Main", 
     252                    "Error initializing application."); 
     253 
     254            JOptionPane.showMessageDialog(new JWindow(), e.getMessage(), 
     255                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE); 
     256 
     257            System.exit(-1); 
     258        } 
     259 
    427260    } 
    428261} 
  • trunk/src/tmcsim/client/ClockView.java

    r62 r64  
    1616 * The CADClientView class is the view component to the CAD Client application. 
    1717 * 
     18 * @author jdalbey 
    1819 */ 
    1920@SuppressWarnings("serial") 
    20 public class CADClockView extends JFrame 
     21public class ClockView extends JFrame 
    2122{ 
    2223    /** 
     
    2627    private JPanel mainPane; 
    2728    private JLabel currentTime; 
     29    private final static Dimension SCREEN_SIZE = new Dimension(1100, 255); 
    2830 
    2931    /** 
    3032     * Constructor. Build panes, add key listeners, and set up observer 
    31      * relationship between the footer and main panes. 
    32      * 
    33      * @param position The CAD position for this client terminal. 
     33     * relationship between the footer and main panes. TODO: Consider having 
     34     * screen size and font size in properties file. 
    3435     */ 
    35     public CADClockView() 
     36    public ClockView() 
    3637    { 
    3738        super("Simulation Clock"); 
     
    4142        currentTime.setFont(new Font("Geneva", Font.BOLD, 200)); 
    4243        mainPane = new JPanel(); 
    43         setSize(new Dimension(1100, 255)); 
    44         setMaximumSize(new Dimension(1100, 255)); 
    45         setMinimumSize(new Dimension(1100, 255)); 
     44        setSize(SCREEN_SIZE); 
     45        setMaximumSize(SCREEN_SIZE); 
     46        setMinimumSize(SCREEN_SIZE); 
    4647        mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); 
    4748        mainPane.setBorder(BorderFactory.createLineBorder(Color.black)); 
  • trunk/src/tmcsim/client/cadclientgui/screens/AssignedIncidents.java

    r63 r64  
    1515import java.rmi.RemoteException; 
    1616import java.util.List; 
     17import java.util.logging.Level; 
     18import java.util.logging.Logger; 
    1719import javax.swing.Box; 
    1820import javax.swing.BoxLayout; 
     
    6264    // labels for the drop down menu 
    6365    private JLabel[] dropDownLabels = new JLabel[LABELS.length]; 
     66    private static Logger clientLogger = Logger.getLogger("tmcsim.client"); 
    6467    private long lastLeftClick;// used for double clicking feature 
    6568 
     
    110113                { 
    111114                    comp = super.prepareRenderer(renderer, row, column); 
    112                 } catch (ArrayIndexOutOfBoundsException ex) 
    113                 { 
    114                     // our workaround is to just return a dummy value 
    115                     // all will be redrawn in the next one second interval 
     115                } catch (Exception ex) 
     116                { 
     117                    clientLogger.logp(Level.INFO, "AssignedIncidents", 
     118                            "prepareRenderer", "row=" + row + " col=" + column, ex); 
     119 
     120                    // Our workaround is to just return a dummy value. 
     121                    // It will be erased in the next one second refresh 
    116122                    return new JLabel("?"); 
    117123                } 
  • trunk/src/tmcsim/client/cadclientgui/screens/UnitStatus.java

    r63 r64  
    1818import java.rmi.RemoteException; 
    1919import java.util.List; 
     20import java.util.logging.Level; 
     21import java.util.logging.Logger; 
    2022import javax.swing.Box; 
    2123import javax.swing.BoxLayout; 
     
    4850public class UnitStatus extends JFrame 
    4951{ 
    50     private final int ONE_SECOND = 1000; 
     52    private final static int ONE_SECOND = 1000; 
     53    private static Logger clientLogger = Logger.getLogger("tmcsim.client"); 
    5154    private final String SCREEN_TITLE = "(Shift + F4)  Unit Status"; 
    5255    private final Dimension SCREEN_DIMENSIONS = new Dimension(1400, 250); 
     
    152155                { 
    153156                    comp = super.prepareRenderer(renderer, row, column); 
    154                 } catch (ArrayIndexOutOfBoundsException ex) 
    155                 { 
    156                     // our workaround is to just return a dummy value 
    157                     // all will be redrawn in the next one second interval 
     157                } catch (Exception ex) 
     158                { 
     159                    clientLogger.logp(Level.INFO, "UnitStatus", 
     160                            "prepareRenderer", "row=" + row + " col=" + column, ex); 
     161                    // Our workaround is to just return a dummy value. 
     162                    // It will be erased in the next one second refresh 
    158163                    return new JLabel("?"); 
    159164                } 
Note: See TracChangeset for help on using the changeset viewer.