Index: trunk/test/atmsdriver/TrafficModelEventDriver.java
===================================================================
--- trunk/src/tmcsim/client/ATMSBatchDriver.java	(revision 184)
+++ trunk/test/atmsdriver/TrafficModelEventDriver.java	(revision 192)
@@ -1,5 +1,5 @@
-package tmcsim.client;
-
-import atmsdriver.ConsoleTrafficDriver;
+package atmsdriver;
+
+import tmcsim.client.*;
 import atmsdriver.model.Highways;
 import atmsdriver.model.TrafficEvent;
@@ -9,5 +9,4 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.rmi.Naming;
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
@@ -36,19 +35,11 @@
 /**
  * Skeleton for ATMS Driver that reads a "batch" file of highway status update
- * commands. It operates as a client of the CAD server, using RMI to poll the
- * server every second for the current simulation clock time. It uses the
- * simulation clock time to fire update commands at the desired time. Note: Sim
- * Mgr must be running before starting this application. TODO: We probably want
- * to be able to "override" a command, to force clearing an incident.
- *
+ * commands.  A console display of the highway network is output
+ * for each event.
  * @author jdalbey
  */
-public class ATMSBatchDriver extends UnicastRemoteObject implements
+public class TrafficModelEventDriver extends UnicastRemoteObject implements
         CADClientInterface
 {
-
-    private static final String CONFIG_FILE_NAME = "cad_client_config.properties";
-    private final static int ONE_SECOND = 1000;
-    private static final int FEPSIM_INTERVAL = 30000;
     private final static SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
     /**
@@ -64,43 +55,4 @@
 
     /**
-     * Enumeration containing properties name values. See CADClient class
-     * description for more information.
-     *
-     * @author Matthew Cechini
-     * @see CADClient
-     */
-    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");
-        public String name;
-
-        private PROPERTIES(String n)
-        {
-            name = n;
-        }
-    }
-    /**
-     * CADClientSocket Object to handle socket communication between the Client
-     * and CAD Simulator.
-     */
-    private CADClientSocket theClientSocket;
-
-    /**
-     * Properties object for the CADClient class.
-     */
-    private Properties cadClientProp;
-    /**
-     * RMI interface for communication with the remote Coordinator.
-     */
-    private static CoordinatorInterface theCoorInt;
-    /**
-     * reference to itself to be used for disconnecting from CADSimulator
-     */
-    private CADClientInterface client = this;
-
-    /**
      * Highways in traffic network
      */
@@ -115,14 +67,4 @@
      */
     private Map<String, List<TrafficEvent>> incidents;
-
-    /**
-     * Instance of ConsoleTrafficDriver that contains the highway model
-     */
-    private ConsoleTrafficDriver console;
-
-    /**
-     * GUI for this driver
-     */
-    private ATMSBatchViewer theView;
 
     /**
@@ -133,11 +75,6 @@
      * file containing configuration data.
      */
