Changeset 416 in tmcsimulator for trunk


Ignore:
Timestamp:
06/18/2019 10:56:55 AM (7 years ago)
Author:
jdalbey
Message:

Create new ExportAction?.java for Sim Mgr and a new client, CADlogDisplay that outputs to console the current CAD log every 10 seconds.

Location:
trunk/src
Files:
2 added
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/application.properties

    r407 r416  
    1 #Thu, 16 May 2019 14:30:48 -0700 
     1#Wed, 05 Jun 2019 16:17:15 -0700 
    22 
    3 Application.revision=406 
     3Application.revision=414 
    44 
    5 Application.buildnumber=138 
     5Application.buildnumber=140 
  • trunk/src/tmcsim/cadsimulator/Coordinator.java

    r407 r416  
    9898     * The name of the file where the simulation clock time is written 
    9999     */ 
    100     private String kSimClockFilename = "webapps" +  
    101             System.getProperty("file.separator") + "dynamicdata" +  
    102             System.getProperty("file.separator") + "sim_elapsedtime.json";         
     100    private String kSimClockFilename; 
    103101    /** 
    104102     * Error logger. 
     
    125123     * Constructor. Call UnicastRemoteObject constructor and call 
    126124     * initializeSimulation. 
    127      * 
     125     * @param simTimeFilename name of the file where the simulation clock time is written 
    128126     * @throws RemoteException 
    129127     */ 
  • trunk/src/tmcsim/client/CADlogDisplay.java

    r64 r416  
    88import java.rmi.server.UnicastRemoteObject; 
    99import java.util.Properties; 
     10import java.util.Vector; 
    1011import java.util.concurrent.TimeUnit; 
    1112import java.util.logging.Level; 
     
    1516import javax.swing.Timer; 
    1617import javax.swing.UIManager; 
     18import javax.swing.table.DefaultTableModel; 
     19import tmcsim.client.cadclientgui.data.Incident; 
     20import tmcsim.client.cadclientgui.enums.CADDataEnums.INC_TABLE; 
    1721import tmcsim.common.SimulationException; 
    1822import tmcsim.interfaces.CADClientInterface; 
     
    2024 
    2125/** 
    22  * ClockClient shows the simulation clock time. It operates as a client of the 
     26 * CADlogDisplays shows the current CAD log for all incidents. It operates as a client of the 
    2327 * 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.  
    2529 * 
    2630 * @author jdalbey 
    2731 */ 
    28 public class ClockClient extends UnicastRemoteObject implements 
     32public class CADlogDisplay extends UnicastRemoteObject implements 
    2933        CADClientInterface 
    3034{ 
     
    8286    private CADClientInterface client = this; 
    8387    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; 
    8589 
    8690    /** 
     
    9195     * file containing configuration data. 
    9296     */ 
    93     public ClockClient(String propertiesFile) throws SimulationException, 
     97    public CADlogDisplay(String propertiesFile) throws SimulationException, 
    9498            RemoteException 
    9599    { 
     
    102106                cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim()); 
    103107 
    104         theView = new ClockView(); 
    105         theView.setVisible(true); 
     108        //theView = new ClockView(); 
     109        //theView.setVisible(true); 
    106110 
    107111        // 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() 
    109113        { 
    110114            public void actionPerformed(ActionEvent e) 
     
    112116                try 
    113117                { 
    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)); 
    116146                } catch (RemoteException ex) 
    117147                { 
    118                     Logger.getLogger(ClockClient.class.getName()).log(Level.SEVERE, null, ex); 
     148                    Logger.getLogger(CADlogDisplay.class.getName()).log(Level.SEVERE, null, ex); 
    119149                } 
    120150            } 
     
    245275        { 
    246276            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    247             new ClockClient(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); 
    248278 
    249279        } catch (Exception e) 
  • trunk/src/tmcsim/simulationmanager/SimulationManagerView.java

    r365 r416  
    4747import tmcsim.simulationmanager.actions.DeleteIncidentAction; 
    4848import tmcsim.simulationmanager.actions.ExitAction; 
     49import tmcsim.simulationmanager.actions.ExportAction; 
    4950import tmcsim.simulationmanager.actions.GotoTimeIndexAction; 
    5051import tmcsim.simulationmanager.actions.LoadParamicsNetworkAction; 
     
    686687    private void createMenuBar() { 
    687688 
    688         gotoMenuItem = new JMenuItem(new GotoTimeIndexAction(this));         
     689        gotoMenuItem = new JMenuItem(new GotoTimeIndexAction(this));     
     690        exportMenuItem = new JMenuItem(new ExportAction(this)); 
    689691        exitMenuItem = new JMenuItem(new ExitAction(this)); 
    690692         
    691693        fileMenu = new JMenu("File"); 
    692694        fileMenu.add(gotoMenuItem); 
     695        fileMenu.add(exportMenuItem); 
    693696        fileMenu.add(exitMenuItem); 
    694697         
     
    12551258    private JMenu fileMenu; 
    12561259    private JMenuItem gotoMenuItem; 
     1260    private JMenuItem exportMenuItem; 
    12571261    private JMenuItem exitMenuItem; 
    12581262     
  • trunk/src/tmcsim/simulationmanager/actions/ExportAction.java

    r2 r416  
    44import java.io.File; 
    55import java.util.Vector; 
     6import java.util.logging.Level; 
     7import java.util.logging.Logger; 
    68 
    79import javax.swing.AbstractAction; 
    810import javax.swing.JFileChooser; 
    911import javax.swing.JOptionPane; 
     12import javax.swing.table.DefaultTableModel; 
    1013import javax.xml.parsers.SAXParserFactory; 
    1114 
     
    2023 
    2124/** 
    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 
    3428 */ 
    3529@SuppressWarnings("serial") 
    36 public class AddIncidentAction extends AbstractAction { 
     30public class ExportAction extends AbstractAction { 
    3731     
    3832    /** Reference to the SimulationManagerView object. */ 
    3933    private SimulationManagerView theSimManagerView = null; 
    40      
    41     /** AddIncidentDialog used for adding new incidents into the simulation. */ 
    42     private AddIncidentDialog theAddIncidentDialog;  
    4334     
    4435    /**  
     
    4637     * @param view View class object for the Simulation Manager. 
    4738     */      
    48     public AddIncidentAction(SimulationManagerView view) { 
    49         super("Add New Incident"); 
    50          
     39    public ExportAction(SimulationManagerView view) { 
     40        super("Export Incident Notes"); 
    5141        theSimManagerView = view; 
    52  
    53         theAddIncidentDialog  = new AddIncidentDialog( 
    54                 theSimManagerView); 
    5542    } 
    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(); 
    6356                     
    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 
    7877                        } 
    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); 
    16283                } 
    16384            } 
    16485        }; 
    165          
     86 
    16687        Thread theThread = new Thread(addRunnable); 
    167         theThread.start(); 
     88            theThread.start(); 
    16889 
    16990    } 
Note: See TracChangeset for help on using the changeset viewer.