Changeset 135 in tmcsimulator for trunk/src


Ignore:
Timestamp:
10/17/2017 05:10:07 PM (9 years ago)
Author:
jdalbey
Message:

ATMSBatchDriver.java Implemented "clear incident" feature.

Location:
trunk/src/tmcsim
Files:
4 edited

Legend:

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

    r127 r135  
    1 #Mon, 16 Oct 2017 17:41:29 -0700 
     1#Tue, 17 Oct 2017 18:13:47 -0700 
    22 
    3 Application.revision=125 
     3Application.revision=133 
    44 
    55Application.buildnumber=53 
  • trunk/src/tmcsim/client/ATMSBatchDriver.java

    r129 r135  
    155155        readBatchFile(); 
    156156        // Launch the display 
    157         theView = new ATMSBatchViewer(); 
     157        theView = new ATMSBatchViewer(this, new ArrayList<String>(incidents.keySet())); 
    158158        theView.setVisible(true); 
    159         theView.update("0:00", eventQueue);         
     159        theView.update("0:00", eventQueue); 
     160 
    160161        // Create a timer that fetches the simulation time every second. 
    161162        Timer timer = new Timer(ONE_SECOND, new ActionListener() 
     
    201202                    } 
    202203                    //System.out.println("Next event will be launched at: " + formatter.format(eventTime)); 
    203                     theView.update(currentClock, eventQueue); 
    204204                    // Check the queue of events to see if the first 
    205205                    // item should be launched.  IF so,  
     
    230230                        } 
    231231                    } 
     232                    theView.update(currentClock, eventQueue); 
    232233                } 
    233234            } 
     
    236237 
    237238        // Start the FEP thread (to update ATMS every 30 sec). (See class def below) 
    238         new WriteToFEPThread().run(); 
     239        Thread wtfep = new WriteToFEPThread(); 
     240        wtfep.start(); 
    239241 
    240242        ensureProperShutdown(); 
     
    277279    } 
    278280     
     281    /** Clear an incident.  For each event associated with an incident, 
     282     * turn the dots in its range Green and remove it from the event queue. 
     283     * @param incidentNumber incident to be cleared. 
     284     */ 
     285    public void clearIncident(String incidentNumber) 
     286    { 
     287        boolean ok = incidents.containsKey(incidentNumber); 
     288        if (!ok)  
     289        { 
     290            System.out.println("Sorry, that incident number isn't found."); 
     291            return; 
     292        } 
     293        System.out.println("Clearing incident " + incidentNumber); 
     294        List<String> events = incidents.get(incidentNumber); 
     295        // Process each event associated with this incident  
     296        for (String event: events) 
     297        { 
     298            System.out.println("Event: " + event + " cleared."); 
     299            eventQueue.remove(event); 
     300            // Extract fields from event and prepare them  
     301            Scanner lineScan = new Scanner(event); 
     302            try 
     303            { 
     304                lineScan.next(); // skip incident number field 
     305                lineScan.next(); // skip time field 
     306                int routeNumber = lineScan.nextInt(); 
     307                Station.DIRECTION dir = Station.DIRECTION.toDirection(lineScan.next()); 
     308                double postmile = lineScan.nextDouble(); 
     309                int range = lineScan.nextInt(); 
     310                // apply colorization to highways, forcing to green, indicating cleared 
     311                console.applyColorToHighwayStretch(routeNumber, dir, postmile, range, ConsoleDriver.DOTCOLOR.GREEN); 
     312            } 
     313            catch (InputMismatchException ex) 
     314            { 
     315                System.out.println("Internal error, please report to programmers." + event); 
     316            } 
     317             
     318        } 
     319        // Now refresh the view with the updated queue of events 
     320        theView.update("0:00", eventQueue); 
     321    } 
     322     
    279323    /** 
    280324     * Connect to the Coordinator's RMI object, and register this object for 
  • trunk/src/tmcsim/client/ATMSBatchViewer.form

    r128 r135  
    2828              <EmptySpace max="-2" attributes="0"/> 
    2929          </Group> 
     30          <Group type="102" alignment="0" attributes="0"> 
     31              <EmptySpace min="-2" pref="76" max="-2" attributes="0"/> 
     32              <Component id="pnlIncidents" min="-2" max="-2" attributes="0"/> 
     33              <EmptySpace max="32767" attributes="0"/> 
     34          </Group> 
    3035      </Group> 
    3136    </DimensionLayout> 
     
    3439          <Group type="102" alignment="0" attributes="0"> 
    3540              <Component id="pnlEvents" min="-2" max="-2" attributes="0"/> 
    36               <EmptySpace min="0" pref="129" max="32767" attributes="0"/> 
     41              <EmptySpace max="-2" attributes="0"/> 
     42              <Component id="pnlIncidents" max="32767" attributes="0"/> 
     43              <EmptySpace max="-2" attributes="0"/> 
    3744          </Group> 
    3845      </Group> 
     
    4653          <Group type="103" groupAlignment="0" attributes="0"> 
    4754              <Group type="102" alignment="1" attributes="0"> 
    48                   <EmptySpace pref="83" max="32767" attributes="0"/> 
     55                  <EmptySpace pref="74" max="32767" attributes="0"/> 
    4956                  <Component id="scrollEvents" min="-2" pref="354" max="-2" attributes="0"/> 
    5057                  <EmptySpace min="-2" pref="59" max="-2" attributes="0"/> 
     
    104111      </SubComponents> 
    105112    </Container> 
     113    <Container class="javax.swing.JPanel" name="pnlIncidents"> 
     114 
     115      <Layout> 
     116        <DimensionLayout dim="0"> 
     117          <Group type="103" groupAlignment="0" attributes="0"> 
     118              <Group type="102" attributes="0"> 
     119                  <Group type="103" groupAlignment="0" attributes="0"> 
     120                      <Component id="btnClear" min="-2" max="-2" attributes="0"/> 
     121                      <Component id="jScrollPane1" min="-2" pref="211" max="-2" attributes="0"/> 
     122                  </Group> 
     123                  <EmptySpace min="0" pref="173" max="32767" attributes="0"/> 
     124              </Group> 
     125          </Group> 
     126        </DimensionLayout> 
     127        <DimensionLayout dim="1"> 
     128          <Group type="103" groupAlignment="0" attributes="0"> 
     129              <Group type="102" alignment="1" attributes="0"> 
     130                  <Component id="jScrollPane1" min="-2" pref="179" max="-2" attributes="0"/> 
     131                  <EmptySpace max="-2" attributes="0"/> 
     132                  <Component id="btnClear" min="-2" max="-2" attributes="0"/> 
     133                  <EmptySpace max="32767" attributes="0"/> 
     134              </Group> 
     135          </Group> 
     136        </DimensionLayout> 
     137      </Layout> 
     138      <SubComponents> 
     139        <Component class="javax.swing.JButton" name="btnClear"> 
     140          <Properties> 
     141            <Property name="text" type="java.lang.String" value="Clear Incident"/> 
     142          </Properties> 
     143          <Events> 
     144            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClearActionPerformed"/> 
     145          </Events> 
     146        </Component> 
     147        <Container class="javax.swing.JScrollPane" name="jScrollPane1"> 
     148          <AuxValues> 
     149            <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> 
     150          </AuxValues> 
     151 
     152          <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> 
     153          <SubComponents> 
     154            <Component class="javax.swing.JList" name="lstIncidents"> 
     155              <Properties> 
     156                <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> 
     157                  <Font name="Noto Mono" size="15" style="0"/> 
     158                </Property> 
     159                <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor"> 
     160                  <StringArray count="5"> 
     161                    <StringItem index="0" value="Item 1"/> 
     162                    <StringItem index="1" value="Item 2"/> 
     163                    <StringItem index="2" value="Item 3"/> 
     164                    <StringItem index="3" value="Item 4"/> 
     165                    <StringItem index="4" value="Item 5"/> 
     166                  </StringArray> 
     167                </Property> 
     168                <Property name="selectionMode" type="int" value="0"/> 
     169              </Properties> 
     170              <AuxValues> 
     171                <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/> 
     172              </AuxValues> 
     173            </Component> 
     174          </SubComponents> 
     175        </Container> 
     176      </SubComponents> 
     177    </Container> 
    106178  </SubComponents> 
    107179</Form> 
  • trunk/src/tmcsim/client/ATMSBatchViewer.java

    r128 r135  
    1 /* 
    2  * To change this license header, choose License Headers in Project Properties. 
    3  * To change this template file, choose Tools | Templates 
    4  * and open the template in the editor. 
    5  */ 
     1 
    62package tmcsim.client; 
    73 
     4import java.util.ArrayList; 
     5import java.util.HashSet; 
    86import java.util.LinkedList; 
     7import java.util.List; 
    98import java.util.Queue; 
     9import java.util.Set; 
    1010import java.util.Vector; 
    1111import javax.swing.AbstractListModel; 
     12import javax.swing.JLabel; 
    1213import javax.swing.JList; 
     14import javax.swing.JOptionPane; 
    1315 
    1416/** 
     
    1820public class ATMSBatchViewer extends javax.swing.JFrame  
    1921{ 
     22    /** Reference to the driver associated with this GUI */ 
     23    private ATMSBatchDriver driver;  
     24    private final List<String> incidents; 
    2025    /** 
    21      * Creates new form ATMSBatchViewer 
     26     * Creates new form ATMSBatchViewer. 
     27     * @param incidents a list of incidents to show in a list. 
    2228     */ 
    23     public ATMSBatchViewer()  
     29    public ATMSBatchViewer(ATMSBatchDriver driver, List<String> incidentList)  
    2430    { 
    2531        initComponents(); 
     32        this.driver = driver;  
     33        this.incidents = incidentList; 
     34        lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 
     35        { 
     36            public int getSize() { return incidents.size(); } 
     37            public String getElementAt(int i) { return incidents.get(i); } 
     38        });         
    2639    } 
    2740 
     
    4861    @SuppressWarnings("unchecked") 
    4962    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 
    50     private void initComponents() { 
     63    private void initComponents() 
     64    { 
    5165 
    5266        pnlEvents = new javax.swing.JPanel(); 
     
    5468        lstEvents = new javax.swing.JList<>(); 
    5569        txtClockTime = new javax.swing.JLabel(); 
     70        pnlIncidents = new javax.swing.JPanel(); 
     71        btnClear = new javax.swing.JButton(); 
     72        jScrollPane1 = new javax.swing.JScrollPane(); 
     73        lstIncidents = new javax.swing.JList<>(); 
    5674 
    5775        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
    5876 
    5977        lstEvents.setFont(new java.awt.Font("Noto Mono", 0, 12)); // NOI18N 
    60         lstEvents.setModel(new javax.swing.AbstractListModel<String>() { 
     78        lstEvents.setModel(new javax.swing.AbstractListModel<String>() 
     79        { 
    6180            String[] strings = { "item 1", "item 2" }; 
    6281            public int getSize() { return strings.length; } 
     
    7392            pnlEventsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    7493            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEventsLayout.createSequentialGroup() 
    75                 .addContainerGap(83, Short.MAX_VALUE) 
     94                .addContainerGap(74, Short.MAX_VALUE) 
    7695                .addComponent(scrollEvents, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE) 
    7796                .addGap(59, 59, 59)) 
     
    90109        ); 
    91110 
     111        btnClear.setText("Clear Incident"); 
     112        btnClear.addActionListener(new java.awt.event.ActionListener() 
     113        { 
     114            public void actionPerformed(java.awt.event.ActionEvent evt) 
     115            { 
     116                btnClearActionPerformed(evt); 
     117            } 
     118        }); 
     119 
     120        lstIncidents.setFont(new java.awt.Font("Noto Mono", 0, 15)); // NOI18N 
     121        lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 
     122        { 
     123            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; 
     124            public int getSize() { return strings.length; } 
     125            public String getElementAt(int i) { return strings[i]; } 
     126        }); 
     127        lstIncidents.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 
     128        jScrollPane1.setViewportView(lstIncidents); 
     129 
     130        javax.swing.GroupLayout pnlIncidentsLayout = new javax.swing.GroupLayout(pnlIncidents); 
     131        pnlIncidents.setLayout(pnlIncidentsLayout); 
     132        pnlIncidentsLayout.setHorizontalGroup( 
     133            pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     134            .addGroup(pnlIncidentsLayout.createSequentialGroup() 
     135                .addGroup(pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     136                    .addComponent(btnClear) 
     137                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)) 
     138                .addGap(0, 173, Short.MAX_VALUE)) 
     139        ); 
     140        pnlIncidentsLayout.setVerticalGroup( 
     141            pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     142            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlIncidentsLayout.createSequentialGroup() 
     143                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) 
     144                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
     145                .addComponent(btnClear) 
     146                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
     147        ); 
     148 
    92149        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
    93150        getContentPane().setLayout(layout); 
     
    97154                .addComponent(pnlEvents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
    98155                .addContainerGap()) 
     156            .addGroup(layout.createSequentialGroup() 
     157                .addGap(76, 76, 76) 
     158                .addComponent(pnlIncidents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
     159                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
    99160        ); 
    100161        layout.setVerticalGroup( 
     
    102163            .addGroup(layout.createSequentialGroup() 
    103164                .addComponent(pnlEvents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
    104                 .addGap(0, 129, Short.MAX_VALUE)) 
     165                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
     166                .addComponent(pnlIncidents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
     167                .addContainerGap()) 
    105168        ); 
    106169 
    107170        pack(); 
    108171    }// </editor-fold>//GEN-END:initComponents 
     172 
     173    private void btnClearActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnClearActionPerformed 
     174    {//GEN-HEADEREND:event_btnClearActionPerformed 
     175        String selectedItem =  lstIncidents.getSelectedValue(); 
     176        if (selectedItem == null) 
     177        { 
     178            JOptionPane.showMessageDialog(this, "No Incident Selected", "Warning", JOptionPane.INFORMATION_MESSAGE); 
     179        } 
     180        else 
     181        { 
     182            System.out.println("Clicked Incident:" + selectedItem); 
     183            if (driver != null) driver.clearIncident(selectedItem); 
     184            lstIncidents.clearSelection(); 
     185            // Remove selectedItem from list model; 
     186            incidents.remove(selectedItem); 
     187            // Update the list displayed 
     188            String[] array = new String[incidents.size()]; 
     189            array = incidents.toArray(array); 
     190            lstIncidents.setListData(array); 
     191        } 
     192    }//GEN-LAST:event_btnClearActionPerformed 
    109193 
    110194    /** 
     
    141225                sample.add("Greetings"); 
    142226                sample.add("Earthling"); 
    143                 ATMSBatchViewer view = new ATMSBatchViewer(); 
     227                List<String> items = new ArrayList<String>(); 
     228                items.add("Able"); items.add("Baker"); 
     229                ATMSBatchViewer view = new ATMSBatchViewer(null,items); 
    144230                view.setVisible(true); 
    145231                view.update("01", sample); 
     
    150236 
    151237    // Variables declaration - do not modify//GEN-BEGIN:variables 
     238    private javax.swing.JButton btnClear; 
     239    private javax.swing.JScrollPane jScrollPane1; 
    152240    private javax.swing.JList<String> lstEvents; 
     241    private javax.swing.JList<String> lstIncidents; 
    153242    private javax.swing.JPanel pnlEvents; 
     243    private javax.swing.JPanel pnlIncidents; 
    154244    private javax.swing.JScrollPane scrollEvents; 
    155245    private javax.swing.JLabel txtClockTime; 
Note: See TracChangeset for help on using the changeset viewer.