Changeset 6 in tmcsimulator for trunk/src/tmcsim/simulationmanager/SimulationManager.java
- Timestamp:
- 04/20/2016 02:29:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/simulationmanager/SimulationManager.java
r2 r6 9 9 import java.util.logging.Level; 10 10 import java.util.logging.Logger; 11 12 11 import javax.swing.JOptionPane; 13 12 import javax.swing.UIManager; 14 13 import tmcsim.common.CADEnums.PARAMICS_STATUS; 15 14 import tmcsim.common.SimulationException; 16 import tmcsim.common.CADEnums.PARAMICS_STATUS;17 15 18 16 /** 19 * Simulation Manager is the main class for this module. The Simulation Manager20 * is used to control the view and control the simulation. Simulation incidents21 * are loaded, removed, reschedule, and added from the Simulation Manager. The17 * 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 22 20 * 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> 30 30 * <code> 31 31 * -----------------------------------------------------------------------------<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> 34 34 * -----------------------------------------------------------------------------<br> 35 35 * 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> 38 38 * -----------------------------------------------------------------------------<br> 39 39 * </code> 40 40 * 41 41 * @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 43 43 */ 44 public class SimulationManager { 45 46 /** Error logger. */ 44 public class SimulationManager 45 { 46 47 /** 48 * Error logger. 49 */ 47 50 private static Logger simManLogger = Logger.getLogger("tmcsim.simulationmanager"); 48 51 49 52 /** 50 53 * Enumeration containing property names. 54 * 51 55 * @author Matthew Cechini 52 56 */ 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"); 59 64 public String name; 60 61 private PROPERTIES(String n) { 65 66 private PROPERTIES(String n) 67 { 62 68 name = n; 63 69 } 64 65 70 } 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 72 76 * the model. 73 77 */ 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 */ 84 89 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 { 95 104 simManagerProperties = new Properties(); 96 105 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(); 100 109 101 110 //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 { 106 118 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", 112 124 "Exception in reading properties file.", e); 113 125 114 126 throw new SimulationException(SimulationException.INITIALIZE_ERROR, e); 115 127 } 116 128 117 129 //Construct the SimulationManagerModel 118 try 119 { 130 try 131 { 120 132 theSimManagerModel = new SimulationManagerModel( 121 simManagerProperties.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), 133 simManagerProperties.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), 122 134 simManagerProperties.getProperty(PROPERTIES.CAD_SIM_PORT.name).trim()); 123 135 124 136 //Construct the SimulationManagerView and set up the Model-View references. 125 137 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", 131 142 "Unable to establish RMI ", re); 132 143 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 { 144 175 theSimManagerModel.disconnect(); 145 176 System.exit(0); 146 } 177 } 147 178 }); 148 179 149 if (Boolean.parseBoolean(simManagerProperties.getProperty(180 if (Boolean.parseBoolean(simManagerProperties.getProperty( 150 181 PROPERTIES.FAKE_PARAMICS.name).trim())) 151 182 { … … 154 185 155 186 //Show the SimulationManager 156 theSimManagerView.setVisible(true); 187 theSimManagerView.setVisible(true); 157 188 } 158 159 /** 160 * Main class. 161 * 189 190 /** 191 * Main class. 192 * 162 193 * @param args Command line arguments. 163 194 */ 164 static public void main(String[] args) { 195 static public void main(String[] args) 196 { 165 197 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) 169 203 { 170 204 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 171 205 172 206 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", 182 214 "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 187 219 System.exit(-1); 188 } 189 220 } 221 190 222 } 191 223 } 192 193 194 195 196 197 198
Note: See TracChangeset
for help on using the changeset viewer.
