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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  
Note: See TracChangeset for help on using the changeset viewer.