Changeset 135 in tmcsimulator for trunk/src/tmcsim/client/ATMSBatchDriver.java


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

ATMSBatchDriver.java Implemented "clear incident" feature.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.