Changeset 47 in tmcsimulator for trunk


Ignore:
Timestamp:
06/28/2016 02:25:42 PM (10 years ago)
Author:
jdalbey
Message:

Merge 305 modifications into trunk.

Location:
trunk
Files:
20 added
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/IDE_metadata/NetBeans/TMCSim/build.xml

    r44 r47  
    7171    <!--         *** Build a jar with everything ***            --> 
    7272    <property name="deploy.jar.name" value="TMCSimAll"/> 
    73     <property name="deploy.dir" value="deploy"/> 
     73    <property name="deploy.dir" value="${workdir}/deploy"/> 
    7474    <property name="deploy.jar" value="${deploy.dir}/${deploy.jar.name}.jar"/> 
    7575 
  • trunk/src/tmcsim/application.properties

    r44 r47  
    1 #Thu, 23 Jun 2016 19:19:14 -0700 
     1#Tue, 28 Jun 2016 14:56:40 -0700 
    22 
    3 Application.revision=43 
     3Application.revision=44 
    44 
    5 Application.buildnumber=1 
     5Application.buildnumber=10 
  • trunk/src/tmcsim/paramicscommunicator/ParamicsCommunicator.java

    r33 r47  
    1919import java.util.logging.Level; 
    2020import java.util.logging.Logger; 
    21  
     21import javax.swing.JFrame; 
    2222import javax.swing.JOptionPane; 
    2323import javax.swing.UIManager; 
     
    140140    public ParamicsCommunicator(String propertiesFile) 
    141141    { 
     142        paramLogger.logp(Level.INFO, "ParamicsCommunicator", "Constructor", 
     143                "Entering "); 
    142144 
    143145        writers = new TreeMap<String, ParamicsFileWriter>(); 
    144146        readers = new TreeMap<String, ParamicsFileReader>(); 
    145147 
     148        theGUI = new ParamicsCommunicatorGUI(); 
     149        addObserver(theGUI); 
     150        theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    146151        try 
    147152        { 
     
    301306                        "Dropped Connection", JOptionPane.ERROR_MESSAGE); 
    302307                break; 
     308            } 
     309            try 
     310            { 
     311                Thread.sleep(2000); 
     312                paramLogger.logp(Level.INFO, "ParamicsCommunicator", 
     313                        "run", "sleeping."); 
     314            } catch (InterruptedException ex) 
     315            { 
     316                paramLogger.logp(Level.INFO, "ParamicsCommunicator", 
     317                        "run", "Exception in reading data from the socket.", ex); 
    303318            } 
    304319        } 
     
    456471            } catch (SocketTimeoutException ste) 
    457472            { 
    458                 System.out.println("...waiting for socket connection from the CAD Simulator..."); 
     473                System.out.println("...waiting..."); 
     474                try 
     475                { 
     476                    Thread.sleep(2000); 
     477                    paramLogger.logp(Level.INFO, "ParamicsCommunicator", 
     478                            "initializeSockets", "sleeping."); 
     479                } catch (InterruptedException ex) 
     480                { 
     481                    paramLogger.logp(Level.INFO, "ParamicsCommunicator", 
     482                            "initializeSockets", "Exception exiting for socket.", ex); 
     483                } 
    459484            } catch (IOException ioe) 
    460485            { 
     
    462487                        + "the receiving socket on port " + socketPort); 
    463488            } 
     489 
    464490        } 
    465491 
  • trunk/src/tmcsim/paramicscommunicator/ParamicsFileReader.java

    r40 r47  
    55import java.io.FileWriter; 
    66import java.io.IOException; 
     7import java.text.SimpleDateFormat; 
    78import java.util.Observable; 
    89import java.util.Timer; 
     
    6768     */ 
    6869    private long readerInterval; 
     70    /** 
     71     * Time formatter for diagnostic messages 
     72     */ 
     73    private SimpleDateFormat formatter; 
    6974 
    7075    /** 
     
    8085        public void run() 
    8186        { 
    82 //            paramLogger.logp(Level.INFO, 
    83 //                    "ParamicsFileReader.ReaderTimerTask", "run()", 
    84 //                    "Waiting for " + inputFile + " to be modified."); 
     87//            System.out.println( 
     88//                    "Checking last modified time on " + inputFile.getName() 
     89//                    + formatter.format(lastModified) + ":" + formatter.format(inputFile.lastModified())); 
     90 
    8591            if (lastModified < inputFile.lastModified()) 
    8692            { 
    87 //                paramLogger.logp(Level.INFO, 
    88 //                        "ParamicsFileReader.ReaderTimerTask", "run()", 
    89 //                        "Cool, " + inputFile + " has been modified, let's read it."); 
    9093 
    9194                try 
     
    101104                    Element messageElem = readerDoc.createElement(PARAMICS_COMM_TAGS.MESSAGE.tag); 
    102105                    String fileContents = readFromFile(); 
    103  //                   int stringlen = Math.min(160, fileContents.length()-1); 
    104                     // Log two lines that were read 
    105 //                    paramLogger.logp(Level.INFO, 
    106 //                            "ParamicsFileReader.ReaderTimerTask", "run()", 
    107 //                            "Nice, we read " + fileContents.length() + " bytes."); 
    108106                    messageElem.appendChild(readerDoc.createTextNode(fileContents)); 
    109107                    readerElem.appendChild(messageElem); 
     
    142140        try 
    143141        { 
     142            formatter = new SimpleDateFormat("HH:mm:ss"); 
    144143            readerID = id; 
    145144            readerInterval = interval; 
     
    159158        { 
    160159            paramLogger.logp(Level.SEVERE, "ParamicsFileReader", 
    161                     "Constructor()", "Exception in initializing file reading.", ioe); 
     160                    "Constructor()", "Exception in initializing file reading of "+workingDir + targetFile, ioe); 
    162161        } 
    163162    } 
     
    194193 
    195194        lastModified = inputFile.lastModified(); 
     195//        System.out.println( 
     196//                "Read from a file last modified at " + formatter.format(lastModified)); 
    196197 
    197198        setChanged(); 
  • trunk/src/tmcsim/paramicscommunicator/gui/ParamicsCommunicatorGUI.java

    r29 r47  
    1111import java.util.logging.LogRecord; 
    1212import java.util.logging.Logger; 
    13  
    1413import javax.swing.BorderFactory; 
    1514import javax.swing.Box; 
     
    2120import javax.swing.JTabbedPane; 
    2221import javax.swing.JTextArea; 
    23  
    2422import tmcsim.common.RevisionNumber; 
    2523import tmcsim.paramicscommunicator.FileIOUpdate; 
     
    126124                        "Exception in receiving FileIOUpdate object.", e); 
    127125            } 
    128         } else if (arg instanceof FileRegUpdate) 
     126        } 
     127        else if (arg instanceof FileRegUpdate) 
    129128        { 
    130129            try 
     
    218217                BorderFactory.createRaisedBevelBorder(), "Registered Readers "), 
    219218                BorderFactory.createEmptyBorder(5, 5, 5, 5))); 
    220          
     219 
    221220        fileWriterTabs = new JTabbedPane(); 
    222221        fileWriterTabs.setAlignmentX(Box.CENTER_ALIGNMENT); 
     
    243242        tabbedBox.add(fileReaderTabs); 
    244243        tabbedBox.add(fileWriterTabs); 
    245          
     244 
    246245        Box guiBox = new Box(BoxLayout.Y_AXIS); 
    247246        guiBox.add(tabbedBox); 
     
    255254        setResizable(false); 
    256255        pack(); 
    257         setVisible(true); 
     256        //setVisible(true); 
    258257    } 
    259258 
     
    284283 
    285284    } 
    286      
    287285    private JTabbedPane fileReaderTabs; 
    288286    private JTabbedPane fileWriterTabs; 
  • trunk/src/tmcsim/paramicslog/ParamicsLog.java

    r33 r47  
    1010import java.util.logging.Level; 
    1111import java.util.logging.Logger; 
    12  
    1312import javax.swing.JOptionPane; 
    14  
    15 import org.w3c.dom.Element; 
    16  
    1713import tmcsim.common.SimulationException; 
    1814import tmcsim.interfaces.CoordinatorInterface; 
     
    2117/** 
    2218 * Logs communication from ParamicsCommunicator to ParamicsSimulator. 
    23  *  
    24  * The system property "PARAMICS_LOG_CONFIG" should be set to the path 
    25  * where the properties file for this class is located. <br><br> 
     19 * 
     20 * The system property "PARAMICS_LOG_CONFIG" should be set to the path where the 
     21 * properties file for this class is located. <br><br> 
    2622 * The data for the properties file follows. <br> 
    2723 * <code> 
    2824 * -----------------------------------------------------------------<br> 
    29  * Log File                The file to write the communication to. 
    30  * CAD Simulator Host      The host that runs the CAD Simulator. 
    31  * CAD Simulator RMI Port  The port on the host that runs the CAD  
    32  *                         Simulator where the RMI Coordinator 
    33  *                         object is registered to.  
     25 * Log File The file to write the communication to. CAD Simulator Host The host 
     26 * that runs the CAD Simulator. CAD Simulator RMI Port The port on the host that 
     27 * runs the CAD Simulator where the RMI Coordinator object is registered to. 
    3428 * -----------------------------------------------------------------<br> 
    3529 * Example File: <br> 
    36  * LogFile=c:\\log.txt 
    37  * CADSimulatorHost=localhost 
    38  * CADSimulatorRMIPort=4445 
     30 * LogFile=c:\\log.txt CADSimulatorHost=localhost CADSimulatorRMIPort=4445 
    3931 * -----------------------------------------------------------------<br> 
    4032 * </code> 
    41  *  
     33 * 
    4234 * @author Nathaniel Lehrer 
    43  * @version  
     35 * @version 
    4436 */ 
    45 public class ParamicsLog extends Observable  
    46 {    
     37public class ParamicsLog extends Observable 
     38{ 
     39 
    4740    /** 
    4841     * Enmeration containing property names. 
     42     * 
    4943     * @author Nathaniel Lehrer 
    5044     */ 
    51     private enum PROPERTIES  
    52     { 
    53         LOG_FILE      ("LogFile"), 
    54         CAD_SIM_HOST  ("CADSimulatorHost"), 
    55         CAD_SIM_PORT  ("CADSimulatorRMIPort"); 
    56          
     45    private enum PROPERTIES 
     46    { 
     47 
     48        LOG_FILE("LogFile"), 
     49        CAD_SIM_HOST("CADSimulatorHost"), 
     50        CAD_SIM_PORT("CADSimulatorRMIPort"); 
    5751        public String name; 
    58          
     52 
    5953        private PROPERTIES(String n) 
    6054        { 
     
    6256        } 
    6357    } 
    64  
    65         private static final String CONFIG_FILE_NAME = "paramics_communicator_logging.properties"; 
    66      
    67     /** Error logger. */ 
     58    private static final String CONFIG_FILE_NAME = "paramics_communicator_logging.properties"; 
     59    /** 
     60     * Error logger. 
     61    */ 
    6862    private static Logger paramLogger = Logger.getLogger("tmcsim.paramicslog"); 
    69      
    70     /** Static instance. */ 
     63    /** 
     64     * Static instance. 
     65     */ 
    7166    private static ParamicsLog instance; 
    72      
    73     /** Properties object. */ 
     67    /** 
     68     * Properties object. 
     69     */ 
    7470    private Properties paramicsLogProp; 
    75      
    76     /** File log entries are written to */ 
     71    /** 
     72     * File log entries are written to 
     73     */ 
    7774    private File logFile; 
    78      
    79     /** Stores the log entries. This contains the same information logFile. */ 
     75    /** 
     76     * Stores the log entries. This contains the same information logFile. 
     77     */ 
    8078    private StringBuilder log; 
    81  
    82     /** Remote reference to the simulation */ 
     79    /** 
     80     * Remote reference to the simulation 
     81     */ 
    8382    private CoordinatorInterface theCoorInt; 
    84      
    85     /** Object for synchronizing IO */ 
     83    /** 
     84     * Object for synchronizing IO 
     85     */ 
    8686    Object lock; 
    87      
     87 
    8888    /** 
    8989     * Creates the singleton instance of this class. 
    9090     */ 
    91     static { 
    92         try { 
    93                 if(System.getProperty("CONFIG_DIR") == null){ 
    94                 System.setProperty("CONFIG_DIR", "config"); 
    95             } 
    96                  
    97                 instance = new ParamicsLog(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
    98         }  
    99         catch (Exception e)  
     91    static 
     92    { 
     93        try 
     94        { 
     95            if (System.getProperty("CONFIG_DIR") == null) 
     96            { 
     97                System.setProperty("CONFIG_DIR", "config"); 
     98            } 
     99 
     100            instance = new ParamicsLog(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
     101        } catch (Exception e) 
    100102        { 
    101103            instance = new ParamicsLog(); 
    102              
    103             paramLogger.logp(Level.WARNING, "ParamicsLog", "static initializer",  
     104 
     105            paramLogger.logp(Level.WARNING, "ParamicsLog", "static initializer", 
    104106                    "Error occured initializing application", e); 
    105107 
    106             JOptionPane.showMessageDialog(null, e.getMessage(),  
    107                     "Error - ParamicsLog will not save log to file.",  
    108                     JOptionPane.ERROR_MESSAGE);  
    109         } 
    110          
     108            JOptionPane.showMessageDialog(null, e.getMessage(), 
     109                    "Error - ParamicsLog will not save log to file.", 
     110                    JOptionPane.ERROR_MESSAGE); 
     111        } 
     112 
    111113        instance.addObserver(ParamicsLogGUI.getInstance()); 
    112114    } 
    113      
    114     /** 
    115      * Creates an instance of ParamicsLog that does not write to a file when  
     115 
     116    /** 
     117     * Creates an instance of ParamicsLog that does not write to a file when 
    116118     * writeToLog is called. 
    117119     */ 
    118     private ParamicsLog() { 
    119          
     120    private ParamicsLog() 
     121    { 
     122 
    120123        lock = new Object(); 
    121124        log = new StringBuilder(""); 
    122125    } 
    123      
    124     /** 
    125      * Creates an instance of ParamicsLog that writes to a file when writeToLog is called. 
     126 
     127    /** 
     128     * Creates an instance of ParamicsLog that writes to a file when writeToLog 
     129     * is called. 
     130     * 
    126131     * @param propertiesFile 
    127132     */ 
    128     private ParamicsLog(String propertiesFile) { 
     133    private ParamicsLog(String propertiesFile) 
     134    { 
    129135        this(); 
    130          
     136 
    131137        String logFile = null; 
    132138        String CADSIMHost = null; 
    133139        String CADSIMPort = null; 
    134          
    135         try { 
     140 
     141        try 
     142        { 
    136143            paramicsLogProp = new Properties(); 
    137144            paramicsLogProp.load(new FileInputStream(propertiesFile)); 
    138              
     145 
    139146            if ((logFile = paramicsLogProp.getProperty(PROPERTIES.LOG_FILE.name)) == null) 
    140147            { 
     
    142149            } 
    143150            else if ((CADSIMHost = paramicsLogProp.getProperty(PROPERTIES.CAD_SIM_HOST.name)) == null) 
    144             {    
     151            { 
    145152                throw new Exception("Properties file missing CAD Simulator host."); 
    146153            } 
     
    149156                throw new Exception("Properties file missing CAD Simulator RMI port."); 
    150157            } 
    151              
     158 
    152159            try 
    153160            { 
    154161                connect(CADSIMHost, CADSIMPort); 
    155             } 
    156             catch (Exception e) 
    157             { 
    158                 JOptionPane.showMessageDialog(null,  
    159                         "ParamicsLog: Could not connect to remote Coordinator object.",  
    160                         "Network Error", JOptionPane.ERROR_MESSAGE);                 
    161             } 
    162              
    163             try  
     162            } catch (Exception e) 
     163            { 
     164                JOptionPane.showMessageDialog(null, 
     165                        "ParamicsLog: Could not connect to remote Coordinator object.", 
     166                        "Network Error", JOptionPane.ERROR_MESSAGE); 
     167            } 
     168 
     169            try 
    164170            { 
    165171                createLogFile(logFile); 
    166             } 
    167             catch (Exception e) 
    168             { 
    169                 JOptionPane.showMessageDialog(null,  
    170                         "ParamicsLog: Could not create new log file.",  
     172            } catch (Exception e) 
     173            { 
     174                JOptionPane.showMessageDialog(null, 
     175                        "ParamicsLog: Could not create new log file.", 
    171176                        "File Error", JOptionPane.ERROR_MESSAGE); 
    172177            } 
    173              
    174         } catch (Exception e) { 
    175              
    176             paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor",  
     178 
     179        } catch (Exception e) 
     180        { 
     181 
     182            paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 
    177183                    "Properties file incorrect or missing.", e); 
    178              
    179             JOptionPane.showMessageDialog(null,  
    180                     "ParamicsLog: Properties file invalid.",  
     184 
     185            JOptionPane.showMessageDialog(null, 
     186                    "ParamicsLog: Properties file invalid.", 
    181187                    "Invalid Configuration", JOptionPane.ERROR_MESSAGE); 
    182188        } 
    183189    } 
    184      
     190 
    185191    /** 
    186192     * Creates the log file. 
     193     * 
    187194     * @param filePath The path to the file including the file name. 
    188195     * @throws IOException If the log file could not be created. 
     
    190197    private void createLogFile(String filePath) throws IOException 
    191198    { 
    192         try { 
     199        try 
     200        { 
    193201            logFile = new File(filePath); 
    194              
    195             if (logFile.exists()) { 
     202 
     203            if (logFile.exists()) 
     204            { 
    196205                logFile.delete(); 
    197206            } 
    198              
     207 
    199208            logFile.createNewFile(); 
    200              
    201         } catch (Exception e) { 
    202              
     209 
     210        } catch (Exception e) 
     211        { 
     212 
    203213            logFile = null; 
    204              
    205             paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor",  
     214 
     215            paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 
    206216                    "Could not create new log file.", e); 
    207              
     217 
    208218            throw new IOException("Could not create log file."); 
    209         }                
    210     } 
    211      
     219        } 
     220    } 
     221 
    212222    /** 
    213223     * Connect to the Coordinator's RMI object. 
    214      * @param hostname Host name of the CAD Simulator.     
    215      * @param portNumber Port number of the CAD Simulator RMI communication.  
    216      * @throws SimulationException if there is an error creating the RMI connection. 
    217      */  
    218     private void connect(String hostname, String portNumber)  
    219         throws SimulationException { 
    220          
     224     * 
     225     * @param hostname Host name of the CAD Simulator. 
     226     * @param portNumber Port number of the CAD Simulator RMI communication. 
     227     * @throws SimulationException if there is an error creating the RMI 
     228     * connection. 
     229     */ 
     230    private void connect(String hostname, String portNumber) 
     231            throws SimulationException 
     232    { 
     233 
    221234        String coorIntURL = ""; 
    222          
    223         try {   
    224             coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator";  
    225              
    226             theCoorInt = (CoordinatorInterface)Naming.lookup(coorIntURL);            
    227         } 
    228         catch (Exception e)  
    229         { 
    230             paramLogger.logp(Level.WARNING, "ParamicsLog",  
    231                     "establishRMIConnection", "Unable to establish RMI " + 
    232                     "communication with the CAD Simulator.  URL <" + coorIntURL + ">", e); 
    233         }    
    234     } 
    235      
     235 
     236        try 
     237        { 
     238            coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator"; 
     239 
     240            theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); 
     241        } catch (Exception e) 
     242        { 
     243            paramLogger.logp(Level.WARNING, "ParamicsLog", 
     244                    "establishRMIConnection", "Unable to establish RMI " 
     245                    + "communication with the CAD Simulator.  URL <" + coorIntURL + ">", e); 
     246        } 
     247    } 
     248 
    236249    /** 
    237250     * Accessor to the entries in the log. No file IO is used. 
     251     * 
    238252     * @return The entries in the log. 
    239253     */ 
    240     public String getLog() { 
    241          
     254    public String getLog() 
     255    { 
     256 
    242257        return log.toString(); 
    243258    } 
    244      
    245     /** 
    246      * Writes an entry to the log.  
    247      * The simulator time when the message was sent is prepended to the entry. 
    248      * Entries are padded by a blank line before and after them. 
    249      * TODO: Ensure output is written in order of request. 
     259 
     260    /** 
     261     * Writes an entry to the log. The simulator time when the message was sent 
     262     * is prepended to the entry. Entries are padded by a blank line before and 
     263     * after them. TODO: Ensure output is written in order of request. 
     264     * 
    250265     * @param entry 
    251266     */ 
    252     public void writeToLog(String entry) { 
    253          
     267    public void writeToLog(String entry) 
     268    { 
     269 
    254270        String time = "?"; 
    255271        String formattedEntry; 
    256          
     272 
    257273        if (theCoorInt != null) 
    258274        { 
     
    260276            { 
    261277                time = formatTime(theCoorInt.getCurrentSimulationTime()); 
    262             } 
    263             catch (Exception e) 
    264             { 
    265                 paramLogger.logp(Level.WARNING, "ParamicsLog",  
     278            } catch (Exception e) 
     279            { 
     280                paramLogger.logp(Level.WARNING, "ParamicsLog", 
    266281                        "RMICommunication", "Unable to communicate with RMI object", e); 
    267282            } 
    268283        } 
    269          
     284 
    270285        formattedEntry = "\n" + "<!-- Time written to file: " + time + " -->\n" + entry + "\n"; 
    271286        log.append(formattedEntry); 
    272          
     287 
    273288        if (logFile != null) 
    274289        { 
    275             try  
    276             { 
    277                 synchronized(lock) 
     290            try 
     291            { 
     292                synchronized (lock) 
    278293                { 
    279294                    FileWriter writer = new FileWriter(logFile, true); 
     
    282297                    writer.close(); 
    283298                } 
    284             }  
    285             catch (IOException e)  
    286             { 
    287                 paramLogger.logp(Level.WARNING, "ParamicsLog", "writeToLog",  
     299            } catch (IOException e) 
     300            { 
     301                paramLogger.logp(Level.WARNING, "ParamicsLog", "writeToLog", 
    288302                        "Could not write to log file.", e); 
    289303            } 
    290304        } 
    291          
     305 
    292306        setChanged(); 
    293307        notifyObservers(entry); 
    294308    } 
    295      
     309 
    296310    /** 
    297311     * Formats the time given in seconds to hh:mm:ss format. 
     312     * 
    298313     * @param time The time in seconds. 
    299314     */ 
    300     private String formatTime(long time) 
     315    public String formatTime(long time) 
    301316    { 
    302317        long seconds = time % 60; 
     
    306321        return padr(hours) + ":" + padr(minutes) + ":" + padr(seconds); 
    307322    } 
    308      
     323 
    309324    private String padr(long n) 
    310325    { 
     
    317332        } 
    318333    } 
    319      
     334 
    320335    /** 
    321336     * Accessor for static instance of this class. 
     337     * 
    322338     * @return The instance of this class. 
    323339     */ 
    324     public static ParamicsLog getInstance() { 
    325          
     340    public static ParamicsLog getInstance() 
     341    { 
     342 
    326343        return instance; 
    327344    } 
  • trunk/src/tmcsim/paramicslog/gui/ParamicsLogGUI.java

    r2 r47  
    11package tmcsim.paramicslog.gui; 
    22 
    3 import javax.swing.*; 
    43import java.awt.event.WindowEvent; 
    54import java.util.*; 
     5import javax.swing.*; 
    66 
    77/** 
    8  * The UI for ParamicsLog.  
     8 * The UI for ParamicsLog. 
     9 * 
    910 * @author Nathaniel Lehrer 
    1011 * @version 
    1112 */ 
    12 public class ParamicsLogGUI extends JFrame implements Observer { 
     13public class ParamicsLogGUI extends JFrame implements Observer 
     14{ 
    1315 
    14     /** The static instance */ 
     16    /** 
     17     * The static instance 
     18     */ 
    1519    private static ParamicsLogGUI instance = new ParamicsLogGUI(); 
     20    /** 
     21     * The text area to display the log in 
     22     */ 
     23    private JTextArea textArea; 
    1624 
    17     /** The text area to display the log in */ 
    18     private JTextArea textArea; 
    19      
    20     /** Creates an instance of this class */ 
    21     public ParamicsLogGUI() { 
    22          
     25    /** 
     26     * Creates an instance of this class 
     27     */ 
     28    public ParamicsLogGUI() 
     29    { 
     30 
    2331        setupGUI(); 
    2432    } 
    25      
    26     /** Creates the UI */ 
     33 
     34    /** 
     35     * Creates the UI 
     36     */ 
    2737    private void setupGUI() 
    2838    { 
    29         try { 
     39        try 
     40        { 
    3041            UIManager.setLookAndFeel( 
    31                 UIManager.getSystemLookAndFeelClassName()); 
    32         } catch (Exception e) { 
     42                    UIManager.getSystemLookAndFeelClassName()); 
     43        } catch (Exception ex) 
     44        { 
     45            System.out.println(ex.getMessage()); 
    3346            System.err.println("Couldn't use system look and feel."); 
    3447        } 
    35          
    36         this.addWindowListener(new java.awt.event.WindowAdapter() { 
    37              
     48 
     49        this.addWindowListener(new java.awt.event.WindowAdapter() 
     50        { 
    3851            public void windowClosing(WindowEvent e) 
    3952            { 
     
    4154            } 
    4255        }); 
    43          
    44          
     56 
     57 
    4558        setTitle("Paramics Log"); 
    46          
     59 
    4760        textArea = new JTextArea(); 
    4861        textArea.setColumns(60); 
    4962        textArea.setRows(30); 
    5063        JScrollPane scrollPane = new JScrollPane(textArea); 
    51          
     64 
    5265        getContentPane().add(scrollPane); 
    53          
     66 
    5467    } 
    55      
    56     /** Shows the UI window */ 
     68 
     69    /** 
     70     * Shows the UI window 
     71     */ 
    5772    public void display() 
    5873    { 
     
    6277 
    6378    /** 
    64      * Updates the text area. If the observable class given is of type ParamicsLog then 
    65      * the log entries are displayed. 
     79     * Updates the text area. If the observable class given is of type 
     80     * ParamicsLog then the log entries are displayed. 
     81     * 
    6682     * @param o The model for this viewer. 
    6783     * @param arg An argument that is not used. 
     
    7288        { 
    7389            textArea.setText(((tmcsim.paramicslog.ParamicsLog) o).getLog()); 
    74         }  
     90        } 
    7591 
    7692        repaint(); 
    7793    } 
    78      
     94 
    7995    /** 
    8096     * Accessor for the instance of ParamicsLogGUI. 
     97     * 
    8198     * @return The instance of ParamicsLogGUI. 
    8299     */ 
    83     public static ParamicsLogGUI getInstance() { 
     100    public static ParamicsLogGUI getInstance() 
     101    { 
    84102        return instance; 
    85103    } 
    86      
    87104} 
  • trunk/src/tmcsim/simulationmanager/SimulationManager.java

    r33 r47  
    99import java.util.logging.Level; 
    1010import java.util.logging.Logger; 
    11  
    1211import javax.swing.JOptionPane; 
    1312import javax.swing.UIManager; 
    14  
    1513import tmcsim.common.CADEnums.PARAMICS_STATUS; 
     14import tmcsim.common.ScriptException; 
    1615import tmcsim.common.SimulationException; 
    1716 
     
    4847 
    4948    private static final String CONFIG_FILE_NAME = "sim_manager_config.properties"; 
    50         /** 
     49    /** 
    5150     * Error logger. 
    5251     */ 
     
    192191 
    193192    /** 
     193     * Load a simulation script from the specified file. 
     194     * 
     195     * @param scriptFile the XML file containing the simulation control script 
     196     * to be run. 
     197     * @throws ScriptException if the script throws an exception 
     198     * @throws SimulationException if the simulation throws an exception 
     199     */ 
     200    public void loadScript(File scriptFile) throws ScriptException, SimulationException 
     201    { 
     202        theSimManagerModel.loadScript(scriptFile); 
     203    } 
     204 
     205    /** 
    194206     * Main class. 
    195207     * 
    196208     * @param args Command line arguments. 
    197209     */ 
    198     static public void main(String[] args) { 
     210    static public void main(String[] args) 
     211    { 
    199212        //System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 
    200         if(System.getProperty("CONFIG_DIR") == null){ 
    201                 System.setProperty("CONFIG_DIR", "config"); 
    202         } 
    203          
    204         try {            
    205                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
     213        if (System.getProperty("CONFIG_DIR") == null) 
     214        { 
     215            System.setProperty("CONFIG_DIR", "config"); 
     216        } 
     217 
     218        try 
     219        { 
     220            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    206221            new SimulationManager(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
    207         } catch (Exception e) { 
     222        } catch (Exception e) 
     223        { 
    208224            simManLogger.logp(Level.SEVERE, "SimulationManager", "Main", 
    209225                    "Error occured initializing application", e); 
  • trunk/src/tmcsim/simulationmanager/SimulationManagerView.java

    r9 r47  
    866866        paramicsStatusLabel     = new JLabel("Status:"); 
    867867        paramicsStatusInfoLabel = new JLabel("Unknown"); 
     868        paramicsStatusInfoLabel.setName("paramicsStatusInfoLabel"); 
    868869        paramicsStatusBox.add(paramicsStatusLabel); 
    869870        paramicsStatusBox.add(Box.createHorizontalStrut(10)); 
  • trunk/test/tmcsim/cadsimulator/CADSimulatorFixture.java

    r26 r47  
    3434            + "ATMSProperties         = empty.txt\n" 
    3535            + "MediaProperties        = empty.txt\n"; 
    36     static final String configpData = "ParamicsCommHost = 192.168.251.45\n" 
     36    static final String paramicsData = "ParamicsCommHost      = 192.168.251.45\n" 
    3737            + "ParamicsCommPort       = 4450\n" 
    3838            + "IncidentUpdateInterval = 30\n" 
     
    6060        System.setOut(ps); 
    6161        writedata("config.txt", configData); 
    62         writedata("pconfig.txt", configpData); 
    63         writedata("pmcprops.txt", paramConfig); 
     62        writedata("pconfig.txt", paramicsData); 
    6463        writedata("empty.txt", ""); 
    6564        writeScriptfiles(); 
  • trunk/test/tmcsim/cadsimulator/CADSimulatorGUITest.java

    r34 r47  
    55import java.util.logging.Level; 
    66import java.util.logging.Logger; 
    7  
    87import static junit.framework.Assert.assertEquals; 
    98import static junit.framework.Assert.fail; 
     
    5049        removeMe.delete(); 
    5150    } 
    52  
    53     /** 
    54      * Test of getCADTime method, of class CADSimulator. 
    55      */ 
    56     public void testGetCADTime() 
    57     { 
    58         System.out.println("getCADTime"); 
    59         String result = CADSimulator.getCADTime(); 
    60         // Just test length for now 
    61         assertEquals(4, result.length()); 
    62     } 
    63  
    64     /** 
    65      * Test of getCADDate method, of class CADSimulator. 
    66      */ 
    67     public void testGetCADDate() 
    68     { 
    69         System.out.println("getCADDate"); 
    70         String result = CADSimulator.getCADDate(); 
    71         // Just test length for now 
    72         assertEquals(6, result.length()); 
    73     } 
    7451    /** 
    7552     * Test of main method, of class CADSimulator. 
     
    7956    public void testConstructor() throws SimulationException, RemoteException, ScriptException 
    8057    { 
     58        System.out.println("CADSimulator constructor"); 
    8159        CADSimulatorFixture.writeConfigData(); 
    8260        CADSimulatorFixture.writedata("config.txt", configData); 
    83         System.out.println("CADSimulator constructor"); 
     61        Window cadwindow = null; 
     62//        try 
     63//        { 
     64//            app = new CADSimulator("config.txt"); 
     65//        } catch (Exception e) 
     66//        { 
     67//            fail("Couldn't launch CADSimulator" + e.getMessage()); 
     68//        } 
     69 
    8470        System.setProperty("CONFIG_DIR", "config/testConfig"); 
    85         Window cadwindow = null; 
    8671        if (System.getProperty("CONFIG_DIR") != null) 
    8772        { 
     
    10085                } 
    10186            }); 
    102         } else 
     87        } 
     88        else 
    10389        { 
    10490            fail("CONFIG_DIR system property not defined."); 
    10591        } 
    106         assertEquals("CAD Simulator", cadwindow.getTitle()); 
     92 
     93        System.out.println("Tests for text fields."); 
     94        // Create a UISpec window from the CADSimulator's Viewer (gui) 
     95//        cadwindow = new Window((CADSimulatorViewer) app.theViewer); 
     96        assertTrue("Title bar incorrect", cadwindow.getTitle().startsWith("CAD Simulator revision:")); 
    10797        Panel mainPanel = cadwindow.getPanel("contentPane"); 
    10898        TextBox txtStatus = mainPanel.getTextBox("simulationStatus"); 
    109         assertEquals("No Script", txtStatus.getText()); 
     99        assertEquals("simulation status should say No Script", "No Script", txtStatus.getText().trim()); 
    110100        TextBox terminals = mainPanel.getTextBox("termConnectedTF"); 
    111         assertEquals("0", terminals.getText().trim()); 
    112         assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim()); 
    113         assertEquals("0:00:00", mainPanel.getTextBox("simulationClockLabel").getText()); 
     101        assertEquals("should be 0 terminals", "0", terminals.getText().trim()); 
     102        assertEquals("mgr connected should be no", "No", mainPanel.getTextBox("managerConnectedTF").getText().trim()); 
     103        assertEquals("paramics connected should be no", "No", mainPanel.getTextBox("paramicsConnectedTF").getText().trim()); 
     104        assertEquals("initial time should be 0:00:00", "0:00:00", mainPanel.getTextBox("simulationClockLabel").getText().trim()); 
    114105 
    115         CADClientInterface ci = new FakeClient(); 
     106        CADClientInterface ci = mock(CADClientInterface.class); 
    116107        app.theCoordinator.registerForCallback(ci); 
    117         assertEquals("1", terminals.getText().trim()); 
     108        assertEquals("should be 1 terminal", "1", terminals.getText().trim()); 
    118109        app.theCoordinator.registerForCallback(ci); 
    119         assertEquals("2", terminals.getText().trim()); 
     110        assertEquals("should be 2 terminals", "2", terminals.getText().trim()); 
    120111 
    121112        SimulationManagerInterface si = mock(SimulationManagerInterface.class); 
     113 
    122114        app.theCoordinator.registerForCallback(si); 
    123         assertEquals("Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim()); 
     115        assertEquals("mgr connected should be yes", "Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim()); 
    124116 
    125117        Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator"); 
    126118        cadSimLogger.logp(Level.INFO, "", "", "Sample Info Message."); 
    127119 
     120        System.out.println("Tests for message panes."); 
    128121        Panel infoPane = mainPanel.getPanel("infoMessagesPane"); 
    129122        TextBox infoText = infoPane.getTextBox("infoMessagesTA"); 
    130         assertEquals(". = Sample Info Message.", infoText.getText().trim()); 
     123        assertEquals("wrong info msg text", ". = Sample Info Message.", infoText.getText().trim()); 
    131124 
    132125        cadSimLogger.logp(Level.SEVERE, "", "", "Sample Error Message."); 
     
    134127        Panel errPane = mainPanel.getPanel("errorMessagesPane"); 
    135128        TextBox errText = errPane.getTextBox("errorMessagesTA"); 
    136         assertEquals(". = Sample Error Message.", errText.getText().trim()); 
     129        assertEquals("wrong error msg text", ". = Sample Error Message.", errText.getText().trim()); 
    137130 
     131        System.out.println("Tests for status changes."); 
    138132        app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.CONNECTED); 
    139133        CADSimulatorFixture.pause(500); 
    140         assertEquals("Yes", mainPanel.getTextBox("paramicsConnectedTF").getText().trim()); 
    141         assertEquals("None", mainPanel.getTextBox("networkLoadedTF").getText().trim()); 
     134        assertEquals("paramics connected should be yes", "Yes", mainPanel.getTextBox("paramicsConnectedTF").getText().trim()); 
     135        assertEquals("network id should be None", "None", mainPanel.getTextBox("networkLoadedTF").getText().trim()); 
    142136 
    143137//        app.theCoordinator.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING); 
     
    148142        app.theCoordinator.loadScriptFile(new File(autoloadScriptname)); 
    149143        // The status should now say Ready 
    150         assertEquals("Ready", mainPanel.getTextBox("simulationStatus").getText().trim()); 
     144        assertEquals("sim status should be ready", "Ready", mainPanel.getTextBox("simulationStatus").getText().trim()); 
    151145 
    152146        app.theCoordinator.startSimulation(); 
    153         CADSimulatorFixture.pause(500); 
    154         assertEquals("Running", mainPanel.getTextBox("simulationStatus").getText().trim()); 
    155         assertEquals("0:00:01", mainPanel.getTextBox("simulationClockLabel").getText()); 
     147        CADSimulatorFixture.pause(900); 
     148        assertEquals("sim status should be running", "Running", mainPanel.getTextBox("simulationStatus").getText().trim()); 
     149        assertEquals("sim time should be 0:00:01", "0:00:01", mainPanel.getTextBox("simulationClockLabel").getText().trim()); 
    156150 
    157151        ParamicsSimulationManager psm = mock(ParamicsSimulationManager.class); 
    158152        when(psm.isConnected()).thenReturn(Boolean.TRUE); 
     153        when(psm.getParamicsNetworkLoaded()).thenReturn(1); // provide the network ID to return 
    159154        app.theParamicsSimMgr = psm; 
    160         app.theCoordinator.loadParamicsNetwork(1); 
    161  
    162 //        app.theViewer.dispose(); 
    163 //        Window confirmPopup = null; 
    164 //        confirmPopup = WindowInterceptor.run(new Trigger() 
    165 //        { 
    166 //            public void run() 
    167 //            { 
    168 //                app.theViewer.closeViewer(); 
    169 //            } 
    170 //        }); 
    171 //        confirmPopup.getButton("OK").click(); 
    172     } 
    173  
    174     class FakeClient implements CADClientInterface 
    175     { 
    176  
    177         @Override 
    178         public void refresh() throws RemoteException 
    179         { 
    180         } 
     155        // this will tell the model it has a new network ID 
     156        app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.LOADED); 
     157        CADSimulatorFixture.pause(500); 
     158        assertEquals("network id should be 1", "1", mainPanel.getTextBox("networkLoadedTF").getText().trim()); 
     159        //mainPanel.getMenu().getItem("Exit").click(); 
     160        boolean breakpoint = true; 
    181161    } 
    182162} 
Note: See TracChangeset for help on using the changeset viewer.