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

Revision 89, 19.8 KB checked in by bmcguffin, 9 years ago (diff)

Added dropdown menu item to ScriptBuilderFrame?: "Delete Incident". When clicked, user may select an existing incident to delete. Program will prompt user to confirm the deletion, then remove the incident from the script and refresh the display.

Added button to individual event editor window: "Remove this event". When clicked, the currently displayed event will be removed from the timeslice it is in. The display will be refreshed accordingly. NOTE: This still has some bugs, namely that the last remaining event in a timeslice fails to be deleted.

Restructured Interface ScriptEventEditorPanel? to include a removeAssociatedEvent method, which calls a new method in I_ScriptEvent called removeThis, which causes the event to be removed from its timeslice.

Editor.Java previously contained several classes and enums, none of which were set to private scope. Moved these extra classes to their own files to decrease clutter in Editor.java and increase readability of all files.

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