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

source: tmcsimulator-scriptbuilder/trunk/src/event/editor/ParamicsPanel.java @ 140

Revision 140, 18.6 KB checked in by bmcguffin, 8 years ago (diff)

Fixed defect #67. Removing an event and then closing the event editor window no longer causes the program to hang; a null check for the event is encountered before taking action upon close of the window.

RevLine 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.ArrayList;
5import java.util.Observable;
6import javax.swing.JCheckBox;
7import scriptbuilder.structures.events.ParamicsEvent;
8import scriptbuilder.structures.events.I_ScriptEvent;
9
10/**
11 *
12 * @author nathaniellehrer
13 */
14public class ParamicsPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel
15{
16
17    private ActionListener removeListener;
18    private ParamicsEvent event;
19    ArrayList<JCheckBox> lanes = new ArrayList<JCheckBox>();
20
21    /**
22     * Creates new form ParamicsPanel
23     */
24    public ParamicsPanel()
25    {
26        initComponents();
27    }
28
29    @Override
30    public void getEventObject(I_ScriptEvent sei)
31    {
32        event = (ParamicsEvent) sei;
33        boolean containsItem = false;
34        for (int i = 0; i < LocationDropdown.getItemCount() && !containsItem; i++)
35        {
36            if (event.locationID.equalsIgnoreCase(LocationDropdown.getItemAt(i).toString()))
37            {
38                LocationDropdown.setSelectedIndex(i);
39                containsItem = true;
40            }
41        }
42
43        if (!containsItem)
44        {
45            LocationDropdown.addItem(event.locationID);
46            LocationDropdown.setSelectedItem(LocationDropdown.getItemCount() - 1);
47        }
48
49        for (int i = 0; i < StatusDropdown.getItemCount(); i++)
50        {
51            if (event.status.equalsIgnoreCase(StatusDropdown.getItemAt(i).toString()))
52            {
53                StatusDropdown.setSelectedIndex(i);
54            }
55        }
56
57        for (int i = 0; i < TypeDropdown.getItemCount(); i++)
58        {
59            if (event.type.equalsIgnoreCase(TypeDropdown.getItemAt(i).toString()))
60            {
61                TypeDropdown.setSelectedIndex(i);
62            }
63        }
64
65        lanes.add(jCheckBox1);
66        lanes.add(jCheckBox2);
67        lanes.add(jCheckBox3);
68        lanes.add(jCheckBox4);
69        lanes.add(jCheckBox5);
70        lanes.add(jCheckBox6);
71        lanes.add(jCheckBox7);
72        lanes.add(jCheckBox8);
73        lanes.add(jCheckBox9);
74        lanes.add(jCheckBox10);
75        for (Integer num : event.laneNums)
76        {
77            lanes.get(num - 1).doClick();
78        }
79    }
80
81    @Override
82    public void update(Observable o, Object arg)
83    {
84        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
85    }
86
87    @Override
88    public boolean removeAssociatedEvent()
89    {
90        event.removeThis();
91        event = null;
92        return true;
93    }
94
95    @Override
96    public void uponClose()
97    {
98        if (event != null)
99        {
100            event.locationID = LocationDropdown.getSelectedItem().toString();
101            event.status = StatusDropdown.getSelectedItem().toString();
102            event.type = TypeDropdown.getSelectedItem().toString();
103            for (JCheckBox lane : lanes)
104            {
105                lane.getActionListeners()[0].actionPerformed(new ActionEvent(lane, 0, "record"));
106            }
107        }
108    }
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        jLabel1 = new javax.swing.JLabel();
121        jLabel2 = new javax.swing.JLabel();
122        StatusDropdown = new javax.swing.JComboBox();
123        TypeDropdown = new javax.swing.JComboBox();
124        jLabel3 = new javax.swing.JLabel();
125        jLabel4 = new javax.swing.JLabel();
126        jCheckBox1 = new javax.swing.JCheckBox();
127        jCheckBox2 = new javax.swing.JCheckBox();
128        jCheckBox3 = new javax.swing.JCheckBox();
129        jCheckBox4 = new javax.swing.JCheckBox();
130        jCheckBox5 = new javax.swing.JCheckBox();
131        jCheckBox6 = new javax.swing.JCheckBox();
132        jCheckBox7 = new javax.swing.JCheckBox();
133        jCheckBox8 = new javax.swing.JCheckBox();
134        jCheckBox9 = new javax.swing.JCheckBox();
135        jCheckBox10 = new javax.swing.JCheckBox();
136        LocationDropdown = new javax.swing.JComboBox();
137
138        jLabel1.setText("Location");
139
140        jLabel2.setText("Status");
141
142        StatusDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "New", "Changed", "Cleared" }));
143
144        TypeDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lane Breakdown", "Lane Obstruction" }));
145
146        jLabel3.setText("Incident Type");
147
148        jLabel4.setText("Lanes affected:");
149
150        jCheckBox1.setText("Lane 1");
151        jCheckBox1.addActionListener(new java.awt.event.ActionListener()
152        {
153            public void actionPerformed(java.awt.event.ActionEvent evt)
154            {
155                jCheckBox1ActionPerformed(evt);
156            }
157        });
158
159        jCheckBox2.setText("Lane 2");
160        jCheckBox2.addActionListener(new java.awt.event.ActionListener()
161        {
162            public void actionPerformed(java.awt.event.ActionEvent evt)
163            {
164                jCheckBox2ActionPerformed(evt);
165            }
166        });
167
168        jCheckBox3.setText("Lane 3");
169        jCheckBox3.addActionListener(new java.awt.event.ActionListener()
170        {
171            public void actionPerformed(java.awt.event.ActionEvent evt)
172            {
173                jCheckBox3ActionPerformed(evt);
174            }
175        });
176
177        jCheckBox4.setText("Lane 4");
178        jCheckBox4.addActionListener(new java.awt.event.ActionListener()
179        {
180            public void actionPerformed(java.awt.event.ActionEvent evt)
181            {
182                jCheckBox4ActionPerformed(evt);
183            }
184        });
185
186        jCheckBox5.setText("Lane 5");
187        jCheckBox5.addActionListener(new java.awt.event.ActionListener()
188        {
189            public void actionPerformed(java.awt.event.ActionEvent evt)
190            {
191                jCheckBox5ActionPerformed(evt);
192            }
193        });
194
195        jCheckBox6.setText("Lane 8");
196        jCheckBox6.addActionListener(new java.awt.event.ActionListener()
197        {
198            public void actionPerformed(java.awt.event.ActionEvent evt)
199            {
200                jCheckBox6ActionPerformed(evt);
201            }
202        });
203
204        jCheckBox7.setText("Lane 6");
205        jCheckBox7.addActionListener(new java.awt.event.ActionListener()
206        {
207            public void actionPerformed(java.awt.event.ActionEvent evt)
208            {
209                jCheckBox7ActionPerformed(evt);
210            }
211        });
212
213        jCheckBox8.setText("Lane 7");
214        jCheckBox8.addActionListener(new java.awt.event.ActionListener()
215        {
216            public void actionPerformed(java.awt.event.ActionEvent evt)
217            {
218                jCheckBox8ActionPerformed(evt);
219            }
220        });
221
222        jCheckBox9.setText("Lane 10");
223        jCheckBox9.addActionListener(new java.awt.event.ActionListener()
224        {
225            public void actionPerformed(java.awt.event.ActionEvent evt)
226            {
227                jCheckBox9ActionPerformed(evt);
228            }
229        });
230
231        jCheckBox10.setText("Lane 9");
232        jCheckBox10.addActionListener(new java.awt.event.ActionListener()
233        {
234            public void actionPerformed(java.awt.event.ActionEvent evt)
235            {
236                jCheckBox10ActionPerformed(evt);
237            }
238        });
239
240        LocationDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "187_S_55_ML", "187_N_405_HV" }));
241
242        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
243        this.setLayout(layout);
244        layout.setHorizontalGroup(
245            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
246            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
247                .addContainerGap()
248                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
249                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3)
250                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
251                        .add(jLabel4)
252                        .add(18, 18, 18)
253                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
254                            .add(jCheckBox2)
255                            .add(jCheckBox1))
256                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
257                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
258                            .add(jCheckBox3)
259                            .add(jCheckBox4))
260                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
261                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
262                            .add(jCheckBox7)
263                            .add(jCheckBox5))
264                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
265                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
266                            .add(jCheckBox8)
267                            .add(jCheckBox6))
268                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
269                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
270                            .add(jCheckBox10)
271                            .add(jCheckBox9)))
272                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
273                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
274                            .add(jLabel1)
275                            .add(jLabel2))
276                        .add(36, 36, 36)
277                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
278                            .add(org.jdesktop.layout.GroupLayout.TRAILING, TypeDropdown, 0, 597, Short.MAX_VALUE)
279                            .add(StatusDropdown, 0, 597, Short.MAX_VALUE)
280                            .add(LocationDropdown, 0, 597, Short.MAX_VALUE))))
281                .addContainerGap())
282        );
283        layout.setVerticalGroup(
284            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
285            .add(layout.createSequentialGroup()
286                .add(41, 41, 41)
287                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
288                    .add(jLabel1)
289                    .add(LocationDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
290                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
291                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
292                    .add(StatusDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
293                    .add(jLabel2))
294                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
295                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
296                    .add(jLabel3)
297                    .add(TypeDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
298                .add(18, 18, 18)
299                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
300                    .add(layout.createSequentialGroup()
301                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
302                            .add(jLabel4)
303                            .add(jCheckBox1))
304                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
305                        .add(jCheckBox2))
306                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
307                        .add(layout.createSequentialGroup()
308                            .add(jCheckBox5)
309                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
310                            .add(jCheckBox7))
311                        .add(layout.createSequentialGroup()
312                            .add(jCheckBox3)
313                            .add(2, 2, 2)
314                            .add(jCheckBox4))
315                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
316                            .add(layout.createSequentialGroup()
317                                .add(jCheckBox10)
318                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
319                                .add(jCheckBox9))
320                            .add(layout.createSequentialGroup()
321                                .add(jCheckBox8)
322                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
323                                .add(jCheckBox6)))))
324                .addContainerGap(116, Short.MAX_VALUE))
325        );
326    }// </editor-fold>//GEN-END:initComponents
327
328    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
329        if (jCheckBox1.isSelected())
330        {
331            if (!event.laneNums.contains(1))
332            {
333                event.laneNums.add(1);
334            }
335        }
336        else
337        {
338            if (event.laneNums.contains(1))
339            {
340                event.laneNums.remove(1);
341            }
342        }
343    }//GEN-LAST:event_jCheckBox1ActionPerformed
344
345    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
346        if (jCheckBox2.isSelected())
347        {
348            if (!event.laneNums.contains(2))
349            {
350                event.laneNums.add(2);
351            }
352        }
353        else
354        {
355            if (event.laneNums.contains(2))
356            {
357                event.laneNums.remove(2);
358            }
359        }
360    }//GEN-LAST:event_jCheckBox2ActionPerformed
361
362    private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
363        if (jCheckBox3.isSelected())
364        {
365            if (!event.laneNums.contains(3))
366            {
367                event.laneNums.add(3);
368            }
369        }
370        else
371        {
372            if (event.laneNums.contains(3))
373            {
374                event.laneNums.remove(3);
375            }
376        }
377    }//GEN-LAST:event_jCheckBox3ActionPerformed
378
379    private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed
380        if (jCheckBox4.isSelected())
381        {
382            if (!event.laneNums.contains(4))
383            {
384                event.laneNums.add(4);
385            }
386        }
387        else
388        {
389            if (event.laneNums.contains(4))
390            {
391                event.laneNums.remove(4);
392            }
393        }
394    }//GEN-LAST:event_jCheckBox4ActionPerformed
395
396    private void jCheckBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox5ActionPerformed
397        if (jCheckBox5.isSelected())
398        {
399            if (!event.laneNums.contains(5))
400            {
401                event.laneNums.add(5);
402            }
403        }
404        else
405        {
406            if (event.laneNums.contains(5))
407            {
408                event.laneNums.remove(5);
409            }
410        }
411    }//GEN-LAST:event_jCheckBox5ActionPerformed
412
413    private void jCheckBox6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox6ActionPerformed
414        if (jCheckBox6.isSelected())
415        {
416            if (!event.laneNums.contains(6))
417            {
418                event.laneNums.add(6);
419            }
420        }
421        else
422        {
423            if (event.laneNums.contains(6))
424            {
425                event.laneNums.remove(6);
426            }
427        }
428    }//GEN-LAST:event_jCheckBox6ActionPerformed
429
430    private void jCheckBox7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox7ActionPerformed
431        if (jCheckBox7.isSelected())
432        {
433            if (!event.laneNums.contains(7))
434            {
435                event.laneNums.add(7);
436            }
437        }
438        else
439        {
440            if (event.laneNums.contains(7))
441            {
442                event.laneNums.remove(7);
443            }
444        }
445    }//GEN-LAST:event_jCheckBox7ActionPerformed
446
447    private void jCheckBox8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox8ActionPerformed
448        if (jCheckBox8.isSelected())
449        {
450            if (!event.laneNums.contains(8))
451            {
452                event.laneNums.add(8);
453            }
454        }
455        else
456        {
457            if (event.laneNums.contains(8))
458            {
459                event.laneNums.remove(8);
460            }
461        }
462    }//GEN-LAST:event_jCheckBox8ActionPerformed
463
464    private void jCheckBox9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox9ActionPerformed
465        if (jCheckBox9.isSelected())
466        {
467            if (!event.laneNums.contains(9))
468            {
469                event.laneNums.add(9);
470            }
471        }
472        else
473        {
474            if (event.laneNums.contains(9))
475            {
476                event.laneNums.remove(9);
477            }
478        }
479    }//GEN-LAST:event_jCheckBox9ActionPerformed
480
481    private void jCheckBox10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox10ActionPerformed
482        if (jCheckBox10.isSelected())
483        {
484            if (!event.laneNums.contains(10))
485            {
486                event.laneNums.add(10);
487            }
488        }
489        else
490        {
491            if (event.laneNums.contains(10))
492            {
493                event.laneNums.remove(10);
494            }
495        }
496    }//GEN-LAST:event_jCheckBox10ActionPerformed
497
498
499    // Variables declaration - do not modify//GEN-BEGIN:variables
500    private javax.swing.JComboBox LocationDropdown;
501    private javax.swing.JComboBox StatusDropdown;
502    private javax.swing.JComboBox TypeDropdown;
503    private javax.swing.JCheckBox jCheckBox1;
504    private javax.swing.JCheckBox jCheckBox10;
505    private javax.swing.JCheckBox jCheckBox2;
506    private javax.swing.JCheckBox jCheckBox3;
507    private javax.swing.JCheckBox jCheckBox4;
508    private javax.swing.JCheckBox jCheckBox5;
509    private javax.swing.JCheckBox jCheckBox6;
510    private javax.swing.JCheckBox jCheckBox7;
511    private javax.swing.JCheckBox jCheckBox8;
512    private javax.swing.JCheckBox jCheckBox9;
513    private javax.swing.JLabel jLabel1;
514    private javax.swing.JLabel jLabel2;
515    private javax.swing.JLabel jLabel3;
516    private javax.swing.JLabel jLabel4;
517    // End of variables declaration//GEN-END:variables
518
519}
Note: See TracBrowser for help on using the repository browser.