Changeset 6 in tmcsimulator for trunk/src


Ignore:
Timestamp:
04/20/2016 02:29:52 PM (10 years ago)
Author:
jdalbey
Message:

Multifile commit. Add version # to Paramics Communicator. Move Load button in Sim Mgr. Add several tests. Add package jars target.

Location:
trunk/src/tmcsim
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/paramicscommunicator/ParamicsCommunicator.java

    r2 r6  
    1717import java.util.Properties; 
    1818import java.util.TreeMap; 
    19 import java.util.logging.FileHandler; 
    2019import java.util.logging.Level; 
    2120import java.util.logging.Logger; 
    22  
    2321import javax.swing.JOptionPane; 
    2422import javax.swing.UIManager; 
    25  
    2623import org.w3c.dom.Document; 
    2724import org.w3c.dom.Element; 
    28  
    2925import tmcsim.common.CADProtocol.PARAMICS_ACTIONS; 
    3026import tmcsim.common.CADProtocol.PARAMICS_COMM_TAGS; 
     
    3228import tmcsim.paramicscommunicator.FileRegUpdate.REG_TYPE; 
    3329import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI; 
    34 import tmcsim.simulationmanager.SimulationManager; 
    35  
    3630 
    3731/** 
    38  * ParamicsCommunicator is the main class for this module.  The Paramics  
    39  * Communicator is used to provide communication between the CAD Simulator 
    40  * and the Paramics traffic modeler.  While the application is running, data  
    41  * is received on a socket from the CAD Simulator.  Transmitted data are 
    42  * XML documents containing information and action commands. The CAD Simulator  
    43  * registers readers and writers with the ParamicsCommunicator.  Any data read  
    44  * by a ParamicsReader is sent back to the CAD Simulator.  All data to be  
    45  * written by a ParamicsWriter is received through the socket.<br><br>   
    46  * The properties file for the ParamicsCommunicator class contains the following data.<br> 
     32 * ParamicsCommunicator is the main class for this module. The Paramics 
     33 * Communicator is used to provide communication between the CAD Simulator and 
     34 * the Paramics traffic modeler. While the application is running, data is 
     35 * received on a socket from the CAD Simulator. Transmitted data are XML 
     36 * documents containing information and action commands. The CAD Simulator 
     37 * registers readers and writers with the ParamicsCommunicator. Any data read by 
     38 * a ParamicsReader is sent back to the CAD Simulator. All data to be written by 
     39 * a ParamicsWriter is received through the socket.<br><br> 
     40 * The properties file for the ParamicsCommunicator class contains the following 
     41 * data.<br> 
    4742 * <code> 
    4843 * -----------------------------------------------------------------------------<br> 
    49  * Socket Port          The port number to use for socket communication.<br> 
    50  * Working Directory    The working directory use for Paramics file communication.<br> 
    51  * Error File           The target file to use for error logging.<br> 
     44 * Socket Port The port number to use for socket communication.<br> 
     45 * Working Directory The working directory use for Paramics file 
     46 * communication.<br> 
     47 * Error File The target file to use for error logging.<br> 
    5248 * -----------------------------------------------------------------------------<br> 
    5349 * Example File: <br> 
    54  * SocketPort          = 4450 <br> 
    55  * WorkingDirectory    = c:\\tmc_simulator\\ <br> 
    56  * ErrorFile           = sim_mgr_error.xml <br> 
     50 * SocketPort = 4450 <br> 
     51 * WorkingDirectory = c:\\tmc_simulator\\ <br> 
     52 * ErrorFile = sim_mgr_error.xml <br> 
    5753 * -----------------------------------------------------------------------------<br> 
    5854 * </code> 
    5955 * 
    6056 * @author Matthew Cechini (mcechini@calpoly.edu) 
    61  * @version $Date: 2009/04/17 16:27:46 $ $Revision: 1.7  
     57 * @version $Date: 2009/04/17 16:27:46 $ $Revision: 1.7 
    6258 */ 
    63 public class ParamicsCommunicator extends Observable implements Observer, Runnable { 
    64  
    65     /** Error logger. */ 
     59public class ParamicsCommunicator extends Observable implements Observer, Runnable 
     60{ 
     61 
     62    /** 
     63     * Error logger. 
     64     */ 
    6665    private static Logger paramLogger = Logger.getLogger("tmcsim.paramicscommunicator"); 
    67      
     66 
    6867    /** 
    6968     * Enumeration containing property names. 
     69     * 
    7070     * @author Matthew Cechini 
    7171     */ 
    72     private static enum PROPERTIES { 
    73          
    74         SOCKET_PORT ("SocketPort"), 
    75         WORKING_DIR ("WorkingDirectory");        
    76          
     72    private static enum PROPERTIES 
     73    { 
     74 
     75        SOCKET_PORT("SocketPort"), 
     76        WORKING_DIR("WorkingDirectory"); 
    7777        public String name; 
    78          
    79         private PROPERTIES(String n) { 
     78 
     79        private PROPERTIES(String n) 
     80        { 
    8081            name = n; 
    8182        } 
    8283    } 
    83      
    84          
    85     /** Properties object. */ 
    86     private Properties paramicsCommProp = null;  
    87      
    88     /** Current working directory where files will be read and written */ 
     84    /** 
     85     * Properties object. 
     86     */ 
     87    private Properties paramicsCommProp = null; 
     88    /** 
     89     * Current working directory where files will be read and written 
     90     */ 
    8991    private String workingDirectory = null; 
    90      
    91     /** Socket used to create socket communication with the CAD Simulator.  */ 
     92    /** 
     93     * Socket used to create socket communication with the CAD Simulator. 
     94     */ 
    9295    private ServerSocket serverSocket = null; 
    93      
    94     /** Soccket used to communicate with CAD Simulator.*/ 
    95     private Socket paramicsSocket = null;    
    96      
    97     /** Input Stream for reading data from the CAD Simulator. */ 
     96    /** 
     97     * Soccket used to communicate with CAD Simulator. 
     98     */ 
     99    private Socket paramicsSocket = null; 
     100    /** 
     101     * Input Stream for reading data from the CAD Simulator. 
     102     */ 
    98103    private ObjectInputStream in = null; 
    99      
    100     /** Output Stream for writing data to the CAD Simulator.  */ 
     104    /** 
     105     * Output Stream for writing data to the CAD Simulator. 
     106     */ 
    101107    private ObjectOutputStream out = null; 
    102      
    103     /** Map of all current ParamicsFileWriters referenced by I/O ID. */ 
     108    /** 
     109     * Map of all current ParamicsFileWriters referenced by I/O ID. 
     110     */ 
    104111    private TreeMap<String, ParamicsFileWriter> writers = null; 
    105      
    106     /** Map of all current ParamicsFileReaders referenced by I/O ID.  */ 
     112    /** 
     113     * Map of all current ParamicsFileReaders referenced by I/O ID. 
     114     */ 
    107115    private TreeMap<String, ParamicsFileReader> readers = null; 
    108      
    109     /** The view class for the ParamicsCommunicator. */ 
     116    /** 
     117     * The view class for the ParamicsCommunicator. 
     118     */ 
    110119    private ParamicsCommunicatorGUI theGUI; 
    111      
    112     /** 
    113      * Constructor.  Read in the property values.  If the properties file  
    114      * does not contain a value for the working directory, open a dialog 
    115      * to prompt the user for the path of the Paramics working directory. 
    116      * An empty string is not accepted.  A null signifies that the user 
    117      * pressed cancel.  Prompt the user to accept the cancel and exit the 
    118      * application if confirmed.  Continue until a valid directory has been 
    119      * entered, that exists, and append a '\' to the end of the directory 
    120      * if necessary. 
    121      *  
    122      * Initialize the Sockets 
    123      * and begin communication. 
    124      * 
    125      * @param propertiesFilePath File Path of ParamicsCommunicator properties file. 
    126      */ 
    127     public ParamicsCommunicator (String propertiesFile)  
    128     { 
    129          
     120 
     121    /** 
     122     * Constructor. Read in the property values. If the properties file does not 
     123     * contain a value for the working directory, open a dialog to prompt the 
     124     * user for the path of the Paramics working directory. An empty string is 
     125     * not accepted. A null signifies that the user pressed cancel. Prompt the 
     126     * user to accept the cancel and exit the application if confirmed. Continue 
     127     * until a valid directory has been entered, that exists, and append a '\' 
     128     * to the end of the directory if necessary. 
     129     * 
     130     * Initialize the Sockets and begin communication. 
     131     * 
     132     * @param propertiesFilePath File Path of ParamicsCommunicator properties 
     133     * file. 
     134     */ 
     135    public ParamicsCommunicator(String propertiesFile) 
     136    { 
     137 
    130138        writers = new TreeMap<String, ParamicsFileWriter>(); 
    131139        readers = new TreeMap<String, ParamicsFileReader>(); 
     
    133141        theGUI = new ParamicsCommunicatorGUI(); 
    134142        addObserver(theGUI); 
    135         theGUI.addWindowListener(new WindowListener() {          
    136             public void windowActivated(WindowEvent arg0) {}; 
    137             public void windowClosed(WindowEvent arg0) {}; 
    138             public void windowClosing(WindowEvent arg0) { 
     143        theGUI.addWindowListener(new WindowListener() 
     144        { 
     145            public void windowActivated(WindowEvent arg0) 
     146            { 
     147            } 
     148 
     149            ; 
     150            public void windowClosed(WindowEvent arg0) 
     151            { 
     152            } 
     153 
     154            ; 
     155            public void windowClosing(WindowEvent arg0) 
     156            { 
    139157                System.exit(0); 
    140158            } 
    141             public void windowDeactivated(WindowEvent arg0) {}; 
    142             public void windowDeiconified(WindowEvent arg0) {}; 
    143             public void windowIconified(WindowEvent arg0) {}; 
    144             public void windowOpened(WindowEvent arg0) {}; 
     159 
     160            public void windowDeactivated(WindowEvent arg0) 
     161            { 
     162            } 
     163 
     164            ; 
     165            public void windowDeiconified(WindowEvent arg0) 
     166            { 
     167            } 
     168 
     169            ; 
     170            public void windowIconified(WindowEvent arg0) 
     171            { 
     172            } 
     173 
     174            ; 
     175            public void windowOpened(WindowEvent arg0) 
     176            { 
     177            } 
     178        ; 
    145179        }); 
    146          
    147         try { 
     180 
     181        try 
     182        { 
    148183            paramicsCommProp = new Properties(); 
    149184            paramicsCommProp.load(new FileInputStream(propertiesFile)); 
    150              
    151             if(paramicsCommProp.getProperty(PROPERTIES.SOCKET_PORT.name) == null)  
    152             { 
    153                 JOptionPane.showMessageDialog(theGUI,  
    154                         "Properties file missing CAD Simulator Port information.",  
     185 
     186            if (paramicsCommProp.getProperty(PROPERTIES.SOCKET_PORT.name) == null) 
     187            { 
     188                JOptionPane.showMessageDialog(theGUI, 
     189                        "Properties file missing CAD Simulator Port information.", 
    155190                        "Invalid Configuration", JOptionPane.ERROR_MESSAGE); 
    156191                System.exit(0); 
    157             } 
    158             else if(paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name) == null ||  
    159                     paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name).length() == 0) { 
    160                  
    161                 try { 
     192            } else if (paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name) == null 
     193                    || paramicsCommProp.getProperty(PROPERTIES.WORKING_DIR.name).length() == 0) 
     194            { 
     195 
     196                try 
     197                { 
    162198                    String workingDir = null; 
    163                      
    164                     while (workingDir == null || workingDir.length() == 0) {                         
     199 
     200                    while (workingDir == null || workingDir.length() == 0) 
     201                    { 
    165202                        workingDir = JOptionPane.showInputDialog(null, 
    166203                                "Please set the output directory for Paramics communication.", 
    167204                                "Paramics Working Directory", JOptionPane.QUESTION_MESSAGE); 
    168                          
    169                         if(workingDir == null) { 
    170                              
    171                         } 
    172                         else if(!new File(workingDir).exists()) { 
     205 
     206                        if (workingDir == null) 
     207                        { 
     208                        } else if (!new File(workingDir).exists()) 
     209                        { 
    173210                            JOptionPane.showMessageDialog(null, 
    174211                                    "Directory does not exist.", 
    175212                                    "Invalid Working Directory", JOptionPane.WARNING_MESSAGE); 
    176                              
     213 
    177214                            workingDir = null; 
    178                         } 
    179                         else if(!new File(workingDir).isDirectory()) { 
     215                        } else if (!new File(workingDir).isDirectory()) 
     216                        { 
    180217                            JOptionPane.showMessageDialog(null, 
    181218                                    workingDir + " is not a directory.", 
    182219                                    "Invalid Working Directory", JOptionPane.WARNING_MESSAGE); 
    183                              
     220 
    184221                            workingDir = null; 
    185                         }                        
     222                        } 
    186223                    } 
    187224 
    188                     if(workingDir.lastIndexOf("\\") != workingDir.length()-1) { 
     225                    if (workingDir.lastIndexOf("\\") != workingDir.length() - 1) 
     226                    { 
    189227                        workingDir = workingDir + "\\"; 
    190228                    } 
    191                      
    192                     paramicsCommProp.setProperty(PROPERTIES.WORKING_DIR.name, workingDir);       
     229 
     230                    paramicsCommProp.setProperty(PROPERTIES.WORKING_DIR.name, workingDir); 
    193231                    paramicsCommProp.store(new FileOutputStream(propertiesFile), ""); 
    194                 } catch (IOException ioe) { 
    195                     paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor",  
     232                } catch (IOException ioe) 
     233                { 
     234                    paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor", 
    196235                            "Exception in writing properties file.", ioe); 
    197236                } 
    198                  
     237 
    199238            } 
    200239 
    201240            workingDirectory = paramicsCommProp.getProperty( 
    202                     PROPERTIES.WORKING_DIR.name).trim();                     
    203  
    204         } catch (Exception e) { 
    205             paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor",  
     241                    PROPERTIES.WORKING_DIR.name).trim(); 
     242 
     243        } catch (Exception e) 
     244        { 
     245            paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor", 
    206246                    "Exception in reading properties file.", e); 
    207247        } 
    208          
    209          
    210         try { 
     248 
     249 
     250        try 
     251        { 
    211252            initializeSockets(Integer.parseInt(paramicsCommProp.getProperty( 
    212253                    PROPERTIES.SOCKET_PORT.name).trim())); 
    213         } 
    214         catch (Exception e) { 
    215             paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor",  
     254        } catch (Exception e) 
     255        { 
     256            paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Constructor", 
    216257                    "Exception in initializing sockets.", e); 
    217258        } 
    218259 
    219260    } 
    220      
     261 
    221262    /** 
    222263     * Transmits a message XML document object to the CAD Simulator. 
     
    224265     * @param mess The ParamicsCommMessage to be transmitted. 
    225266     */ 
    226     private void write(Document mess) { 
    227          
    228         synchronized(paramicsSocket) { 
    229             try { 
     267    private void write(Document mess) 
     268    { 
     269 
     270        synchronized (paramicsSocket) 
     271        { 
     272            try 
     273            { 
    230274                out.writeObject(mess); 
    231275                out.flush(); 
    232             } 
    233             catch (Exception e) { 
    234                 paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "write",  
     276            } catch (Exception e) 
     277            { 
     278                paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "write", 
    235279                        "Exception in writing to the socket.", e); 
    236280            } 
    237281        } 
    238282    } 
    239      
    240     /** 
    241      * Observer/Observable update method.  The Paramics Communicator observers 
    242      * registered ParamicsReaders.  When messages are to be sent, they are sent 
    243      * through this method.  All messages are ParamicsCommMessage objects.  Send  
     283 
     284    /** 
     285     * Observer/Observable update method. The Paramics Communicator observers 
     286     * registered ParamicsReaders. When messages are to be sent, they are sent 
     287     * through this method. All messages are ParamicsCommMessage objects. Send 
    244288     * these messages to the write() method for transmission on the socket. 
    245289     */ 
    246     public void update(Observable o, Object arg) {       
    247  
    248         if(arg instanceof Document) { 
    249             write((Document)arg);                
    250         }            
    251     } 
    252      
    253     /** 
    254      * Runnable method.  While this thread is not interrupted, read in an  
    255      * object from the socket input stream.  If an object exists, call 
    256      * doMessage() to parse and perform the received action in the message.   
    257      */ 
    258     public void run() { 
    259          
    260         while(true) {                        
    261             try { 
    262                 doMessage((Document)in.readObject()); 
    263             }  
    264             catch(SocketTimeoutException ste) { 
     290    public void update(Observable o, Object arg) 
     291    { 
     292 
     293        if (arg instanceof Document) 
     294        { 
     295            write((Document) arg); 
     296        } 
     297    } 
     298 
     299    /** 
     300     * Runnable method. While this thread is not interrupted, read in an object 
     301     * from the socket input stream. If an object exists, call doMessage() to 
     302     * parse and perform the received action in the message. 
     303     */ 
     304    public void run() 
     305    { 
     306 
     307        while (true) 
     308        { 
     309            try 
     310            { 
     311                doMessage((Document) in.readObject()); 
     312            } catch (SocketTimeoutException ste) 
     313            { 
    265314                //just try again 
    266             }    
    267             catch(EOFException eofe) { 
    268                 paramLogger.logp(Level.SEVERE, "ParamicsCommunicator",  
     315            } catch (EOFException eofe) 
     316            { 
     317                paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", 
    269318                        "run", "EOF Exception in reading data from the socket.", eofe); 
    270             } 
    271             catch(Exception e) { 
    272                 paramLogger.logp(Level.SEVERE, "ParamicsCommunicator",  
     319            } catch (Exception e) 
     320            { 
     321                paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", 
    273322                        "run", "Exception in reading data from the socket.", e); 
    274323 
    275                 JOptionPane.showMessageDialog(theGUI,  
    276                         "Connection has been lost to the CAD Simulator.  " + 
    277                         "Paramics Communicator will now shutdown.",  
     324                JOptionPane.showMessageDialog(theGUI, 
     325                        "Connection has been lost to the CAD Simulator.  " 
     326                        + "Paramics Communicator will now shutdown.", 
    278327                        "Dropped Connection", JOptionPane.ERROR_MESSAGE); 
    279328                break; 
    280             }                    
    281         } 
    282          
    283          
    284         try { in.close(); } catch (Exception e) {} 
    285         try { out.close(); } catch (Exception e) {} 
    286         try { serverSocket.close(); } catch (Exception e) {} 
    287         try { paramicsSocket.close(); } catch (Exception e) {} 
    288          
    289     } 
    290      
     329            } 
     330        } 
     331 
     332 
     333        try 
     334        { 
     335            in.close(); 
     336        } catch (Exception e) 
     337        { 
     338        } 
     339        try 
     340        { 
     341            out.close(); 
     342        } catch (Exception e) 
     343        { 
     344        } 
     345        try 
     346        { 
     347            serverSocket.close(); 
     348        } catch (Exception e) 
     349        { 
     350        } 
     351        try 
     352        { 
     353            paramicsSocket.close(); 
     354        } catch (Exception e) 
     355        { 
     356        } 
     357 
     358    } 
     359 
    291360    /** 
    292361     * Perform the action represented in the received XML document message. 
    293      * First determine if the action is from a READER, WRITER, and RESET.   
    294      * If the paramics action is REGISTER, add a new ParamicsFileReader/Writer  
    295      * to the local list of readers/writers and update the GUI with a  
    296      * FileRegUpdate object. If the paramics action is UNREGISTER, remove the  
    297      * ParamicsFileReader/Writer from the local list of readers/writers and update 
    298      * the GUI with a FileRegUpdate object.  If RESET is received, clear all  
    299      * readers and writers.  
    300      *  
     362     * First determine if the action is from a READER, WRITER, and RESET. If the 
     363     * paramics action is REGISTER, add a new ParamicsFileReader/Writer to the 
     364     * local list of readers/writers and update the GUI with a FileRegUpdate 
     365     * object. If the paramics action is UNREGISTER, remove the 
     366     * ParamicsFileReader/Writer from the local list of readers/writers and 
     367     * update the GUI with a FileRegUpdate object. If RESET is received, clear 
     368     * all readers and writers. 
     369     * 
    301370     * @param mess Received XML document message. 
    302371     */ 
    303     private void doMessage (Document mess) { 
    304          
     372    private void doMessage(Document mess) 
     373    { 
     374 
    305375        Element rootElement = mess.getDocumentElement(); 
    306376 
    307         String id     = null; 
     377        String id = null; 
    308378        String action = null; 
    309          
    310         switch(PARAMICS_COMM_TAGS.fromString(rootElement.getNodeName())) { 
     379 
     380        switch (PARAMICS_COMM_TAGS.fromString(rootElement.getNodeName())) 
     381        { 
    311382            case READER: 
    312                 id     = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
     383                id = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
    313384                action = rootElement.getAttribute(PARAMICS_COMM_TAGS.ACTION.tag); 
    314                  
    315                 switch(PARAMICS_ACTIONS.fromString(action)) { 
     385 
     386                switch (PARAMICS_ACTIONS.fromString(action)) 
     387                { 
    316388                    case REGISTER: 
    317                         Integer interval   = Integer.parseInt(rootElement.getChildNodes().item(0).getTextContent()); 
    318                         String  targetFile = rootElement.getChildNodes().item(1).getTextContent(); 
    319                          
    320                         readers.put(id, new ParamicsFileReader(workingDirectory, id,  
     389                        Integer interval = Integer.parseInt(rootElement.getChildNodes().item(0).getTextContent()); 
     390                        String targetFile = rootElement.getChildNodes().item(1).getTextContent(); 
     391 
     392                        readers.put(id, new ParamicsFileReader(workingDirectory, id, 
    321393                                interval, targetFile)); 
    322394                        readers.get(id).addObserver(this); 
    323395                        readers.get(id).addObserver(theGUI); 
    324                          
     396 
    325397                        setChanged(); 
    326                         notifyObservers(new FileRegUpdate(IO_TYPE.READ,  
     398                        notifyObservers(new FileRegUpdate(IO_TYPE.READ, 
    327399                                REG_TYPE.REGISTER, id, targetFile, interval)); 
    328400                        break; 
    329                     case UNREGISTER:  
     401                    case UNREGISTER: 
    330402                        readers.get(id).deleteObserver(this); 
    331403                        readers.get(id).deleteObserver(theGUI); 
     
    333405 
    334406                        setChanged(); 
    335                         notifyObservers(new FileRegUpdate(IO_TYPE.READ,  
    336                                 REG_TYPE.UNREGISTER, id, null, null));                       
     407                        notifyObservers(new FileRegUpdate(IO_TYPE.READ, 
     408                                REG_TYPE.UNREGISTER, id, null, null)); 
    337409                        break; 
    338410                } 
    339411                break; 
    340412            case WRITER: 
    341                 id     = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
     413                id = rootElement.getAttribute(PARAMICS_COMM_TAGS.ID.tag); 
    342414                action = rootElement.getAttribute(PARAMICS_COMM_TAGS.ACTION.tag); 
    343                  
    344                 switch(PARAMICS_ACTIONS.fromString(action)) { 
     415 
     416                switch (PARAMICS_ACTIONS.fromString(action)) 
     417                { 
    345418                    case REGISTER: 
    346                         String targetFile = rootElement.getChildNodes().item(0).getTextContent();  
    347                          
    348                         writers.put(id, new ParamicsFileWriter(id,  
     419                        String targetFile = rootElement.getChildNodes().item(0).getTextContent(); 
     420 
     421                        writers.put(id, new ParamicsFileWriter(id, 
    349422                                workingDirectory, targetFile)); 
    350423                        writers.get(id).addObserver(theGUI); 
    351                          
     424 
    352425                        setChanged(); 
    353                         notifyObservers(new FileRegUpdate(IO_TYPE.WRITE,  
    354                                 REG_TYPE.REGISTER, id, targetFile, null));       
     426                        notifyObservers(new FileRegUpdate(IO_TYPE.WRITE, 
     427                                REG_TYPE.REGISTER, id, targetFile, null)); 
    355428                        break; 
    356                     case UNREGISTER:  
     429                    case UNREGISTER: 
    357430                        writers.remove(id); 
    358                          
     431 
    359432                        writers.get(id).deleteObserver(theGUI); 
    360433 
    361434                        setChanged(); 
    362                         notifyObservers(new FileRegUpdate(IO_TYPE.WRITE,  
     435                        notifyObservers(new FileRegUpdate(IO_TYPE.WRITE, 
    363436                                REG_TYPE.UNREGISTER, id, null, null)); 
    364437                        break; 
    365438                    case WRITE_FILE: 
    366                         writers.get(id).writeMessage((Element)rootElement.getChildNodes().item(0)); 
     439                        writers.get(id).writeMessage((Element) rootElement.getChildNodes().item(0)); 
    367440                        break; 
    368441                } 
     
    372445                writers.clear(); 
    373446                break; 
    374         }    
    375     } 
    376      
    377     /** 
    378      * Method waits to accept a socket connection from the CAD Simulator.   
    379      * When a connection has been established the method exits.  The input and 
    380      * output streams are created on the new socket. 
    381      *  
    382      * @param socketPort Socket port to use for establishing Socket communication. 
    383      * @throws IOException if there is an exception in establishing Socket communication. 
    384      */ 
    385     private void initializeSockets(Integer socketPort) throws IOException { 
    386      
     447        } 
     448    } 
     449 
     450    /** 
     451     * Method waits to accept a socket connection from the CAD Simulator. When a 
     452     * connection has been established the method exits. The input and output 
     453     * streams are created on the new socket. 
     454     * 
     455     * @param socketPort Socket port to use for establishing Socket 
     456     * communication. 
     457     * @throws IOException if there is an exception in establishing Socket 
     458     * communication. 
     459     */ 
     460    private void initializeSockets(Integer socketPort) throws IOException 
     461    { 
     462 
    387463        boolean waiting = true; 
    388          
    389         try { 
    390             serverSocket = new ServerSocket(socketPort);             
    391             //delay for accept timeout(milliseconds)         
    392             serverSocket.setSoTimeout(10 * 1000);   
    393         } 
    394         catch (IOException ioe) { 
    395             throw new IOException("Exception in creating " + 
    396                     "the server socket on port " + socketPort); 
    397         } 
    398          
    399         while(waiting) {             
    400             try{ 
     464 
     465        try 
     466        { 
     467            serverSocket = new ServerSocket(socketPort); 
     468            //delay for accept timeout(milliseconds) 
     469            serverSocket.setSoTimeout(10 * 1000); 
     470        } catch (IOException ioe) 
     471        { 
     472            throw new IOException("Exception in creating " 
     473                    + "the server socket on port " + socketPort); 
     474        } 
     475 
     476        while (waiting) 
     477        { 
     478            try 
     479            { 
    401480                paramicsSocket = serverSocket.accept(); 
    402481                waiting = false; 
    403             }  
    404             catch(SocketTimeoutException ste) { 
     482            } catch (SocketTimeoutException ste) 
     483            { 
    405484                System.out.println("...waiting..."); 
    406             }    
    407             catch(IOException ioe) { 
    408                 throw new IOException("Exception in creating " + 
    409                         "the receiving socket on port " + socketPort); 
    410             } 
    411         } 
    412  
    413          
     485            } catch (IOException ioe) 
     486            { 
     487                throw new IOException("Exception in creating " 
     488                        + "the receiving socket on port " + socketPort); 
     489            } 
     490        } 
     491 
     492 
    414493        //** out must be performed before in to unlock for connecting socket **// 
    415         try {        
    416             out     = new ObjectOutputStream(paramicsSocket.getOutputStream()); 
    417             in      = new ObjectInputStream(paramicsSocket.getInputStream()); 
    418         } 
    419         catch (IOException ioe) { 
    420             throw new IOException("Exception in creating input " + 
    421                     "and output streams on socket."); 
    422         } 
    423              
    424     } 
    425  
    426     /** 
    427      * Construct the ParamicsCommunicator with the properties file path,  
    428      * either from the command line arguments or default. 
    429      *  
     494        try 
     495        { 
     496            out = new ObjectOutputStream(paramicsSocket.getOutputStream()); 
     497            in = new ObjectInputStream(paramicsSocket.getInputStream()); 
     498        } catch (IOException ioe) 
     499        { 
     500            throw new IOException("Exception in creating input " 
     501                    + "and output streams on socket."); 
     502        } 
     503 
     504    } 
     505 
     506    /** 
     507     * Construct the ParamicsCommunicator with the properties file path, either 
     508     * from the command line arguments or default. 
     509     * 
    430510     * @param args Command line arguments. 
    431511     */ 
    432     public static void main(String[] args) { 
    433  
    434         try 
    435         { 
    436             if(System.getProperty("PARAMICS_COMM_PROPERTIES") != null) 
     512    public static void main(String[] args) 
     513    { 
     514        System.setProperty("PARAMICS_COMM_PROPERTIES", "config/paramics_communicator_config.properties"); 
     515 
     516        try 
     517        { 
     518            if (System.getProperty("PARAMICS_COMM_PROPERTIES") != null) 
    437519            { 
    438520                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    439      
     521 
    440522                new Thread(new ParamicsCommunicator(System.getProperty( 
    441523                        "PARAMICS_COMM_PROPERTIES"))).start(); 
    442             } 
    443             else 
    444             { 
    445                 throw new Exception ("PARAMICS_COMM_PROPERTIES system property not defined."); 
    446             } 
    447         }  
    448         catch (Exception e)  
    449         { 
    450             paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Main",  
     524            } else 
     525            { 
     526                throw new Exception("PARAMICS_COMM_PROPERTIES system property not defined."); 
     527            } 
     528        } catch (Exception e) 
     529        { 
     530            paramLogger.logp(Level.SEVERE, "ParamicsCommunicator", "Main", 
    451531                    "Error occured initializing application", e); 
    452532 
    453             JOptionPane.showMessageDialog(null, e.getMessage(),  
    454                     "Error - Program Exiting", JOptionPane.ERROR_MESSAGE);   
    455              
     533            JOptionPane.showMessageDialog(null, e.getMessage(), 
     534                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE); 
     535 
    456536            System.exit(-1); 
    457537        } 
    458      
    459          
    460     }    
    461      
     538 
     539 
     540    } 
    462541} 
  • trunk/src/tmcsim/paramicscommunicator/ParamicsFileReader.java

    r2 r6  
    1010import java.util.logging.Level; 
    1111import java.util.logging.Logger; 
    12  
    1312import javax.xml.parsers.DocumentBuilderFactory; 
    14  
    1513import org.w3c.dom.Document; 
    1614import org.w3c.dom.Element; 
    17  
    1815import tmcsim.common.CADProtocol.PARAMICS_ACTIONS; 
    1916import tmcsim.common.CADProtocol.PARAMICS_COMM_TAGS; 
    2017import tmcsim.paramicscommunicator.FileIOUpdate.IO_TYPE; 
    2118 
    22  
    2319/** 
    24  * The ParamicsFileReader handles reading fom a target file which 
    25  * is written to by Paramics.  Once initialized, a timer task is 
    26  * started which periodically checks the target file for updates. 
    27  * If the file has been modified, it is read and cleared.  The read 
    28  * data is transmitted to the CAD Simulator. 
     20 * The ParamicsFileReader handles reading fom a target file which is written to 
     21 * by Paramics. Once initialized, a timer task is started which periodically 
     22 * checks the target file for updates. If the file has been modified, it is read 
     23 * and cleared. The read data is transmitted to the CAD Simulator. 
    2924 * 
    3025 * @author Matthew Cechini 
    31  * @version 
     26 * @version 0.1 Notes by jdalbey: Paramics modeler is licensed third-party 
     27 * software and apparently we don't have an SDK for it. So it seems the 
     28 * workaround was to communicate with it via data files that the modeler 
     29 * produces. Wacky, but it works for now. Look at the run() method below: if 
     30 * (lastModified &lt; inputFile.lastModified()) Means it's watching the file to 
     31 * see if it has been updated by the modeler. 
    3232 */ 
    33 public class ParamicsFileReader extends Observable { 
    34      
    35     /** Error Logger. */ 
    36     private Logger paramLogger = Logger.getLogger("tmcsim.paramicscommunicator");    
    37      
    38     /** FileReader ID used for creation of the ParamicsCommMessage */ 
     33public class ParamicsFileReader extends Observable 
     34{ 
     35 
     36    /** 
     37     * Error Logger. 
     38     */ 
     39    private Logger paramLogger = Logger.getLogger("tmcsim.paramicscommunicator"); 
     40    /** 
     41     * FileReader ID used for creation of the ParamicsCommMessage 
     42     */ 
    3943    private String readerID = null; 
    40      
    41     /** File reference to the file where data is read. */ 
     44    /** 
     45     * File reference to the file where data is read. 
     46     */ 
    4247    private File inputFile = null; 
    43      
    44     /** FileReader used to read data from the input file. */ 
     48    /** 
     49     * FileReader used to read data from the input file. 
     50     */ 
    4551    private FileReader fileReader = null; 
    46      
    47     /** FileWriter used to clear the input file. */ 
     52    /** 
     53     * FileWriter used to clear the input file. 
     54     */ 
    4855    private FileWriter fileWriter = null; 
    49      
    50     /** Value (seconds since 1/1/1970) of input file's last modification time. */ 
     56    /** 
     57     * Value (seconds since 1/1/1970) of input file's last modification time. 
     58     */ 
    5159    private long lastModified = 0; 
    52      
    53     /** Timer used to schedule file reading tasks. */ 
     60    /** 
     61     * Timer used to schedule file reading tasks. 
     62     */ 
    5463    private Timer readerTimer = null; 
    55      
    56     /**  
    57      * Duration (in seconds) that the TimerTask will be scheduled to 
    58      * read from the target file. 
     64    /** 
     65     * Duration (in seconds) that the TimerTask will be scheduled to read from 
     66     * the target file. 
    5967     */ 
    6068    private long readerInterval; 
    61      
     69 
    6270    /** 
    63      * A TimerTask to read from the target file.  If the file has been modified since 
    64      * last read, read the file and transmit the data to the CAD Simulator. 
     71     * A TimerTask to read from the target file. If the file has been modified 
     72     * since last read, read the file and transmit the data to the CAD 
     73     * Simulator. 
     74     * 
    6575     * @author Matthew Cechini 
    6676     */ 
    67     private class ReaderTimerTask extends TimerTask { 
    68         public void run() {      
    69              
    70             if (lastModified < inputFile.lastModified()) { 
    71                                  
    72                 try { 
     77    private class ReaderTimerTask extends TimerTask 
     78    { 
     79 
     80        public void run() 
     81        { 
     82 
     83            if (lastModified < inputFile.lastModified()) 
     84            { 
     85 
     86                try 
     87                { 
    7388                    Document readerDoc = DocumentBuilderFactory.newInstance() 
    74                         .newDocumentBuilder().newDocument(); 
    75              
     89                            .newDocumentBuilder().newDocument(); 
     90 
    7691                    Element readerElem = readerDoc.createElement(PARAMICS_COMM_TAGS.READER.tag); 
    7792                    readerElem.setAttribute(PARAMICS_COMM_TAGS.ID.tag, readerID); 
    78                     readerElem.setAttribute(PARAMICS_COMM_TAGS.ACTION.tag,  
     93                    readerElem.setAttribute(PARAMICS_COMM_TAGS.ACTION.tag, 
    7994                            PARAMICS_ACTIONS.READ_FILE.action); 
    80                      
     95 
    8196                    Element messageElem = readerDoc.createElement(PARAMICS_COMM_TAGS.MESSAGE.tag); 
    82                     messageElem.appendChild(readerDoc.createTextNode(readFromFile())); 
     97                    String fileContents = readFromFile(); 
     98                    messageElem.appendChild(readerDoc.createTextNode(fileContents)); 
    8399                    readerElem.appendChild(messageElem); 
    84                      
    85                     readerDoc.appendChild(readerElem);           
    86                          
     100 
     101                    readerDoc.appendChild(readerElem); 
     102 
    87103                    setChanged(); 
    88104                    notifyObservers(readerDoc); 
    89                 }                    
    90                 catch (Exception e) { 
    91                     paramLogger.logp(Level.SEVERE,  
    92                             "ParamicsFileReader.ReaderTimerTask", "run()",  
    93                             "Exception in reading from file: " +  
    94                             inputFile.getName(), e); 
     105                } catch (Exception e) 
     106                { 
     107                    paramLogger.logp(Level.SEVERE, 
     108                            "ParamicsFileReader.ReaderTimerTask", "run()", 
     109                            "Exception in reading from file: " 
     110                            + inputFile.getName(), e); 
    95111                } 
    96112            } 
     
    98114    } 
    99115 
    100  
    101116    /** 
    102      * Constructor.  Set the reader id and interval from the parsed 
    103      * ParamicsCommMessage.  The interval is found within the first three 
    104      * characters of the object's "message" data member.  Create a file 
    105      * object for the target file, and create a new file if it does 
    106      * not already exist.  Instantiate the timer and ReaderTimerTask 
    107      * to begin periodic reading of the file. 
    108      *  
    109      * @param workingDir Target working directory. 
     117     * Constructor. Set the reader id and interval from the parsed 
     118     * ParamicsCommMessage. The interval is found within the first three 
     119     * characters of the object's "message" data member. Create a file object 
     120     * for the target file, and create a new file if it does not already exist. 
     121     * Instantiate the timer and ReaderTimerTask to begin periodic reading of 
     122     * the file. 
     123     * 
     124     * @param workingDir Target working directory. // Oops, the following seem 
     125     * obsolete 
    110126     * @param mess ParamicsCommMessage object containing registration data. 
    111127     * @param theComm Reference to the ParamicsCommunicator. 
    112128     */ 
    113     public ParamicsFileReader(String workingDir, String id, Integer interval, String targetFile) { 
    114          
    115         try {        
    116             readerID       = id; 
     129    public ParamicsFileReader(String workingDir, String id, Integer interval, String targetFile) 
     130    { 
     131 
     132        try 
     133        { 
     134            readerID = id; 
    117135            readerInterval = interval; 
    118                      
    119             inputFile = new File(workingDir + targetFile);   
    120                          
    121             if(!inputFile.exists()) { 
     136 
     137            inputFile = new File(workingDir + targetFile); 
     138 
     139            if (!inputFile.exists()) 
     140            { 
    122141                inputFile.createNewFile(); 
    123142            } 
    124              
     143 
    125144            readerTimer = new Timer(); 
    126             readerTimer.scheduleAtFixedRate(new ReaderTimerTask(),  
    127                 0L, readerInterval * 1000);  
    128              
    129         } catch (IOException ioe) { 
    130             paramLogger.logp(Level.SEVERE, "ParamicsFileReader",  
     145            readerTimer.scheduleAtFixedRate(new ReaderTimerTask(), 
     146                    0L, readerInterval * 1000); 
     147 
     148        } catch (IOException ioe) 
     149        { 
     150            paramLogger.logp(Level.SEVERE, "ParamicsFileReader", 
    131151                    "Constructor()", "Exception in initializing file reading.", ioe); 
    132152        } 
    133153    } 
    134      
    135      
     154 
    136155    /** 
    137      * Method opens the target file and reads all contents.  The file is then  
     156     * Method opens the target file and reads all contents. The file is then 
    138157     * cleared. 
    139158     * 
    140159     * @returns 
    141      * @throws IOException if there is an error in reading or writing to the file. 
     160     * @throws IOException if there is an error in reading or writing to the 
     161     * file. 
    142162     */ 
    143     private String readFromFile() throws IOException { 
    144          
    145         char[] input = new char[(int)inputFile.length()]; 
    146          
     163    private String readFromFile() throws IOException 
     164    { 
     165 
     166        char[] input = new char[(int) inputFile.length()]; 
     167 
    147168        fileReader = new FileReader(inputFile); 
    148         fileReader.read(input);      
     169        fileReader.read(input); 
    149170        fileReader.close(); 
    150          
     171 
    151172        //make sure the new file has a modified time that is different 
    152         try { 
     173        try 
     174        { 
    153175            Thread.sleep(1000); 
     176        } catch (Exception e) 
     177        { 
    154178        } 
    155         catch (Exception e) {} 
    156          
     179 
    157180        //clear file after reading contents 
    158181        fileWriter = new FileWriter(inputFile); 
    159182        fileWriter.write(""); 
    160183        fileWriter.close(); 
    161          
     184 
    162185        lastModified = inputFile.lastModified(); 
    163          
     186 
    164187        setChanged(); 
    165         notifyObservers(new FileIOUpdate(IO_TYPE.READ, readerID, (long)input.length));       
    166                          
     188        notifyObservers(new FileIOUpdate(IO_TYPE.READ, readerID, (long) input.length)); 
     189 
    167190        return new String(input); 
    168     }        
     191    } 
    169192} 
  • trunk/src/tmcsim/paramicscommunicator/gui/ParamicsCommunicatorGUI.java

    r2 r6  
    1111import java.util.logging.LogRecord; 
    1212import java.util.logging.Logger; 
    13  
    1413import javax.swing.BorderFactory; 
    1514import javax.swing.Box; 
    1615import javax.swing.BoxLayout; 
    1716import javax.swing.JFrame; 
     17import javax.swing.JMenuBar; 
     18import javax.swing.JOptionPane; 
    1819import javax.swing.JScrollPane; 
    1920import javax.swing.JTabbedPane; 
    2021import javax.swing.JTextArea; 
    21  
     22import tmcsim.common.RevisionNumber; 
    2223import tmcsim.paramicscommunicator.FileIOUpdate; 
    2324import tmcsim.paramicscommunicator.FileRegUpdate; 
    2425 
    2526/** 
    26  * ParamicsCommunicatorGUI is the view class for the ParamicsCommunicator. 
    27  * The user interface shows a tab for each I/O reader or writer that has 
    28  * been registered with the ParamicsCommunicator.  The tab shows the  
    29  * history of I/O reads and writes, and the unique information for the 
    30  * target file and I/O interval. 
    31  *  
     27 * ParamicsCommunicatorGUI is the view class for the ParamicsCommunicator. The 
     28 * user interface shows a tab for each I/O reader or writer that has been 
     29 * registered with the ParamicsCommunicator. The tab shows the history of I/O 
     30 * reads and writes, and the unique information for the target file and I/O 
     31 * interval. 
     32 * 
    3233 * @author Matthew Cechini 
    3334 * @version 
    3435 */ 
    3536@SuppressWarnings("serial") 
    36 public class ParamicsCommunicatorGUI extends JFrame implements Observer { 
    37      
    38     /** 
    39      * Logging handler that writes all received log records to the 
    40      * error text area. 
     37public class ParamicsCommunicatorGUI extends JFrame implements Observer 
     38{ 
     39 
     40    /** 
     41     * Logging handler that writes all received log records to the error text 
     42     * area. 
     43     * 
    4144     * @author Matthew Cechini 
    4245     */ 
    43     protected class ParamicsLoggerHandler extends Handler { 
     46    protected class ParamicsLoggerHandler extends Handler 
     47    { 
    4448 
    4549        DateFormat timeFormat = DateFormat.getTimeInstance(); 
    46          
    47         public void close() throws SecurityException { 
    48         } 
    49          
    50         public void flush() { 
    51         } 
    52          
    53         public void publish(LogRecord record) { 
     50 
     51        public void close() throws SecurityException 
     52        { 
     53        } 
     54 
     55        public void flush() 
     56        { 
     57        } 
     58 
     59        public void publish(LogRecord record) 
     60        { 
    5461            StringBuffer errorBuf = new StringBuffer(); 
    55              
     62 
    5663            errorBuf.append(timeFormat.format(new Date(record.getMillis()))); 
    57             errorBuf.append("  -  " + record.getMessage() + "\n");           
    58              
    59             errorTA.setText(errorTA.getText() + errorBuf.toString());  
    60         }        
    61     } 
    62  
    63     /** Map of FileIOTableModel objects for each reader id. */ 
     64            errorBuf.append("  -  " + record.getMessage() + "\n"); 
     65 
     66            errorTA.setText(errorTA.getText() + errorBuf.toString()); 
     67        } 
     68    } 
     69    /** 
     70     * Map of FileIOTableModel objects for each reader id. 
     71     */ 
    6472    protected TreeMap<String, FileIOTableModel> readerTables; 
    65  
    66     /** Map of FileIOTableModel objects for each writer id. */ 
     73    /** 
     74     * Map of FileIOTableModel objects for each writer id. 
     75     */ 
    6776    protected TreeMap<String, FileIOTableModel> writerTables; 
    68      
    69     /** 
    70      * Constructor.  Initialize local lists, set up the logging handler and 
     77 
     78    /** 
     79     * Constructor. Initialize local lists, set up the logging handler and 
    7180     * initialize the GUI. 
    7281     */ 
    73     public ParamicsCommunicatorGUI() {       
     82    public ParamicsCommunicatorGUI() 
     83    { 
    7484        super("Paramics Communicator"); 
    75          
     85 
    7686        readerTables = new TreeMap<String, FileIOTableModel>(); 
    7787        writerTables = new TreeMap<String, FileIOTableModel>(); 
    78          
     88 
    7989        Logger.getLogger("tmcsim.paramicscommunicator").addHandler(new ParamicsLoggerHandler()); 
    80          
     90 
    8191        initializeGUI(); 
    82     }    
    83      
    84     /** 
    85      * Observer update method.  If the update object is a FileIOUpdate object, 
    86      * update the TableModel corresponding to the unique I/O id.  If the 
    87      * update object is a FileRegUpdate object, add a new tab if the  
    88      * registration type is REGISTER, or update an existing tab if the 
    89      * registration type is UNREGISTER. 
    90      */ 
    91     public void update(Observable o, Object arg) { 
    92          
    93         if(arg instanceof FileIOUpdate) { 
    94  
    95             try { 
    96                 FileIOUpdate update = (FileIOUpdate)arg; 
    97                  
    98                 switch(update.ioType) { 
     92    } 
     93 
     94    /** 
     95     * Observer update method. If the update object is a FileIOUpdate object, 
     96     * update the TableModel corresponding to the unique I/O id. If the update 
     97     * object is a FileRegUpdate object, add a new tab if the registration type 
     98     * is REGISTER, or update an existing tab if the registration type is 
     99     * UNREGISTER. 
     100     */ 
     101    public void update(Observable o, Object arg) 
     102    { 
     103 
     104        if (arg instanceof FileIOUpdate) 
     105        { 
     106 
     107            try 
     108            { 
     109                FileIOUpdate update = (FileIOUpdate) arg; 
     110 
     111                switch (update.ioType) 
     112                { 
    99113                    case READ: 
    100114                        readerTables.get(update.ioID).addIOUpdate(update); 
     
    104118                        break; 
    105119                } 
    106             } 
    107             catch (Exception e) { 
     120            } catch (Exception e) 
     121            { 
    108122                Logger.getLogger("tmcsim.paramicscommunicator.gui").logp( 
    109                         Level.SEVERE, "ParamicsCommunicatorGUI", "update",  
     123                        Level.SEVERE, "ParamicsCommunicatorGUI", "update", 
    110124                        "Exception in receiving FileIOUpdate object.", e); 
    111125            } 
    112         } 
    113         else if(arg instanceof FileRegUpdate) { 
    114             try { 
    115                 FileRegUpdate update = (FileRegUpdate)arg; 
    116                  
    117                 switch(update.ioType) { 
     126        } else if (arg instanceof FileRegUpdate) 
     127        { 
     128            try 
     129            { 
     130                FileRegUpdate update = (FileRegUpdate) arg; 
     131 
     132                switch (update.ioType) 
     133                { 
    118134                    case READ: 
    119                         switch(update.regType) { 
     135                        switch (update.regType) 
     136                        { 
    120137                            case REGISTER: 
    121138                                FileIOTableModel model = new FileIOTableModel(); 
    122139                                readerTables.put(update.ioID, model); 
    123      
     140 
    124141                                addTab(update, model); 
    125142                                break; 
     
    130147                        break; 
    131148                    case WRITE: 
    132                         switch(update.regType) { 
     149                        switch (update.regType) 
     150                        { 
    133151                            case REGISTER: 
    134152                                FileIOTableModel model = new FileIOTableModel(); 
    135153                                writerTables.put(update.ioID, model); 
    136                                  
     154 
    137155                                addTab(update, model); 
    138156                                break; 
     
    140158                                //unregister 
    141159                                break; 
    142                         }                    
     160                        } 
    143161                        break; 
    144162                } 
    145163 
    146             } 
    147             catch (Exception e) { 
     164            } catch (Exception e) 
     165            { 
    148166                Logger.getLogger("tmcsim.paramicscommunicator.gui").logp( 
    149                         Level.SEVERE, "ParamicsCommunicatorGUI", "update",  
     167                        Level.SEVERE, "ParamicsCommunicatorGUI", "update", 
    150168                        "Exception in receiving FileRegUpdate object.", e); 
    151169            } 
    152         }        
    153     } 
    154      
    155     private void initializeGUI() { 
    156          
    157         /* Added by Nathaniel Lehrer */ 
    158         this.setJMenuBar(new javax.swing.JMenuBar() { 
    159             { 
    160                 javax.swing.JMenu fileMenu = new javax.swing.JMenu("File"); 
    161                 javax.swing.JMenuItem logItem = new javax.swing.JMenuItem("Show Log"); 
    162                  
    163                 logItem.addActionListener(new java.awt.event.ActionListener() { 
    164                     public void actionPerformed(java.awt.event.ActionEvent evt) { 
    165                         tmcsim.paramicslog.gui.ParamicsLogGUI.getInstance().display();  
    166                     } 
    167                 }); 
    168                  
    169                 fileMenu.add(logItem); 
    170                 this.add(fileMenu); 
     170        } 
     171    } 
     172 
     173    private void initializeGUI() 
     174    { 
     175 
     176        JMenuBar menuBar = new JMenuBar(); 
     177 
     178        javax.swing.JMenu fileMenu = new javax.swing.JMenu("File"); 
     179        javax.swing.JMenuItem logItem = new javax.swing.JMenuItem("Show Log"); 
     180 
     181        logItem.addActionListener(new java.awt.event.ActionListener() 
     182        { 
     183            public void actionPerformed(java.awt.event.ActionEvent evt) 
     184            { 
     185                tmcsim.paramicslog.gui.ParamicsLogGUI.getInstance().display(); 
    171186            } 
    172187        }); 
    173         /* End Add by Nathaniel Lehrer */ 
    174          
     188 
     189        fileMenu.add(logItem); 
     190        menuBar.add(fileMenu); 
     191 
     192        javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help"); 
     193        javax.swing.JMenuItem aboutItem = new javax.swing.JMenuItem("About"); 
     194 
     195        aboutItem.addActionListener(new java.awt.event.ActionListener() 
     196        { 
     197            public void actionPerformed(java.awt.event.ActionEvent evt) 
     198            { 
     199                String ver = RevisionNumber.getString(); 
     200                JOptionPane.showMessageDialog(rootPane, "Version: " + ver, "About", JOptionPane.INFORMATION_MESSAGE); 
     201            } 
     202        }); 
     203 
     204        helpMenu.add(aboutItem); 
     205        menuBar.add(helpMenu); 
     206 
     207        this.setJMenuBar(menuBar); 
     208 
    175209        fileIOTabs = new JTabbedPane(); 
    176210        fileIOTabs.setAlignmentX(Box.CENTER_ALIGNMENT); 
     
    180214        fileIOTabs.setBorder(BorderFactory.createCompoundBorder( 
    181215                BorderFactory.createTitledBorder( 
    182                     BorderFactory.createRaisedBevelBorder(), "Registered I/O"), 
    183                     BorderFactory.createEmptyBorder(5,5,5,5))); 
    184      
     216                BorderFactory.createRaisedBevelBorder(), "Registered I/O"), 
     217                BorderFactory.createEmptyBorder(5, 5, 5, 5))); 
     218 
    185219        errorTA = new JTextArea(); 
    186220        errorTA.setLineWrap(true); 
    187          
     221 
    188222        errorPane = new JScrollPane(); 
    189223        errorPane.setViewportView(errorTA); 
     
    191225        errorPane.setBorder(BorderFactory.createCompoundBorder( 
    192226                BorderFactory.createTitledBorder( 
    193                     BorderFactory.createRaisedBevelBorder(), "Errors"), 
    194                     BorderFactory.createEmptyBorder(5,5,5,5))); 
    195          
    196          
     227                BorderFactory.createRaisedBevelBorder(), "Errors"), 
     228                BorderFactory.createEmptyBorder(5, 5, 5, 5))); 
     229 
     230 
    197231        Box guiBox = new Box(BoxLayout.Y_AXIS); 
    198232        guiBox.add(fileIOTabs); 
    199233        guiBox.add(Box.createVerticalStrut(10)); 
    200234        guiBox.add(errorPane); 
    201          
     235 
    202236        add(guiBox); 
    203          
     237 
    204238        setMinimumSize(new Dimension(420, 680)); 
    205239        setPreferredSize(new Dimension(420, 680)); 
     
    208242        setVisible(true); 
    209243    } 
    210      
    211     /** 
    212      * Method creates a new tab for the new I/O object.  The tab is labeled 
     244 
     245    /** 
     246     * Method creates a new tab for the new I/O object. The tab is labeled 
    213247     * "Reader #" or "Writer #", where '#' is the I/O object's ID. 
     248     * 
    214249     * @param update Initial update object. 
    215      * @param model TableModel for reader/writer that will display I/O operations. 
    216      */ 
    217     private void addTab(FileRegUpdate update, FileIOTableModel model) { 
    218          
     250     * @param model TableModel for reader/writer that will display I/O 
     251     * operations. 
     252     */ 
     253    private void addTab(FileRegUpdate update, FileIOTableModel model) 
     254    { 
     255 
    219256        String tabName = null; 
    220          
    221         switch(update.ioType) { 
     257 
     258        switch (update.ioType) 
     259        { 
    222260            case READ: 
    223261                tabName = "Reader " + update.ioID; 
     
    227265                break; 
    228266        } 
    229          
     267 
    230268        fileIOTabs.add(tabName, new ParamicsIOInfoPanel(update, model)); 
    231269    } 
    232      
    233270    private JTabbedPane fileIOTabs; 
    234  
    235271    private JScrollPane errorPane; 
    236      
    237272    private JTextArea errorTA; 
    238  
    239273} 
  • trunk/src/tmcsim/simulationmanager/SimulationManager.java

    r2 r6  
    99import java.util.logging.Level; 
    1010import java.util.logging.Logger; 
    11  
    1211import javax.swing.JOptionPane; 
    1312import javax.swing.UIManager; 
    14  
     13import tmcsim.common.CADEnums.PARAMICS_STATUS; 
    1514import tmcsim.common.SimulationException; 
    16 import tmcsim.common.CADEnums.PARAMICS_STATUS; 
    1715 
    1816/** 
    19  * Simulation Manager is the main class for this module.  The Simulation Manager 
    20  * is used to control the view and control the simulation.  Simulation incidents 
    21  * are loaded, removed, reschedule, and added from the Simulation Manager.  The 
     17 * Simulation Manager is the main class for this module. The Simulation Manager 
     18 * is used to control the view and control the simulation. Simulation incidents 
     19 * are loaded, removed, reschedule, and added from the Simulation Manager. The 
    2220 * Simulation Manager provides functionality for connecting to the paramics 
    23  * communicator and applying diversions.  A history of all events is shown as well.<br>  
    24  * The SimulationManager may be started at any point before, during, or after  
    25  * a simulation has begun. The SimulationManager connects to the CADSimulator  
    26  * and communicates through Java RMI methods.  If two SimulationManagers are started, 
    27  * the second one started, chronologically, will receive communication from the  
    28  * CADSimulator. <br><br>   
    29  * The properties file for the SimulationManager class contains the following data.<br> 
     21 * communicator and applying diversions. A history of all events is shown as 
     22 * well.<br> 
     23 * The SimulationManager may be started at any point before, during, or after a 
     24 * simulation has begun. The SimulationManager connects to the CADSimulator and 
     25 * communicates through Java RMI methods. If two SimulationManagers are started, 
     26 * the second one started, chronologically, will receive communication from the 
     27 * CADSimulator. <br><br> 
     28 * The properties file for the SimulationManager class contains the following 
     29 * data.<br> 
    3030 * <code> 
    3131 * -----------------------------------------------------------------------------<br> 
    32  * Host Name              The host name where the CADSimulator is located.<br> 
    33  * Error File             The target file to use for error logging.<br> 
     32 * Host Name The host name where the CADSimulator is located.<br> 
     33 * Error File The target file to use for error logging.<br> 
    3434 * -----------------------------------------------------------------------------<br> 
    3535 * Example File: <br> 
    36  * CADSimulatorHost    = localhost <br> 
    37  * ErrorFile           = sim_mgr_error.xml <br> 
     36 * CADSimulatorHost = localhost <br> 
     37 * ErrorFile = sim_mgr_error.xml <br> 
    3838 * -----------------------------------------------------------------------------<br> 
    3939 * </code> 
    4040 * 
    4141 * @author Matthew Cechini (mcechini@calpoly.edu) 
    42  * @version $Date: 2009/04/17 16:27:47 $ $Revision: 1.7  
     42 * @version $Date: 2009/04/17 16:27:47 $ $Revision: 1.7 
    4343 */ 
    44 public class SimulationManager { 
    45          
    46     /** Error logger. */ 
     44public class SimulationManager 
     45{ 
     46 
     47    /** 
     48     * Error logger. 
     49     */ 
    4750    private static Logger simManLogger = Logger.getLogger("tmcsim.simulationmanager"); 
    48      
     51 
    4952    /** 
    5053     * Enumeration containing property names. 
     54     * 
    5155     * @author Matthew Cechini 
    5256     */ 
    53     private static enum PROPERTIES { 
    54         CAD_SIM_HOST  ("CADSimulatorHost"), 
    55         CAD_SIM_PORT  ("CADSimulatorRMIPort"), 
    56         SCRIPT_DIR    ("ScriptDir"), 
    57         FAKE_PARAMICS ("FakeParamicsConnection"); 
    58          
     57    private static enum PROPERTIES 
     58    { 
     59 
     60        CAD_SIM_HOST("CADSimulatorHost"), 
     61        CAD_SIM_PORT("CADSimulatorRMIPort"), 
     62        SCRIPT_DIR("ScriptDir"), 
     63        FAKE_PARAMICS("FakeParamicsConnection"); 
    5964        public String name; 
    60          
    61         private PROPERTIES(String n) { 
     65 
     66        private PROPERTIES(String n) 
     67        { 
    6268            name = n; 
    6369        } 
    64          
    6570    } 
    66          
    67     /** 
    68      * Instance of the SimulationManagerModel which communicates with the  
    69      * CAD Simulator to display the current simulation information.  This 
    70      * model class contains the data that is displayed by the SimulationManagerView 
    71      * class.  The View purely provides a GUI interface for the data contained within 
     71    /** 
     72     * Instance of the SimulationManagerModel which communicates with the CAD 
     73     * Simulator to display the current simulation information. This model class 
     74     * contains the data that is displayed by the SimulationManagerView class. 
     75     * The View purely provides a GUI interface for the data contained within 
    7276     * the model. 
    7377     */ 
    74     private SimulationManagerModel  theSimManagerModel; 
    75      
    76     /** 
    77      * Instance of the SimulationManagerView class which provides a GUI for the user 
    78      * to view the current simulation information and to manage the simulation.  The  
    79      * view communicates to the SimulationManagerModel class to get and set data. 
    80      */ 
    81     SimulationManagerView   theSimManagerView; 
    82      
    83     /** The Properties object for the Simulation Manager. */ 
     78    SimulationManagerModel theSimManagerModel; 
     79    /** 
     80     * Instance of the SimulationManagerView class which provides a GUI for the 
     81     * user to view the current simulation information and to manage the 
     82     * simulation. The view communicates to the SimulationManagerModel class to 
     83     * get and set data. 
     84     */ 
     85    SimulationManagerView theSimManagerView; 
     86    /** 
     87     * The Properties object for the Simulation Manager. 
     88     */ 
    8489    private Properties simManagerProperties; 
    85      
    86     /** 
    87      * Constructor.  Set communication data members from properties file.  Instantiate 
    88      * the SimulationManager Model and View objects, and set visibility to true. 
    89      *  
    90      * @param propertiesFile Properties file containing info for Simulation Manager. 
    91      */ 
    92     public SimulationManager(String propertiesFile) throws SimulationException {     
    93  
    94         try { 
     90 
     91    /** 
     92     * Constructor. Set communication data members from properties file. 
     93     * Instantiate the SimulationManager Model and View objects, and set 
     94     * visibility to true. 
     95     * 
     96     * @param propertiesFile Properties file containing info for Simulation 
     97     * Manager. 
     98     */ 
     99    public SimulationManager(String propertiesFile) throws SimulationException 
     100    { 
     101 
     102        try 
     103        { 
    95104            simManagerProperties = new Properties(); 
    96105            simManagerProperties.load(new FileInputStream(new File(propertiesFile))); 
    97              
    98             SimulationManagerView.SCRIPT_DIR =  
    99                 simManagerProperties.getProperty(PROPERTIES.SCRIPT_DIR.name).trim(); 
     106 
     107            SimulationManagerView.SCRIPT_DIR = 
     108                    simManagerProperties.getProperty(PROPERTIES.SCRIPT_DIR.name).trim(); 
    100109 
    101110            //make sure properties aren't null 
    102             if(simManagerProperties.getProperty(PROPERTIES.CAD_SIM_HOST.name) == null) 
    103                 throw new Exception("CAD Simulator host property is null.");   
    104                  
    105             if(simManagerProperties.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) 
     111            if (simManagerProperties.getProperty(PROPERTIES.CAD_SIM_HOST.name) == null) 
     112            { 
     113                throw new Exception("CAD Simulator host property is null."); 
     114            } 
     115 
     116            if (simManagerProperties.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) 
     117            { 
    106118                throw new Exception("CAD Simulator port property is null."); 
    107              
    108         } 
    109         catch (Exception e) 
    110         {      
    111             simManLogger.logp(Level.SEVERE, "SimulationManager", "Constructor",  
     119            } 
     120 
     121        } catch (Exception e) 
     122        { 
     123            simManLogger.logp(Level.SEVERE, "SimulationManager", "Constructor", 
    112124                    "Exception in reading properties file.", e); 
    113              
     125 
    114126            throw new SimulationException(SimulationException.INITIALIZE_ERROR, e); 
    115127        } 
    116128 
    117129        //Construct the SimulationManagerModel 
    118         try  
    119         {                 
     130        try 
     131        { 
    120132            theSimManagerModel = new SimulationManagerModel( 
    121                     simManagerProperties.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(),  
     133                    simManagerProperties.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), 
    122134                    simManagerProperties.getProperty(PROPERTIES.CAD_SIM_PORT.name).trim()); 
    123135 
    124136            //Construct the SimulationManagerView and set up the Model-View references. 
    125137            theSimManagerView = new SimulationManagerView(theSimManagerModel); 
    126             theSimManagerModel.setView(theSimManagerView);                            
    127         } 
    128         catch (RemoteException re)  
    129         { 
    130             simManLogger.logp(Level.SEVERE, "SimulationManager", "Constructor",  
     138            theSimManagerModel.setView(theSimManagerView); 
     139        } catch (RemoteException re) 
     140        { 
     141            simManLogger.logp(Level.SEVERE, "SimulationManager", "Constructor", 
    131142                    "Unable to establish RMI ", re); 
    132143 
    133             throw new SimulationException(SimulationException.CAD_SIM_CONNECT, re);  
    134         } 
    135  
    136         theSimManagerView.addWindowListener(new WindowListener() { 
    137             public void windowClosed(WindowEvent e)  {} 
    138             public void windowOpened(WindowEvent e)  {}             
    139             public void windowIconified(WindowEvent e)  {}          
    140             public void windowDeiconified(WindowEvent e)  {}     
    141             public void windowActivated(WindowEvent e)  {}                              
    142             public void windowDeactivated(WindowEvent e)  {}          
    143             public void windowClosing(WindowEvent e)  {      
     144            throw new SimulationException(SimulationException.CAD_SIM_CONNECT, re); 
     145        } 
     146 
     147        theSimManagerView.addWindowListener(new WindowListener() 
     148        { 
     149            public void windowClosed(WindowEvent e) 
     150            { 
     151            } 
     152 
     153            public void windowOpened(WindowEvent e) 
     154            { 
     155            } 
     156 
     157            public void windowIconified(WindowEvent e) 
     158            { 
     159            } 
     160 
     161            public void windowDeiconified(WindowEvent e) 
     162            { 
     163            } 
     164 
     165            public void windowActivated(WindowEvent e) 
     166            { 
     167            } 
     168 
     169            public void windowDeactivated(WindowEvent e) 
     170            { 
     171            } 
     172 
     173            public void windowClosing(WindowEvent e) 
     174            { 
    144175                theSimManagerModel.disconnect(); 
    145176                System.exit(0); 
    146             }            
     177            } 
    147178        }); 
    148179 
    149         if(Boolean.parseBoolean(simManagerProperties.getProperty( 
     180        if (Boolean.parseBoolean(simManagerProperties.getProperty( 
    150181                PROPERTIES.FAKE_PARAMICS.name).trim())) 
    151182        { 
     
    154185 
    155186        //Show the SimulationManager 
    156         theSimManagerView.setVisible(true);         
     187        theSimManagerView.setVisible(true); 
    157188    } 
    158      
    159     /** 
    160      * Main class.   
    161      *  
     189 
     190    /** 
     191     * Main class. 
     192     * 
    162193     * @param args Command line arguments. 
    163194     */ 
    164     static public void main(String[] args) { 
     195    static public void main(String[] args) 
     196    { 
    165197        System.setProperty("SIM_MGR_PROPERTIES", "config/sim_manager_config.properties"); 
    166  
    167         try { 
    168             if(System.getProperty("SIM_MGR_PROPERTIES") != null) 
     198        //System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 
     199 
     200        try 
     201        { 
     202            if (System.getProperty("SIM_MGR_PROPERTIES") != null) 
    169203            { 
    170204                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    171                  
     205 
    172206                new SimulationManager(System.getProperty("SIM_MGR_PROPERTIES")); 
    173             } 
    174             else 
    175             { 
    176                 throw new Exception ("SIM_MGR_PROPERTIES system property not defined."); 
    177             } 
    178         }  
    179         catch (Exception e)  
    180         { 
    181             simManLogger.logp(Level.SEVERE, "SimulationManager", "Main",  
     207            } else 
     208            { 
     209                throw new Exception("SIM_MGR_PROPERTIES system property not defined."); 
     210            } 
     211        } catch (Exception e) 
     212        { 
     213            simManLogger.logp(Level.SEVERE, "SimulationManager", "Main", 
    182214                    "Error occured initializing application", e); 
    183              
    184             JOptionPane.showMessageDialog(null, e.getMessage(),  
    185                 "Error - Program Exiting", JOptionPane.ERROR_MESSAGE);   
    186              
     215 
     216            JOptionPane.showMessageDialog(null, e.getMessage(), 
     217                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE); 
     218 
    187219            System.exit(-1); 
    188         }    
    189          
     220        } 
     221 
    190222    } 
    191223} 
    192  
    193  
    194  
    195  
    196  
    197  
    198  
  • trunk/src/tmcsim/simulationmanager/SimulationManagerModel.java

    r2 r6  
    1010import java.util.logging.Level; 
    1111import java.util.logging.Logger; 
    12  
    1312import tmcsim.cadmodels.CMSDiversion; 
    1413import tmcsim.cadmodels.CMSInfo; 
    1514import tmcsim.client.cadclientgui.data.Incident; 
    1615import tmcsim.client.cadclientgui.data.IncidentEvent; 
     16import tmcsim.common.CADEnums.PARAMICS_STATUS; 
     17import tmcsim.common.CADEnums.SCRIPT_STATUS; 
    1718import tmcsim.common.ScriptException; 
    1819import tmcsim.common.SimulationException; 
    19 import tmcsim.common.CADEnums.PARAMICS_STATUS; 
    20 import tmcsim.common.CADEnums.SCRIPT_STATUS; 
    2120import tmcsim.interfaces.CoordinatorInterface; 
    2221import tmcsim.interfaces.SimulationManagerInterface; 
    2322 
    24  
    2523/** 
    26  * SimulationManagerModel is the model class for the Simulation Manager.  All communication 
    27  * between the Coordinator and the Simulation Manager passes through this object.  The view 
    28  * passes requests through local methods, and the Coordinator calls remote functions in this 
    29  * object to update the viewed simulation data. 
    30  * <br/>  
    31  * At construction, the SimulationManagerModel registers itself with the coordinator.   
    32  * Administrative commands for the simulation are received from the SimlationManagerView  
    33  * class, and then the appropriate Coordinator remote method is executed.  During a  
    34  * simulation, the Coordinator calls remote methods contained in the SimulationManagerInterface.   
    35  * For a description of those methods, see the interface's documentation.  After construction,  
    36  * this model class must have its setView() method called to set the reference to its view class. 
    37  *  
     24 * SimulationManagerModel is the model class for the Simulation Manager. All 
     25 * communication between the Coordinator and the Simulation Manager passes 
     26 * through this object. The view passes requests through local methods, and the 
     27 * Coordinator calls remote functions in this object to update the viewed 
     28 * simulation data. 
     29 * <br/> 
     30 * At construction, the SimulationManagerModel registers itself with the 
     31 * coordinator. Administrative commands for the simulation are received from the 
     32 * SimlationManagerView class, and then the appropriate Coordinator remote 
     33 * method is executed. During a simulation, the Coordinator calls remote methods 
     34 * contained in the SimulationManagerInterface. For a description of those 
     35 * methods, see the interface's documentation. After construction, this model 
     36 * class must have its setView() method called to set the reference to its view 
     37 * class. 
     38 * 
    3839 * @see SimulationManagerView 
    3940 * @see SimulationManagerInterface 
    40  * @author Matthew Cechini  
     41 * @author Matthew Cechini 
    4142 * @version $Revision: 1.3 $ $Date: 2006/06/06 20:46:41 $ 
    4243 */ 
    4344@SuppressWarnings("serial") 
    44 public class SimulationManagerModel extends UnicastRemoteObject  
    45     implements SimulationManagerInterface { 
    46      
    47     /** Error Logger. */ 
     45public class SimulationManagerModel extends UnicastRemoteObject 
     46        implements SimulationManagerInterface 
     47{ 
     48 
     49    /** 
     50     * Error Logger. 
     51     */ 
    4852    private Logger simManagerLogger = Logger.getLogger("tmcsim.simulationmanager"); 
    49      
    50     /** RMI interface for communication with the remote Coordinator. */  
     53    /** 
     54     * RMI interface for communication with the remote Coordinator. 
     55     */ 
    5156    private static CoordinatorInterface theCoorInt; 
    52      
    53     /** The SimulationManagerView object. */ 
    54     private SimulationManagerView theSimManagerView;     
    55      
    56  
    57     /** 
    58      * Constructor.  Establishes the RMI communication with the Coordinator. 
    59      * 
    60      * @param hostname Host name of the CAD Simulator.     
    61      * @param portNumber Port number of the CAD Simulator RMI communication.  
     57    /** 
     58     * The SimulationManagerView object. 
     59     */ 
     60    private SimulationManagerView theSimManagerView; 
     61 
     62    /** 
     63     * Constructor. Establishes the RMI communication with the Coordinator. 
     64     * 
     65     * @param hostname Host name of the CAD Simulator. 
     66     * @param portNumber Port number of the CAD Simulator RMI communication. 
    6267     * @throws RemoteException if error in RMI communication 
    63      * @throws SimulationException if there is an error in registering RMI methods. 
    64      */ 
    65     public SimulationManagerModel(String hostname, String portNumber)  
    66             throws RemoteException, SimulationException { 
    67         super();                                 
    68                                          
     68     * @throws SimulationException if there is an error in registering RMI 
     69     * methods. 
     70     */ 
     71    public SimulationManagerModel(String hostname, String portNumber) 
     72            throws RemoteException, SimulationException 
     73    { 
     74        super(); 
     75 
    6976        connect(hostname, portNumber); 
    70     }        
    71      
     77    } 
     78 
    7279    /** 
    7380     * Connect to the Coordinator's RMI object, and register this object for 
    7481     * callback with the Coordinator. 
    75      * @param hostname Host name of the CAD Simulator.     
    76      * @param portNumber Port number of the CAD Simulator RMI communication.  
    77      * @throws SimulationException if there is an error creating the RMI connection. 
    78      */  
    79     protected void connect(String hostname, String portNumber)  
    80         throws SimulationException { 
    81          
     82     * 
     83     * @param hostname Host name of the CAD Simulator. 
     84     * @param portNumber Port number of the CAD Simulator RMI communication. 
     85     * @throws SimulationException if there is an error creating the RMI 
     86     * connection. 
     87     */ 
     88    protected void connect(String hostname, String portNumber) 
     89            throws SimulationException 
     90    { 
     91 
    8292        String coorIntURL = ""; 
    83          
    84         try {   
    85             coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator";  
    86              
    87             theCoorInt = (CoordinatorInterface)Naming.lookup(coorIntURL); 
    88             theCoorInt.registerForCallback(this);            
    89              
    90         } 
    91         catch (Exception e) { 
    92             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    93                     "establishRMIConnection", "Unable to establish RMI " + 
    94                     "communication with the CAD Simulator.  URL <" + coorIntURL + ">", e); 
    95              
     93 
     94        try 
     95        { 
     96            coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator"; 
     97 
     98            theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); 
     99            theCoorInt.registerForCallback(this); 
     100 
     101        } catch (Exception e) 
     102        { 
     103            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     104                    "establishRMIConnection", "Unable to establish RMI " 
     105                    + "communication with the CAD Simulator.  URL <" + coorIntURL + ">", e); 
     106 
    96107            throw new SimulationException(SimulationException.CAD_SIM_CONNECT, e); 
    97         }    
    98     } 
    99      
    100     /** 
    101      * This method unregisters this SimulationManager from the Coordinator and closes 
    102      * the RMI communication. 
    103      */ 
    104     public void disconnect() { 
    105         try { 
     108        } 
     109    } 
     110 
     111    /** 
     112     * This method unregisters this SimulationManager from the Coordinator and 
     113     * closes the RMI communication. 
     114     */ 
     115    public void disconnect() 
     116    { 
     117        try 
     118        { 
    106119            theCoorInt.unregisterForCallback(this); 
    107120            theCoorInt = null; 
    108         } 
    109         catch (Exception e) { 
    110             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    111                     "closeSimManager", "Exception in unregistering Simulation" + 
    112                     "Manager from the CAD Simulator.", e); 
    113         } 
    114     } 
    115      
    116     /** 
    117      * Set the local reference to the SimulationManagerView object.  The view 
    118      * is updated with the current simulation time, script status, and Paramics 
    119      * connection status.  
     121        } catch (Exception e) 
     122        { 
     123            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     124                    "closeSimManager", "Exception in unregistering Simulation" 
     125                    + "Manager from the CAD Simulator.", e); 
     126        } 
     127    } 
     128 
     129    /** 
     130     * Set the local reference to the SimulationManagerView object. The view is 
     131     * updated with the current simulation time, script status, and Paramics 
     132     * connection status. 
    120133     * 
    121134     * @param newView The instance of the SimulationManagerView class. 
    122      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    123      */ 
    124     public void setView(SimulationManagerView newView) throws SimulationException { 
    125         try { 
     135     * @throws SimulationException if there is an error in RMI communication to 
     136     * the CAD Simulator. 
     137     */ 
     138    public void setView(SimulationManagerView newView) throws SimulationException 
     139    { 
     140        try 
     141        { 
    126142            theSimManagerView = newView; 
    127              
    128             theSimManagerView.tick(theCoorInt.getCurrentSimulationTime());   
     143 
     144            theSimManagerView.tick(theCoorInt.getCurrentSimulationTime()); 
    129145            theSimManagerView.setScriptStatus(theCoorInt.getScriptStatus()); 
    130146            theSimManagerView.setParamicsStatus(theCoorInt.getParamicsStatus()); 
    131              
     147 
    132148            initialize(); 
    133         } 
    134         catch (RemoteException re) { 
    135             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    136                     "startSimulation", "Unable to communicate with the " + 
    137                     "CAD Simulator.", re); 
    138              
    139             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    140         }    
    141          
    142     }    
    143      
     149        } catch (RemoteException re) 
     150        { 
     151            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     152                    "startSimulation", "Unable to communicate with the " 
     153                    + "CAD Simulator.", re); 
     154 
     155            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     156        } 
     157 
     158    } 
     159 
    144160    /** 
    145161     * This method initializes the SimulationManager with all current simulation 
    146      * data from the Coordinator.  If the simulation is running when the Simulation 
    147      * Manager is initialized, all previously occured incidents, events, and current 
    148      * diversion must be displayed.  This method first loads the list of current 
    149      * incidents from the coordinator, then the triggered events, followed by  
    150      * all CMSInfo objects.  The SimulationManagerView is notified of any current 
    151      * diversions within the CMSInfo objects.   
    152      *  
    153      * @throws SimulationException if there is an error in RMI communication or if the  
    154      *         SimulationManagerView reference has not been set. 
    155      */ 
    156     protected void initialize() throws SimulationException { 
    157          
    158         try { 
    159          
     162     * data from the Coordinator. If the simulation is running when the 
     163     * Simulation Manager is initialized, all previously occured incidents, 
     164     * events, and current diversion must be displayed. This method first loads 
     165     * the list of current incidents from the coordinator, then the triggered 
     166     * events, followed by all CMSInfo objects. The SimulationManagerView is 
     167     * notified of any current diversions within the CMSInfo objects. 
     168     * 
     169     * @throws SimulationException if there is an error in RMI communication or 
     170     * if the SimulationManagerView reference has not been set. 
     171     */ 
     172    protected void initialize() throws SimulationException 
     173    { 
     174 
     175        try 
     176        { 
     177 
    160178            //Load all incidents from Coordinator 
    161             loadIncidents();  
    162              
     179            loadIncidents(); 
     180 
    163181            //Load all triggered incidents from Coordinator 
    164182            TreeMap<Integer, Vector<IncidentEvent>> tempEvents = theCoorInt.getTriggeredEvents(); 
    165             for(Integer key : tempEvents.keySet())  {            
    166                 for(IncidentEvent ie : tempEvents.get(key))  
    167                     eventOccured(key, ie);            
    168             }            
    169                    
     183            for (Integer key : tempEvents.keySet()) 
     184            { 
     185                for (IncidentEvent ie : tempEvents.get(key)) 
     186                { 
     187                    eventOccured(key, ie); 
     188                } 
     189            } 
     190 
    170191            //Load all current diversions from the Coordinator 
    171192            TreeSet<String> cmsIDs = theCoorInt.getCMSIDs(); 
    172             CMSInfo cmsinfo  = null; 
    173             for(String cms_id : cmsIDs) { 
     193            CMSInfo cmsinfo = null; 
     194            for (String cms_id : cmsIDs) 
     195            { 
    174196                cmsinfo = theCoorInt.getCMSDiversionInfo(cms_id); 
    175                  
    176                 for(CMSDiversion div : cmsinfo.possibleDiversions) { 
    177                     if(div.getCurrDiv() != 0) {                      
     197 
     198                for (CMSDiversion div : cmsinfo.possibleDiversions) 
     199                { 
     200                    if (div.getCurrDiv() != 0) 
     201                    { 
    178202                        theSimManagerView.addDiversion(cmsinfo, div); 
    179                     }        
     203                    } 
    180204                } 
    181             }    
    182              
     205            } 
     206 
    183207            //Send the list of CMS IDs to the View. 
    184208            theSimManagerView.setCMS_IDList(cmsIDs.toArray()); 
    185         } 
    186         catch (Exception e) { 
    187             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
     209 
     210        } catch (Exception e) 
     211        { 
     212            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
    188213                    "initialize", "Unable to initialize the SimulationManager.", e); 
    189              
     214 
    190215            throw new SimulationException(SimulationException.CAD_SIM_COMM, e); 
    191         }    
    192     } 
    193  
    194     public void tick(long theTime) throws RemoteException { 
    195         if(theSimManagerView != null) 
    196             theSimManagerView.tick(theTime);     
    197     } 
    198      
    199     public void incidentAdded(Incident newIncident) throws RemoteException { 
    200         if(theSimManagerView != null) { 
     216        } 
     217    } 
     218 
     219    public void tick(long theTime) throws RemoteException 
     220    { 
     221        if (theSimManagerView != null) 
     222        { 
     223            theSimManagerView.tick(theTime); 
     224        } 
     225    } 
     226 
     227    public void incidentAdded(Incident newIncident) throws RemoteException 
     228    { 
     229        if (theSimManagerView != null) 
     230        { 
    201231            Integer logNum = new Integer(newIncident.getLogNumber()); 
    202              
    203             theSimManagerView.addIncident(newIncident);          
     232 
     233            theSimManagerView.addIncident(newIncident); 
    204234            theSimManagerView.addIncidentTab(logNum); 
    205235        } 
    206236    } 
    207237 
    208     public void incidentStarted(Integer logNumber) throws RemoteException { 
    209         if(theSimManagerView != null) { 
     238    public void incidentStarted(Integer logNumber) throws RemoteException 
     239    { 
     240        if (theSimManagerView != null) 
     241        { 
    210242            theSimManagerView.startIncident(logNumber); 
    211243        } 
    212244    } 
    213245 
    214     public void incidentRemoved(Integer logNumber) throws RemoteException { 
    215         if(theSimManagerView != null) { 
     246    public void incidentRemoved(Integer logNumber) throws RemoteException 
     247    { 
     248        if (theSimManagerView != null) 
     249        { 
    216250            theSimManagerView.removeIncident(logNumber); 
    217251            theSimManagerView.removeIncidentTab(logNumber); 
    218252        } 
    219253    } 
    220      
    221     public void eventOccured(Integer logNumber, IncidentEvent theEvent) throws RemoteException { 
    222         if(theSimManagerView != null) { 
     254 
     255    public void eventOccured(Integer logNumber, IncidentEvent theEvent) throws RemoteException 
     256    { 
     257        if (theSimManagerView != null) 
     258        { 
    223259            theSimManagerView.addIncidentEvent(logNumber, theEvent); 
    224260        } 
    225261    } 
    226      
    227     public void setScriptStatus(SCRIPT_STATUS newStatus) throws RemoteException { 
    228         if(theSimManagerView != null) 
    229             theSimManagerView.setScriptStatus(newStatus);        
    230     } 
    231  
    232     public void setParamicsStatus(PARAMICS_STATUS newStatus) throws RemoteException { 
    233         if(theSimManagerView != null) 
    234             theSimManagerView.setParamicsStatus(newStatus);      
    235          
    236     } 
    237      
    238     /** 
    239      * This method passes the view's request to start the simulation  
    240      * on to the remote coordinator. 
     262 
     263    public void setScriptStatus(SCRIPT_STATUS newStatus) throws RemoteException 
     264    { 
     265        if (theSimManagerView != null) 
     266        { 
     267            theSimManagerView.setScriptStatus(newStatus); 
     268        } 
     269    } 
     270 
     271    public void setParamicsStatus(PARAMICS_STATUS newStatus) throws RemoteException 
     272    { 
     273        if (theSimManagerView != null) 
     274        { 
     275            theSimManagerView.setParamicsStatus(newStatus); 
     276        } 
     277 
     278    } 
     279 
     280    /** 
     281     * This method passes the view's request to start the simulation on to the 
     282     * remote coordinator. 
    241283     * 
    242284     * @throws ScriptException if an error occurs in started the simulation. 
    243      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    244      */   
    245     public void startSimulation() throws ScriptException, SimulationException { 
    246  
    247         try { 
     285     * @throws SimulationException if there is an error in RMI communication to 
     286     * the CAD Simulator. 
     287     */ 
     288    public void startSimulation() throws ScriptException, SimulationException 
     289    { 
     290 
     291        try 
     292        { 
    248293            theCoorInt.startSimulation(); 
    249         } 
    250         catch (RemoteException re) { 
    251             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    252                     "startSimulation", "Unable to communicate with the " + 
    253                     "CAD Simulator.", re); 
    254              
    255             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    256         }    
    257  
    258     } 
    259      
    260     /** 
    261      * This method passes the view's request to reset the simulation  
    262      * on to the remote coordinator.  The View's simulation time is reset to 0. 
    263      * The view's incident tabs are cleared and incident list reset and initialized 
    264      * with the current list of incidents.  The list of diversions is also reset. 
    265      *  
    266      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    267      */ 
    268     public void resetSimulation() throws SimulationException {       
    269  
    270         try { 
     294        } catch (RemoteException re) 
     295        { 
     296            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     297                    "startSimulation", "Unable to communicate with the " 
     298                    + "CAD Simulator.", re); 
     299 
     300            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     301        } 
     302 
     303    } 
     304 
     305    /** 
     306     * This method passes the view's request to reset the simulation on to the 
     307     * remote coordinator. The View's simulation time is reset to 0. The view's 
     308     * incident tabs are cleared and incident list reset and initialized with 
     309     * the current list of incidents. The list of diversions is also reset. 
     310     * 
     311     * @throws SimulationException if there is an error in RMI communication to 
     312     * the CAD Simulator. 
     313     */ 
     314    public void resetSimulation() throws SimulationException 
     315    { 
     316 
     317        try 
     318        { 
    271319            theCoorInt.resetSimulation(); 
    272              
     320 
    273321            tick(0); 
    274322            theSimManagerView.resetIncidentTabs(); 
     
    276324            theSimManagerView.resetDiversions(); 
    277325 
    278             loadIncidents();  
    279         } 
    280         catch (RemoteException re) { 
    281             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    282                     "resetSimulation", "Unable to communicate with the " + 
    283                     "CAD Simulator.", re); 
    284              
    285             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    286         }    
    287  
    288     } 
    289      
    290     /** 
    291      * This method passes the view's request to pause the simulation  
    292      * on to the remote coordinator. 
    293      *       
    294      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    295      */ 
    296     public void pauseSimulation() throws SimulationException { 
    297  
    298         try { 
     326            loadIncidents(); 
     327        } catch (RemoteException re) 
     328        { 
     329            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     330                    "resetSimulation", "Unable to communicate with the " 
     331                    + "CAD Simulator.", re); 
     332 
     333            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     334        } 
     335 
     336    } 
     337 
     338    /** 
     339     * This method passes the view's request to pause the simulation on to the 
     340     * remote coordinator. 
     341     * 
     342     * @throws SimulationException if there is an error in RMI communication to 
     343     * the CAD Simulator. 
     344     */ 
     345    public void pauseSimulation() throws SimulationException 
     346    { 
     347 
     348        try 
     349        { 
    299350            theCoorInt.pauseSimulation(); 
    300          } 
    301         catch (RemoteException re) { 
    302             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    303                     "pauseSimulation", "Unable to communicate with the " + 
    304                     "CAD Simulator.", re); 
    305              
    306             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    307         }    
    308  
    309     } 
    310      
    311     /** 
    312      * This method passes the view's request to goto a new simulation  
    313      * time on to the remote coordinator. 
    314      *  
    315      * @param time Simulation time  
    316      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    317      */ 
    318     public void gotoSimulationTime(long time) throws SimulationException { 
    319          
    320         try { 
     351        } catch (RemoteException re) 
     352        { 
     353            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     354                    "pauseSimulation", "Unable to communicate with the " 
     355                    + "CAD Simulator.", re); 
     356 
     357            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     358        } 
     359 
     360    } 
     361 
     362    /** 
     363     * This method passes the view's request to goto a new simulation time on to 
     364     * the remote coordinator. 
     365     * 
     366     * @param time Simulation time 
     367     * @throws SimulationException if there is an error in RMI communication to 
     368     * the CAD Simulator. 
     369     */ 
     370    public void gotoSimulationTime(long time) throws SimulationException 
     371    { 
     372 
     373        try 
     374        { 
    321375            theCoorInt.gotoSimulationTime(time); 
    322         } 
    323         catch (RemoteException re) { 
    324             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    325                     "gotoSimulationTime", "Unable to communicate with the " + 
    326                     "CAD Simulator.", re); 
    327              
    328             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    329         }    
    330     } 
    331      
    332     /** 
    333      * This method passes the view's request to load a script file on to the  
    334      * remote Coordinator.  If this is successful, the View's incident tabs  
    335      * are cleared and incident list reset and initialized with the current  
    336      * list of incidents.  If the load is not successful, the View's incident tabs 
    337      * and incident list are cleared. The list of diversions is also reset. 
     376        } catch (RemoteException re) 
     377        { 
     378            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     379                    "gotoSimulationTime", "Unable to communicate with the " 
     380                    + "CAD Simulator.", re); 
     381 
     382            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     383        } 
     384    } 
     385 
     386    /** 
     387     * This method passes the view's request to load a script file on to the 
     388     * remote Coordinator. If this is successful, the View's incident tabs are 
     389     * cleared and incident list reset and initialized with the current list of 
     390     * incidents. If the load is not successful, the View's incident tabs and 
     391     * incident list are cleared. The list of diversions is also reset. 
    338392     * 
    339393     * @param scriptFile the File chosen by the user in the open file dialog. 
    340394     * @throws ScriptException if an error occurs in reading the script file. 
    341      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    342      */ 
    343     public void loadScript(File scriptFile) throws ScriptException, SimulationException{     
    344          
    345         try { 
     395     * @throws SimulationException if there is an error in RMI communication to 
     396     * the CAD Simulator. 
     397     */ 
     398    public void loadScript(File scriptFile) throws ScriptException, SimulationException 
     399    { 
     400 
     401        try 
     402        { 
    346403            theCoorInt.loadScriptFile(scriptFile); 
    347              
     404 
    348405            tick(0); 
    349406            theSimManagerView.resetIncidentTabs(); 
    350407            theSimManagerView.resetIncidents(); 
    351408            theSimManagerView.resetDiversions(); 
    352              
     409 
    353410            loadIncidents(); 
    354          }  
    355          catch(ScriptException se) { 
     411        } catch (ScriptException se) 
     412        { 
    356413            theSimManagerView.resetIncidentTabs(); 
    357414            theSimManagerView.resetIncidents(); 
    358415            theSimManagerView.resetDiversions(); 
    359416            throw se; 
    360          } 
    361         catch (RemoteException re) { 
    362             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    363                     "loadScript", "Unable to communicate with the " + 
    364                     "CAD Simulator.", re); 
    365              
    366             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    367         }            
    368     } 
    369      
    370      /** 
    371       * This method passes the view's request to create a connection between 
    372       * the CADSimulator and the Paramics Communicator on to the remote Coordinator.  
    373       * 
    374       * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    375       */ 
    376      public void connectToParamics() throws SimulationException { 
    377  
    378         try { 
     417        } catch (RemoteException re) 
     418        { 
     419            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     420                    "loadScript", "Unable to communicate with the " 
     421                    + "CAD Simulator.", re); 
     422 
     423            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     424        } 
     425    } 
     426 
     427    /** 
     428     * This method passes the view's request to create a connection between the 
     429     * CADSimulator and the Paramics Communicator on to the remote Coordinator. 
     430     * 
     431     * @throws SimulationException if there is an error in RMI communication to 
     432     * the CAD Simulator. 
     433     */ 
     434    public void connectToParamics() throws SimulationException 
     435    { 
     436 
     437        try 
     438        { 
    379439            theCoorInt.connectToParamics(); 
    380         }  
    381         catch (RemoteException re) { 
    382             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    383                     "connectToParamics", "Unable to communicate with the " + 
    384                     "CAD Simulator.", re); 
    385              
    386             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    387         } 
    388      } 
    389       
    390      /**  
    391       * This method passes the view's request to drop the connection between 
    392       * the CADSimulator and the Paramics Communicator on to the 
    393       * remote Coordinator.  
    394       * 
    395       * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    396       */ 
    397      public void disconnectFromParamics() throws SimulationException {  
    398  
    399         try { 
     440        } catch (RemoteException re) 
     441        { 
     442            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     443                    "connectToParamics", "Unable to communicate with the " 
     444                    + "CAD Simulator.", re); 
     445 
     446            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     447        } 
     448    } 
     449 
     450    /** 
     451     * This method passes the view's request to drop the connection between the 
     452     * CADSimulator and the Paramics Communicator on to the remote Coordinator. 
     453     * 
     454     * @throws SimulationException if there is an error in RMI communication to 
     455     * the CAD Simulator. 
     456     */ 
     457    public void disconnectFromParamics() throws SimulationException 
     458    { 
     459 
     460        try 
     461        { 
    400462            theCoorInt.disconnectFromParamics(); 
    401         }  
    402         catch (RemoteException re) { 
    403             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    404                     "disconnectFromParamics", "Unable to communicate with the " + 
    405                     "CAD Simulator.", re); 
    406              
    407             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    408         } 
    409      } 
    410       
    411      /** 
    412       * This method passes the view's request to load a paramics 
    413       * network on to the remote Coordinator.  
    414       * 
    415       * @param networkID The unique network ID that is being loaded 
    416       * 
    417       * @throws ScriptException if there is an error in loading the network 
    418       * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    419       */ 
    420      public void loadParamicsNetwork(int networkID) throws ScriptException, SimulationException { 
    421         try { 
    422              theCoorInt.loadParamicsNetwork(networkID);          
    423         } catch (RemoteException re) { 
    424             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    425                     "loadParamicsNetwork", "Unable to communicate with the " + 
    426                     "CAD Simulator.", re); 
    427              
    428             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    429         } 
    430      } 
    431           
    432      /** 
    433       * This method passes the view's request to get the value of the 
    434       * currently loaded paramics network on to the remote Coordinator. 
    435       *  
    436       * @return Value of the loaded paramics network.   
    437       * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    438       */ 
    439      public int getParamicsNetworkLoaded() throws SimulationException { 
    440          try { 
    441             return theCoorInt.getParamicsNetworkLoaded();            
    442         } catch (RemoteException re) { 
    443             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    444                     "getParamicsNetworkLoaded", "Unable to communicate with the " + 
    445                     "CAD Simulator.", re); 
    446              
    447             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    448         } 
    449      } 
    450      
    451     /** 
    452      * This method passes the view's request to trigger an incident  
    453      * on to the remote Coordinator. 
     463        } catch (RemoteException re) 
     464        { 
     465            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     466                    "disconnectFromParamics", "Unable to communicate with the " 
     467                    + "CAD Simulator.", re); 
     468 
     469            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     470        } 
     471    } 
     472 
     473    /** 
     474     * This method passes the view's request to load a paramics network on to 
     475     * the remote Coordinator. 
     476     * 
     477     * @param networkID The unique network ID that is being loaded 
     478     * 
     479     * @throws ScriptException if there is an error in loading the network 
     480     * @throws SimulationException if there is an error in RMI communication to 
     481     * the CAD Simulator. 
     482     */ 
     483    public void loadParamicsNetwork(int networkID) throws ScriptException, SimulationException 
     484    { 
     485        try 
     486        { 
     487            theCoorInt.loadParamicsNetwork(networkID); 
     488        } catch (RemoteException re) 
     489        { 
     490            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     491                    "loadParamicsNetwork", "Unable to communicate with the " 
     492                    + "CAD Simulator.", re); 
     493 
     494            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     495        } 
     496    } 
     497 
     498    /** 
     499     * This method passes the view's request to get the value of the currently 
     500     * loaded paramics network on to the remote Coordinator. 
     501     * 
     502     * @return Value of the loaded paramics network. 
     503     * @throws SimulationException if there is an error in RMI communication to 
     504     * the CAD Simulator. 
     505     */ 
     506    public int getParamicsNetworkLoaded() throws SimulationException 
     507    { 
     508        try 
     509        { 
     510            return theCoorInt.getParamicsNetworkLoaded(); 
     511        } catch (RemoteException re) 
     512        { 
     513            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     514                    "getParamicsNetworkLoaded", "Unable to communicate with the " 
     515                    + "CAD Simulator.", re); 
     516 
     517            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     518        } 
     519    } 
     520 
     521    /** 
     522     * This method passes the view's request to trigger an incident on to the 
     523     * remote Coordinator. 
    454524     * 
    455525     * @throws ScriptException if an error occurs in triggering an event. 
    456      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    457      */ 
    458     public void triggerIncident(int logNumber) throws ScriptException, SimulationException { 
    459         try { 
     526     * @throws SimulationException if there is an error in RMI communication to 
     527     * the CAD Simulator. 
     528     */ 
     529    public void triggerIncident(int logNumber) throws ScriptException, SimulationException 
     530    { 
     531        try 
     532        { 
    460533            theCoorInt.triggerIncident(logNumber); 
    461              
    462         } catch (RemoteException re) { 
    463             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    464                     "startIncident", "Unable to communicate with the " + 
    465                     "CAD Simulator.", re); 
    466              
    467             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    468         } 
    469     } 
    470  
    471      /** 
    472       * This method passes the view's request to add an incident into the  
    473       * simulation on to the remote Coordinator. 
    474       * 
    475       * @param newIncident Incident to add to the simulation 
    476       * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    477       */ 
    478      public void addIncident(final Incident newIncident) throws SimulationException {        
    479  
    480         try { 
     534 
     535        } catch (RemoteException re) 
     536        { 
     537            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     538                    "startIncident", "Unable to communicate with the " 
     539                    + "CAD Simulator.", re); 
     540 
     541            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     542        } 
     543    } 
     544 
     545    /** 
     546     * This method passes the view's request to add an incident into the 
     547     * simulation on to the remote Coordinator. 
     548     * 
     549     * @param newIncident Incident to add to the simulation 
     550     * @throws SimulationException if there is an error in RMI communication to 
     551     * the CAD Simulator. 
     552     */ 
     553    public void addIncident(final Incident newIncident) throws SimulationException 
     554    { 
     555 
     556        try 
     557        { 
    481558            theCoorInt.addIncident(newIncident); 
    482      
    483         } catch (RemoteException re) { 
    484             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    485                     "addIncident", "Unable to communicate with the " + 
    486                     "CAD Simulator.", re); 
    487              
    488             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    489         }        
    490  
    491     } 
    492      
    493     /** 
    494      * This method passes the view's request to delete an incident from the  
     559 
     560        } catch (RemoteException re) 
     561        { 
     562            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     563                    "addIncident", "Unable to communicate with the " 
     564                    + "CAD Simulator.", re); 
     565 
     566            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     567        } 
     568 
     569    } 
     570 
     571    /** 
     572     * This method passes the view's request to delete an incident from the 
    495573     * simulation on to the remote Coordinator. 
    496574     * 
    497575     * @throws ScriptException if an error occurs in deleting an event. 
    498      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    499      */ 
    500     public void deleteIncident(int logNumber) throws ScriptException, SimulationException { 
    501  
    502         try { 
    503             theCoorInt.deleteIncident(logNumber);    
    504      
    505         } catch (RemoteException re) { 
    506             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    507                     "deleteIncident", "Unable to communicate with the " + 
    508                     "CAD Simulator.", re); 
    509              
    510             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    511         }        
    512     }    
    513      
    514      
    515     /** 
    516      * This method passes the view's request to reschedule an incident on to  
    517      * the remote Coordinator. 
     576     * @throws SimulationException if there is an error in RMI communication to 
     577     * the CAD Simulator. 
     578     */ 
     579    public void deleteIncident(int logNumber) throws ScriptException, SimulationException 
     580    { 
     581 
     582        try 
     583        { 
     584            theCoorInt.deleteIncident(logNumber); 
     585 
     586        } catch (RemoteException re) 
     587        { 
     588            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     589                    "deleteIncident", "Unable to communicate with the " 
     590                    + "CAD Simulator.", re); 
     591 
     592            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     593        } 
     594    } 
     595 
     596    /** 
     597     * This method passes the view's request to reschedule an incident on to the 
     598     * remote Coordinator. 
    518599     * 
    519600     * @param newTime New simulation time (in seconds). 
    520      * @throws ScriptException if the Incident has already started or the time for  
    521      *         recheduling has already passed. 
    522      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    523      */ 
    524      public void rescheduleIncident(long newTime, int logNumber) throws ScriptException, SimulationException { 
    525              
    526         try { 
     601     * @throws ScriptException if the Incident has already started or the time 
     602     * for recheduling has already passed. 
     603     * @throws SimulationException if there is an error in RMI communication to 
     604     * the CAD Simulator. 
     605     */ 
     606    public void rescheduleIncident(long newTime, int logNumber) throws ScriptException, SimulationException 
     607    { 
     608 
     609        try 
     610        { 
    527611            theCoorInt.rescheduleIncident(logNumber, newTime); 
    528         } catch (RemoteException re) { 
    529             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    530                     "rescheduleIncident", "Unable to communicate with the " + 
    531                     "CAD Simulator.", re); 
    532              
    533             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    534         }                
    535      } 
    536       
    537     /** 
    538      * This method passes the view's request to get the current list of  
     612        } catch (RemoteException re) 
     613        { 
     614            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     615                    "rescheduleIncident", "Unable to communicate with the " 
     616                    + "CAD Simulator.", re); 
     617 
     618            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     619        } 
     620    } 
     621 
     622    /** 
     623     * This method passes the view's request to get the current list of 
    539624     * Incidents loaded into the simulation on to the remote Coordinator. 
    540625     * 
    541626     * @return Vector The Vector of currently loaded incidents. 
    542      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    543      */ 
    544     public Vector<Incident> getIncidentList() throws SimulationException { 
    545  
    546         try { 
     627     * @throws SimulationException if there is an error in RMI communication to 
     628     * the CAD Simulator. 
     629     */ 
     630    public Vector<Incident> getIncidentList() throws SimulationException 
     631    { 
     632 
     633        try 
     634        { 
    547635            return theCoorInt.getIncidentList(); 
    548              
    549         } catch (RemoteException re) { 
    550             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    551                     "getIncidentList", "Unable to communicate with the " + 
    552                     "CAD Simulator.", re); 
    553              
    554             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    555         } 
    556     }     
    557               
    558     /** 
    559      * This method passes the view's request to get the CMSInfo object  
    560      * that corresponds to a unique CMS ID String on to the remote Coordinator. 
    561      *  
     636 
     637        } catch (RemoteException re) 
     638        { 
     639            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     640                    "getIncidentList", "Unable to communicate with the " 
     641                    + "CAD Simulator.", re); 
     642 
     643            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     644        } 
     645    } 
     646 
     647    /** 
     648     * This method passes the view's request to get the CMSInfo object that 
     649     * corresponds to a unique CMS ID String on to the remote Coordinator. 
     650     * 
    562651     * @param cms_id Unique CMS ID String. 
    563652     * @return CMSInfo object corresponding to the parameter CMS id. 
    564      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    565      */ 
    566     public CMSInfo getCMSDiversionInfo(String cms_id) throws SimulationException { 
    567          
    568         try { 
     653     * @throws SimulationException if there is an error in RMI communication to 
     654     * the CAD Simulator. 
     655     */ 
     656    public CMSInfo getCMSDiversionInfo(String cms_id) throws SimulationException 
     657    { 
     658 
     659        try 
     660        { 
    569661            return theCoorInt.getCMSDiversionInfo(cms_id); 
    570         } catch (RemoteException re) { 
    571             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    572                     "getCMSDiversionInfo", "Unable to communicate with the " + 
    573                     "CAD Simulator.", re); 
    574              
    575             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    576         } 
    577     } 
    578       
    579     /** 
    580      * This method passes the view's request to update diversions for a 
    581      * CMS on to the remote Coordinator. 
    582      *  
     662        } catch (RemoteException re) 
     663        { 
     664            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     665                    "getCMSDiversionInfo", "Unable to communicate with the " 
     666                    + "CAD Simulator.", re); 
     667 
     668            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     669        } 
     670    } 
     671 
     672    /** 
     673     * This method passes the view's request to update diversions for a CMS on 
     674     * to the remote Coordinator. 
     675     * 
    583676     * @param diversion CMS diversions information to apply. 
    584      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    585      */ 
    586     public void applyDiversions(CMSInfo diversion) throws SimulationException { 
    587          
    588         try { 
     677     * @throws SimulationException if there is an error in RMI communication to 
     678     * the CAD Simulator. 
     679     */ 
     680    public void applyDiversions(CMSInfo diversion) throws SimulationException 
     681    { 
     682 
     683        try 
     684        { 
    589685            theCoorInt.applyDiversions(diversion); 
    590686 
    591         } catch (RemoteException re) { 
    592             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    593                     "applyDiversions", "Unable to communicate with the " + 
    594                     "CAD Simulator.", re); 
    595              
    596             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    597         } 
    598     } 
    599      
    600     /** 
    601      * This method loads the current list of incidents from the Coordinator into the 
    602      * SimulationManager.  For each incident in the simulation, notify the view to 
    603      * add a new incident tab.  If the Incident has begun in the simulation,  
    604      * call the incidentStarted() method to update the view accordingly. 
    605      *  
    606      * @throws SimulationException if there is an error in RMI communication to the CAD Simulator. 
    607      */  
    608     private void loadIncidents() throws SimulationException {        
    609          
    610         try {            
    611             for(Incident inc : theCoorInt.getIncidentList()) { 
    612      
     687        } catch (RemoteException re) 
     688        { 
     689            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     690                    "applyDiversions", "Unable to communicate with the " 
     691                    + "CAD Simulator.", re); 
     692 
     693            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     694        } 
     695    } 
     696 
     697    /** 
     698     * This method loads the current list of incidents from the Coordinator into 
     699     * the SimulationManager. For each incident in the simulation, notify the 
     700     * view to add a new incident tab. If the Incident has begun in the 
     701     * simulation, call the incidentStarted() method to update the view 
     702     * accordingly. 
     703     * 
     704     * @throws SimulationException if there is an error in RMI communication to 
     705     * the CAD Simulator. 
     706     */ 
     707    private void loadIncidents() throws SimulationException 
     708    { 
     709 
     710        try 
     711        { 
     712            for (Incident inc : theCoorInt.getIncidentList()) 
     713            { 
     714 
    613715                Integer logNum = new Integer(inc.getLogNumber()); 
    614                  
     716 
    615717                theSimManagerView.addIncidentTab(logNum); 
    616718                theSimManagerView.addIncident(inc); 
    617              
    618                 if(inc.getSecondsToStart() < theCoorInt.getCurrentSimulationTime()) { 
     719 
     720                if (inc.getSecondsToStart() < theCoorInt.getCurrentSimulationTime()) 
     721                { 
    619722                    incidentStarted(logNum); 
    620723                } 
    621724            } 
    622         } catch (RemoteException re) { 
    623             simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel",  
    624                     "loadIncidentListTable", "Unable to communicate with the " + 
    625                     "CAD Simulator.", re); 
    626              
    627             throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
    628         } 
    629          
    630     } 
    631      
    632  
     725        } catch (RemoteException re) 
     726        { 
     727            simManagerLogger.logp(Level.SEVERE, "SimulationManagerModel", 
     728                    "loadIncidentListTable", "Unable to communicate with the " 
     729                    + "CAD Simulator.", re); 
     730 
     731            throw new SimulationException(SimulationException.CAD_SIM_COMM, re); 
     732        } 
     733 
     734    } 
    633735} 
  • trunk/src/tmcsim/simulationmanager/SimulationManagerView.java

    r2 r6  
    737737        simulationStatus     = new JLabel("Simulation Status"); 
    738738        simulationStatusText = new JLabel("No Script"); 
     739        simulationStatusText.setName("simulationStatusText"); 
    739740        simulationStatusText.setFont(new Font("Geneva", Font.BOLD, 14)); 
    740741         
     
    746747        pauseButton  = new JButton(new PauseSimulationAction(this)); 
    747748        resetButton = new JButton(new ResetSimulationAction(this)); 
     749        loadScriptButton = new JButton(new LoadScriptAction(this)); 
     750        loadScriptButton.setAlignmentX(Box.CENTER_ALIGNMENT); 
    748751         
    749752        startButton.setEnabled(false); 
     
    756759        simulationTimeButtonBox = new Box(BoxLayout.X_AXIS); 
    757760         
     761        simulationTimeButtonBox.add(loadScriptButton); 
    758762        simulationTimeButtonBox.add(startButton); 
    759763        simulationTimeButtonBox.add(pauseButton); 
    760764        simulationTimeButtonBox.add(resetButton); 
     765//        currentScript = new JLabel(" no script loaded"); 
     766        //currentScript.setAlignmentX(Box.LEFT_ALIGNMENT); 
     767//        simulationTimeButtonBox.add (currentScript); 
    761768         
    762769        simulationStatus.setAlignmentX(Box.CENTER_ALIGNMENT); 
    763770        simulationStatusText.setAlignmentX(Box.CENTER_ALIGNMENT); 
    764         simulationStatusText.setName("simulationStatusText"); 
    765771         
    766772        TitledBorder title = BorderFactory.createTitledBorder( 
     
    779785        scriptBox.setAlignmentX(Box.CENTER_ALIGNMENT); 
    780786         
    781         loadScriptButton = new JButton(new LoadScriptAction(this)); 
    782         loadScriptButton.setAlignmentX(Box.CENTER_ALIGNMENT); 
    783          
    784787        scriptBox.add(simulationStatusBox); 
    785788        scriptBox.add(Box.createVerticalStrut(5)); 
    786         scriptBox.add(loadScriptButton); 
    787789         
    788790        simulationClockLabel = new JLabel("0:00:00"); 
     
    800802        simulationTimeAndStatusBox = Box.createHorizontalBox(); 
    801803        simulationTimeAndStatusBox.setAlignmentX(Box.LEFT_ALIGNMENT); 
    802         simulationTimeAndStatusBox.setMaximumSize(new Dimension(640, 200)); 
    803         simulationTimeAndStatusBox.setPreferredSize(new Dimension(640, 160)); 
     804        simulationTimeAndStatusBox.setMaximumSize(new Dimension(640, 300)); 
     805        simulationTimeAndStatusBox.setPreferredSize(new Dimension(640, 1600)); 
    804806        simulationTimeAndStatusBox.add(Box.createHorizontalStrut(5)); 
    805807        simulationTimeAndStatusBox.add(simulationTimeBox); 
     
    12241226    private JLabel timeScheduledLabel; 
    12251227    private JLabel CADClientClockLabel; 
    1226              
     1228    private JLabel currentScript; 
    12271229    private Box adminInteractionBox;     
    12281230    private Box simulationRightSideBox; 
  • trunk/src/tmcsim/simulationmanager/actions/LoadScriptAction.java

    r2 r6  
    5454                    try{  
    5555                        theSimManagerView.getModel().loadScript(selectedFile); 
     56                        theSimManagerView.setTitle("Simulation Manager: " + selectedFile.getName()); 
    5657                    } 
    5758                    catch (ScriptException se) { 
Note: See TracChangeset for help on using the changeset viewer.