Index: trunk/src/tmcsim/client/CADClockDisplay.java
===================================================================
--- trunk/src/tmcsim/client/CADClockDisplay.java	(revision 61)
+++ trunk/src/tmcsim/client/CADClockDisplay.java	(revision 62)
@@ -1,4 +1,6 @@
 package tmcsim.client;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -7,6 +9,4 @@
 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;
@@ -14,9 +14,8 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
-
 import javax.swing.JOptionPane;
 import javax.swing.JWindow;
+import javax.swing.Timer;
 import javax.swing.UIManager;
-
 import tmcsim.client.cadclientgui.CADClientGUI;
 import tmcsim.common.SimulationException;
@@ -25,37 +24,11 @@
 
 /**
- * CADClient is the main class for the CAD Client application. The main method
- * instantiates an instance of the CADClient object with the default properties
- * file "..\config\CADClient.properties" or the first argument fom the command
- * line invocation. Properties data values are used to bind socket communication
- * between the CAD Client and the CAD Simulator. The CADClientModel object is
- * instantiated and the CAD Client registers itself with the CAD Simulator.
- * Finally, the CADClockView is initialized, the model-view and observer
- * relationships are established, and the view is shown.<br>
- * <br>
- * The properties file contains the following data: <br>
- * <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>
- * -----------------------------------------------------------------------------<br>
- * Example File: <br>
- * CADSimulatorHost = localhost<br>
- * CADSimulatorSocketPort = 4444<br>
- * CADPosition = 1 <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 $
+ * CADClockDisplay shows the simulation clock time. It operates as a client of
+ * the CAD server, using RMI to poll the server every second for the current
+ * simulation clock time.
  */
 public class CADClockDisplay extends UnicastRemoteObject implements
         CADClientInterface
 {
-
     /**
      * Error logger.
@@ -72,5 +45,4 @@
     private static enum PROPERTIES
     {
-
         CAD_SIM_HOST("CADSimulatorHost"), CAD_SIM_PORT("CADSimulatorSocketPort"), CAD_RMI_PORT(
         "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID(
@@ -114,24 +86,9 @@
     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);
-    }
-    
+    private final static int ONE_SECOND = 1000;
+
     /**
      * Constructor. Initialize data from parsed properties file. Create a socket
-     * connection to the CADSimulator. The ClientScreenModel is initialized with
-     * the input and output I/O streams for socket communication. The
-     * ClientScreenModel registers with the CAD Simulator, using CAD position
-     * 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.
+     * connection to the CADSimulator.
      *
      * @param propertiesFile File path (absolute or relative) to the properties
@@ -149,27 +106,23 @@
                 cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim());
 
-        // Instantiate the CADScreenView and set up the model-view observer
-        // relationship.
         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();
-
+        // Create a timer that fetches the simulation time every second.
+        Timer timer = new Timer(ONE_SECOND, new ActionListener()
+        {
+            public void actionPerformed(ActionEvent e)
+            {
+                try
+                {
+                    long simtime = theCoorInt.getCurrentSimulationTime();
+                    theClientScreenView.updateTime("" + formatInterval(simtime));
+                } catch (RemoteException ex)
+                {
+                    Logger.getLogger(CADClockDisplay.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }
+        });
+        timer.start();
 
         ensureProperShutdown();
@@ -259,5 +212,6 @@
                     cadClientProp.store(new FileOutputStream(propertiesFile),
                             "");
-                } else
+                }
+                else
                 {
                     throw new SimulationException(
@@ -277,5 +231,6 @@
                     cadClientProp.store(new FileOutputStream(propertiesFile),
                             "");
-                } else
+                }
+                else
                 {
                     throw new SimulationException(
@@ -457,3 +412,17 @@
         });
     }
+
+    /**
+     * Format a time in seconds as HH:MM:SS
+     *
+     * @param l
+     * @return
+     */
+    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);
+    }
 }
