Changeset 183 in tmcsimulator for trunk/src/tmcsim/client
- Timestamp:
- 10/28/2017 03:51:23 PM (9 years ago)
- Location:
- trunk/src/tmcsim/client
- Files:
-
- 3 edited
-
ATMSBatchDriver.java (modified) (23 diffs)
-
ATMSBatchViewer.form (modified) (6 diffs)
-
ATMSBatchViewer.java (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/client/ATMSBatchDriver.java
r180 r183 1 1 package tmcsim.client; 2 2 3 import atmsdriver.ATMSDriver;4 3 import atmsdriver.ConsoleTrafficDriver; 5 import atmsdriver.ExchangeInfo;6 4 import atmsdriver.model.Highways; 7 import atmsdriver.model. Station;5 import atmsdriver.model.TrafficEvent; 8 6 import atmsdriver.model.LoopDetector.DOTCOLOR; 9 7 import java.awt.event.ActionEvent; … … 17 15 import java.text.SimpleDateFormat; 18 16 import java.util.ArrayList; 17 import java.util.Collections; 19 18 import java.util.Date; 20 19 import java.util.HashMap; 21 import java.util.InputMismatchException;22 20 import java.util.LinkedList; 23 21 import java.util.List; 24 22 import java.util.Map; 25 23 import java.util.Properties; 26 import java.util.Queue;27 24 import java.util.Scanner; 28 25 import java.util.concurrent.TimeUnit; … … 33 30 import javax.swing.Timer; 34 31 import javax.swing.UIManager; 35 import tmcsim.cadsimulator.CADServer;36 32 import tmcsim.common.SimulationException; 37 33 import tmcsim.interfaces.CADClientInterface; … … 39 35 40 36 /** 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 * 51 44 * @author jdalbey 52 45 */ … … 54 47 CADClientInterface 55 48 { 49 56 50 private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 57 51 private final static int ONE_SECOND = 1000; … … 79 73 { 80 74 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"); 84 78 public String name; 85 79 … … 112 106 */ 113 107 final private Highways highways; 114 115 /** 116 * Queueof batch events117 */ 118 private Queue<String> eventQueue;108 109 /** 110 * LinkedList of batch events 111 */ 112 private LinkedList<TrafficEvent> eventQueue; 119 113 /** 120 114 * Map of incidents to events 121 115 */ 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 */ 125 121 private ConsoleTrafficDriver console; 126 127 /** GUI for this driver */ 122 123 /** 124 * GUI for this driver 125 */ 128 126 private ATMSBatchViewer theView; 129 127 130 128 /** 131 129 * Constructor. Initialize data from parsed properties file. Create a socket … … 143 141 } 144 142 // Initialize the highway model 145 incidents = new HashMap<String, List< String>>();143 incidents = new HashMap<String, List<TrafficEvent>>(); 146 144 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 VM151 "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 153 151 connect(cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), 154 152 cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim()); … … 169 167 String currentClock = ""; 170 168 String currentATMStime = ""; 171 Date simClock = new Date(); 169 Date simClock = new Date(); 172 170 // Obtain the simulation time from the CAD server 173 171 try … … 179 177 // Date atmsdate = new Date(ATMStime); 180 178 // currentATMStime = formatter.format(atmsdate); 181 try { 179 try 180 { 182 181 simClock = formatter.parse(currentClock); 183 } catch (ParseException ex) { 182 } 183 catch (ParseException ex) 184 { 184 185 Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex); 185 186 System.out.println("Invalid simulation clock time found in ATMSDriverClient"); 186 187 System.exit(-1); 187 } 188 } 188 189 //System.out.println("Current clock: " + currentClock); 189 } catch (RemoteException ex) 190 } 191 catch (RemoteException ex) 190 192 { 191 193 System.out.println("Remote Exception reading sim or ATMS clock time"); … … 196 198 { 197 199 // 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; 211 202 //System.out.println("Next event will be launched at: " + formatter.format(eventTime)); 212 203 // Check the queue of events to see if the first … … 215 206 if (eventTime.before(simClock) || eventTime.equals(simClock)) 216 207 { 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()); 229 209 // 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); 231 212 // Remove this event from the queue, we're done with it. 232 213 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 241 216 theView.update(currentClock, currentATMStime, eventQueue); 242 217 } … … 255 230 { 256 231 FileInputStream fis; 257 try { 232 try 233 { 258 234 fis = new FileInputStream("config/vds_data/atmsBatchEvents.txt"); 259 eventQueue = new LinkedList< String>();235 eventQueue = new LinkedList<TrafficEvent>(); 260 236 // Read all lines from the file of events 261 237 Scanner scan = new Scanner(fis); … … 263 239 { 264 240 // Read a line and add it to the event queue 265 String line = scan.nextLine() ;241 String line = scan.nextLine().trim(); 266 242 if (line.charAt(0) != '#') 267 243 { 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 } 285 270 } 286 271 } 287 } catch (FileNotFoundException ex) { 272 } 273 catch (FileNotFoundException ex) 274 { 288 275 Logger.getLogger(ATMSBatchDriver.class.getName()).log(Level.SEVERE, null, ex); 289 276 } 290 277 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 * 295 286 * @param incidentNumber incident to be cleared. 296 287 */ … … 298 289 { 299 290 boolean ok = incidents.containsKey(incidentNumber); 300 if (!ok) 291 if (!ok) 301 292 { 302 293 System.out.println("Sorry, that incident number isn't found."); … … 304 295 } 305 296 System.out.println("Clearing incident " + incidentNumber); 306 List< String> events = incidents.get(incidentNumber);297 List<TrafficEvent> events = incidents.get(incidentNumber); 307 298 // Process each event associated with this incident 308 for ( String event: events)299 for (TrafficEvent event : events) 309 300 { 310 301 System.out.println("Event: " + event + " cleared."); 311 302 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 330 308 } 331 309 // Now refresh the view with the updated queue of events 332 310 theView.update("0:00", "0:00", eventQueue); 333 311 } 334 312 335 313 /** 336 314 * Connect to the Coordinator's RMI object, and register this object for … … 354 332 theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); 355 333 theCoorInt.registerForCallback(this); 356 } catch (Exception e) 334 } 335 catch (Exception e) 357 336 { 358 337 throw new SimulationException(SimulationException.CAD_SIM_CONNECT, 359 338 e); 360 339 361 340 } 362 341 } … … 384 363 cadClientProp = new Properties(); 385 364 cadClientProp.load(new FileInputStream(propertiesFile)); 386 } catch (Exception e) 365 } 366 catch (Exception e) 387 367 { 388 368 cadClientLogger.logp(Level.SEVERE, "SimulationManager", … … 392 372 e); 393 373 } 394 395 374 396 375 // Ensure that the properties file does not have null values for the … … 430 409 { 431 410 theCoorInt.unregisterForCallback(client); 432 } catch (RemoteException e) 411 } 412 catch (RemoteException e) 433 413 { 434 414 e.printStackTrace(); … … 456 436 new ATMSBatchDriver(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 457 437 458 } catch (Exception e) 438 } 439 catch (Exception e) 459 440 { 460 441 cadClientLogger.logp(Level.SEVERE, "SimulationManager", "Main", … … 478 459 while (true) 479 460 { 480 try { 461 try 462 { 481 463 // Write the highway network status to the FEP Simulator 482 464 highways.writeToFEP(); 483 } catch (SimulationException ex) 465 } 466 catch (SimulationException ex) 484 467 { 485 468 // Ask user if they want to proceed without FEP Sim connection … … 487 470 if (reply == JOptionPane.NO_OPTION) 488 471 { 489 System.exit(0);472 System.exit(0); 490 473 } 491 474 System.out.println("Skipping writeToFEP..."); -
trunk/src/tmcsim/client/ATMSBatchViewer.form
r168 r183 26 26 <Group type="103" groupAlignment="0" attributes="0"> 27 27 <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"/> 33 32 <Component id="pnlIncidents" max="32767" attributes="0"/> 34 33 </Group> 35 34 <Component id="pnlEvents" min="-2" max="-2" attributes="0"/> 36 35 </Group> 37 <EmptySpace min="0" pref="2 7" max="32767" attributes="0"/>36 <EmptySpace min="0" pref="26" max="32767" attributes="0"/> 38 37 </Group> 39 38 </Group> … … 44 43 <Component id="pnlEvents" min="-2" max="-2" attributes="0"/> 45 44 <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"/> 53 46 <EmptySpace max="-2" attributes="0"/> 54 47 </Group> … … 130 123 <Group type="103" groupAlignment="0" attributes="0"> 131 124 <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> 133 129 <EmptySpace min="0" pref="0" max="32767" attributes="0"/> 134 130 </Group> … … 138 134 <Group type="103" groupAlignment="0" attributes="0"> 139 135 <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"/> 141 139 <Component id="btnClear" min="-2" max="-2" attributes="0"/> 142 140 <EmptySpace max="32767" attributes="0"/> … … 146 144 </Layout> 147 145 <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="<String>"/> 171 </AuxValues> 172 </Component> 173 </SubComponents> 174 </Container> 148 175 <Component class="javax.swing.JButton" name="btnClear"> 149 176 <Properties> … … 156 183 </SubComponents> 157 184 </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="<String>"/>183 </AuxValues>184 </Component>185 </SubComponents>186 </Container>187 185 </SubComponents> 188 186 </Form> -
trunk/src/tmcsim/client/ATMSBatchViewer.java
r168 r183 1 2 1 package tmcsim.client; 3 2 3 import atmsdriver.model.TrafficEvent; 4 import java.text.ParseException; 4 5 import java.util.ArrayList; 5 import java.util.HashSet;6 6 import java.util.LinkedList; 7 7 import java.util.List; 8 import java.util.Queue; 9 import java.util.Set; 10 import java.util.Vector; 8 import java.util.logging.Level; 9 import java.util.logging.Logger; 11 10 import javax.swing.AbstractListModel; 12 import javax.swing.JLabel;13 import javax.swing.JList;14 11 import javax.swing.JOptionPane; 15 import tmcsim.cadsimulator.CADServer;16 12 17 13 /** … … 19 15 * @author jdalbey 20 16 */ 21 public class ATMSBatchViewer extends javax.swing.JFrame 17 public class ATMSBatchViewer extends javax.swing.JFrame 22 18 { 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; 25 24 private final List<String> incidents; 25 26 26 /** 27 27 * Creates new form ATMSBatchViewer. 28 * 28 29 * @param incidents a list of incidents to show in a list. 29 30 */ 30 public ATMSBatchViewer(ATMSBatchDriver driver, List<String> incidentList) 31 public ATMSBatchViewer(ATMSBatchDriver driver, List<String> incidentList) 31 32 { 32 33 initComponents(); 33 this.driver = driver; 34 this.driver = driver; 34 35 this.incidents = incidentList; 35 36 lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 36 37 { 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 }); 40 48 } 41 49 42 public void update(String currentTime, String atmsTime, Queue<String> events)50 public void update(String currentTime, String atmsTime, List<TrafficEvent> events) 43 51 { 44 52 lstEvents.setModel(new MyListModel(events)); 45 txtClockTime.setText(currentTime + " / " + atmsTime);53 txtClockTime.setText(currentTime + " / " + atmsTime); 46 54 } 55 47 56 class MyListModel extends AbstractListModel<String> 48 57 { 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 } 56 75 } 76 57 77 /** 58 78 * This method is called from within the constructor to initialize the form. … … 70 90 txtClockTime = new javax.swing.JLabel(); 71 91 pnlIncidents = new javax.swing.JPanel(); 72 btnClear = new javax.swing.JButton();73 92 jScrollPane1 = new javax.swing.JScrollPane(); 74 93 lstIncidents = new javax.swing.JList<>(); 94 btnClear = new javax.swing.JButton(); 75 95 76 96 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); … … 112 132 ); 113 133 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 114 144 btnClear.setText("Clear Incident"); 115 145 btnClear.addActionListener(new java.awt.event.ActionListener() … … 126 156 pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 127 157 .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)) 129 161 .addGap(0, 0, Short.MAX_VALUE)) 130 162 ); … … 132 164 pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 133 165 .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) 135 169 .addComponent(btnClear) 136 170 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 137 171 ); 138 139 lstIncidents.setFont(new java.awt.Font("Noto Mono", 0, 15)); // NOI18N140 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);148 172 149 173 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); … … 152 176 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 153 177 .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) 159 182 .addComponent(pnlIncidents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 160 183 .addComponent(pnlEvents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 161 .addGap(0, 2 7, Short.MAX_VALUE))184 .addGap(0, 26, Short.MAX_VALUE)) 162 185 ); 163 186 layout.setVerticalGroup( … … 166 189 .addComponent(pnlEvents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 167 190 .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) 173 192 .addContainerGap()) 174 193 ); … … 179 198 private void btnClearActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnClearActionPerformed 180 199 {//GEN-HEADEREND:event_btnClearActionPerformed 181 String selectedItem = lstIncidents.getSelectedValue();200 String selectedItem = lstIncidents.getSelectedValue(); 182 201 if (selectedItem == null) 183 202 { … … 187 206 { 188 207 System.out.println("Clicked Incident:" + selectedItem); 189 if (driver != null) driver.clearIncident(selectedItem); 208 if (driver != null) 209 { 210 driver.clearIncident(selectedItem); 211 } 190 212 lstIncidents.clearSelection(); 191 213 // Remove selectedItem from list model; … … 201 223 * @param args the command line arguments 202 224 */ 203 public static void main(String args[]) { 225 public static void main(String args[]) 226 { 204 227 /* Set the Nimbus look and feel */ 205 228 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> … … 207 230 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 208 231 */ 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 { 212 238 javax.swing.UIManager.setLookAndFeel(info.getClassName()); 213 239 break; 214 240 } 215 241 } 216 } catch (ClassNotFoundException ex) { 242 } 243 catch (ClassNotFoundException ex) 244 { 217 245 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 { 219 249 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 { 221 253 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 { 223 257 java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 224 258 } … … 226 260 227 261 /* 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 239 286 } 240 287 });
Note: See TracChangeset
for help on using the changeset viewer.
