Changeset 206 in tmcsimulator for trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java
- Timestamp:
- 11/01/2017 12:31:34 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java
r204 r206 18 18 import java.util.List; 19 19 import java.util.Map; 20 import java.util.Observable; 20 21 import java.util.Properties; 21 22 import java.util.Scanner; 23 import java.util.Vector; 22 24 import java.util.concurrent.TimeUnit; 23 25 import java.util.logging.Level; … … 38 40 * @version 2.0 39 41 */ 40 public class TrafficModelManager 42 public class TrafficModelManager extends Observable 41 43 { 42 44 private final static int ONE_SECOND = 1000; … … 89 91 90 92 /** 93 * Current simulation clock time 94 */ 95 private String currentClock = ""; 96 97 /** 91 98 * GUI for this driver 92 99 */ 93 private TrafficModelViewer theView;100 //private TrafficModelViewer theView; 94 101 95 102 /** … … 111 118 props.getProperty(PROPERTIES.FEPSIM_IP_ADDR.name), 112 119 8080); 113 114 // Read the text file of events and put in a queue 115 FileInputStream fis = null; 116 try 117 { 118 fis = new FileInputStream(props.getProperty(PROPERTIES.EVENTS_FILE.name)); 119 } catch (FileNotFoundException ex) 120 { 121 Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, 122 "Missing Traffic Events file " + props.getProperty(PROPERTIES.EVENTS_FILE.name)); 123 System.exit(-1); 124 } 125 // Read all lines from the file of events 126 Scanner fileScanner = new Scanner(fis); 127 eventQueue = readBatchFile(fileScanner); 128 // Extract the incidents and create a map 129 incidents = createIncidentMap(eventQueue); 130 // Launch the GUI display 131 theView = new TrafficModelViewer(this, new ArrayList<String>(incidents.keySet())); 132 theView.setVisible(true); 133 theView.update("0:00", "1:11", eventQueue); 134 120 121 loadEvents(); 122 135 123 // Create a timer that fetches the simulation time every second. 136 124 Timer timer = new Timer(ONE_SECOND, new ActionListener() … … 139 127 public void actionPerformed(ActionEvent e) 140 128 { 141 String currentClock = "";142 129 String currentATMStime = ""; 143 130 Date simClock = new Date(); … … 184 171 // Remove this event from the queue, we're done with it. 185 172 eventQueue.remove(); 186 } 187 188 theView.update(currentClock, currentATMStime, eventQueue); 173 setChanged(); 174 notifyObservers(getEventQueue()); 175 } 176 setChanged(); 177 notifyObservers(currentClock); 189 178 } 190 179 } … … 205 194 206 195 } 207 196 /** Accessor to event queue 197 * 198 * @return defensive copy of current queue of events 199 */ 200 public LinkedList<TrafficEvent> getEventQueue() 201 { 202 return new LinkedList<TrafficEvent>(eventQueue); 203 } 204 public Vector<String> getIncidents() 205 { 206 return new Vector<String>(incidents.keySet()); 207 } 208 public String getClockTime() 209 { 210 return currentClock; 211 } 212 public void loadEvents() 213 { 214 // Read the text file of events and put in a queue 215 FileInputStream fis = null; 216 try 217 { 218 fis = new FileInputStream(props.getProperty(PROPERTIES.EVENTS_FILE.name)); 219 } catch (FileNotFoundException ex) 220 { 221 Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, 222 "Missing Traffic Events file " + props.getProperty(PROPERTIES.EVENTS_FILE.name)); 223 System.exit(-1); 224 } 225 // Read all lines from the file of events 226 Scanner fileScanner = new Scanner(fis); 227 eventQueue = readBatchFile(fileScanner); 228 // Extract the incidents and create a map 229 incidents = createIncidentMap(eventQueue); 230 setChanged(); 231 notifyObservers("-:--"); 232 setChanged(); 233 notifyObservers(getIncidents()); 234 setChanged(); 235 notifyObservers(getEventQueue()); 236 } 208 237 /** 209 238 * This method verifies that the needed configuration properties are not … … 327 356 328 357 } 358 incidents.remove(incidentNumber); 329 359 // Now refresh the view with the updated queue of events 330 theView.update("0:00", "0:00", eventQueue); 360 setChanged(); 361 notifyObservers(getEventQueue()); 362 setChanged(); 363 notifyObservers(getIncidents()); 331 364 } 332 365 … … 363 396 { 364 397 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 365 new TrafficModelManager(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME,398 TrafficModelManager mgr = new TrafficModelManager(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME, 366 399 theCoordinator); 367 400 TrafficModelViewer view = new TrafficModelViewer(mgr); 401 view.setVisible(true); 402 mgr.addObserver(view); 368 403 } 369 404 catch (Exception e)
Note: See TracChangeset
for help on using the changeset viewer.
