- Timestamp:
- 06/18/2019 10:56:55 AM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 2 added
- 3 edited
- 2 copied
-
spikes/DocumentSizeFilter.java (added)
-
spikes/TextComponentDemo.java (added)
-
tmcsim/application.properties (modified) (1 diff)
-
tmcsim/cadsimulator/Coordinator.java (modified) (2 diffs)
-
tmcsim/client/CADlogDisplay.java (copied) (copied from trunk/src/tmcsim/client/ClockClient.java) (8 diffs)
-
tmcsim/simulationmanager/SimulationManagerView.java (modified) (3 diffs)
-
tmcsim/simulationmanager/actions/ExportAction.java (copied) (copied from trunk/src/tmcsim/simulationmanager/actions/AddIncidentAction.java) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/application.properties
r407 r416 1 # Thu, 16 May 2019 14:30:48-07001 #Wed, 05 Jun 2019 16:17:15 -0700 2 2 3 Application.revision=4 063 Application.revision=414 4 4 5 Application.buildnumber=1 385 Application.buildnumber=140 -
trunk/src/tmcsim/cadsimulator/Coordinator.java
r407 r416 98 98 * The name of the file where the simulation clock time is written 99 99 */ 100 private String kSimClockFilename = "webapps" + 101 System.getProperty("file.separator") + "dynamicdata" + 102 System.getProperty("file.separator") + "sim_elapsedtime.json"; 100 private String kSimClockFilename; 103 101 /** 104 102 * Error logger. … … 125 123 * Constructor. Call UnicastRemoteObject constructor and call 126 124 * initializeSimulation. 127 * 125 * @param simTimeFilename name of the file where the simulation clock time is written 128 126 * @throws RemoteException 129 127 */ -
trunk/src/tmcsim/client/CADlogDisplay.java
r64 r416 8 8 import java.rmi.server.UnicastRemoteObject; 9 9 import java.util.Properties; 10 import java.util.Vector; 10 11 import java.util.concurrent.TimeUnit; 11 12 import java.util.logging.Level; … … 15 16 import javax.swing.Timer; 16 17 import javax.swing.UIManager; 18 import javax.swing.table.DefaultTableModel; 19 import tmcsim.client.cadclientgui.data.Incident; 20 import tmcsim.client.cadclientgui.enums.CADDataEnums.INC_TABLE; 17 21 import tmcsim.common.SimulationException; 18 22 import tmcsim.interfaces.CADClientInterface; … … 20 24 21 25 /** 22 * C lockClient shows the simulation clock time. It operates as a client of the26 * CADlogDisplays shows the current CAD log for all incidents. It operates as a client of the 23 27 * CAD server, using RMI to poll the server every second for the current 24 * simulation clock time.28 * list of incidents and associated comments/notes table. 25 29 * 26 30 * @author jdalbey 27 31 */ 28 public class C lockClientextends UnicastRemoteObject implements32 public class CADlogDisplay extends UnicastRemoteObject implements 29 33 CADClientInterface 30 34 { … … 82 86 private CADClientInterface client = this; 83 87 private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 84 private final static int ONE_SECOND = 1000;88 private final static int TEN_SECONDS = 10000; 85 89 86 90 /** … … 91 95 * file containing configuration data. 92 96 */ 93 public C lockClient(String propertiesFile) throws SimulationException,97 public CADlogDisplay(String propertiesFile) throws SimulationException, 94 98 RemoteException 95 99 { … … 102 106 cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim()); 103 107 104 theView = new ClockView();105 theView.setVisible(true);108 //theView = new ClockView(); 109 //theView.setVisible(true); 106 110 107 111 // Create a timer that fetches the simulation time every second. 108 Timer timer = new Timer( ONE_SECOND, new ActionListener()112 Timer timer = new Timer(TEN_SECONDS, new ActionListener() 109 113 { 110 114 public void actionPerformed(ActionEvent e) … … 112 116 try 113 117 { 114 long simtime = theCoorInt.getCurrentSimulationTime(); 115 theView.updateTime("" + formatInterval(simtime)); 118 Vector<Incident> incList = theCoorInt.getIncidentList(); 119 StringBuffer sb = new StringBuffer(); 120 121 for (Incident incident: incList) 122 { 123 // DefaultTableModel noteTable = (DefaultTableModel) theCoorInt.getCadDataIncidentTable(INC_TABLE.COMMENTS_NOTES, incident.getLogNum()); 124 // Output noteTable 125 sb.append("Incident # " + incident.logNum + "\n"); 126 // Retrieve the table of comments/notes the users created 127 DefaultTableModel notesTable = incident.getCommentsNotesTable(); 128 // Retrieve the notes chronologically (Most recent is in first row) 129 for (int row=notesTable.getRowCount()-1; row >=0; row--) 130 { 131 // Combine the fields into one export entry 132 sb.append(notesTable.getValueAt(row,1) + " "); // time 133 String initials = (String) notesTable.getValueAt(row,2); // initials 134 // If there are no user intials, it's a scripted item 135 if (initials.length() == 0) 136 { 137 initials = "Script"; 138 } 139 sb.append(initials + " "); 140 sb.append(notesTable.getValueAt(row,4) + "\n"); // notes 141 } 142 } 143 System.out.println(sb); 144 //long simtime = theCoorInt.getCurrentSimulationTime(); 145 //theView.updateTime("" + formatInterval(simtime)); 116 146 } catch (RemoteException ex) 117 147 { 118 Logger.getLogger(C lockClient.class.getName()).log(Level.SEVERE, null, ex);148 Logger.getLogger(CADlogDisplay.class.getName()).log(Level.SEVERE, null, ex); 119 149 } 120 150 } … … 245 275 { 246 276 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 247 new C lockClient(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME);277 new CADlogDisplay(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 248 278 249 279 } catch (Exception e) -
trunk/src/tmcsim/simulationmanager/SimulationManagerView.java
r365 r416 47 47 import tmcsim.simulationmanager.actions.DeleteIncidentAction; 48 48 import tmcsim.simulationmanager.actions.ExitAction; 49 import tmcsim.simulationmanager.actions.ExportAction; 49 50 import tmcsim.simulationmanager.actions.GotoTimeIndexAction; 50 51 import tmcsim.simulationmanager.actions.LoadParamicsNetworkAction; … … 686 687 private void createMenuBar() { 687 688 688 gotoMenuItem = new JMenuItem(new GotoTimeIndexAction(this)); 689 gotoMenuItem = new JMenuItem(new GotoTimeIndexAction(this)); 690 exportMenuItem = new JMenuItem(new ExportAction(this)); 689 691 exitMenuItem = new JMenuItem(new ExitAction(this)); 690 692 691 693 fileMenu = new JMenu("File"); 692 694 fileMenu.add(gotoMenuItem); 695 fileMenu.add(exportMenuItem); 693 696 fileMenu.add(exitMenuItem); 694 697 … … 1255 1258 private JMenu fileMenu; 1256 1259 private JMenuItem gotoMenuItem; 1260 private JMenuItem exportMenuItem; 1257 1261 private JMenuItem exitMenuItem; 1258 1262 -
trunk/src/tmcsim/simulationmanager/actions/ExportAction.java
r2 r416 4 4 import java.io.File; 5 5 import java.util.Vector; 6 import java.util.logging.Level; 7 import java.util.logging.Logger; 6 8 7 9 import javax.swing.AbstractAction; 8 10 import javax.swing.JFileChooser; 9 11 import javax.swing.JOptionPane; 12 import javax.swing.table.DefaultTableModel; 10 13 import javax.xml.parsers.SAXParserFactory; 11 14 … … 20 23 21 24 /** 22 * AddIncidentAction is an AbstractAction that is used for adding an incident 23 * into the current simulation. When the action is performed, a file chooser 24 * is shown and the user is prompted to select which file they want to load 25 * script incidents from. If the user selects a file, the script file is parsed 26 * and available incidents are displayed in the AddIncidentDialog. When the dialog 27 * window is closed, the action checks for selected incidents. If a selected incident 28 * has a conflicting log number with a current incident, or if the scheduled time 29 * is prior to the current simulation time, the dialog is reshown with an error. 30 * Once the user has selected 0 or more incidents that can be added to the 31 * simulation, the SimulationManagerModel is called with the new incidents to add. 32 * If incidents were added and the simulation has not been started, the 33 * ScriptStatus is set to SCRIPT_STOPPED_NOT_STARTED. 25 * ExportAction is an AbstractAction that exports Incident data from the 26 * current simulation. (Initially, just shows data in popup window). 27 * @author jdalbey 34 28 */ 35 29 @SuppressWarnings("serial") 36 public class AddIncidentAction extends AbstractAction {30 public class ExportAction extends AbstractAction { 37 31 38 32 /** Reference to the SimulationManagerView object. */ 39 33 private SimulationManagerView theSimManagerView = null; 40 41 /** AddIncidentDialog used for adding new incidents into the simulation. */42 private AddIncidentDialog theAddIncidentDialog;43 34 44 35 /** … … 46 37 * @param view View class object for the Simulation Manager. 47 38 */ 48 public AddIncidentAction(SimulationManagerView view) { 49 super("Add New Incident"); 50 39 public ExportAction(SimulationManagerView view) { 40 super("Export Incident Notes"); 51 41 theSimManagerView = view; 52 53 theAddIncidentDialog = new AddIncidentDialog(54 theSimManagerView);55 42 } 56 57 public void actionPerformed(ActionEvent evt) { 58 Runnable addRunnable = new Runnable(){ 59 public void run() { 60 try{ 61 JFileChooser chooser = new JFileChooser( 62 SimulationManagerView.SCRIPT_DIR); 43 /** Perform the action of exporting. */ 44 public void actionPerformed(ActionEvent evt) 45 { 46 /** Create a process that can run in a separate thread so the 47 * simulation can get back to work. 48 */ 49 Runnable addRunnable = new Runnable() 50 { 51 public void run() 52 { 53 try { 54 // Retrieve the current incidents from the simulation mgr. 55 Vector<Incident> currIncidents = theSimManagerView.getModel().getIncidentList(); 63 56 64 chooser.setDialogTitle("Open Simulation Script File"); 65 chooser.setMultiSelectionEnabled(false); 66 67 if(chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { 68 69 File selectedFile = chooser.getSelectedFile(); 70 ScriptHandler sh = null; 71 72 try { 73 sh = new ScriptHandler(); 74 SAXParserFactory.newInstance().newSAXParser().parse(selectedFile, sh); 75 76 } catch (Exception e) { 77 throw new SimulationException(SimulationException.INVALID_SCRIPT_FILE); 57 StringBuffer sb = new StringBuffer(); 58 // For each incident in the list 59 for (Incident inc : currIncidents) 60 { 61 sb.append("Incident # " + inc.logNum + "\n"); 62 // Retrieve the table of comments/notes the users created 63 DefaultTableModel notesTable = inc.getCommentsNotesTable(); 64 // Retrieve the notes chronologically (Most recent is in first row) 65 for (int row=notesTable.getRowCount()-1; row >=0; row--) 66 { 67 // Combine the fields into one export entry 68 sb.append(notesTable.getValueAt(row,1) + " "); // time 69 String initials = (String) notesTable.getValueAt(row,2); // initials 70 // If there are no user intials, it's a scripted item 71 if (initials.length() == 0) 72 { 73 initials = "Script"; 74 } 75 sb.append(initials + " "); 76 sb.append(notesTable.getValueAt(row,4) + "\n"); // notes 78 77 } 79 80 boolean incidentsAdded = false; 81 boolean incidentsValidated = true; 82 Vector<Incident> currIncidents = theSimManagerView.getModel().getIncidentList(); 83 Vector<Incident> parsedIncidents = sh.getIncidents(); 84 Vector<Integer> duplicateIncNum = new Vector<Integer>(); 85 Vector<Integer> invalidIncTime = new Vector<Integer>(); 86 87 //Show the dialog with the initialized list of incidents. 88 theAddIncidentDialog.setModelData(parsedIncidents); 89 90 //Loop until the user selects a list(may be empty) of valid incidents. 91 do { 92 incidentsValidated = true; 93 theAddIncidentDialog.showDialog(); 94 95 duplicateIncNum.clear(); 96 invalidIncTime.clear(); 97 98 //Validate the selected incidents. Validation fails if: 99 // + A selected incident's log number matches a log number already in the simulation. 100 // + A selected incident has been scheduled to occur at a time that has passed in the simulation. 101 for(Integer incidentNum : theAddIncidentDialog.getSelectedIncidentTimes().keySet()) { 102 103 for(Incident inc : currIncidents) { 104 if(inc.logNum.equals(incidentNum)) { 105 duplicateIncNum.add(incidentNum); 106 incidentsValidated = false; 107 } 108 } 109 110 long incSchedTime = theAddIncidentDialog.getSelectedIncidentTimes().get(incidentNum); 111 if(incSchedTime < theSimManagerView.getCurrentSimTime()) 112 { 113 invalidIncTime.add(incidentNum); 114 incidentsValidated = false; 115 } 116 } 117 118 if(duplicateIncNum.size() > 0) { 119 JOptionPane.showMessageDialog(null, 120 "Duplicate incidents selected: " + 121 duplicateIncNum.toString().substring(1, 122 duplicateIncNum.toString().length()-1), 123 "Error", 124 JOptionPane.ERROR_MESSAGE); 125 } 126 else if(invalidIncTime.size() > 0) { 127 JOptionPane.showMessageDialog(null, 128 "Simulation time already passed for incidents: " + 129 invalidIncTime.toString().substring(1, 130 invalidIncTime.toString().length()-1), 131 "Error", 132 JOptionPane.ERROR_MESSAGE); 133 } 134 135 } while(!incidentsValidated); 136 137 138 //Loop through all selected incidents, set the new start time, and add the Incident 139 //to simulation. 140 for(Integer incidentNum : theAddIncidentDialog.getSelectedIncidentTimes().keySet()) { 141 for(Incident inc : parsedIncidents) { 142 if(inc.logNum.equals(incidentNum)) { 143 incidentsAdded = true; 144 inc.setSecondsToStart(theAddIncidentDialog 145 .getSelectedIncidentTimes().get(incidentNum)); 146 147 theSimManagerView.getModel().addIncident(inc); 148 } 149 } 150 } 151 152 153 if(incidentsAdded && !theSimManagerView.isSimulationStarted()) 154 { 155 theSimManagerView.setScriptStatus( 156 SCRIPT_STATUS.SCRIPT_STOPPED_NOT_STARTED); 157 } 158 } 159 } 160 catch (SimulationException se) { 161 theSimManagerView.SimulationExceptionHandler(se); 78 System.out.println(sb); 79 } 80 JOptionPane.showMessageDialog(theSimManagerView, sb, "Export", JOptionPane.INFORMATION_MESSAGE); 81 } catch (SimulationException ex) { 82 Logger.getLogger(ExportAction.class.getName()).log(Level.SEVERE, null, ex); 162 83 } 163 84 } 164 85 }; 165 86 166 87 Thread theThread = new Thread(addRunnable); 167 theThread.start();88 theThread.start(); 168 89 169 90 }
Note: See TracChangeset
for help on using the changeset viewer.
