Changeset 183 in tmcsimulator for trunk/src/tmcsim/client


Ignore:
Timestamp:
10/28/2017 03:51:23 PM (9 years ago)
Author:
jdalbey
Message:

ATMSBatchDriver.java Enhanced to automatically sort events chronologically (using new class TrafficEvent?).

Location:
trunk/src/tmcsim/client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/ATMSBatchDriver.java

    r180 r183  
    11package tmcsim.client; 
    22 
    3 import atmsdriver.ATMSDriver; 
    43import atmsdriver.ConsoleTrafficDriver; 
    5 import atmsdriver.ExchangeInfo; 
    64import atmsdriver.model.Highways; 
    7 import atmsdriver.model.Station; 
     5import atmsdriver.model.TrafficEvent; 
    86import atmsdriver.model.LoopDetector.DOTCOLOR; 
    97import java.awt.event.ActionEvent; 
     
    1715import java.text.SimpleDateFormat; 
    1816import java.util.ArrayList; 
     17import java.util.Collections; 
    1918import java.util.Date; 
    2019import java.util.HashMap; 
    21 import java.util.InputMismatchException; 
    2220import java.util.LinkedList; 
    2321import java.util.List; 
    2422import java.util.Map; 
    2523import java.util.Properties; 
    26 import java.util.Queue; 
    2724import java.util.Scanner; 
    2825import java.util.concurrent.TimeUnit; 
     
    3330import javax.swing.Timer; 
    3431import javax.swing.UIManager; 
    35 import tmcsim.cadsimulator.CADServer; 
    3632import tmcsim.common.SimulationException; 
    3733import tmcsim.interfaces.CADClientInterface; 
     
    3935 
    4036/** 
    41  * Skeleton for ATMS Driver that reads a "batch" file of highway 
    42  * status update commands.  
    43  * It operates as a client of the 
    44  * CAD server, using RMI to poll the server every second for the current 
    45  * simulation clock time.  It uses the simulation clock time 
    46  * to fire update commands at the desired time. 
    47  * Note: Sim Mgr must be running before starting this application. 
    48  * TODO: We probably want to be able to "override" a command, to force  
    49  * clearing an incident. 
    50  
     37 * Skeleton for ATMS Driver that reads a "batch" file of highway status update 
     38 * commands. It operates as a client of the CAD server, using RMI to poll the 
     39 * server every second for the current simulation clock time. It uses the 
     40 * simulation clock time to fire update commands at the desired time. Note: Sim 
     41 * Mgr must be running before starting this application. TODO: We probably want 
     42 * to be able to "override" a command, to force clearing an incident. 
     43 * 
    5144 * @author jdalbey 
    5245 */ 
     
    5447        CADClientInterface 
    5548{ 
     49 
    5650    private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 
    5751    private final static int ONE_SECOND = 1000; 
     
    7973    { 
    8074        CAD_SIM_HOST("CADSimulatorHost"), CAD_SIM_PORT("CADSimulatorSocketPort"), CAD_RMI_PORT( 
    81         "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID( 
    82         "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE( 
    83         "DisplayType"); 
     75                "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID( 
     76                "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE( 
     77                "DisplayType"); 
    8478        public String name; 
    8579 
     
    112106     */ 
    113107    final private Highways highways; 
    114      
    115     /**  
    116      * Queue of batch events 
    117      */ 
    118     private Queue<String> eventQueue; 
     108 
     109    /** 
     110     * LinkedList of batch events 
     111     */ 
     112    private LinkedList<TrafficEvent> eventQueue; 
    119113    /** 
    120114     * Map of incidents to events 
    121115     */ 
    122     private Map<String, List<String>> incidents; 
    123      
    124     /** Instance of ConsoleTrafficDriver that contains the highway model */ 
     116    private Map<String, List<TrafficEvent>> incidents; 
     117 
     118    /** 
     119     * Instance of ConsoleTrafficDriver that contains the highway model 
     120     */ 
    125121    private ConsoleTrafficDriver console; 
    126      
    127     /** GUI for this driver */ 
     122 
     123    /** 
     124     * GUI for this driver 
     125     */ 
    128126    private ATMSBatchViewer theView; 
    129      
     127 
    130128    /** 
    131129     * Constructor. Initialize data from parsed properties file. Create a socket 
     
    143141        } 
    144142        // Initialize the highway model 
    145         incidents = new HashMap<String, List<String>> (); 
     143        incidents = new HashMap<String, List<TrafficEvent>>(); 
    146144        highways = new Highways( 
    147         "config/vds_data/lds.txt", 
    148         "config/vds_data/loop.txt", 
    149         "config/vds_data/highwaysMeta.txt", 
    150 //        "192.168.251.46", 8080);  //IP address of FEP Sim Linux VM 
    151        "localhost", 8080); 
    152          
     145                "config/vds_data/lds.txt", 
     146                "config/vds_data/loop.txt", 
     147                "config/vds_data/highwaysMeta.txt", 
     148                //        "192.168.251.46", 8080);  //IP address of FEP Sim Linux VM 
     149                "localhost", 8080); 
     150 
    153151        connect(cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), 
    154152                cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim()); 
     
    169167                String currentClock = ""; 
    170168                String currentATMStime = ""; 
    171                 Date simClock = new Date();                 
     169                Date simClock = new Date(); 
    172170                // Obtain the simulation time from the CAD server 
    173171                try 
     
    179177//                    Date atmsdate = new Date(ATMStime); 
    180178//                    currentATMStime = formatter.format(atmsdate); 
    181                     try { 
     179                    try 
     180                    { 
    182181                        simClock = formatter.parse(currentClock); 
    183                     } catch (ParseException ex) { 
     182                    } 
     183                    catch (ParseException ex) 
     184                    { 
    184185                        Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex); 
    185186                        System.out.println("Invalid simulation clock time found in ATMSDriverClient"); 
    186187                        System.exit(-1); 
    187                     }                     
     188                    } 
    188189                    //System.out.println("Current clock: " + currentClock); 
    189                 } catch (RemoteException ex) 
     190                } 
     191                catch (RemoteException ex) 
    190192                { 
    191193                    System.out.println("Remote Exception reading sim or ATMS clock time"); 
     
    196198                { 
    197199                    // Get the time to launch the next event 
    198                     String nextEvent = eventQueue.peek(); 
    199 //                    String eventTimeField = nextEvent.substring(0,8); 
    200                     Scanner evtScan = new Scanner(nextEvent); 
    201                     String inci = evtScan.next();       
    202                     String eventTimeField = evtScan.next(); 
    203                     Date eventTime = new Date(); 
    204                     try { 
    205                         eventTime = formatter.parse(eventTimeField); 
    206                     } catch (ParseException ex) { 
    207                         Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.WARNING, null, ex); 
    208                         System.out.println("Unable to parse event time: " + nextEvent + " skipping."); 
    209                         eventQueue.remove(); 
    210                     } 
     200                    TrafficEvent nextEvent = eventQueue.peek(); 
     201                    Date eventTime = nextEvent.eventDate; 
    211202                    //System.out.println("Next event will be launched at: " + formatter.format(eventTime)); 
    212203                    // Check the queue of events to see if the first 
     
    215206                    if (eventTime.before(simClock) || eventTime.equals(simClock)) 
    216207                    { 
    217                         System.out.println("LAUNCHING EVENT at " + nextEvent ); 
    218                         // Extract fields from event and prepare them  
    219                         Scanner lineScan = new Scanner(nextEvent); 
    220                         try 
    221                         { 
    222                         lineScan.next(); // skip incident number field 
    223                         lineScan.next(); // skip time field 
    224                         int routeNumber = lineScan.nextInt(); 
    225                         Station.DIRECTION dir = Station.DIRECTION.toDirection(lineScan.next()); 
    226                         double postmile = lineScan.nextDouble(); 
    227                         double range = lineScan.nextDouble(); 
    228                         DOTCOLOR dotcolor = DOTCOLOR.toDotColor(lineScan.next()); 
     208                        System.out.println("LAUNCHING EVENT: " + nextEvent.toString()); 
    229209                        // apply colorization to highways 
    230                         highways.applyColorToHighwayStretch(routeNumber, dir, postmile, range, dotcolor); 
     210                        highways.applyColorToHighwayStretch(nextEvent.routeNumber, nextEvent.dir, 
     211                                nextEvent.postmile, nextEvent.range, nextEvent.color); 
    231212                        // Remove this event from the queue, we're done with it. 
    232213                        eventQueue.remove(); 
    233                         } 
    234                         catch (InputMismatchException ex) 
    235                         { 
    236                             System.out.println("Wrong format data in batch event file: " + nextEvent + " \nskipping."); 
    237                             eventQueue.remove(); 
    238                         } 
    239                     } 
    240                      
     214                    } 
     215 
    241216                    theView.update(currentClock, currentATMStime, eventQueue); 
    242217                } 
     
    255230    { 
    256231        FileInputStream fis; 
    257         try { 
     232        try 
     233        { 
    258234            fis = new FileInputStream("config/vds_data/atmsBatchEvents.txt"); 
    259             eventQueue = new LinkedList<String>(); 
     235            eventQueue = new LinkedList<TrafficEvent>(); 
    260236            // Read all lines from the file of events 
    261237            Scanner scan = new Scanner(fis); 
     
    263239            { 
    264240                // Read a line and add it to the event queue 
    265                 String line = scan.nextLine(); 
     241                String line = scan.nextLine().trim(); 
    266242                if (line.charAt(0) != '#') 
    267243                { 
    268                     eventQueue.add(line); 
    269                     // Parse the incident from the line 
    270                     Scanner lineScan = new Scanner(line); 
    271                     String incident = lineScan.next(); 
    272                     // Add the line to the list for the corresponding incident 
    273                     List evtList; 
    274                     if (incidents.containsKey(incident)) 
    275                     { 
    276                         evtList = incidents.get(incident); 
    277                     } 
    278                     else 
    279                     { 
    280                         evtList = new ArrayList<String>(); 
    281                     }                
    282                     evtList.add(line); 
    283                     // and put it back in the map 
    284                     incidents.put(incident, evtList); 
     244                    TrafficEvent evt; 
     245                    try 
     246                    { 
     247                        evt = new TrafficEvent(line); 
     248                        eventQueue.add(evt); 
     249                        String incident = evt.incident; 
     250                        // Add the line to the list for the corresponding incident 
     251                        List evtList; 
     252                        if (incidents.containsKey(evt.incident)) 
     253                        { 
     254                            evtList = incidents.get(evt.incident); 
     255                        } 
     256                        else 
     257                        { 
     258                            evtList = new ArrayList<String>(); 
     259                        } 
     260                        evtList.add(evt); 
     261                        // and put it back in the map 
     262                        incidents.put(incident, evtList); 
     263                    } 
     264                    catch (ParseException ex) 
     265                    { 
     266                        Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex); 
     267                        System.out.println("Wrong format data in batch event file: " + line + " \nskipping."); 
     268                        System.out.println("Skipping badly formatted event."); 
     269                    } 
    285270                } 
    286271            } 
    287         } catch (FileNotFoundException ex) { 
     272        } 
     273        catch (FileNotFoundException ex) 
     274        { 
    288275            Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex); 
    289276        } 
    290277        System.out.println("Events file read, " + eventQueue.size() + " events queued."); 
    291     } 
    292      
    293     /** Clear an incident.  For each event associated with an incident, 
    294      * turn the dots in its range Green and remove it from the event queue. 
     278        // Put the events in chronological order 
     279        Collections.sort(eventQueue); 
     280    } 
     281 
     282    /** 
     283     * Clear an incident. For each event associated with an incident, turn the 
     284     * dots in its range Green and remove it from the event queue. 
     285     * 
    295286     * @param incidentNumber incident to be cleared. 
    296287     */ 
     
    298289    { 
    299290        boolean ok = incidents.containsKey(incidentNumber); 
    300         if (!ok)  
     291        if (!ok) 
    301292        { 
    302293            System.out.println("Sorry, that incident number isn't found."); 
     
    304295        } 
    305296        System.out.println("Clearing incident " + incidentNumber); 
    306         List<String> events = incidents.get(incidentNumber); 
     297        List<TrafficEvent> events = incidents.get(incidentNumber); 
    307298        // Process each event associated with this incident  
    308         for (String event: events) 
     299        for (TrafficEvent event : events) 
    309300        { 
    310301            System.out.println("Event: " + event + " cleared."); 
    311302            eventQueue.remove(event); 
    312             // Extract fields from event and prepare them  
    313             Scanner lineScan = new Scanner(event); 
    314             try 
    315             { 
    316                 lineScan.next(); // skip incident number field 
    317                 lineScan.next(); // skip time field 
    318                 int routeNumber = lineScan.nextInt(); 
    319                 Station.DIRECTION dir = Station.DIRECTION.toDirection(lineScan.next()); 
    320                 double postmile = lineScan.nextDouble(); 
    321                 double range = lineScan.nextDouble(); 
    322                 // apply colorization to highways, forcing to green, indicating cleared 
    323                 highways.applyColorToHighwayStretch(routeNumber, dir, postmile, range, DOTCOLOR.GREEN); 
    324             } 
    325             catch (InputMismatchException ex) 
    326             { 
    327                 System.out.println("Internal error, please report to programmers." + event); 
    328             } 
    329              
     303 
     304            // apply colorization to highways, forcing to green, indicating cleared 
     305            highways.applyColorToHighwayStretch(event.routeNumber, event.dir, 
     306                    event.postmile, event.range, DOTCOLOR.GREEN); 
     307 
    330308        } 
    331309        // Now refresh the view with the updated queue of events 
    332310        theView.update("0:00", "0:00", eventQueue); 
    333311    } 
    334      
     312 
    335313    /** 
    336314     * Connect to the Coordinator's RMI object, and register this object for 
     
    354332            theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); 
    355333            theCoorInt.registerForCallback(this); 
    356         } catch (Exception e) 
     334        } 
     335        catch (Exception e) 
    357336        { 
    358337            throw new SimulationException(SimulationException.CAD_SIM_CONNECT, 
    359338                    e); 
    360              
     339 
    361340        } 
    362341    } 
     
    384363            cadClientProp = new Properties(); 
    385364            cadClientProp.load(new FileInputStream(propertiesFile)); 
    386         } catch (Exception e) 
     365        } 
     366        catch (Exception e) 
    387367        { 
    388368            cadClientLogger.logp(Level.SEVERE, "SimulationManager", 
     
    392372                    e); 
    393373        } 
    394  
    395374 
    396375        // Ensure that the properties file does not have null values for the 
     
    430409                { 
    431410                    theCoorInt.unregisterForCallback(client); 
    432                 } catch (RemoteException e) 
     411                } 
     412                catch (RemoteException e) 
    433413                { 
    434414                    e.printStackTrace(); 
     
    456436            new ATMSBatchDriver(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
    457437 
    458         } catch (Exception e) 
     438        } 
     439        catch (Exception e) 
    459440        { 
    460441            cadClientLogger.logp(Level.SEVERE, "SimulationManager", "Main", 
     
    478459            while (true) 
    479460            { 
    480                 try { 
     461                try 
     462                { 
    481463                    // Write the highway network status to the FEP Simulator 
    482464                    highways.writeToFEP(); 
    483                 } catch (SimulationException ex)  
     465                } 
     466                catch (SimulationException ex) 
    484467                { 
    485468                    // Ask user if they want to proceed without FEP Sim connection 
     
    487470                    if (reply == JOptionPane.NO_OPTION) 
    488471                    { 
    489                       System.exit(0); 
     472                        System.exit(0); 
    490473                    } 
    491474                    System.out.println("Skipping writeToFEP..."); 
  • trunk/src/tmcsim/client/ATMSBatchViewer.form

    r168 r183  
    2626      <Group type="103" groupAlignment="0" attributes="0"> 
    2727          <Group type="102" alignment="0" attributes="0"> 
    28               <Group type="103" groupAlignment="1" max="-2" attributes="0"> 
    29                   <Group type="102" alignment="0" attributes="0"> 
    30                       <EmptySpace max="-2" attributes="0"/> 
    31                       <Component id="jScrollPane1" min="-2" pref="211" max="-2" attributes="0"/> 
    32                       <EmptySpace max="-2" attributes="0"/> 
     28              <EmptySpace min="-2" pref="1" max="-2" attributes="0"/> 
     29              <Group type="103" groupAlignment="0" max="-2" attributes="0"> 
     30                  <Group type="102" attributes="0"> 
     31                      <EmptySpace min="12" pref="12" max="-2" attributes="0"/> 
    3332                      <Component id="pnlIncidents" max="32767" attributes="0"/> 
    3433                  </Group> 
    3534                  <Component id="pnlEvents" min="-2" max="-2" attributes="0"/> 
    3635              </Group> 
    37               <EmptySpace min="0" pref="27" max="32767" attributes="0"/> 
     36              <EmptySpace min="0" pref="26" max="32767" attributes="0"/> 
    3837          </Group> 
    3938      </Group> 
     
    4443              <Component id="pnlEvents" min="-2" max="-2" attributes="0"/> 
    4544              <EmptySpace max="-2" attributes="0"/> 
    46               <Group type="103" groupAlignment="0" attributes="0"> 
    47                   <Component id="pnlIncidents" max="32767" attributes="0"/> 
    48                   <Group type="102" attributes="0"> 
    49                       <Component id="jScrollPane1" min="-2" pref="179" max="-2" attributes="0"/> 
    50                       <EmptySpace min="0" pref="0" max="32767" attributes="0"/> 
    51                   </Group> 
    52               </Group> 
     45              <Component id="pnlIncidents" max="32767" attributes="0"/> 
    5346              <EmptySpace max="-2" attributes="0"/> 
    5447          </Group> 
     
    130123          <Group type="103" groupAlignment="0" attributes="0"> 
    131124              <Group type="102" attributes="0"> 
    132                   <Component id="btnClear" min="-2" max="-2" attributes="0"/> 
     125                  <Group type="103" groupAlignment="0" attributes="0"> 
     126                      <Component id="btnClear" min="-2" max="-2" attributes="0"/> 
     127                      <Component id="jScrollPane1" min="-2" pref="211" max="-2" attributes="0"/> 
     128                  </Group> 
    133129                  <EmptySpace min="0" pref="0" max="32767" attributes="0"/> 
    134130              </Group> 
     
    138134          <Group type="103" groupAlignment="0" attributes="0"> 
    139135              <Group type="102" alignment="1" attributes="0"> 
    140                   <EmptySpace min="-2" pref="185" max="-2" attributes="0"/> 
     136                  <EmptySpace max="-2" attributes="0"/> 
     137                  <Component id="jScrollPane1" min="-2" pref="179" max="-2" attributes="0"/> 
     138                  <EmptySpace max="-2" attributes="0"/> 
    141139                  <Component id="btnClear" min="-2" max="-2" attributes="0"/> 
    142140                  <EmptySpace max="32767" attributes="0"/> 
     
    146144      </Layout> 
    147145      <SubComponents> 
     146        <Container class="javax.swing.JScrollPane" name="jScrollPane1"> 
     147          <AuxValues> 
     148            <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> 
     149          </AuxValues> 
     150 
     151          <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> 
     152          <SubComponents> 
     153            <Component class="javax.swing.JList" name="lstIncidents"> 
     154              <Properties> 
     155                <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> 
     156                  <Font name="Noto Mono" size="15" style="0"/> 
     157                </Property> 
     158                <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor"> 
     159                  <StringArray count="5"> 
     160                    <StringItem index="0" value="Item 1"/> 
     161                    <StringItem index="1" value="Item 2"/> 
     162                    <StringItem index="2" value="Item 3"/> 
     163                    <StringItem index="3" value="Item 4"/> 
     164                    <StringItem index="4" value="Item 5"/> 
     165                  </StringArray> 
     166                </Property> 
     167                <Property name="selectionMode" type="int" value="0"/> 
     168              </Properties> 
     169              <AuxValues> 
     170                <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/> 
     171              </AuxValues> 
     172            </Component> 
     173          </SubComponents> 
     174        </Container> 
    148175        <Component class="javax.swing.JButton" name="btnClear"> 
    149176          <Properties> 
     
    156183      </SubComponents> 
    157184    </Container> 
    158     <Container class="javax.swing.JScrollPane" name="jScrollPane1"> 
    159       <AuxValues> 
    160         <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> 
    161       </AuxValues> 
    162  
    163       <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> 
    164       <SubComponents> 
    165         <Component class="javax.swing.JList" name="lstIncidents"> 
    166           <Properties> 
    167             <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> 
    168               <Font name="Noto Mono" size="15" style="0"/> 
    169             </Property> 
    170             <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor"> 
    171               <StringArray count="5"> 
    172                 <StringItem index="0" value="Item 1"/> 
    173                 <StringItem index="1" value="Item 2"/> 
    174                 <StringItem index="2" value="Item 3"/> 
    175                 <StringItem index="3" value="Item 4"/> 
    176                 <StringItem index="4" value="Item 5"/> 
    177               </StringArray> 
    178             </Property> 
    179             <Property name="selectionMode" type="int" value="0"/> 
    180           </Properties> 
    181           <AuxValues> 
    182             <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/> 
    183           </AuxValues> 
    184         </Component> 
    185       </SubComponents> 
    186     </Container> 
    187185  </SubComponents> 
    188186</Form> 
  • trunk/src/tmcsim/client/ATMSBatchViewer.java

    r168 r183  
    1  
    21package tmcsim.client; 
    32 
     3import atmsdriver.model.TrafficEvent; 
     4import java.text.ParseException; 
    45import java.util.ArrayList; 
    5 import java.util.HashSet; 
    66import java.util.LinkedList; 
    77import java.util.List; 
    8 import java.util.Queue; 
    9 import java.util.Set; 
    10 import java.util.Vector; 
     8import java.util.logging.Level; 
     9import java.util.logging.Logger; 
    1110import javax.swing.AbstractListModel; 
    12 import javax.swing.JLabel; 
    13 import javax.swing.JList; 
    1411import javax.swing.JOptionPane; 
    15 import tmcsim.cadsimulator.CADServer; 
    1612 
    1713/** 
     
    1915 * @author jdalbey 
    2016 */ 
    21 public class ATMSBatchViewer extends javax.swing.JFrame  
     17public class ATMSBatchViewer extends javax.swing.JFrame 
    2218{ 
    23     /** Reference to the driver associated with this GUI */ 
    24     private ATMSBatchDriver driver;  
     19 
     20    /** 
     21     * Reference to the driver associated with this GUI 
     22     */ 
     23    private ATMSBatchDriver driver; 
    2524    private final List<String> incidents; 
     25 
    2626    /** 
    2727     * Creates new form ATMSBatchViewer. 
     28     * 
    2829     * @param incidents a list of incidents to show in a list. 
    2930     */ 
    30     public ATMSBatchViewer(ATMSBatchDriver driver, List<String> incidentList)  
     31    public ATMSBatchViewer(ATMSBatchDriver driver, List<String> incidentList) 
    3132    { 
    3233        initComponents(); 
    33         this.driver = driver;  
     34        this.driver = driver; 
    3435        this.incidents = incidentList; 
    3536        lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 
    3637        { 
    37             public int getSize() { return incidents.size(); } 
    38             public String getElementAt(int i) { return incidents.get(i); } 
    39         });         
     38            public int getSize() 
     39            { 
     40                return incidents.size(); 
     41            } 
     42 
     43            public String getElementAt(int i) 
     44            { 
     45                return incidents.get(i); 
     46            } 
     47        }); 
    4048    } 
    4149 
    42     public void update(String currentTime, String atmsTime, Queue<String> events) 
     50    public void update(String currentTime, String atmsTime, List<TrafficEvent> events) 
    4351    { 
    4452        lstEvents.setModel(new MyListModel(events)); 
    45         txtClockTime.setText(currentTime + " / " +atmsTime); 
     53        txtClockTime.setText(currentTime + " / " + atmsTime); 
    4654    } 
     55 
    4756    class MyListModel extends AbstractListModel<String> 
    4857    { 
    49             String[] strings = { "item 1", "item 2" }; 
    50             public MyListModel(Queue<String> events) 
    51             { 
    52                 strings = events.toArray(new String[events.size()]);                
    53             } 
    54             public int getSize() { return strings.length; } 
    55             public String getElementAt(int i) { return strings[i]; }         
     58 
     59        TrafficEvent[] strings;// = { "item 1", "item 2" }; 
     60 
     61        public MyListModel(List<TrafficEvent> events) 
     62        { 
     63            strings = events.toArray(new TrafficEvent[events.size()]); 
     64        } 
     65 
     66        public int getSize() 
     67        { 
     68            return strings.length; 
     69        } 
     70 
     71        public String getElementAt(int i) 
     72        { 
     73            return strings[i].rawString; 
     74        } 
    5675    } 
     76 
    5777    /** 
    5878     * This method is called from within the constructor to initialize the form. 
     
    7090        txtClockTime = new javax.swing.JLabel(); 
    7191        pnlIncidents = new javax.swing.JPanel(); 
    72         btnClear = new javax.swing.JButton(); 
    7392        jScrollPane1 = new javax.swing.JScrollPane(); 
    7493        lstIncidents = new javax.swing.JList<>(); 
     94        btnClear = new javax.swing.JButton(); 
    7595 
    7696        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
     
    112132        ); 
    113133 
     134        lstIncidents.setFont(new java.awt.Font("Noto Mono", 0, 15)); // NOI18N 
     135        lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 
     136        { 
     137            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; 
     138            public int getSize() { return strings.length; } 
     139            public String getElementAt(int i) { return strings[i]; } 
     140        }); 
     141        lstIncidents.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 
     142        jScrollPane1.setViewportView(lstIncidents); 
     143 
    114144        btnClear.setText("Clear Incident"); 
    115145        btnClear.addActionListener(new java.awt.event.ActionListener() 
     
    126156            pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    127157            .addGroup(pnlIncidentsLayout.createSequentialGroup() 
    128                 .addComponent(btnClear) 
     158                .addGroup(pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     159                    .addComponent(btnClear) 
     160                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)) 
    129161                .addGap(0, 0, Short.MAX_VALUE)) 
    130162        ); 
     
    132164            pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    133165            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlIncidentsLayout.createSequentialGroup() 
    134                 .addGap(185, 185, 185) 
     166                .addContainerGap() 
     167                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) 
     168                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    135169                .addComponent(btnClear) 
    136170                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
    137171        ); 
    138  
    139         lstIncidents.setFont(new java.awt.Font("Noto Mono", 0, 15)); // NOI18N 
    140         lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 
    141         { 
    142             String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; 
    143             public int getSize() { return strings.length; } 
    144             public String getElementAt(int i) { return strings[i]; } 
    145         }); 
    146         lstIncidents.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 
    147         jScrollPane1.setViewportView(lstIncidents); 
    148172 
    149173        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     
    152176            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    153177            .addGroup(layout.createSequentialGroup() 
    154                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) 
    155                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() 
    156                         .addContainerGap() 
    157                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE) 
    158                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
     178                .addGap(1, 1, 1) 
     179                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 
     180                    .addGroup(layout.createSequentialGroup() 
     181                        .addGap(12, 12, 12) 
    159182                        .addComponent(pnlIncidents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
    160183                    .addComponent(pnlEvents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
    161                 .addGap(0, 27, Short.MAX_VALUE)) 
     184                .addGap(0, 26, Short.MAX_VALUE)) 
    162185        ); 
    163186        layout.setVerticalGroup( 
     
    166189                .addComponent(pnlEvents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
    167190                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    168                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    169                     .addComponent(pnlIncidents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
    170                     .addGroup(layout.createSequentialGroup() 
    171                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) 
    172                         .addGap(0, 0, Short.MAX_VALUE))) 
     191                .addComponent(pnlIncidents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
    173192                .addContainerGap()) 
    174193        ); 
     
    179198    private void btnClearActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnClearActionPerformed 
    180199    {//GEN-HEADEREND:event_btnClearActionPerformed 
    181         String selectedItem =  lstIncidents.getSelectedValue(); 
     200        String selectedItem = lstIncidents.getSelectedValue(); 
    182201        if (selectedItem == null) 
    183202        { 
     
    187206        { 
    188207            System.out.println("Clicked Incident:" + selectedItem); 
    189             if (driver != null) driver.clearIncident(selectedItem); 
     208            if (driver != null) 
     209            { 
     210                driver.clearIncident(selectedItem); 
     211            } 
    190212            lstIncidents.clearSelection(); 
    191213            // Remove selectedItem from list model; 
     
    201223     * @param args the command line arguments 
    202224     */ 
    203     public static void main(String args[]) { 
     225    public static void main(String args[]) 
     226    { 
    204227        /* Set the Nimbus look and feel */ 
    205228        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
     
    207230         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html  
    208231         */ 
    209         try { 
    210             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
    211                 if ("Nimbus".equals(info.getName())) { 
     232        try 
     233        { 
     234            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) 
     235            { 
     236                if ("Nimbus".equals(info.getName())) 
     237                { 
    212238                    javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
    213239                    break; 
    214240                } 
    215241            } 
    216         } catch (ClassNotFoundException ex) { 
     242        } 
     243        catch (ClassNotFoundException ex) 
     244        { 
    217245            java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    218         } catch (InstantiationException ex) { 
     246        } 
     247        catch (InstantiationException ex) 
     248        { 
    219249            java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    220         } catch (IllegalAccessException ex) { 
     250        } 
     251        catch (IllegalAccessException ex) 
     252        { 
    221253            java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    222         } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
     254        } 
     255        catch (javax.swing.UnsupportedLookAndFeelException ex) 
     256        { 
    223257            java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    224258        } 
     
    226260 
    227261        /* Create and display the form */ 
    228         java.awt.EventQueue.invokeLater(new Runnable() { 
    229             public void run() { 
    230                 Queue<String> sample = new LinkedList<String>(); 
    231                 sample.add("Greetings"); 
    232                 sample.add("Earthling"); 
    233                 List<String> items = new ArrayList<String>(); 
    234                 items.add("Able"); items.add("Baker"); 
    235                 ATMSBatchViewer view = new ATMSBatchViewer(null,items); 
    236                 view.setVisible(true); 
    237                 view.update("01", "02", sample); 
    238                  
     262        java.awt.EventQueue.invokeLater(new Runnable() 
     263        { 
     264            public void run() 
     265            { 
     266                try 
     267                { 
     268                    TrafficEvent alpha = new TrafficEvent("181 00:01:30 405 S 0.6 11.0 G"); 
     269                    TrafficEvent beta = new TrafficEvent("183 00:12:30 405 S 0.6 11.0 G"); 
     270                    TrafficEvent charly = new TrafficEvent("181 00:22:00 5 S 0.6 11.0 G"); 
     271                    LinkedList<TrafficEvent> sample = new LinkedList<TrafficEvent>(); 
     272                    sample.add(alpha); 
     273                    sample.add(beta); 
     274                    List<String> items = new ArrayList<String>(); 
     275                    items.add("180"); 
     276                    items.add("1291"); 
     277                    ATMSBatchViewer view = new ATMSBatchViewer(null, items); 
     278                    view.setVisible(true); 
     279                    view.update("01", "02", sample); 
     280                } 
     281                catch (ParseException ex) 
     282                { 
     283                    Logger.getLogger(ATMSBatchViewer.class.getName()).log(Level.SEVERE, null, ex); 
     284                } 
     285 
    239286            } 
    240287        }); 
Note: See TracChangeset for help on using the changeset viewer.