Index: trunk/src/tmcsim/client/CADClockDisplay.java
===================================================================
--- trunk/src/tmcsim/client/CADClockDisplay.java	(revision 57)
+++ trunk/src/tmcsim/client/CADClockDisplay.java	(revision 61)
@@ -1,6 +1,4 @@
 package tmcsim.client;
 
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -9,10 +7,12 @@
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Properties;
 import java.util.Vector;
+import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.swing.JFrame;
 import javax.swing.JOptionPane;
 import javax.swing.JWindow;
@@ -20,10 +20,4 @@
 
 import tmcsim.client.cadclientgui.CADClientGUI;
-import tmcsim.client.cadclientgui.CardfileReader;
-import tmcsim.client.cadclientgui.GUIScriptReader;
-import tmcsim.client.cadclientgui.data.CADData;
-import tmcsim.client.cadclientgui.screens.Login;
-import tmcsim.client.cadclientgui.screens.ScreenManager;
-import tmcsim.common.CADEnums;
 import tmcsim.common.SimulationException;
 import tmcsim.interfaces.CADClientInterface;
@@ -43,26 +37,28 @@
  * <code>
  * -----------------------------------------------------------------------------<br>
- * Host Name     The host name where the CAD Simulator is located.<br>
- * Port Number   The port number that the CAD Simulator is bound on.<br>
- * CAD Position  The integer (>= 0) position for this CAD Client.<br>
- * CAD User ID   The unique user id for this CAD Client.<br>
- * Error File    Filename of error logging file.<br>
+ * Host Name The host name where the CAD Simulator is located.<br>
+ * Port Number The port number that the CAD Simulator is bound on.<br>
+ * CAD Position The integer (>= 0) position for this CAD Client.<br>
+ * CAD User ID The unique user id for this CAD Client.<br>
+ * Error File Filename of error logging file.<br>
  * -----------------------------------------------------------------------------<br>
  * Example File: <br>
- * CADSimulatorHost       = localhost<br>
+ * CADSimulatorHost = localhost<br>
  * CADSimulatorSocketPort = 4444<br>
  * CADPosition = 1 <br>
- * CADUserID   = A12345<br>
- * ErrorFile   = cad_client_err.txt<br>
+ * CADUserID = A12345<br>
+ * ErrorFile = cad_client_err.txt<br>
  * </code>
- * 
+ *
  * @author Matthew Cechini (mcechini@calpoly.edu)
  * @version $Date: 2009/04/17 16:27:47 $ $Revision: 1.8 $
  */
-
 public class CADClockDisplay extends UnicastRemoteObject implements