-    public ATMSBatchDriver(String propertiesFile) throws SimulationException,
-            RemoteException
-    {
-        if (!verifyProperties(propertiesFile))
-        {
-            System.exit(0);
-        }
+    public TrafficModelEventDriver() throws RemoteException
+    {
         // Initialize the highway model
         incidents = new HashMap<String, List<TrafficEvent>>();
@@ -147,80 +84,22 @@
                 "localhost", 8080);
 
-        connect(cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(),
-                cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim());
-
         // READ THE BATCH FILE OF COMMANDS and put in a queue
         readBatchFile();
-        // Launch the display
-        theView = new ATMSBatchViewer(this, new ArrayList<String>(incidents.keySet()));
-        theView.setVisible(true);
-        theView.update("0:00", "1:11", eventQueue);
-
-        // Create a timer that fetches the simulation time every second.
-        Timer timer = new Timer(ONE_SECOND, new ActionListener()
-        {
-            // Every second, see if an event should be launched
-            public void actionPerformed(ActionEvent e)
-            {
-                String currentClock = "";
-                String currentATMStime = "";
-                Date simClock = new Date();
-                // Obtain the simulation time from the CAD server
-                try
-                {
-                    long simtime = theCoorInt.getCurrentSimulationTime();
-                    currentClock = formatInterval(simtime);
-                    // For Debugging, show the ATMS time
-//                    long ATMStime = theCoorInt.getATMStime();       
-//                    Date atmsdate = new Date(ATMStime);
-//                    currentATMStime = formatter.format(atmsdate);
-                    try
-                    {
-                        simClock = formatter.parse(currentClock);
-                    }
-                    catch (ParseException ex)
-                    {
-                        Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex);
-                        System.out.println("Invalid simulation clock time found in ATMSDriverClient");
-                        System.exit(-1);
-                    }
-                    //System.out.println("Current clock: " + currentClock);
-                }
-                catch (RemoteException ex)
-                {
-                    System.out.println("Remote Exception reading sim or ATMS clock time");
-                    Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex);
-                }
-                // If we have any events left to process
-                if (!eventQueue.isEmpty())
-                {
-                    // Get the time to launch the next event
-                    TrafficEvent nextEvent = eventQueue.peek();
-                    Date eventTime = nextEvent.eventDate;
-                    //System.out.println("Next event will be launched at: " + formatter.format(eventTime));
-                    // Check the queue of events to see if the first
-                    // item should be launched.  IF so, 
-                    // issue that command and remove it from queue.
-                    if (eventTime.before(simClock) || eventTime.equals(simClock))
-                    {
-                        System.out.println("LAUNCHING EVENT: " + nextEvent.toString());
-                        // apply colorization to highways
-                        highways.applyColorToHighwayStretch(nextEvent.routeNumber, nextEvent.dir,
-                                nextEvent.postmile, nextEvent.range, nextEvent.color);
-                        // Remove this event from the queue, we're done with it.
-                        eventQueue.remove();
-                    }
-
-                    theView.update(currentClock, currentATMStime, eventQueue);
-                }
-            }
-        });
-        timer.start();
-
-        // Start the FEP thread (to update ATMS every 30 sec). (See class def below)
-        Thread wtfep = new WriteToFEPThread();
-        wtfep.start();
-
-        ensureProperShutdown();
+
+        // If we have any events left to process
+        while (!eventQueue.isEmpty())
+        {
+            // Get the time to launch the next event
+            TrafficEvent nextEvent = eventQueue.peek();
+            System.out.println("LAUNCHING EVENT: " + nextEvent.toString());
+            // apply colorization to highways
+            highways.applyColorToHighwayStretch(nextEvent.routeNumber, nextEvent.dir,
+                    nextEvent.postmile, nextEvent.range, nextEvent.color);
+            System.out.println(highways.toString());
+            // Remove this event from the queue, we're done with it.
+            eventQueue.remove();
+
+        }
+
     }
 
@@ -262,5 +141,5 @@
                     catch (ParseException ex)
                     {
-                        Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex);
+                        Logger.getLogger(TrafficModelEventDriver.class.getName()).log(Level.SEVERE, null, ex);
                         System.out.println("Wrong format data in batch event file: " + line + " \nskipping.");
                         System.out.println("Skipping badly formatted event.");
@@ -271,115 +150,9 @@
         catch (FileNotFoundException ex)
         {
-            Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex);
+            Logger.getLogger(TrafficModelEventDriver.class.getName()).log(Level.SEVERE, null, ex);
         }
         System.out.println("Events file read, " + eventQueue.size() + " events queued.");
         // Put the events in chronological order
         Collections.sort(eventQueue);
