Index: trunk/src/tmcsim/paramicslog/ParamicsLog.java
===================================================================
--- trunk/src/tmcsim/paramicslog/ParamicsLog.java	(revision 33)
+++ trunk/src/tmcsim/paramicslog/ParamicsLog.java	(revision 47)
@@ -10,9 +10,5 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
-
 import javax.swing.JOptionPane;
-
-import org.w3c.dom.Element;
-
 import tmcsim.common.SimulationException;
 import tmcsim.interfaces.CoordinatorInterface;
@@ -21,40 +17,38 @@
 /**
  * Logs communication from ParamicsCommunicator to ParamicsSimulator.
- * 
- * The system property "PARAMICS_LOG_CONFIG" should be set to the path
- * where the properties file for this class is located. <br><br>
+ *
+ * The system property "PARAMICS_LOG_CONFIG" should be set to the path where the
+ * properties file for this class is located. <br><br>
  * The data for the properties file follows. <br>
  * <code>
  * -----------------------------------------------------------------<br>
- * Log File                The file to write the communication to.
- * CAD Simulator Host      The host that runs the CAD Simulator.
- * CAD Simulator RMI Port  The port on the host that runs the CAD 
- *                         Simulator where the RMI Coordinator
- *                         object is registered to. 
+ * Log File The file to write the communication to. CAD Simulator Host The host
+ * that runs the CAD Simulator. CAD Simulator RMI Port The port on the host that
+ * runs the CAD Simulator where the RMI Coordinator object is registered to.
  * -----------------------------------------------------------------<br>
  * Example File: <br>
- * LogFile=c:\\log.txt
- * CADSimulatorHost=localhost
- * CADSimulatorRMIPort=4445
+ * LogFile=c:\\log.txt CADSimulatorHost=localhost CADSimulatorRMIPort=4445
  * -----------------------------------------------------------------<br>
  * </code>
- * 
+ *
  * @author Nathaniel Lehrer
- * @version 
+ * @version
  */