-        CADClientInterface {
-
-    /** Error logger. */
+        CADClientInterface
+{
+
+    /**
+     * Error logger.
+     */
     private static Logger cadClientLogger = Logger.getLogger("tmcsim.client");
 
@@ -70,21 +66,22 @@
      * Enumeration containing properties name values. See CADClient class
      * description for more information.
-     * 
+     *
      * @author Matthew Cechini
      * @see CADClient
      */
-    private static enum PROPERTIES {
+    private static enum PROPERTIES
+    {
+
         CAD_SIM_HOST("CADSimulatorHost"), CAD_SIM_PORT("CADSimulatorSocketPort"), CAD_RMI_PORT(
-                "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID(
-                "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE(
-                "DisplayType");
-
+        "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID(
+        "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE(
+        "DisplayType");
         public String name;
 
-        private PROPERTIES(String n) {
+        private PROPERTIES(String n)
+        {
             name = n;
         }
     }
-
     /**
      * CADClientSocket Object to handle socket communication between the Client
@@ -92,26 +89,37 @@
      */
     private CADClientSocket theClientSocket;
-
-    /** Instance of the CADClientModel. */
+    /**
+     * Instance of the CADClientModel.
+     */
     private CADClientModel theClientScreenModel;
-
-    /** Instance of the CADClockView. */
+    /**
+     * Instance of the CADClockView.
+     */
     private CADClockView theClientScreenView;
-
     /**
      * Instance of the CADCLientGUI Replaces CADClockView
      */
     private CADClientGUI theClientGUI;
-
-    /** Properties object for the CADClient class. */
+    /**
+     * Properties object for the CADClient class.
+     */
     private Properties cadClientProp;
-
-    /** RMI interface for communication with the remote Coordinator. */
+    /**
+     * RMI interface for communication with the remote Coordinator.
+     */
     private static CoordinatorInterface theCoorInt;
-
-    /** reference to itself to be used for disconnecting from CADSimulator */
+    /**
+     * reference to itself to be used for disconnecting from CADSimulator
+     */
     private CADClientInterface client = this;
-
     private static final String CONFIG_FILE_NAME = "cad_client_config.properties";
+
+    private String formatInterval(final long l)
+    {
+        final long hr = TimeUnit.SECONDS.toHours(l);
+        final long min = TimeUnit.SECONDS.toMinutes(l - TimeUnit.HOURS.toSeconds(hr));
+        final long sec = TimeUnit.SECONDS.toSeconds(l - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min));
+        return String.format("%02d:%02d:%02d", hr, min, sec);
+    }
     
     /**
@@ -122,148 +130,47 @@
      * and userID read in from the properties file. The ClientScreenView is then
      * created and initialized and set as an observer of the model.
-     * 
+     *
      * A thread is created with the runnable ClientScreenModel and is started.
      * When this thread is no longer alive, or the ClientScrenView and
      * CADClientSocket are closed. The program then exits.
-     * 
-     * @param propertiesFile
-     *            File path (absolute or relative) to the properties file
-     *            containing configuration data.
+     *
+     * @param propertiesFile File path (absolute or relative) to the properties
+     * file containing configuration data.
      */
     public CADClockDisplay(String propertiesFile) throws SimulationException,
-            RemoteException {
+            RemoteException
+    {
         if (!verifyProperties(propertiesFile))
+        {
             System.exit(0);
+        }
 
         connect(cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(),
                 cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim());
 
-        // Instantiate the Socket and Model Objects.
-        theClientSocket = new CADClientSocket(cadClientProp.getProperty(
-                PROPERTIES.CAD_SIM_HOST.name).trim(),
-                Integer.parseInt(cadClientProp.getProperty(
-                        PROPERTIES.CAD_SIM_PORT.name).trim()));
-        theClientScreenModel = new CADClientModel();
-        theClientScreenModel.initializeScreen(theClientSocket.getInputStream(),
-                theClientSocket.getOutputStream());
-
-        // Register this CAD Client with the Simulation Manager
-        theClientScreenModel.register(Integer.parseInt(cadClientProp
-                .getProperty(PROPERTIES.CLIENT_CAD_POS.name)), cadClientProp
-                .getProperty(PROPERTIES.CLIENT_USER_ID.name));
-
         // Instantiate the CADScreenView and set up the model-view observer
         // relationship.
-        theClientScreenView = new CADClockView(theClientScreenModel);
-        theClientScreenModel.addObserver(theClientScreenView);
+        theClientScreenView = new CADClockView();
         theClientScreenView.setVisible(true);
+
+        try
+        {
+            while (true)
+            {
+                long simtime = theCoorInt.getCurrentSimulationTime();
+                //System.out.println("" + formatInterval(simtime));
+                theClientScreenView.updateTime("" + formatInterval(simtime));
+                Thread.sleep(1000);
+            }
+        } catch (InterruptedException ex)
+        {
+            Logger.getLogger(CADClockDisplay.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
         // Create the CAD Client thread to run the CADClientModel Object.
-        Thread clientThread = new Thread(theClientScreenModel);
-        clientThread.start();
-        
-        // TODO: set up model-view relationship similar to ClientView and
-        // ScreenView
-        // Can repurpose the old model, but may be better to copy over and
-        // modify in parallel
-        // This is required to perform powerline commands on the data
-//        theClientGUI = new CADClientGUI();
-
-        // Each screen of the UI should have a reference to either it's parent
-        // object or the main client
-        // This ensures they all have access to each other and the data model
-//        theClientGUI.screen = new ScreenManager(theCoorInt);
-//        theClientGUI.login = new Login();
-//        theClientGUI.client = this;
-
-        // setup keyboard settings for CAD Client
-//        if (cadClientProp.getProperty(PROPERTIES.KEYBOARD_TYPE.name).trim()
-//                .equals("CAD")) {
-//            CADEnums.CAD_KEYS.setupCADKeyboard();
-//        }
-//        // STD
-//        else {
-//            CADEnums.CAD_KEYS.setupStandardKeyboard();
-//        }
-//
-//        theClientScreenModel.addObserver(theClientScreenView);
-//
-//        // Initialize the display
-//        if (cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name).equals(
-//                "FULL_SCREEN")) {
-//
-//            theClientScreenView.addWindowListener(new WindowListener() {
-//                public void windowClosed(WindowEvent e) {
-//                }
-//
-//                public void windowOpened(WindowEvent e) {
-//                }
-//
-//                public void windowIconified(WindowEvent e) {
-//                }
-//
-//                public void windowDeiconified(WindowEvent e) {
-//                }
-//
-//                public void windowActivated(WindowEvent e) {
-//                }
-//
-//                public void windowDeactivated(WindowEvent e) {
-//                }
-//
-//                public void windowClosing(WindowEvent e) {
-//
-//                    try {
-//                        theClientSocket.closeSocket();
-//                    } catch (SimulationException se) {
-//                    }
-//
-//                    System.exit(0);
-//                }
-//            });
-//
-//            theClientScreenView.initWindow();
-//            theClientScreenView.setVisible(false);
-//        } else {
-//            JFrame cadFrame = new JFrame("CAD Client");
-//            cadFrame.add(theClientScreenView.initBox());
-//            cadFrame.setSize(800, 600);
-//
-//            cadFrame.addWindowListener(new WindowListener() {
-//                public void windowClosed(WindowEvent e) {
-//                }
-//
-//                public void windowOpened(WindowEvent e) {
-//                }
-//
-//                public void windowIconified(WindowEvent e) {
-//                }
-//
-//                public void windowDeiconified(WindowEvent e) {
-//                }
-//
-//                public void windowActivated(WindowEvent e) {
-//                }
-//
-//                public void windowDeactivated(WindowEvent e) {
-//                }
-//
-//                public void windowClosing(WindowEvent e) {
-//
-//                    try {
-//                        theClientSocket.closeSocket();
-//                    } catch (SimulationException se) {
-//                    }
-//
-//                    System.exit(0);
-//                }
-//            });
-//
-//            cadFrame.setVisible(true);
-//        }
-//
-//        // Create the CAD Client thread to run the CADClientModel Object.
 //        Thread clientThread = new Thread(theClientScreenModel);
 //        clientThread.start();
 
+
         ensureProperShutdown();
     }
@@ -272,23 +179,24 @@
      * Connect to the Coordinator's RMI object, and register this object for
      * callback with the Coordinator.
-     * 
-     * @param hostname
-     *            Host name of the CAD Simulator.
-     * @param portNumber
-     *            Port number of the CAD Simulator RMI communication.
-     * @throws SimulationException
-     *             if there is an error creating the RMI connection.
+     *
+     * @param hostname Host name of the CAD Simulator.
+     * @param portNumber Port number of the CAD Simulator RMI communication.
+     * @throws SimulationException if there is an error creating the RMI
+     * connection.
      */
     protected void connect(String hostname, String portNumber)
-            throws SimulationException {
+            throws SimulationException
+    {
 
         String coorIntURL = "";
 
-        try {
+        try
+        {
             coorIntURL = "rmi://" + hostname + ":" + portNumber
                     + "/coordinator";
             theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL);
             theCoorInt.registerForCallback(this);
-        } catch (Exception e) {
+        } catch (Exception e)
+        {
             throw new SimulationException(SimulationException.CAD_SIM_CONNECT,
                     e);
@@ -302,21 +210,22 @@
      * the properties file. If the user cancels the process of entering these
      * values, the verification fails.
-     * 
-     * @param propertiesFile
-     *            File path (absolute or relative) to the properties file
-     *            containing configuration data.
+     *
+     * @param propertiesFile File path (absolute or relative) to the properties
+     * file containing configuration data.
      * @return True if the properties file is valid, false if not.
-     * @throws SimulationException
-     *             if there is an exception in verifying the properties file, or
-     *             if the user cancels input.
+     * @throws SimulationException if there is an exception in verifying the
+     * properties file, or if the user cancels input.
      */
     private boolean verifyProperties(String propertiesFile)
-            throws SimulationException {
+            throws SimulationException
+    {
 
         // Load the properties file.
-        try {
+        try
+        {
             cadClientProp = new Properties();
             cadClientProp.load(new FileInputStream(propertiesFile));
-        } catch (Exception e) {
+        } catch (Exception e)
+        {
             cadClientLogger.logp(Level.SEVERE, "SimulationManager",
                     "Constructor", "Exception in reading properties file.", e);
@@ -325,10 +234,11 @@
                     e);
         }
-        
+
 
         // Ensure that the properties file does not have null values for the
         // CAD Simulator's connection information.
         if (cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name) == null
-                || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) {
+                || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null)
+        {
             cadClientLogger.logp(Level.SEVERE, "SimulationManager",
                     "Constructor", "Null value in properties file.");
@@ -336,5 +246,6 @@
         }
 
-        try {
+        try
+        {
             // If the properties file does not specify a CAD position, prompt
             // the
@@ -342,11 +253,15 @@
             // new properties values to the file. If the user cancels, else
             // throw an exception.
-            if (cadClientProp.getProperty(PROPERTIES.CLIENT_CAD_POS.name) == null) {
+            if (cadClientProp.getProperty(PROPERTIES.CLIENT_CAD_POS.name) == null)
+            {
                 if (getCADPosition())
+                {
                     cadClientProp.store(new FileOutputStream(propertiesFile),
                             "");
-                else
+                } else
+                {
                     throw new SimulationException(
                             SimulationException.INITIALIZE_ERROR);
+                }
             }
 
@@ -356,13 +271,18 @@
             // new properties values to the file. If the user cancels, else
             // throw an exception.
-            if (cadClientProp.getProperty(PROPERTIES.CLIENT_USER_ID.name) == null) {
+            if (cadClientProp.getProperty(PROPERTIES.CLIENT_USER_ID.name) == null)
+            {
                 if (getUserID())
+                {
                     cadClientProp.store(new FileOutputStream(propertiesFile),
                             "");
-                else
+                } else
+                {
                     throw new SimulationException(
                             SimulationException.INITIALIZE_ERROR);
-            }
-        } catch (IOException ioe) {
+                }
+            }
+        } catch (IOException ioe)
+        {
             cadClientLogger.logp(Level.SEVERE, "SimulationManager",
                     "Constructor",
@@ -374,6 +294,7 @@
         if (cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name) == null
                 || (!cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name)
-                        .equals("FULL_SCREEN") && !cadClientProp.getProperty(
-                        PROPERTIES.DISPLAY_TYPE.name).equals("FRAME"))) {
+                .equals("FULL_SCREEN") && !cadClientProp.getProperty(
+                PROPERTIES.DISPLAY_TYPE.name).equals("FRAME")))
+        {
             cadClientLogger.logp(Level.SEVERE, "SimulationManager",
                     "Constructor", "Invalid display type.");
@@ -388,17 +309,21 @@
      * the user cancels the method returns false, else the Properties object is
      * updated and true is returned.
-     * 
+     *
      * @return True if the user successfully selected a CAD position, false if
-     *         not.
-     */
-    private boolean getCADPosition() {
+     * not.
+     */
+    private boolean getCADPosition()
+    {
 
         Vector<Integer> positions = new Vector<Integer>();
         for (int i = 0; i < 10; i++)
+        {
             positions.add(i);
+        }
 
         Object cadPos = null;
 
-        while (true) {
+        while (true)
+        {
             cadPos = JOptionPane.showInputDialog(null,
                     "Please assign this workstation a CAD position number.",
@@ -407,17 +332,20 @@
 
             // If the user pressed cancel, confirm the exit and return false.
-            if (cadPos == null) {
+            if (cadPos == null)
+            {
                 if (JOptionPane
                         .showConfirmDialog(
-                                null,
-                                "CAD Client cannot load until a valid CAD "
-                                        + "position has been selected.  Do you wish to "
-                                        + "cancel loading the CAD Client?",
-                                "Confirm Exit", JOptionPane.YES_NO_OPTION,
-                                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
+                        null,
+                        "CAD Client cannot load until a valid CAD "
+                        + "position has been selected.  Do you wish to "
+                        + "cancel loading the CAD Client?",
+                        "Confirm Exit", JOptionPane.YES_NO_OPTION,
+                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
+                {
                     return false;
-            }
-            // Else the user selected a CAD position, exit the loop.
-            else {
+                }
+            } // Else the user selected a CAD position, exit the loop.
+            else
+            {
                 break;
             }
@@ -433,35 +361,40 @@
      * cancels the method returns false, else the Properties object is updated
      * and true is returned.
-     * 
+     *
      * @return True if the user successfully selected a CAD position, false if
-     *         not.
-     */
-    private boolean getUserID() {
+     * not.
+     */
+    private boolean getUserID()
+    {
         String cadUID = null;
 
-        while (true) {
+        while (true)
+        {
             cadUID = JOptionPane.showInputDialog(null,
                     "Please assign this workstation a 6-character CAD "
-                            + "User ID.", "CAD User ID Asignment",
+                    + "User ID.", "CAD User ID Asignment",
                     JOptionPane.QUESTION_MESSAGE);
 
             // /If the user pressed cancel, confirm the exit and return false.
-            if (cadUID == null) {
+            if (cadUID == null)
+            {
                 if (JOptionPane.showConfirmDialog(null,
                         "CAD Client cannot load until a valid User ID "
-                                + "has been entered.  Do you wish to "
-                                + "cancel loading the CAD Client?",
+                        + "has been entered.  Do you wish to "
+                        + "cancel loading the CAD Client?",
                         "Confirm Exit", JOptionPane.YES_NO_OPTION,
                         JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
+                {
                     return false;
-            }
-            // If the user does not enter a valid User ID, notify and reprompt.
-            else if (cadUID.length() != 6) {
+                }
+            } // If the user does not enter a valid User ID, notify and reprompt.
+            else if (cadUID.length() != 6)
+            {
                 JOptionPane.showMessageDialog(null,
                         "The User ID must be 6 characters.", "Invalid User ID",
                         JOptionPane.WARNING_MESSAGE);
-            }
-            // Else the user entered a valid value, exit the loop.
-            else {
+            } // Else the user entered a valid value, exit the loop.
+            else
+            {
                 break;
             }
@@ -475,18 +408,21 @@
      * Construct the CADClient with the properties file path, either from the
      * command line arguments or default.
-     * 
-     * @param args
-     *            Command line arguments.
-     */
-    public static void main(String[] args) {
-    	if(System.getProperty("CONFIG_DIR") == null){
-        	System.setProperty("CONFIG_DIR", "config");
-        }
-
-        try {
+     *
+     * @param args Command line arguments.
+     */
+    public static void main(String[] args)
+    {
+        if (System.getProperty("CONFIG_DIR") == null)
+        {
+            System.setProperty("CONFIG_DIR", "config");
+        }
+
+        try
+        {
             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
             new CADClockDisplay(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME);
-         
-        } catch (Exception e) {
+
+        } catch (Exception e)
+        {
             cadClientLogger.logp(Level.SEVERE, "SimulationManager", "Main",
                     "Error initializing application.");
@@ -500,14 +436,20 @@
     }
 
-    public void refresh() {
+    public void refresh()
+    {
         theClientGUI.screen.refreshScreens();
     }
 
-    public void ensureProperShutdown() {
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            public void run() {
-                try {
+    public void ensureProperShutdown()
+    {
+        Runtime.getRuntime().addShutdownHook(new Thread()
+        {
+            public void run()
+            {
+                try
+                {
                     theCoorInt.unregisterForCallback(client);
-                } catch (RemoteException e) {
+                } catch (RemoteException e)
+                {
                     e.printStackTrace();
                 }
@@ -515,4 +457,3 @@
         });
     }
-
 }