-    }
-
-    /**
-     * Clear an incident. For each event associated with an incident, turn the
-     * dots in its range Green and remove it from the event queue.
-     *
-     * @param incidentNumber incident to be cleared.
-     */
-    public void clearIncident(String incidentNumber)
-    {
-        boolean ok = incidents.containsKey(incidentNumber);
-        if (!ok)
-        {
-            System.out.println("Sorry, that incident number isn't found.");
-            return;
-        }
-        System.out.println("Clearing incident " + incidentNumber);
-        List<TrafficEvent> events = incidents.get(incidentNumber);
-        // Process each event associated with this incident 
-        for (TrafficEvent event : events)
-        {
-            System.out.println("Event: " + event + " cleared.");
-            eventQueue.remove(event);
-
-            // apply colorization to highways, forcing to green, indicating cleared
-            highways.applyColorToHighwayStretch(event.routeNumber, event.dir,
-                    event.postmile, event.range, DOTCOLOR.GREEN);
-
-        }
-        // Now refresh the view with the updated queue of events
-        theView.update("0:00", "0:00", eventQueue);
-    }
-
-    /**
-     * 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.
-     */
-    protected void connect(String hostname, String portNumber)
-            throws SimulationException
-    {
-
-        String coorIntURL = "";
-
-        try
-        {
-            coorIntURL = "rmi://" + hostname + ":" + portNumber
-                    + "/coordinator";
-            theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL);
-            theCoorInt.registerForCallback(this);
-        }
-        catch (Exception e)
-        {
-            throw new SimulationException(SimulationException.CAD_SIM_CONNECT,
-                    e);
-
-        }
-    }
-
-    /**
-     * This method verifies that the CAD Simulator Host and Port values are not
-     * null. Also, if a CAD Position or User ID do not exist in the properties
-     * file, the user is prompted to enter values. These values are written to
-     * 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.
-     * @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.
-     */
-    private boolean verifyProperties(String propertiesFile)
-            throws SimulationException
-    {
-
-        // Load the properties file.
-        try
-        {
-            cadClientProp = new Properties();
-            cadClientProp.load(new FileInputStream(propertiesFile));
-        }
-        catch (Exception e)
-        {
-            cadClientLogger.logp(Level.SEVERE, "SimulationManager",
-                    "Constructor", "Exception in reading properties file.", e);
-
-            throw new SimulationException(SimulationException.INITIALIZE_ERROR,
-                    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)
-        {
-            cadClientLogger.logp(Level.SEVERE, "SimulationManager",
-                    "Constructor", "Null value in properties file.");
-            throw new SimulationException(SimulationException.INITIALIZE_ERROR);
-        }
-
-        return true;
     }
 
@@ -397,23 +170,4 @@
         return String.format("%02d:%02d:%02d", hr, min, sec);
     }
-
-    public void ensureProperShutdown()
-    {
-        Runtime.getRuntime().addShutdownHook(new Thread()
-        {
-            public void run()
-            {
-                try
-                {
-                    theCoorInt.unregisterForCallback(client);
-                }
-                catch (RemoteException e)
-                {
-                    e.printStackTrace();
-                }
-            }
-        });
-    }
-
     /**
      * Construct the CADClient with the properties file path, either from the
@@ -432,5 +186,5 @@
         {
             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-            new ATMSBatchDriver(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME);
+            new TrafficModelEventDriver();
 
         }
@@ -448,41 +202,3 @@
     }
 
-    class WriteToFEPThread extends Thread
-    {
-
-        public void run()
-        {
-            System.out.println("WriteToFEP Thread starting.");
-            // Run indefinitely
-            while (true)
-            {
-                try
-                {
-                    // Write the highway network status to the FEP Simulator
-                    highways.writeToFEP();
-                }
-                catch (SimulationException ex)
-                {
-                    // Ask user if they want to proceed without FEP Sim connection
-                    int reply = JOptionPane.showConfirmDialog(null, "Failed to connect to FEP Sim, proceed anyway?", "Network Failure", JOptionPane.YES_NO_OPTION);
-                    if (reply == JOptionPane.NO_OPTION)
-                    {
-                        System.exit(0);
-                    }
-                    System.out.println("Skipping writeToFEP...");
-                }
-
-                // Wait for FEP Sim to process the data we just sent
-                try
-                {
-                    Thread.sleep(FEPSIM_INTERVAL);
-                }
-                catch (InterruptedException ie)
-                {
-                    ie.printStackTrace();
-                }
-            }
-
-        }
-    }
 }
