- Timestamp:
- 10/17/2017 05:10:07 PM (9 years ago)
- Location:
- trunk/src/tmcsim
- Files:
-
- 4 edited
-
application.properties (modified) (1 diff)
-
client/ATMSBatchDriver.java (modified) (5 diffs)
-
client/ATMSBatchViewer.form (modified) (4 diffs)
-
client/ATMSBatchViewer.java (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/application.properties
r127 r135 1 # Mon, 16 Oct 2017 17:41:29-07001 #Tue, 17 Oct 2017 18:13:47 -0700 2 2 3 Application.revision=1 253 Application.revision=133 4 4 5 5 Application.buildnumber=53 -
trunk/src/tmcsim/client/ATMSBatchDriver.java
r129 r135 155 155 readBatchFile(); 156 156 // Launch the display 157 theView = new ATMSBatchViewer( );157 theView = new ATMSBatchViewer(this, new ArrayList<String>(incidents.keySet())); 158 158 theView.setVisible(true); 159 theView.update("0:00", eventQueue); 159 theView.update("0:00", eventQueue); 160 160 161 // Create a timer that fetches the simulation time every second. 161 162 Timer timer = new Timer(ONE_SECOND, new ActionListener() … … 201 202 } 202 203 //System.out.println("Next event will be launched at: " + formatter.format(eventTime)); 203 theView.update(currentClock, eventQueue);204 204 // Check the queue of events to see if the first 205 205 // item should be launched. IF so, … … 230 230 } 231 231 } 232 theView.update(currentClock, eventQueue); 232 233 } 233 234 } … … 236 237 237 238 // 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(); 239 241 240 242 ensureProperShutdown(); … … 277 279 } 278 280 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 279 323 /** 280 324 * Connect to the Coordinator's RMI object, and register this object for -
trunk/src/tmcsim/client/ATMSBatchViewer.form
r128 r135 28 28 <EmptySpace max="-2" attributes="0"/> 29 29 </Group> 30 <Group type="102" alignment="0" attributes="0"> 31 <EmptySpace min="-2" pref="76" max="-2" attributes="0"/> 32 <Component id="pnlIncidents" min="-2" max="-2" attributes="0"/> 33 <EmptySpace max="32767" attributes="0"/> 34 </Group> 30 35 </Group> 31 36 </DimensionLayout> … … 34 39 <Group type="102" alignment="0" attributes="0"> 35 40 <Component id="pnlEvents" min="-2" max="-2" attributes="0"/> 36 <EmptySpace min="0" pref="129" max="32767" attributes="0"/> 41 <EmptySpace max="-2" attributes="0"/> 42 <Component id="pnlIncidents" max="32767" attributes="0"/> 43 <EmptySpace max="-2" attributes="0"/> 37 44 </Group> 38 45 </Group> … … 46 53 <Group type="103" groupAlignment="0" attributes="0"> 47 54 <Group type="102" alignment="1" attributes="0"> 48 <EmptySpace pref=" 83" max="32767" attributes="0"/>55 <EmptySpace pref="74" max="32767" attributes="0"/> 49 56 <Component id="scrollEvents" min="-2" pref="354" max="-2" attributes="0"/> 50 57 <EmptySpace min="-2" pref="59" max="-2" attributes="0"/> … … 104 111 </SubComponents> 105 112 </Container> 113 <Container class="javax.swing.JPanel" name="pnlIncidents"> 114 115 <Layout> 116 <DimensionLayout dim="0"> 117 <Group type="103" groupAlignment="0" attributes="0"> 118 <Group type="102" attributes="0"> 119 <Group type="103" groupAlignment="0" attributes="0"> 120 <Component id="btnClear" min="-2" max="-2" attributes="0"/> 121 <Component id="jScrollPane1" min="-2" pref="211" max="-2" attributes="0"/> 122 </Group> 123 <EmptySpace min="0" pref="173" max="32767" attributes="0"/> 124 </Group> 125 </Group> 126 </DimensionLayout> 127 <DimensionLayout dim="1"> 128 <Group type="103" groupAlignment="0" attributes="0"> 129 <Group type="102" alignment="1" attributes="0"> 130 <Component id="jScrollPane1" min="-2" pref="179" max="-2" attributes="0"/> 131 <EmptySpace max="-2" attributes="0"/> 132 <Component id="btnClear" min="-2" max="-2" attributes="0"/> 133 <EmptySpace max="32767" attributes="0"/> 134 </Group> 135 </Group> 136 </DimensionLayout> 137 </Layout> 138 <SubComponents> 139 <Component class="javax.swing.JButton" name="btnClear"> 140 <Properties> 141 <Property name="text" type="java.lang.String" value="Clear Incident"/> 142 </Properties> 143 <Events> 144 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClearActionPerformed"/> 145 </Events> 146 </Component> 147 <Container class="javax.swing.JScrollPane" name="jScrollPane1"> 148 <AuxValues> 149 <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> 150 </AuxValues> 151 152 <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> 153 <SubComponents> 154 <Component class="javax.swing.JList" name="lstIncidents"> 155 <Properties> 156 <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> 157 <Font name="Noto Mono" size="15" style="0"/> 158 </Property> 159 <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor"> 160 <StringArray count="5"> 161 <StringItem index="0" value="Item 1"/> 162 <StringItem index="1" value="Item 2"/> 163 <StringItem index="2" value="Item 3"/> 164 <StringItem index="3" value="Item 4"/> 165 <StringItem index="4" value="Item 5"/> 166 </StringArray> 167 </Property> 168 <Property name="selectionMode" type="int" value="0"/> 169 </Properties> 170 <AuxValues> 171 <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/> 172 </AuxValues> 173 </Component> 174 </SubComponents> 175 </Container> 176 </SubComponents> 177 </Container> 106 178 </SubComponents> 107 179 </Form> -
trunk/src/tmcsim/client/ATMSBatchViewer.java
r128 r135 1 /* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * and open the template in the editor. 5 */ 1 6 2 package tmcsim.client; 7 3 4 import java.util.ArrayList; 5 import java.util.HashSet; 8 6 import java.util.LinkedList; 7 import java.util.List; 9 8 import java.util.Queue; 9 import java.util.Set; 10 10 import java.util.Vector; 11 11 import javax.swing.AbstractListModel; 12 import javax.swing.JLabel; 12 13 import javax.swing.JList; 14 import javax.swing.JOptionPane; 13 15 14 16 /** … … 18 20 public class ATMSBatchViewer extends javax.swing.JFrame 19 21 { 22 /** Reference to the driver associated with this GUI */ 23 private ATMSBatchDriver driver; 24 private final List<String> incidents; 20 25 /** 21 * Creates new form ATMSBatchViewer 26 * Creates new form ATMSBatchViewer. 27 * @param incidents a list of incidents to show in a list. 22 28 */ 23 public ATMSBatchViewer( )29 public ATMSBatchViewer(ATMSBatchDriver driver, List<String> incidentList) 24 30 { 25 31 initComponents(); 32 this.driver = driver; 33 this.incidents = incidentList; 34 lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 35 { 36 public int getSize() { return incidents.size(); } 37 public String getElementAt(int i) { return incidents.get(i); } 38 }); 26 39 } 27 40 … … 48 61 @SuppressWarnings("unchecked") 49 62 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 50 private void initComponents() { 63 private void initComponents() 64 { 51 65 52 66 pnlEvents = new javax.swing.JPanel(); … … 54 68 lstEvents = new javax.swing.JList<>(); 55 69 txtClockTime = new javax.swing.JLabel(); 70 pnlIncidents = new javax.swing.JPanel(); 71 btnClear = new javax.swing.JButton(); 72 jScrollPane1 = new javax.swing.JScrollPane(); 73 lstIncidents = new javax.swing.JList<>(); 56 74 57 75 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 58 76 59 77 lstEvents.setFont(new java.awt.Font("Noto Mono", 0, 12)); // NOI18N 60 lstEvents.setModel(new javax.swing.AbstractListModel<String>() { 78 lstEvents.setModel(new javax.swing.AbstractListModel<String>() 79 { 61 80 String[] strings = { "item 1", "item 2" }; 62 81 public int getSize() { return strings.length; } … … 73 92 pnlEventsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 74 93 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEventsLayout.createSequentialGroup() 75 .addContainerGap( 83, Short.MAX_VALUE)94 .addContainerGap(74, Short.MAX_VALUE) 76 95 .addComponent(scrollEvents, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE) 77 96 .addGap(59, 59, 59)) … … 90 109 ); 91 110 111 btnClear.setText("Clear Incident"); 112 btnClear.addActionListener(new java.awt.event.ActionListener() 113 { 114 public void actionPerformed(java.awt.event.ActionEvent evt) 115 { 116 btnClearActionPerformed(evt); 117 } 118 }); 119 120 lstIncidents.setFont(new java.awt.Font("Noto Mono", 0, 15)); // NOI18N 121 lstIncidents.setModel(new javax.swing.AbstractListModel<String>() 122 { 123 String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; 124 public int getSize() { return strings.length; } 125 public String getElementAt(int i) { return strings[i]; } 126 }); 127 lstIncidents.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 128 jScrollPane1.setViewportView(lstIncidents); 129 130 javax.swing.GroupLayout pnlIncidentsLayout = new javax.swing.GroupLayout(pnlIncidents); 131 pnlIncidents.setLayout(pnlIncidentsLayout); 132 pnlIncidentsLayout.setHorizontalGroup( 133 pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 134 .addGroup(pnlIncidentsLayout.createSequentialGroup() 135 .addGroup(pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 136 .addComponent(btnClear) 137 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)) 138 .addGap(0, 173, Short.MAX_VALUE)) 139 ); 140 pnlIncidentsLayout.setVerticalGroup( 141 pnlIncidentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 142 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlIncidentsLayout.createSequentialGroup() 143 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) 144 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 145 .addComponent(btnClear) 146 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 147 ); 148 92 149 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 93 150 getContentPane().setLayout(layout); … … 97 154 .addComponent(pnlEvents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 98 155 .addContainerGap()) 156 .addGroup(layout.createSequentialGroup() 157 .addGap(76, 76, 76) 158 .addComponent(pnlIncidents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 159 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 99 160 ); 100 161 layout.setVerticalGroup( … … 102 163 .addGroup(layout.createSequentialGroup() 103 164 .addComponent(pnlEvents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 104 .addGap(0, 129, Short.MAX_VALUE)) 165 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 166 .addComponent(pnlIncidents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 167 .addContainerGap()) 105 168 ); 106 169 107 170 pack(); 108 171 }// </editor-fold>//GEN-END:initComponents 172 173 private void btnClearActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnClearActionPerformed 174 {//GEN-HEADEREND:event_btnClearActionPerformed 175 String selectedItem = lstIncidents.getSelectedValue(); 176 if (selectedItem == null) 177 { 178 JOptionPane.showMessageDialog(this, "No Incident Selected", "Warning", JOptionPane.INFORMATION_MESSAGE); 179 } 180 else 181 { 182 System.out.println("Clicked Incident:" + selectedItem); 183 if (driver != null) driver.clearIncident(selectedItem); 184 lstIncidents.clearSelection(); 185 // Remove selectedItem from list model; 186 incidents.remove(selectedItem); 187 // Update the list displayed 188 String[] array = new String[incidents.size()]; 189 array = incidents.toArray(array); 190 lstIncidents.setListData(array); 191 } 192 }//GEN-LAST:event_btnClearActionPerformed 109 193 110 194 /** … … 141 225 sample.add("Greetings"); 142 226 sample.add("Earthling"); 143 ATMSBatchViewer view = new ATMSBatchViewer(); 227 List<String> items = new ArrayList<String>(); 228 items.add("Able"); items.add("Baker"); 229 ATMSBatchViewer view = new ATMSBatchViewer(null,items); 144 230 view.setVisible(true); 145 231 view.update("01", sample); … … 150 236 151 237 // Variables declaration - do not modify//GEN-BEGIN:variables 238 private javax.swing.JButton btnClear; 239 private javax.swing.JScrollPane jScrollPane1; 152 240 private javax.swing.JList<String> lstEvents; 241 private javax.swing.JList<String> lstIncidents; 153 242 private javax.swing.JPanel pnlEvents; 243 private javax.swing.JPanel pnlIncidents; 154 244 private javax.swing.JScrollPane scrollEvents; 155 245 private javax.swing.JLabel txtClockTime;
Note: See TracChangeset
for help on using the changeset viewer.
