- Timestamp:
- 06/28/2016 02:25:42 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 20 added
- 2 deleted
- 11 edited
-
IDE_metadata/NetBeans/TMCSim/build.xml (modified) (1 diff)
-
src/tmcsim/application.properties (modified) (1 diff)
-
src/tmcsim/paramicscommunicator/PComm.java (added)
-
src/tmcsim/paramicscommunicator/ParamicsCommunicator.java (modified) (5 diffs)
-
src/tmcsim/paramicscommunicator/ParamicsFileReader.java (modified) (7 diffs)
-
src/tmcsim/paramicscommunicator/gui/ParamicsCommunicatorGUI.java (modified) (7 diffs)
-
src/tmcsim/paramicslog/ParamicsLog.java (modified) (10 diffs)
-
src/tmcsim/paramicslog/ParamicsLogFileHandler.java (added)
-
src/tmcsim/paramicslog/gui/ParamicsLogGUI.java (modified) (4 diffs)
-
src/tmcsim/simulationmanager/SimulationManager.java (modified) (3 diffs)
-
src/tmcsim/simulationmanager/SimulationManagerView.java (modified) (1 diff)
-
test/tmcsim/cadsimulator/BOStest.java (added)
-
test/tmcsim/cadsimulator/CADSimulatorConsoleDriver.java (added)
-
test/tmcsim/cadsimulator/CADSimulatorConsoleTest.java (added)
-
test/tmcsim/cadsimulator/CADSimulatorFixture.java (modified) (2 diffs)
-
test/tmcsim/cadsimulator/CADSimulatorGUITest.java (modified) (6 diffs)
-
test/tmcsim/cadsimulator/CADSimulatorNetworkTest.java (deleted)
-
test/tmcsim/cadsimulator/CADSimulatorTest.java (deleted)
-
test/tmcsim/cadsimulator/SystemConsoleTest.java (added)
-
test/tmcsim/cadsimulator/SystemTest.java (added)
-
test/tmcsim/cadsimulator/VisibleSystemDemoDriver.java (added)
-
test/tmcsim/cadsimulator/viewer (added)
-
test/tmcsim/cadsimulator/viewer/CADConsoleViewerTest.java (added)
-
test/tmcsim/cadsimulator/viewer/CADSimulatorViewModelTest.java (added)
-
test/tmcsim/cadsimulator/viewer/model (added)
-
test/tmcsim/cadsimulator/viewer/model/CADSimulatorModelTest.java (added)
-
test/tmcsim/cadsimulator/viewer/model/CADSimulatorStatusTest.java (added)
-
test/tmcsim/paramicslog (added)
-
test/tmcsim/paramicslog/ParamicsLogFileHandlerTest.java (added)
-
test/tmcsim/paramicslog/ParamicsLogRMITestSkeleton.java (added)
-
test/tmcsim/simulationmanager/IncidentHistoryPanelDriver.java (added)
-
test/tmcsim/simulationmanager/model (added)
-
test/tmcsim/simulationmanager/model/AppliedDiversionTableItemTest.java (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/IDE_metadata/NetBeans/TMCSim/build.xml
r44 r47 71 71 <!-- *** Build a jar with everything *** --> 72 72 <property name="deploy.jar.name" value="TMCSimAll"/> 73 <property name="deploy.dir" value=" deploy"/>73 <property name="deploy.dir" value="${workdir}/deploy"/> 74 74 <property name="deploy.jar" value="${deploy.dir}/${deploy.jar.name}.jar"/> 75 75 -
trunk/src/tmcsim/application.properties
r44 r47 1 #T hu, 23 Jun 2016 19:19:14-07001 #Tue, 28 Jun 2016 14:56:40 -0700 2 2 3 Application.revision=4 33 Application.revision=44 4 4 5 Application.buildnumber=1 5 Application.buildnumber=10 -
trunk/src/tmcsim/paramicscommunicator/ParamicsCommunicator.java
r33 r47 19 19 import java.util.logging.Level; 20 20 import java.util.logging.Logger; 21 21 import javax.swing.JFrame; 22 22 import javax.swing.JOptionPane; 23 23 import javax.swing.UIManager; … … 140 140 public ParamicsCommunicator(String propertiesFile) 141 141 { 142 paramLogger.logp(Level.INFO, "ParamicsCommunicator", "Constructor", 143 "Entering "); 142 144 143 145 writers = new TreeMap<String, ParamicsFileWriter>(); 144 146 readers = new TreeMap<String, ParamicsFileReader>(); 145 147 148 theGUI = new ParamicsCommunicatorGUI(); 149 addObserver(theGUI); 150 theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 146 151 try 147 152 { … … 301 306 "Dropped Connection", JOptionPane.ERROR_MESSAGE); 302 307 break; 308 } 309 try 310 { 311 Thread.sleep(2000); 312 paramLogger.logp(Level.INFO, "ParamicsCommunicator", 313 "run", "sleeping."); 314 } catch (InterruptedException ex) 315 { 316 paramLogger.logp(Level.INFO, "ParamicsCommunicator", 317 "run", "Exception in reading data from the socket.", ex); 303 318 } 304 319 } … … 456 471 } catch (SocketTimeoutException ste) 457 472 { 458 System.out.println("...waiting for socket connection from the CAD Simulator..."); 473 System.out.println("...waiting..."); 474 try 475 { 476 Thread.sleep(2000); 477 paramLogger.logp(Level.INFO, "ParamicsCommunicator", 478 "initializeSockets", "sleeping."); 479 } catch (InterruptedException ex) 480 { 481 paramLogger.logp(Level.INFO, "ParamicsCommunicator", 482 "initializeSockets", "Exception exiting for socket.", ex); 483 } 459 484 } catch (IOException ioe) 460 485 { … … 462 487 + "the receiving socket on port " + socketPort); 463 488 } 489 464 490 } 465 491 -
trunk/src/tmcsim/paramicscommunicator/ParamicsFileReader.java
r40 r47 5 5 import java.io.FileWriter; 6 6 import java.io.IOException; 7 import java.text.SimpleDateFormat; 7 8 import java.util.Observable; 8 9 import java.util.Timer; … … 67 68 */ 68 69 private long readerInterval; 70 /** 71 * Time formatter for diagnostic messages 72 */ 73 private SimpleDateFormat formatter; 69 74 70 75 /** … … 80 85 public void run() 81 86 { 82 // paramLogger.logp(Level.INFO, 83 // "ParamicsFileReader.ReaderTimerTask", "run()", 84 // "Waiting for " + inputFile + " to be modified."); 87 // System.out.println( 88 // "Checking last modified time on " + inputFile.getName() 89 // + formatter.format(lastModified) + ":" + formatter.format(inputFile.lastModified())); 90 85 91 if (lastModified < inputFile.lastModified()) 86 92 { 87 // paramLogger.logp(Level.INFO,88 // "ParamicsFileReader.ReaderTimerTask", "run()",89 // "Cool, " + inputFile + " has been modified, let's read it.");90 93 91 94 try … … 101 104 Element messageElem = readerDoc.createElement(PARAMICS_COMM_TAGS.MESSAGE.tag); 102 105 String fileContents = readFromFile(); 103 // int stringlen = Math.min(160, fileContents.length()-1);104 // Log two lines that were read105 // paramLogger.logp(Level.INFO,106 // "ParamicsFileReader.ReaderTimerTask", "run()",107 // "Nice, we read " + fileContents.length() + " bytes.");108 106 messageElem.appendChild(readerDoc.createTextNode(fileContents)); 109 107 readerElem.appendChild(messageElem); … … 142 140 try 143 141 { 142 formatter = new SimpleDateFormat("HH:mm:ss"); 144 143 readerID = id; 145 144 readerInterval = interval; … … 159 158 { 160 159 paramLogger.logp(Level.SEVERE, "ParamicsFileReader", 161 "Constructor()", "Exception in initializing file reading .", ioe);160 "Constructor()", "Exception in initializing file reading of "+workingDir + targetFile, ioe); 162 161 } 163 162 } … … 194 193 195 194 lastModified = inputFile.lastModified(); 195 // System.out.println( 196 // "Read from a file last modified at " + formatter.format(lastModified)); 196 197 197 198 setChanged(); -
trunk/src/tmcsim/paramicscommunicator/gui/ParamicsCommunicatorGUI.java
r29 r47 11 11 import java.util.logging.LogRecord; 12 12 import java.util.logging.Logger; 13 14 13 import javax.swing.BorderFactory; 15 14 import javax.swing.Box; … … 21 20 import javax.swing.JTabbedPane; 22 21 import javax.swing.JTextArea; 23 24 22 import tmcsim.common.RevisionNumber; 25 23 import tmcsim.paramicscommunicator.FileIOUpdate; … … 126 124 "Exception in receiving FileIOUpdate object.", e); 127 125 } 128 } else if (arg instanceof FileRegUpdate) 126 } 127 else if (arg instanceof FileRegUpdate) 129 128 { 130 129 try … … 218 217 BorderFactory.createRaisedBevelBorder(), "Registered Readers "), 219 218 BorderFactory.createEmptyBorder(5, 5, 5, 5))); 220 219 221 220 fileWriterTabs = new JTabbedPane(); 222 221 fileWriterTabs.setAlignmentX(Box.CENTER_ALIGNMENT); … … 243 242 tabbedBox.add(fileReaderTabs); 244 243 tabbedBox.add(fileWriterTabs); 245 244 246 245 Box guiBox = new Box(BoxLayout.Y_AXIS); 247 246 guiBox.add(tabbedBox); … … 255 254 setResizable(false); 256 255 pack(); 257 setVisible(true);256 //setVisible(true); 258 257 } 259 258 … … 284 283 285 284 } 286 287 285 private JTabbedPane fileReaderTabs; 288 286 private JTabbedPane fileWriterTabs; -
trunk/src/tmcsim/paramicslog/ParamicsLog.java
r33 r47 10 10 import java.util.logging.Level; 11 11 import java.util.logging.Logger; 12 13 12 import javax.swing.JOptionPane; 14 15 import org.w3c.dom.Element;16 17 13 import tmcsim.common.SimulationException; 18 14 import tmcsim.interfaces.CoordinatorInterface; … … 21 17 /** 22 18 * Logs communication from ParamicsCommunicator to ParamicsSimulator. 23 * 24 * The system property "PARAMICS_LOG_CONFIG" should be set to the path 25 * where theproperties file for this class is located. <br><br>19 * 20 * The system property "PARAMICS_LOG_CONFIG" should be set to the path where the 21 * properties file for this class is located. <br><br> 26 22 * The data for the properties file follows. <br> 27 23 * <code> 28 24 * -----------------------------------------------------------------<br> 29 * Log File The file to write the communication to. 30 * CAD Simulator Host The host that runs the CAD Simulator. 31 * CAD Simulator RMI Port The port on the host that runs the CAD 32 * Simulator where the RMI Coordinator 33 * object is registered to. 25 * Log File The file to write the communication to. CAD Simulator Host The host 26 * that runs the CAD Simulator. CAD Simulator RMI Port The port on the host that 27 * runs the CAD Simulator where the RMI Coordinator object is registered to. 34 28 * -----------------------------------------------------------------<br> 35 29 * Example File: <br> 36 * LogFile=c:\\log.txt 37 * CADSimulatorHost=localhost 38 * CADSimulatorRMIPort=4445 30 * LogFile=c:\\log.txt CADSimulatorHost=localhost CADSimulatorRMIPort=4445 39 31 * -----------------------------------------------------------------<br> 40 32 * </code> 41 * 33 * 42 34 * @author Nathaniel Lehrer 43 * @version 35 * @version 44 36 */ 45 public class ParamicsLog extends Observable 46 { 37 public class ParamicsLog extends Observable 38 { 39 47 40 /** 48 41 * Enmeration containing property names. 42 * 49 43 * @author Nathaniel Lehrer 50 44 */ 51 private enum PROPERTIES 52 { 53 LOG_FILE ("LogFile"), 54 CAD_SIM_HOST ("CADSimulatorHost"),55 CAD_SIM_ PORT ("CADSimulatorRMIPort");56 45 private enum PROPERTIES 46 { 47 48 LOG_FILE("LogFile"), 49 CAD_SIM_HOST("CADSimulatorHost"), 50 CAD_SIM_PORT("CADSimulatorRMIPort"); 57 51 public String name; 58 52 59 53 private PROPERTIES(String n) 60 54 { … … 62 56 } 63 57 } 64 65 private static final String CONFIG_FILE_NAME = "paramics_communicator_logging.properties"; 66 67 /** Error logger.*/58 private static final String CONFIG_FILE_NAME = "paramics_communicator_logging.properties"; 59 /** 60 * Error logger. 61 */ 68 62 private static Logger paramLogger = Logger.getLogger("tmcsim.paramicslog"); 69 70 /** Static instance. */ 63 /** 64 * Static instance. 65 */ 71 66 private static ParamicsLog instance; 72 73 /** Properties object. */ 67 /** 68 * Properties object. 69 */ 74 70 private Properties paramicsLogProp; 75 76 /** File log entries are written to */ 71 /** 72 * File log entries are written to 73 */ 77 74 private File logFile; 78 79 /** Stores the log entries. This contains the same information logFile. */ 75 /** 76 * Stores the log entries. This contains the same information logFile. 77 */ 80 78 private StringBuilder log; 81 82 /** Remote reference to the simulation */ 79 /** 80 * Remote reference to the simulation 81 */ 83 82 private CoordinatorInterface theCoorInt; 84 85 /** Object for synchronizing IO */ 83 /** 84 * Object for synchronizing IO 85 */ 86 86 Object lock; 87 87 88 88 /** 89 89 * Creates the singleton instance of this class. 90 90 */ 91 static { 92 try { 93 if(System.getProperty("CONFIG_DIR") == null){ 94 System.setProperty("CONFIG_DIR", "config"); 95 } 96 97 instance = new ParamicsLog(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 98 } 99 catch (Exception e) 91 static 92 { 93 try 94 { 95 if (System.getProperty("CONFIG_DIR") == null) 96 { 97 System.setProperty("CONFIG_DIR", "config"); 98 } 99 100 instance = new ParamicsLog(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 101 } catch (Exception e) 100 102 { 101 103 instance = new ParamicsLog(); 102 103 paramLogger.logp(Level.WARNING, "ParamicsLog", "static initializer", 104 105 paramLogger.logp(Level.WARNING, "ParamicsLog", "static initializer", 104 106 "Error occured initializing application", e); 105 107 106 JOptionPane.showMessageDialog(null, e.getMessage(), 107 "Error - ParamicsLog will not save log to file.", 108 JOptionPane.ERROR_MESSAGE); 109 } 110 108 JOptionPane.showMessageDialog(null, e.getMessage(), 109 "Error - ParamicsLog will not save log to file.", 110 JOptionPane.ERROR_MESSAGE); 111 } 112 111 113 instance.addObserver(ParamicsLogGUI.getInstance()); 112 114 } 113 114 /** 115 * Creates an instance of ParamicsLog that does not write to a file when 115 116 /** 117 * Creates an instance of ParamicsLog that does not write to a file when 116 118 * writeToLog is called. 117 119 */ 118 private ParamicsLog() { 119 120 private ParamicsLog() 121 { 122 120 123 lock = new Object(); 121 124 log = new StringBuilder(""); 122 125 } 123 124 /** 125 * Creates an instance of ParamicsLog that writes to a file when writeToLog is called. 126 127 /** 128 * Creates an instance of ParamicsLog that writes to a file when writeToLog 129 * is called. 130 * 126 131 * @param propertiesFile 127 132 */ 128 private ParamicsLog(String propertiesFile) { 133 private ParamicsLog(String propertiesFile) 134 { 129 135 this(); 130 136 131 137 String logFile = null; 132 138 String CADSIMHost = null; 133 139 String CADSIMPort = null; 134 135 try { 140 141 try 142 { 136 143 paramicsLogProp = new Properties(); 137 144 paramicsLogProp.load(new FileInputStream(propertiesFile)); 138 145 139 146 if ((logFile = paramicsLogProp.getProperty(PROPERTIES.LOG_FILE.name)) == null) 140 147 { … … 142 149 } 143 150 else if ((CADSIMHost = paramicsLogProp.getProperty(PROPERTIES.CAD_SIM_HOST.name)) == null) 144 { 151 { 145 152 throw new Exception("Properties file missing CAD Simulator host."); 146 153 } … … 149 156 throw new Exception("Properties file missing CAD Simulator RMI port."); 150 157 } 151 158 152 159 try 153 160 { 154 161 connect(CADSIMHost, CADSIMPort); 155 } 156 catch (Exception e) 157 { 158 JOptionPane.showMessageDialog(null, 159 "ParamicsLog: Could not connect to remote Coordinator object.", 160 "Network Error", JOptionPane.ERROR_MESSAGE); 161 } 162 163 try 162 } catch (Exception e) 163 { 164 JOptionPane.showMessageDialog(null, 165 "ParamicsLog: Could not connect to remote Coordinator object.", 166 "Network Error", JOptionPane.ERROR_MESSAGE); 167 } 168 169 try 164 170 { 165 171 createLogFile(logFile); 166 } 167 catch (Exception e) 168 { 169 JOptionPane.showMessageDialog(null, 170 "ParamicsLog: Could not create new log file.", 172 } catch (Exception e) 173 { 174 JOptionPane.showMessageDialog(null, 175 "ParamicsLog: Could not create new log file.", 171 176 "File Error", JOptionPane.ERROR_MESSAGE); 172 177 } 173 174 } catch (Exception e) { 175 176 paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 178 179 } catch (Exception e) 180 { 181 182 paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 177 183 "Properties file incorrect or missing.", e); 178 179 JOptionPane.showMessageDialog(null, 180 "ParamicsLog: Properties file invalid.", 184 185 JOptionPane.showMessageDialog(null, 186 "ParamicsLog: Properties file invalid.", 181 187 "Invalid Configuration", JOptionPane.ERROR_MESSAGE); 182 188 } 183 189 } 184 190 185 191 /** 186 192 * Creates the log file. 193 * 187 194 * @param filePath The path to the file including the file name. 188 195 * @throws IOException If the log file could not be created. … … 190 197 private void createLogFile(String filePath) throws IOException 191 198 { 192 try { 199 try 200 { 193 201 logFile = new File(filePath); 194 195 if (logFile.exists()) { 202 203 if (logFile.exists()) 204 { 196 205 logFile.delete(); 197 206 } 198 207 199 208 logFile.createNewFile(); 200 201 } catch (Exception e) { 202 209 210 } catch (Exception e) 211 { 212 203 213 logFile = null; 204 205 paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 214 215 paramLogger.logp(Level.WARNING, "ParamicsLog", "ParamicsLog constructor", 206 216 "Could not create new log file.", e); 207 217 208 218 throw new IOException("Could not create log file."); 209 } 210 } 211 219 } 220 } 221 212 222 /** 213 223 * Connect to the Coordinator's RMI object. 214 * @param hostname Host name of the CAD Simulator. 215 * @param portNumber Port number of the CAD Simulator RMI communication. 216 * @throws SimulationException if there is an error creating the RMI connection. 217 */ 218 private void connect(String hostname, String portNumber) 219 throws SimulationException { 220 224 * 225 * @param hostname Host name of the CAD Simulator. 226 * @param portNumber Port number of the CAD Simulator RMI communication. 227 * @throws SimulationException if there is an error creating the RMI 228 * connection. 229 */ 230 private void connect(String hostname, String portNumber) 231 throws SimulationException 232 { 233 221 234 String coorIntURL = ""; 222 223 try {224 coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator";225 226 theCoorInt = (CoordinatorInterface)Naming.lookup(coorIntURL); 227 }228 catch (Exception e)229 { 230 paramLogger.logp(Level.WARNING, "ParamicsLog", 231 "establishRMIConnection", "Unable to establish RMI " +232 "communication with the CAD Simulator. URL <" + coorIntURL + ">", e);233 } 234 } 235 235 236 try 237 { 238 coorIntURL = "rmi://" + hostname + ":" + portNumber + "/coordinator"; 239 240 theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); 241 } catch (Exception e) 242 { 243 paramLogger.logp(Level.WARNING, "ParamicsLog", 244 "establishRMIConnection", "Unable to establish RMI " 245 + "communication with the CAD Simulator. URL <" + coorIntURL + ">", e); 246 } 247 } 248 236 249 /** 237 250 * Accessor to the entries in the log. No file IO is used. 251 * 238 252 * @return The entries in the log. 239 253 */ 240 public String getLog() { 241 254 public String getLog() 255 { 256 242 257 return log.toString(); 243 258 } 244 245 /** 246 * Writes an entry to the log. 247 * The simulator time when the message was sent is prepended to the entry.248 * Entries are padded by a blank line before and after them.249 * TODO: Ensure output is written in order of request.259 260 /** 261 * Writes an entry to the log. The simulator time when the message was sent 262 * is prepended to the entry. Entries are padded by a blank line before and 263 * after them. TODO: Ensure output is written in order of request. 264 * 250 265 * @param entry 251 266 */ 252 public void writeToLog(String entry) { 253 267 public void writeToLog(String entry) 268 { 269 254 270 String time = "?"; 255 271 String formattedEntry; 256 272 257 273 if (theCoorInt != null) 258 274 { … … 260 276 { 261 277 time = formatTime(theCoorInt.getCurrentSimulationTime()); 262 } 263 catch (Exception e) 264 { 265 paramLogger.logp(Level.WARNING, "ParamicsLog", 278 } catch (Exception e) 279 { 280 paramLogger.logp(Level.WARNING, "ParamicsLog", 266 281 "RMICommunication", "Unable to communicate with RMI object", e); 267 282 } 268 283 } 269 284 270 285 formattedEntry = "\n" + "<!-- Time written to file: " + time + " -->\n" + entry + "\n"; 271 286 log.append(formattedEntry); 272 287 273 288 if (logFile != null) 274 289 { 275 try 276 { 277 synchronized (lock)290 try 291 { 292 synchronized (lock) 278 293 { 279 294 FileWriter writer = new FileWriter(logFile, true); … … 282 297 writer.close(); 283 298 } 284 } 285 catch (IOException e) 286 { 287 paramLogger.logp(Level.WARNING, "ParamicsLog", "writeToLog", 299 } catch (IOException e) 300 { 301 paramLogger.logp(Level.WARNING, "ParamicsLog", "writeToLog", 288 302 "Could not write to log file.", e); 289 303 } 290 304 } 291 305 292 306 setChanged(); 293 307 notifyObservers(entry); 294 308 } 295 309 296 310 /** 297 311 * Formats the time given in seconds to hh:mm:ss format. 312 * 298 313 * @param time The time in seconds. 299 314 */ 300 p rivateString formatTime(long time)315 public String formatTime(long time) 301 316 { 302 317 long seconds = time % 60; … … 306 321 return padr(hours) + ":" + padr(minutes) + ":" + padr(seconds); 307 322 } 308 323 309 324 private String padr(long n) 310 325 { … … 317 332 } 318 333 } 319 334 320 335 /** 321 336 * Accessor for static instance of this class. 337 * 322 338 * @return The instance of this class. 323 339 */ 324 public static ParamicsLog getInstance() { 325 340 public static ParamicsLog getInstance() 341 { 342 326 343 return instance; 327 344 } -
trunk/src/tmcsim/paramicslog/gui/ParamicsLogGUI.java
r2 r47 1 1 package tmcsim.paramicslog.gui; 2 2 3 import javax.swing.*;4 3 import java.awt.event.WindowEvent; 5 4 import java.util.*; 5 import javax.swing.*; 6 6 7 7 /** 8 * The UI for ParamicsLog. 8 * The UI for ParamicsLog. 9 * 9 10 * @author Nathaniel Lehrer 10 11 * @version 11 12 */ 12 public class ParamicsLogGUI extends JFrame implements Observer { 13 public class ParamicsLogGUI extends JFrame implements Observer 14 { 13 15 14 /** The static instance */ 16 /** 17 * The static instance 18 */ 15 19 private static ParamicsLogGUI instance = new ParamicsLogGUI(); 20 /** 21 * The text area to display the log in 22 */ 23 private JTextArea textArea; 16 24 17 /** The text area to display the log in */18 private JTextArea textArea;19 20 /** Creates an instance of this class */21 public ParamicsLogGUI(){22 25 /** 26 * Creates an instance of this class 27 */ 28 public ParamicsLogGUI() 29 { 30 23 31 setupGUI(); 24 32 } 25 26 /** Creates the UI */ 33 34 /** 35 * Creates the UI 36 */ 27 37 private void setupGUI() 28 38 { 29 try { 39 try 40 { 30 41 UIManager.setLookAndFeel( 31 UIManager.getSystemLookAndFeelClassName()); 32 } catch (Exception e) { 42 UIManager.getSystemLookAndFeelClassName()); 43 } catch (Exception ex) 44 { 45 System.out.println(ex.getMessage()); 33 46 System.err.println("Couldn't use system look and feel."); 34 47 } 35 36 this.addWindowListener(new java.awt.event.WindowAdapter() {37 48 49 this.addWindowListener(new java.awt.event.WindowAdapter() 50 { 38 51 public void windowClosing(WindowEvent e) 39 52 { … … 41 54 } 42 55 }); 43 44 56 57 45 58 setTitle("Paramics Log"); 46 59 47 60 textArea = new JTextArea(); 48 61 textArea.setColumns(60); 49 62 textArea.setRows(30); 50 63 JScrollPane scrollPane = new JScrollPane(textArea); 51 64 52 65 getContentPane().add(scrollPane); 53 66 54 67 } 55 56 /** Shows the UI window */ 68 69 /** 70 * Shows the UI window 71 */ 57 72 public void display() 58 73 { … … 62 77 63 78 /** 64 * Updates the text area. If the observable class given is of type ParamicsLog then 65 * the log entries are displayed. 79 * Updates the text area. If the observable class given is of type 80 * ParamicsLog then the log entries are displayed. 81 * 66 82 * @param o The model for this viewer. 67 83 * @param arg An argument that is not used. … … 72 88 { 73 89 textArea.setText(((tmcsim.paramicslog.ParamicsLog) o).getLog()); 74 } 90 } 75 91 76 92 repaint(); 77 93 } 78 94 79 95 /** 80 96 * Accessor for the instance of ParamicsLogGUI. 97 * 81 98 * @return The instance of ParamicsLogGUI. 82 99 */ 83 public static ParamicsLogGUI getInstance() { 100 public static ParamicsLogGUI getInstance() 101 { 84 102 return instance; 85 103 } 86 87 104 } -
trunk/src/tmcsim/simulationmanager/SimulationManager.java
r33 r47 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 15 13 import tmcsim.common.CADEnums.PARAMICS_STATUS; 14 import tmcsim.common.ScriptException; 16 15 import tmcsim.common.SimulationException; 17 16 … … 48 47 49 48 private static final String CONFIG_FILE_NAME = "sim_manager_config.properties"; 50 /**49 /** 51 50 * Error logger. 52 51 */ … … 192 191 193 192 /** 193 * Load a simulation script from the specified file. 194 * 195 * @param scriptFile the XML file containing the simulation control script 196 * to be run. 197 * @throws ScriptException if the script throws an exception 198 * @throws SimulationException if the simulation throws an exception 199 */ 200 public void loadScript(File scriptFile) throws ScriptException, SimulationException 201 { 202 theSimManagerModel.loadScript(scriptFile); 203 } 204 205 /** 194 206 * Main class. 195 207 * 196 208 * @param args Command line arguments. 197 209 */ 198 static public void main(String[] args) { 210 static public void main(String[] args) 211 { 199 212 //System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 200 if(System.getProperty("CONFIG_DIR") == null){ 201 System.setProperty("CONFIG_DIR", "config"); 202 } 203 204 try { 205 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 213 if (System.getProperty("CONFIG_DIR") == null) 214 { 215 System.setProperty("CONFIG_DIR", "config"); 216 } 217 218 try 219 { 220 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 206 221 new SimulationManager(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 207 } catch (Exception e) { 222 } catch (Exception e) 223 { 208 224 simManLogger.logp(Level.SEVERE, "SimulationManager", "Main", 209 225 "Error occured initializing application", e); -
trunk/src/tmcsim/simulationmanager/SimulationManagerView.java
r9 r47 866 866 paramicsStatusLabel = new JLabel("Status:"); 867 867 paramicsStatusInfoLabel = new JLabel("Unknown"); 868 paramicsStatusInfoLabel.setName("paramicsStatusInfoLabel"); 868 869 paramicsStatusBox.add(paramicsStatusLabel); 869 870 paramicsStatusBox.add(Box.createHorizontalStrut(10)); -
trunk/test/tmcsim/cadsimulator/CADSimulatorFixture.java
r26 r47 34 34 + "ATMSProperties = empty.txt\n" 35 35 + "MediaProperties = empty.txt\n"; 36 static final String configpData = "ParamicsCommHost= 192.168.251.45\n"36 static final String paramicsData = "ParamicsCommHost = 192.168.251.45\n" 37 37 + "ParamicsCommPort = 4450\n" 38 38 + "IncidentUpdateInterval = 30\n" … … 60 60 System.setOut(ps); 61 61 writedata("config.txt", configData); 62 writedata("pconfig.txt", configpData); 63 writedata("pmcprops.txt", paramConfig); 62 writedata("pconfig.txt", paramicsData); 64 63 writedata("empty.txt", ""); 65 64 writeScriptfiles(); -
trunk/test/tmcsim/cadsimulator/CADSimulatorGUITest.java
r34 r47 5 5 import java.util.logging.Level; 6 6 import java.util.logging.Logger; 7 8 7 import static junit.framework.Assert.assertEquals; 9 8 import static junit.framework.Assert.fail; … … 50 49 removeMe.delete(); 51 50 } 52 53 /**54 * Test of getCADTime method, of class CADSimulator.55 */56 public void testGetCADTime()57 {58 System.out.println("getCADTime");59 String result = CADSimulator.getCADTime();60 // Just test length for now61 assertEquals(4, result.length());62 }63 64 /**65 * Test of getCADDate method, of class CADSimulator.66 */67 public void testGetCADDate()68 {69 System.out.println("getCADDate");70 String result = CADSimulator.getCADDate();71 // Just test length for now72 assertEquals(6, result.length());73 }74 51 /** 75 52 * Test of main method, of class CADSimulator. … … 79 56 public void testConstructor() throws SimulationException, RemoteException, ScriptException 80 57 { 58 System.out.println("CADSimulator constructor"); 81 59 CADSimulatorFixture.writeConfigData(); 82 60 CADSimulatorFixture.writedata("config.txt", configData); 83 System.out.println("CADSimulator constructor"); 61 Window cadwindow = null; 62 // try 63 // { 64 // app = new CADSimulator("config.txt"); 65 // } catch (Exception e) 66 // { 67 // fail("Couldn't launch CADSimulator" + e.getMessage()); 68 // } 69 84 70 System.setProperty("CONFIG_DIR", "config/testConfig"); 85 Window cadwindow = null;86 71 if (System.getProperty("CONFIG_DIR") != null) 87 72 { … … 100 85 } 101 86 }); 102 } else 87 } 88 else 103 89 { 104 90 fail("CONFIG_DIR system property not defined."); 105 91 } 106 assertEquals("CAD Simulator", cadwindow.getTitle()); 92 93 System.out.println("Tests for text fields."); 94 // Create a UISpec window from the CADSimulator's Viewer (gui) 95 // cadwindow = new Window((CADSimulatorViewer) app.theViewer); 96 assertTrue("Title bar incorrect", cadwindow.getTitle().startsWith("CAD Simulator revision:")); 107 97 Panel mainPanel = cadwindow.getPanel("contentPane"); 108 98 TextBox txtStatus = mainPanel.getTextBox("simulationStatus"); 109 assertEquals(" No Script", txtStatus.getText());99 assertEquals("simulation status should say No Script", "No Script", txtStatus.getText().trim()); 110 100 TextBox terminals = mainPanel.getTextBox("termConnectedTF"); 111 assertEquals("0", terminals.getText().trim()); 112 assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim()); 113 assertEquals("0:00:00", mainPanel.getTextBox("simulationClockLabel").getText()); 101 assertEquals("should be 0 terminals", "0", terminals.getText().trim()); 102 assertEquals("mgr connected should be no", "No", mainPanel.getTextBox("managerConnectedTF").getText().trim()); 103 assertEquals("paramics connected should be no", "No", mainPanel.getTextBox("paramicsConnectedTF").getText().trim()); 104 assertEquals("initial time should be 0:00:00", "0:00:00", mainPanel.getTextBox("simulationClockLabel").getText().trim()); 114 105 115 CADClientInterface ci = new FakeClient();106 CADClientInterface ci = mock(CADClientInterface.class); 116 107 app.theCoordinator.registerForCallback(ci); 117 assertEquals(" 1", terminals.getText().trim());108 assertEquals("should be 1 terminal", "1", terminals.getText().trim()); 118 109 app.theCoordinator.registerForCallback(ci); 119 assertEquals(" 2", terminals.getText().trim());110 assertEquals("should be 2 terminals", "2", terminals.getText().trim()); 120 111 121 112 SimulationManagerInterface si = mock(SimulationManagerInterface.class); 113 122 114 app.theCoordinator.registerForCallback(si); 123 assertEquals(" Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim());115 assertEquals("mgr connected should be yes", "Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim()); 124 116 125 117 Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator"); 126 118 cadSimLogger.logp(Level.INFO, "", "", "Sample Info Message."); 127 119 120 System.out.println("Tests for message panes."); 128 121 Panel infoPane = mainPanel.getPanel("infoMessagesPane"); 129 122 TextBox infoText = infoPane.getTextBox("infoMessagesTA"); 130 assertEquals(" . = Sample Info Message.", infoText.getText().trim());123 assertEquals("wrong info msg text", ". = Sample Info Message.", infoText.getText().trim()); 131 124 132 125 cadSimLogger.logp(Level.SEVERE, "", "", "Sample Error Message."); … … 134 127 Panel errPane = mainPanel.getPanel("errorMessagesPane"); 135 128 TextBox errText = errPane.getTextBox("errorMessagesTA"); 136 assertEquals(" . = Sample Error Message.", errText.getText().trim());129 assertEquals("wrong error msg text", ". = Sample Error Message.", errText.getText().trim()); 137 130 131 System.out.println("Tests for status changes."); 138 132 app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.CONNECTED); 139 133 CADSimulatorFixture.pause(500); 140 assertEquals(" Yes", mainPanel.getTextBox("paramicsConnectedTF").getText().trim());141 assertEquals(" None", mainPanel.getTextBox("networkLoadedTF").getText().trim());134 assertEquals("paramics connected should be yes", "Yes", mainPanel.getTextBox("paramicsConnectedTF").getText().trim()); 135 assertEquals("network id should be None", "None", mainPanel.getTextBox("networkLoadedTF").getText().trim()); 142 136 143 137 // app.theCoordinator.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING); … … 148 142 app.theCoordinator.loadScriptFile(new File(autoloadScriptname)); 149 143 // The status should now say Ready 150 assertEquals(" Ready", mainPanel.getTextBox("simulationStatus").getText().trim());144 assertEquals("sim status should be ready", "Ready", mainPanel.getTextBox("simulationStatus").getText().trim()); 151 145 152 146 app.theCoordinator.startSimulation(); 153 CADSimulatorFixture.pause( 500);154 assertEquals(" Running", mainPanel.getTextBox("simulationStatus").getText().trim());155 assertEquals(" 0:00:01", mainPanel.getTextBox("simulationClockLabel").getText());147 CADSimulatorFixture.pause(900); 148 assertEquals("sim status should be running", "Running", mainPanel.getTextBox("simulationStatus").getText().trim()); 149 assertEquals("sim time should be 0:00:01", "0:00:01", mainPanel.getTextBox("simulationClockLabel").getText().trim()); 156 150 157 151 ParamicsSimulationManager psm = mock(ParamicsSimulationManager.class); 158 152 when(psm.isConnected()).thenReturn(Boolean.TRUE); 153 when(psm.getParamicsNetworkLoaded()).thenReturn(1); // provide the network ID to return 159 154 app.theParamicsSimMgr = psm; 160 app.theCoordinator.loadParamicsNetwork(1); 161 162 // app.theViewer.dispose(); 163 // Window confirmPopup = null; 164 // confirmPopup = WindowInterceptor.run(new Trigger() 165 // { 166 // public void run() 167 // { 168 // app.theViewer.closeViewer(); 169 // } 170 // }); 171 // confirmPopup.getButton("OK").click(); 172 } 173 174 class FakeClient implements CADClientInterface 175 { 176 177 @Override 178 public void refresh() throws RemoteException 179 { 180 } 155 // this will tell the model it has a new network ID 156 app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.LOADED); 157 CADSimulatorFixture.pause(500); 158 assertEquals("network id should be 1", "1", mainPanel.getTextBox("networkLoadedTF").getText().trim()); 159 //mainPanel.getMenu().getItem("Exit").click(); 160 boolean breakpoint = true; 181 161 } 182 162 }
Note: See TracChangeset
for help on using the changeset viewer.
