Warning: Can't use blame annotator:
svn blame failed on trunk/src/atmsdriver/TrafficEventsAnimator.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/atmsdriver/TrafficEventsAnimator.java @ 422

Revision 422, 7.0 KB checked in by jdalbey, 7 years ago (diff)

Remove ATMS functionality. Reworked and simplified the Highway model to use only VDS data from PeMS. Updated all unit tests.

RevLine 
1package atmsdriver;
2
3import tmcsim.highwaymodel.Highways;
4import tmcsim.highwaymodel.TrafficEvent;
5import java.io.FileInputStream;
6import java.io.FileNotFoundException;
7import java.rmi.RemoteException;
8import java.util.ArrayList;
9import java.util.HashMap;
10import java.util.LinkedList;
11import java.util.List;
12import java.util.Map;
13import java.util.Properties;
14import java.util.Scanner;
15import java.util.logging.Level;
16import java.util.logging.Logger;
17import javax.swing.JFrame;
18import tmcsim.cadsimulator.managers.TrafficModelManager;
19import tmcsim.common.SimulationException;
20
21/**
22 * Read and process all Traffic Events in a file and show
23 * resulting highway network.
24 * A snapshot of the highway model after each event is saved in a buffer
25 * and a graphical display allows the user to scroll through the history.
26 * This application is used by Traffic Event authors to assist
27 * in verifying the correctness of their data file.
28 * @author jdalbey
29 */
30public class TrafficEventsAnimator extends javax.swing.JPanel
31{
32    /**
33     * Error logger.
34     */
35    private final static Logger logger = Logger.getLogger("trafficmodeleventdriver");
36
37    /**
38     * Highways in traffic network
39     */
40    final private Highways highways;
41
42    /**
43     * LinkedList of batch events
44     */
45    private final LinkedList<TrafficEvent> eventQueue;
46    /**
47     * Map of incidents to events
48     */
49    private Map<String, List<TrafficEvent>> incidents;
50    /**
51     * Highway history
52     */
53    private List<String> history;
54    /**
55     * name of events file obtained from properties
56     */
57    private String events_file = ""; 
58    /**
59     * Creates the JPanel and builds the highways and events.
60     */
61    public TrafficEventsAnimator() throws RemoteException, SimulationException
62    {
63        initComponents();
64
65        // Initialize the highway model
66        incidents = new HashMap<String, List<TrafficEvent>>();
67        highways = new Highways(
68                "config/vds_data/highways_fullmap.txt");
69        final String CONFIG_FILE_NAME = "traffic_model_config.properties";
70        String propertiesFile = "config" + System.getProperty("file.separator") 
71                 + CONFIG_FILE_NAME;
72        Properties props = TrafficModelManager.loadProperties(propertiesFile);
73        events_file = props.getProperty("Events_File");
74        FileInputStream fis = null;
75        try
76        {
77            fis = new FileInputStream(events_file);
78        } catch (FileNotFoundException ex)
79        {
80            Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, 
81                    "Missing Traffic Events file " + events_file);
82            System.exit(-1);
83        }
84        Scanner fileScanner = new Scanner(fis);       
85        // Read all lines from the file of events and put in a queue
86        eventQueue = TrafficModelManager.readBatchFile(fileScanner);
87    }
88    /** Load the traffic events into a history buffer */
89    public void load()
90    {
91        txtDisplay.setText("Loading traffic events from: " + events_file);
92        history = new ArrayList<String>();
93        // If we have any events left to process
94        while (!eventQueue.isEmpty())
95        {
96            // Get next event
97            TrafficEvent nextEvent = eventQueue.peek();
98            System.out.println(nextEvent.eventTime);
99            // apply colorization to highways
100            highways.applyColorToHighwayStretch(nextEvent.routeNumber, nextEvent.dir,
101                    nextEvent.postmile, nextEvent.range, nextEvent.color);
102            history.add(highways.toString()+"\n"+nextEvent.eventTime);
103            // Remove this event from the queue, we're done with it.
104            eventQueue.remove();
105        }
106        scrollBar.setMaximum(history.size());
107        // display the first item from the history
108        txtDisplay.setText(history.get(0));
109    }
110    /**
111     * This method is called from within the constructor to initialize the form.
112     * WARNING: Do NOT modify this code. The content of this method is always
113     * regenerated by the Form Editor.
114     */
115    @SuppressWarnings("unchecked")
116    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
117    private void initComponents()
118    {
119
120        scrollBar = new javax.swing.JScrollBar();
121        jScrollPane1 = new javax.swing.JScrollPane();
122        txtDisplay = new javax.swing.JTextArea();
123
124        scrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener()
125        {
126            public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)
127            {
128                scrollbarValueChanged(evt);
129            }
130        });
131
132        txtDisplay.setColumns(20);
133        txtDisplay.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
134        txtDisplay.setRows(5);
135        jScrollPane1.setViewportView(txtDisplay);
136
137        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
138        this.setLayout(layout);
139        layout.setHorizontalGroup(
140            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
142                .addComponent(scrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
143                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
144                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE))
145        );
146        layout.setVerticalGroup(
147            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
149            .addComponent(scrollBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
150        );
151    }// </editor-fold>//GEN-END:initComponents
152
153    private void scrollbarValueChanged(java.awt.event.AdjustmentEvent evt)//GEN-FIRST:event_scrollbarValueChanged
154    {//GEN-HEADEREND:event_scrollbarValueChanged
155        // when the scroll bar is moved show the corresponding snapshot from history
156        txtDisplay.setText(history.get(evt.getValue()) );
157        repaint();
158    }//GEN-LAST:event_scrollbarValueChanged
159
160    /** Entry point for the application.  Builds a surrounding JFrame and
161     * runs the application.
162     * @param args
163     * @throws RemoteException
164     * @throws SimulationException
165     */
166    public static void main(String[] args) throws RemoteException, SimulationException
167    {
168        JFrame frame = new JFrame("Traffic Events Animator");
169        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
170        frame.setSize(1050,450);
171        TrafficEventsAnimator display = new TrafficEventsAnimator();
172        frame.add(display);
173        frame.setVisible(true);
174        display.load();
175    }
176
177    // Variables declaration - do not modify//GEN-BEGIN:variables
178    private javax.swing.JScrollPane jScrollPane1;
179    private javax.swing.JScrollBar scrollBar;
180    private javax.swing.JTextArea txtDisplay;
181    // End of variables declaration//GEN-END:variables
182}
Note: See TracBrowser for help on using the repository browser.