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

Revision 50, 19.7 KB checked in by bmcguffin, 9 years ago (diff)

Added action listeners and functionality to all editor windows. Changes made inside windows will now be applied to the model.

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