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

Revision 130, 18.6 KB checked in by bmcguffin, 9 years ago (diff)

Changed implementation of save function for event editor panels. Instead of updating their model objects whenever the enter key is pressed, panels are now notified when the window is closed and update their information then.

Line 
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        event.locationID = LocationDropdown.getSelectedItem().toString();
99        event.status = StatusDropdown.getSelectedItem().toString();
100        event.type = TypeDropdown.getSelectedItem().toString();
101        for (JCheckBox lane : lanes)
102        {
103            lane.getActionListeners()[0].actionPerformed(new ActionEvent(lane, 0, "record"));
104        }
105    }
106
107    /**
108     * This method is called from within the constructor to initialize the form.
109     * WARNING: Do NOT modify this code. The content of this method is always
110     * regenerated by the Form Editor.
111     */
112    @SuppressWarnings("unchecked")
113    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
114    private void initComponents()
115    {
116
117        jLabel1 = new javax.swing.JLabel();
118        jLabel2 = new javax.swing.JLabel();
119        StatusDropdown = new javax.swing.JComboBox();
120        TypeDropdown = new javax.swing.JComboBox();
121        jLabel3 = new javax.swing.JLabel();
122        jLabel4 = new javax.swing.JLabel();
123        jCheckBox1 = new javax.swing.JCheckBox();
124        jCheckBox2 = new javax.swing.JCheckBox();
125        jCheckBox3 = new javax.swing.JCheckBox();
126        jCheckBox4 = new javax.swing.JCheckBox();
127        jCheckBox5 = new javax.swing.JCheckBox();
128        jCheckBox6 = new javax.swing.JCheckBox();
129        jCheckBox7 = new javax.swing.JCheckBox();
130        jCheckBox8 = new javax.swing.JCheckBox();
131        jCheckBox9 = new javax.swing.JCheckBox();
132        jCheckBox10 = new javax.swing.JCheckBox();
133        LocationDropdown = new javax.swing.JComboBox();
134
135        jLabel1.setText("Location");
136
137        jLabel2.setText("Status");
138
139        StatusDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "New", "Changed", "Cleared" }));
140
141        TypeDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lane Breakdown", "Lane Obstruction" }));
142
143        jLabel3.setText("Incident Type");
144
145        jLabel4.setText("Lanes affected:");
146
147        jCheckBox1.setText("Lane 1");
148        jCheckBox1.addActionListener(new java.awt.event.ActionListener()
149        {
150            public void actionPerformed(java.awt.event.ActionEvent evt)
151            {
152                jCheckBox1ActionPerformed(evt);
153            }
154        });
155
156        jCheckBox2.setText("Lane 2");
157        jCheckBox2.addActionListener(new java.awt.event.ActionListener()
158        {
159            public void actionPerformed(java.awt.event.ActionEvent evt)
160            {
161                jCheckBox2ActionPerformed(evt);
162            }
163        });
164
165        jCheckBox3.setText("Lane 3");
166        jCheckBox3.addActionListener(new java.awt.event.ActionListener()
167        {
168            public void actionPerformed(java.awt.event.ActionEvent evt)
169            {
170                jCheckBox3ActionPerformed(evt);
171            }
172        });
173
174        jCheckBox4.setText("Lane 4");
175        jCheckBox4.addActionListener(new java.awt.event.ActionListener()
176        {
177            public void actionPerformed(java.awt.event.ActionEvent evt)
178            {
179                jCheckBox4ActionPerformed(evt);
180            }
181        });
182
183        jCheckBox5.setText("Lane 5");
184        jCheckBox5.addActionListener(new java.awt.event.ActionListener()
185        {
186            public void actionPerformed(java.awt.event.ActionEvent evt)
187            {
188                jCheckBox5ActionPerformed(evt);
189            }
190        });
191
192        jCheckBox6.setText("Lane 8");
193        jCheckBox6.addActionListener(new java.awt.event.ActionListener()
194        {
195            public void actionPerformed(java.awt.event.ActionEvent evt)
196            {
197                jCheckBox6ActionPerformed(evt);
198            }
199        });
200
201        jCheckBox7.setText("Lane 6");
202        jCheckBox7.addActionListener(new java.awt.event.ActionListener()
203        {
204            public void actionPerformed(java.awt.event.ActionEvent evt)
205            {
206                jCheckBox7ActionPerformed(evt);
207            }
208        });
209
210        jCheckBox8.setText("Lane 7");
211        jCheckBox8.addActionListener(new java.awt.event.ActionListener()
212        {
213            public void actionPerformed(java.awt.event.ActionEvent evt)
214            {
215                jCheckBox8ActionPerformed(evt);
216            }
217        });
218
219        jCheckBox9.setText("Lane 10");
220        jCheckBox9.addActionListener(new java.awt.event.ActionListener()
221        {
222            public void actionPerformed(java.awt.event.ActionEvent evt)
223            {
224                jCheckBox9ActionPerformed(evt);
225            }
226        });
227
228        jCheckBox10.setText("Lane 9");
229        jCheckBox10.addActionListener(new java.awt.event.ActionListener()
230        {
231            public void actionPerformed(java.awt.event.ActionEvent evt)
232            {
233                jCheckBox10ActionPerformed(evt);
234            }
235        });
236
237        LocationDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "187_S_55_ML", "187_N_405_HV" }));
238
239        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
240        this.setLayout(layout);
241        layout.setHorizontalGroup(
242            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
243            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
244                .addContainerGap()
245                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
246                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3)
247                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
248                        .add(jLabel4)
249                        .add(18, 18, 18)
250                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
251                            .add(jCheckBox2)
252                            .add(jCheckBox1))
253                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
254                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
255                            .add(jCheckBox3)
256                            .add(jCheckBox4))
257                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
258                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
259                            .add(jCheckBox7)
260                            .add(jCheckBox5))
261                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
262                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
263                            .add(jCheckBox8)
264                            .add(jCheckBox6))
265                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
266                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
267                            .add(jCheckBox10)
268                            .add(jCheckBox9)))
269                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
270                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
271                            .add(jLabel1)
272                            .add(jLabel2))
273                        .add(36, 36, 36)
274                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
275                            .add(org.jdesktop.layout.GroupLayout.TRAILING, TypeDropdown, 0, 597, Short.MAX_VALUE)
276                            .add(StatusDropdown, 0, 597, Short.MAX_VALUE)
277                            .add(LocationDropdown, 0, 597, Short.MAX_VALUE))))
278                .addContainerGap())
279        );
280        layout.setVerticalGroup(
281            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
282            .add(layout.createSequentialGroup()
283                .add(41, 41, 41)
284                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
285                    .add(jLabel1)
286                    .add(LocationDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
287                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
288                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
289                    .add(StatusDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
290                    .add(jLabel2))
291                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
292                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
293                    .add(jLabel3)
294                    .add(TypeDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
295                .add(18, 18, 18)
296                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
297                    .add(layout.createSequentialGroup()
298                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
299                            .add(jLabel4)
300                            .add(jCheckBox1))
301                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
302                        .add(jCheckBox2))
303                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
304                        .add(layout.createSequentialGroup()
305                            .add(jCheckBox5)
306                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
307                            .add(jCheckBox7))
308                        .add(layout.createSequentialGroup()
309                            .add(jCheckBox3)
310                            .add(2, 2, 2)
311                            .add(jCheckBox4))
312                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
313                            .add(layout.createSequentialGroup()
314                                .add(jCheckBox10)
315                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
316                                .add(jCheckBox9))
317                            .add(layout.createSequentialGroup()
318                                .add(jCheckBox8)
319                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
320                                .add(jCheckBox6)))))
321                .addContainerGap(116, Short.MAX_VALUE))
322        );
323    }// </editor-fold>//GEN-END:initComponents
324
325    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
326        if (jCheckBox1.isSelected())
327        {
328            if (!event.laneNums.contains(1))
329            {
330                event.laneNums.add(1);
331            }
332        }
333        else
334        {
335            if (event.laneNums.contains(1))
336            {
337                event.laneNums.remove(1);
338            }
339        }
340    }//GEN-LAST:event_jCheckBox1ActionPerformed
341
342    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
343        if (jCheckBox2.isSelected())
344        {
345            if (!event.laneNums.contains(2))
346            {
347                event.laneNums.add(2);
348            }
349        }
350        else
351        {
352            if (event.laneNums.contains(2))
353            {
354                event.laneNums.remove(2);
355            }
356        }
357    }//GEN-LAST:event_jCheckBox2ActionPerformed
358
359    private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
360        if (jCheckBox3.isSelected())
361        {
362            if (!event.laneNums.contains(3))
363            {
364                event.laneNums.add(3);
365            }
366        }
367        else
368        {
369            if (event.laneNums.contains(3))
370            {
371                event.laneNums.remove(3);
372            }
373        }
374    }//GEN-LAST:event_jCheckBox3ActionPerformed
375
376    private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed
377        if (jCheckBox4.isSelected())
378        {
379            if (!event.laneNums.contains(4))
380            {
381                event.laneNums.add(4);
382            }
383        }
384        else
385        {
386            if (event.laneNums.contains(4))
387            {
388                event.laneNums.remove(4);
389            }
390        }
391    }//GEN-LAST:event_jCheckBox4ActionPerformed
392
393    private void jCheckBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox5ActionPerformed
394        if (jCheckBox5.isSelected())
395        {
396            if (!event.laneNums.contains(5))
397            {
398                event.laneNums.add(5);
399            }
400        }
401        else
402        {
403            if (event.laneNums.contains(5))
404            {
405                event.laneNums.remove(5);
406            }
407        }
408    }//GEN-LAST:event_jCheckBox5ActionPerformed
409
410    private void jCheckBox6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox6ActionPerformed
411        if (jCheckBox6.isSelected())
412        {
413            if (!event.laneNums.contains(6))
414            {
415                event.laneNums.add(6);
416            }
417        }
418        else
419        {
420            if (event.laneNums.contains(6))
421            {
422                event.laneNums.remove(6);
423            }
424        }
425    }//GEN-LAST:event_jCheckBox6ActionPerformed
426
427    private void jCheckBox7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox7ActionPerformed
428        if (jCheckBox7.isSelected())
429        {
430            if (!event.laneNums.contains(7))
431            {
432                event.laneNums.add(7);
433            }
434        }
435        else
436        {
437            if (event.laneNums.contains(7))
438            {
439                event.laneNums.remove(7);
440            }
441        }
442    }//GEN-LAST:event_jCheckBox7ActionPerformed
443
444    private void jCheckBox8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox8ActionPerformed
445        if (jCheckBox8.isSelected())
446        {
447            if (!event.laneNums.contains(8))
448            {
449                event.laneNums.add(8);
450            }
451        }
452        else
453        {
454            if (event.laneNums.contains(8))
455            {
456                event.laneNums.remove(8);
457            }
458        }
459    }//GEN-LAST:event_jCheckBox8ActionPerformed
460
461    private void jCheckBox9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox9ActionPerformed
462        if (jCheckBox9.isSelected())
463        {
464            if (!event.laneNums.contains(9))
465            {
466                event.laneNums.add(9);
467            }
468        }
469        else
470        {
471            if (event.laneNums.contains(9))
472            {
473                event.laneNums.remove(9);
474            }
475        }
476    }//GEN-LAST:event_jCheckBox9ActionPerformed
477
478    private void jCheckBox10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox10ActionPerformed
479        if (jCheckBox10.isSelected())
480        {
481            if (!event.laneNums.contains(10))
482            {
483                event.laneNums.add(10);
484            }
485        }
486        else
487        {
488            if (event.laneNums.contains(10))
489            {
490                event.laneNums.remove(10);
491            }
492        }
493    }//GEN-LAST:event_jCheckBox10ActionPerformed
494
495
496    // Variables declaration - do not modify//GEN-BEGIN:variables
497    private javax.swing.JComboBox LocationDropdown;
498    private javax.swing.JComboBox StatusDropdown;
499    private javax.swing.JComboBox TypeDropdown;
500    private javax.swing.JCheckBox jCheckBox1;
501    private javax.swing.JCheckBox jCheckBox10;
502    private javax.swing.JCheckBox jCheckBox2;
503    private javax.swing.JCheckBox jCheckBox3;
504    private javax.swing.JCheckBox jCheckBox4;
505    private javax.swing.JCheckBox jCheckBox5;
506    private javax.swing.JCheckBox jCheckBox6;
507    private javax.swing.JCheckBox jCheckBox7;
508    private javax.swing.JCheckBox jCheckBox8;
509    private javax.swing.JCheckBox jCheckBox9;
510    private javax.swing.JLabel jLabel1;
511    private javax.swing.JLabel jLabel2;
512    private javax.swing.JLabel jLabel3;
513    private javax.swing.JLabel jLabel4;
514    // End of variables declaration//GEN-END:variables
515
516}
Note: See TracBrowser for help on using the repository browser.