-public class ParamicsLog extends Observable 
-{   
+public class ParamicsLog extends Observable
+{
+
     /**
      * Enmeration containing property names.
+     *
      * @author Nathaniel Lehrer
      */
-    private enum PROPERTIES 
-    {
-        LOG_FILE      ("LogFile"),
-        CAD_SIM_HOST  ("CADSimulatorHost"),
-        CAD_SIM_PORT  ("CADSimulatorRMIPort");
-        
+    private enum PROPERTIES
+    {
+
+        LOG_FILE("LogFile"),
+        CAD_SIM_HOST("CADSimulatorHost"),
+        CAD_SIM_PORT("CADSimulatorRMIPort");
         public String name;
-        
+
         private PROPERTIES(String n)
         {
@@ -62,79 +56,92 @@
         }
     }
-
-	private static final String CONFIG_FILE_NAME = "paramics_communicator_logging.properties";
-    
-    /** Error logger. */
+    private static final String CONFIG_FILE_NAME = "paramics_communicator_logging.properties";
+    /**
+     * Error logger.
+     */
     private static Logger paramLogger = Logger.getLogger("tmcsim.paramicslog");
-    
-    /** Static instance. */
+    /**
+     * Static instance.
+     */
     private static ParamicsLog instance;
-    
-    /** Properties object. */
+    /**
+     * Properties object.
+     */
     private Properties paramicsLogProp;
-    
-    /** File log entries are written to */
+    /**
+     * File log entries are written to
+     */
     private File logFile;
-    
-    /** Stores the log entries. This contains the same information logFile. */
+    /**
+     * Stores the log entries. This contains the same information logFile.
+     */
     private StringBuilder log;
-
-    /** Remote reference to the simulation */
+    /**
+     * Remote reference to the simulation
+     */
     private CoordinatorInterface theCoorInt;
-    
-    /** Object for synchronizing IO */
+    /**
+     * Object for synchronizing IO
+     */
     Object lock;
-    
+
     /**
      * Creates the singleton instance of this class.
      */
-    static {
-        try {
-        	if(System.getProperty("CONFIG_DIR") == null){
-            	System.setProperty("CONFIG_DIR", "config");
-            }
-        	
-        	instance = new ParamicsLog(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME);
-        } 
-        catch (Exception e) 
+    static
+    {
+        try
+        {
+            if (System.getProperty("CONFIG_DIR") == null)
+            {
+                System.setProperty("CONFIG_DIR", "config");
+            }
+
+            instance = new ParamicsLog(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME);
+        } catch (Exception e)
         {
             instance = new ParamicsLog();
-            
-            paramLogger.logp(Level.WARNING, "ParamicsLog", "static initializer", 
+
+            paramLogger.logp(Level.WARNING, "ParamicsLog", "static initializer",
                     "Error occured initializing application", e);
 
-            JOptionPane.showMessageDialog(null, e.getMessage(), 
-                    "Error - ParamicsLog will not save log to file.", 
-                    JOptionPane.ERROR_MESSAGE); 
-        }
-        
+            JOptionPane.showMessageDialog(null, e.getMessage(),
+                    "Error - ParamicsLog will not save log to file.",
+                    JOptionPane.ERROR_MESSAGE);
+        }
+
         instance.addObserver(ParamicsLogGUI.getInstance());
     }
-    
-    /**
-     * Creates an instance of ParamicsLog that does not write to a file when 
+
+    /**
+     * Creates an instance of ParamicsLog that does not write to a file when
      * writeToLog is called.
      */
-    private ParamicsLog() {
-        
+    private ParamicsLog()
+    {
+
         lock = new Object();
         log = new StringBuilder("");
     }
-    
-    /**
-     * Creates an instance of ParamicsLog that writes to a file when writeToLog is called.
+
+    /**
+     * Creates an instance of ParamicsLog that writes to a file when writeToLog
+     * is called.
+     *
      * @param propertiesFile
      */
-    private ParamicsLog(String propertiesFile) {
+    private ParamicsLog(String propertiesFile)
+    {
         this();
-        
+
         String logFile = null;
         String CADSIMHost = null;
         String CADSIMPort = null;
-        
-        try {
+
+        try
+        {
             paramicsLogProp = new Properties();
             paramicsLogProp.load(new FileInputStream(propertiesFile));
-            
+
             if ((logFile = paramicsLogProp.getProperty(PROPERTIES.LOG_FILE.name)) == null)
             {
@@ -142,5 +149,5 @@
             }
             else if ((CADSIMHost = paramicsLogProp.getProperty(PROPERTIES.CAD_SIM_HOST.name)) == null)
-            {   
+            {
                 throw new Exception("Properties file missing CAD Simulator host.");
             }
@@ -149,40 +156,40 @@
                 throw new Exception("Properties file missing CAD Simulator RMI port.");
             }
-            
+
             try
             {
                 connect(CADSIMHost, CADSIMPort);
-            }
-            catch (Exception e)
-            {
-                JOptionPane.showMessageDialog(null, 
-                        "ParamicsLog: Could not connect to remote Coordinator object.", 
-                        "Network Error", JOptionPane.ERROR_MESSAGE);                
-            }
-            
-            try 
+            } catch (Exception e)
+            {
+                JOptionPane.showMessageDialog(null,
+                        "ParamicsLog: Could not connect to remote Coordinator object.",
+                        "Network Error", JOptionPane.ERROR_MESSAGE);
+            }
+
+            try
             {
                 createLogFile(logFile);
-            }
-            catch (Exception e)
-            {
-                JOptionPane.showMessageDialog(null, 
-                        "ParamicsLog: Could not create new log file.", 
+            } catch (Exception e)
+            {
+                JOptionPane.showMessageDialog(null,
+                        "ParamicsLog: Could not create new log file.",
                         "File Error", JOptionPane.ERROR_MESSAGE);
             }
-            
-        } catch (Exception e) {
-            
-            paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 
+
+        } catch (Exception e)
+        {
+
+            paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor",
                     "Properties file incorrect or missing.", e);
-            
-            JOptionPane.showMessageDialog(null, 
-                    "ParamicsLog: Properties file invalid.", 
+
+            JOptionPane.showMessageDialog(null,
+                    "ParamicsLog: Properties file invalid.",
                     "Invalid Configuration", JOptionPane.ERROR_MESSAGE);
         }
     }
-    
+
     /**
      * Creates the log file.
+     *
      * @param filePath The path to the file including the file name.
      * @throws IOException If the log file could not be created.
@@ -190,69 +197,78 @@
     private void createLogFile(String filePath) throws IOException
     {
-        try {
+        try
+        {
             logFile = new File(filePath);
-            
-            if (logFile.exists()) {
+
+            if (logFile.exists())
+            {
                 logFile.delete();
             }
-            
+
             logFile.createNewFile();
-            
-        } catch (Exception e) {
-            
+
+        } catch (Exception e)
+        {
+
             logFile = null;
-            
-            paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 
+
+            paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor",
                     "Could not create new log file.", e);
-            
+
             throw new IOException("Could not create log file.");
-        }               
-    }
-    
+        }
+    }
+
     /**
      * Connect to the Coordinator's RMI object.
-     * @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.
-     */ 
-    private void connect(String hostname, String portNumber) 
-        throws SimulationException {
-        
+     *
+     * @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.
+     */
+    private void connect(String hostname, String portNumber)
+            throws SimulationException
+    {
+
         String coorIntURL = "";
-        
-        try {  
-            coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator"; 
-            
-            theCoorInt = (CoordinatorInterface)Naming.lookup(coorIntURL);           
-        }
-        catch (Exception e) 
-        {
-            paramLogger.logp(Level.WARNING, "ParamicsLog", 
-                    "establishRMIConnection", "Unable to establish RMI " +
-                    "communication with the CAD Simulator.  URL <" + coorIntURL + ">", e);
-        }   
-    }
-    
+
+        try
+        {
+            coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator";
+
+            theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL);
+        } catch (Exception e)
+        {
+            paramLogger.logp(Level.WARNING, "ParamicsLog",
+                    "establishRMIConnection", "Unable to establish RMI "
+                    + "communication with the CAD Simulator.  URL <" + coorIntURL + ">", e);
+        }
+    }
+
     /**
      * Accessor to the entries in the log. No file IO is used.
+     *
      * @return The entries in the log.
      */
-    public String getLog() {
-        
+    public String getLog()
+    {
+
         return log.toString();
     }
-    
-    /**
-     * Writes an entry to the log. 
-     * The simulator time when the message was sent is prepended to the entry.
-     * Entries are padded by a blank line before and after them.
-     * TODO: Ensure output is written in order of request.
+
+    /**
+     * Writes an entry to the log. The simulator time when the message was sent
+     * is prepended to the entry. Entries are padded by a blank line before and
+     * after them. TODO: Ensure output is written in order of request.
+     *
      * @param entry
      */
-    public void writeToLog(String entry) {
-        
+    public void writeToLog(String entry)
+    {
+
         String time = "?";
         String formattedEntry;
-        
+
         if (theCoorInt != null)
         {
@@ -260,20 +276,19 @@
             {
                 time = formatTime(theCoorInt.getCurrentSimulationTime());
-            }
-            catch (Exception e)
-            {
-                paramLogger.logp(Level.WARNING, "ParamicsLog", 
+            } catch (Exception e)
+            {
+                paramLogger.logp(Level.WARNING, "ParamicsLog",
                         "RMICommunication", "Unable to communicate with RMI object", e);
             }
         }
-        
+
         formattedEntry = "\n" + "<!-- Time written to file: " + time + " -->\n" + entry + "\n";
         log.append(formattedEntry);
-        
+
         if (logFile != null)
         {
-            try 
-            {
-                synchronized(lock)
+            try
+            {
+                synchronized (lock)
                 {
                     FileWriter writer = new FileWriter(logFile, true);
@@ -282,21 +297,21 @@
                     writer.close();
                 }
-            } 
-            catch (IOException e) 
-            {
-                paramLogger.logp(Level.WARNING, "ParamicsLog", "writeToLog", 
+            } catch (IOException e)
+            {
+                paramLogger.logp(Level.WARNING, "ParamicsLog", "writeToLog",
                         "Could not write to log file.", e);
             }
         }
-        
+
         setChanged();
         notifyObservers(entry);
     }
-    
+
     /**
      * Formats the time given in seconds to hh:mm:ss format.
+     *
      * @param time The time in seconds.
      */
-    private String formatTime(long time)
+    public String formatTime(long time)
     {
         long seconds = time % 60;
@@ -306,5 +321,5 @@
         return padr(hours) + ":" + padr(minutes) + ":" + padr(seconds);
     }
-    
+
     private String padr(long n)
     {
@@ -317,11 +332,13 @@
         }
     }
-    
+
     /**
      * Accessor for static instance of this class.
+     *
      * @return The instance of this class.
      */
-    public static ParamicsLog getInstance() {
-        
+    public static ParamicsLog getInstance()
+    {
+
         return instance;
     }
