source: tmcsimulator-scriptbuilder/trunk/src/event/editor/Editor.java @ 92

Revision 92, 20.0 KB checked in by bmcguffin, 9 years ago (diff)

Removed superfluous "Remove" buttons on several panels.

Removed interface "RemovablePanel?" as it was no longer necessary or useful; removed related methods from classes implementing it.

Line 
1package event.editor;
2
3import java.awt.BorderLayout;
4import java.awt.Color;
5import java.awt.FlowLayout;
6import javax.swing.*;
7import java.util.*;
8import java.awt.event.*;
9import scriptbuilder.gui.IncidentEditorFrame;
10import scriptbuilder.structures.ScriptIncident;
11import scriptbuilder.structures.events.*;
12
13public class Editor extends javax.swing.JFrame implements Observer
14{
15
16    IncidentEditorFrame topFrame = null;
17
18    private PropertyModel model = new PropertyModel();
19
20//    public PropertyModel getPropertyModel()
21//    {
22//        return model;
23//    }
24    public void addProperty(Properties property, I_ScriptEvent se)
25    {
26        model.addProperty(property, se);
27    }
28
29    private ActionListener optionalChangeListener = new ActionListener()
30    {
31        public void actionPerformed(ActionEvent evt)
32        {
33            JCheckBoxMenuItem src = (JCheckBoxMenuItem) evt.getSource();
34            Properties property = Properties.valueOf(src.getText().replaceAll(" ", ""));
35
36            if (src.isSelected())
37            {
38                model.addProperty(property, new CCTVEvent());
39            }
40            else
41            {
42                model.removeProperty(property);
43            }
44        }
45    };
46
47    private ActionListener multipleChangeListener = new ActionListener()
48    {
49        public void actionPerformed(ActionEvent evt)
50        {
51            JMenuItem src = (JMenuItem) evt.getSource();
52            model.addProperty(Properties.valueOf(src.getText().replaceAll(" ", "")), new CCTVEvent());
53        }
54    };
55
56    /**
57     * Blank constructor for a new editor.
58     */
59    public Editor(IncidentEditorFrame frame)
60    {
61        topFrame = frame;
62        initComponents();
63
64        model.addObserver(this);
65
66        // For each menu
67        for (int menuCtr = 0; menuCtr < jMenuBar1.getMenuCount(); menuCtr++)
68        {
69            // for each menu item
70            for (java.awt.Component comp : jMenuBar1.getMenu(menuCtr).getMenuComponents())
71            {
72                JMenuItem item = (JMenuItem) comp;
73
74                String itemName = item.getText().replaceAll(" ", "");
75
76                Properties property = Properties.valueOf(itemName);
77
78                if (property.getType() == PropertyTypes.Multiple)
79                {
80                    item.addActionListener(multipleChangeListener);
81                }
82                else if (property.getType() == PropertyTypes.Optional)
83                {
84                    item.addActionListener(optionalChangeListener);
85                }
86                else
87                {
88                    throw new RuntimeException("Property type not accounted for");
89                }
90            }
91        }
92    }
93
94    /**
95     * This method is called from within the constructor to initialize the form.
96     * WARNING: Do NOT modify this code. The content of this method is always
97     * regenerated by the Form Editor.
98     */
99    @SuppressWarnings("unchecked")
100    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
101    private void initComponents()
102    {
103
104        jPanel1 = new javax.swing.JPanel();
105        jTabbedPane1 = new javax.swing.JTabbedPane();
106        jPanel2 = new javax.swing.JPanel();
107        btnRemoveCurrentEvent = new javax.swing.JButton();
108        jMenuBar1 = new javax.swing.JMenuBar();
109        jMenu1 = new javax.swing.JMenu();
110        ATMS = new javax.swing.JCheckBoxMenuItem();
111        ActivityLog = new javax.swing.JCheckBoxMenuItem();
112        CAD = new javax.swing.JCheckBoxMenuItem();
113        CMS = new javax.swing.JMenuItem();
114        Facilitator = new javax.swing.JCheckBoxMenuItem();
115        Radio = new javax.swing.JCheckBoxMenuItem();
116        JMenu2 = new javax.swing.JMenu();
117        MaintenanceRadio = new javax.swing.JCheckBoxMenuItem();
118        TMTRadio = new javax.swing.JCheckBoxMenuItem();
119        Telephone = new javax.swing.JCheckBoxMenuItem();
120        jMenu3 = new javax.swing.JMenu();
121        Audio = new javax.swing.JMenuItem();
122        CADLog = new javax.swing.JMenuItem();
123        CCTV = new javax.swing.JMenuItem();
124        CHPRadio = new javax.swing.JCheckBoxMenuItem();
125        Paramics = new javax.swing.JMenuItem();
126        Tow = new javax.swing.JMenuItem();
127        Unit = new javax.swing.JMenuItem();
128        Witness = new javax.swing.JMenuItem();
129
130        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
131        jPanel1.setLayout(jPanel1Layout);
132        jPanel1Layout.setHorizontalGroup(
133            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
134            .add(0, 100, Short.MAX_VALUE)
135        );
136        jPanel1Layout.setVerticalGroup(
137            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
138            .add(0, 100, Short.MAX_VALUE)
139        );
140
141        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
142        setTitle("Event Editor");
143
144        btnRemoveCurrentEvent.setText("Remove This Event");
145        btnRemoveCurrentEvent.addActionListener(new java.awt.event.ActionListener()
146        {
147            public void actionPerformed(java.awt.event.ActionEvent evt)
148            {
149                btnRemoveCurrentEventActionPerformed(evt);
150            }
151        });
152
153        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
154        jPanel2.setLayout(jPanel2Layout);
155        jPanel2Layout.setHorizontalGroup(
156            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
157            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
158                .addContainerGap(701, Short.MAX_VALUE)
159                .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
160                .addContainerGap())
161        );
162        jPanel2Layout.setVerticalGroup(
163            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
164            .add(btnRemoveCurrentEvent)
165        );
166
167        jMenu1.setText("Evaluations");
168
169        ATMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
170        ATMS.setText("ATMS");
171        ATMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ATMSEval.png"))); // NOI18N
172        ATMS.addActionListener(new java.awt.event.ActionListener()
173        {
174            public void actionPerformed(java.awt.event.ActionEvent evt)
175            {
176                multipleChange(evt);
177            }
178        });
179        jMenu1.add(ATMS);
180
181        ActivityLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
182        ActivityLog.setText("Activity Log");
183        ActivityLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ActivityLogEval.png"))); // NOI18N
184        ActivityLog.addActionListener(new java.awt.event.ActionListener()
185        {
186            public void actionPerformed(java.awt.event.ActionEvent evt)
187            {
188                multipleChange(evt);
189            }
190        });
191        jMenu1.add(ActivityLog);
192
193        CAD.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
194        CAD.setText("CAD");
195        CAD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CADEval.png"))); // NOI18N
196        CAD.addActionListener(new java.awt.event.ActionListener()
197        {
198            public void actionPerformed(java.awt.event.ActionEvent evt)
199            {
200                multipleChange(evt);
201            }
202        });
203        jMenu1.add(CAD);
204
205        CMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
206        CMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CMSEval.png"))); // NOI18N
207        CMS.setText("CMS");
208        CMS.addMouseListener(new java.awt.event.MouseAdapter()
209        {
210            public void mouseClicked(java.awt.event.MouseEvent evt)
211            {
212                multipleChangeListener(evt);
213            }
214        });
215        CMS.addActionListener(new java.awt.event.ActionListener()
216        {
217            public void actionPerformed(java.awt.event.ActionEvent evt)
218            {
219                multipleChange(evt);
220            }
221        });
222        jMenu1.add(CMS);
223
224        Facilitator.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
225        Facilitator.setText("Facilitator");
226        Facilitator.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FacilitatorEval.png"))); // NOI18N
227        Facilitator.addActionListener(new java.awt.event.ActionListener()
228        {
229            public void actionPerformed(java.awt.event.ActionEvent evt)
230            {
231                optionalChange(evt);
232            }
233        });
234        jMenu1.add(Facilitator);
235
236        Radio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
237        Radio.setText("Radio");
238        Radio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/RadioEval.png"))); // NOI18N
239        Radio.addActionListener(new java.awt.event.ActionListener()
240        {
241            public void actionPerformed(java.awt.event.ActionEvent evt)
242            {
243                optionalChange(evt);
244            }
245        });
246        jMenu1.add(Radio);
247
248        jMenuBar1.add(jMenu1);
249
250        JMenu2.setText("Instructor Actions");
251
252        MaintenanceRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
253        MaintenanceRadio.setText("Maintenance Radio");
254        MaintenanceRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MaintenanceRadio.png"))); // NOI18N
255        MaintenanceRadio.addActionListener(new java.awt.event.ActionListener()
256        {
257            public void actionPerformed(java.awt.event.ActionEvent evt)
258            {
259                optionalChange(evt);
260            }
261        });
262        JMenu2.add(MaintenanceRadio);
263
264        TMTRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
265        TMTRadio.setText("TMT Radio");
266        TMTRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TMTRadio.png"))); // NOI18N
267        TMTRadio.addActionListener(new java.awt.event.ActionListener()
268        {
269            public void actionPerformed(java.awt.event.ActionEvent evt)
270            {
271                optionalChange(evt);
272            }
273        });
274        JMenu2.add(TMTRadio);
275
276        Telephone.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
277        Telephone.setText("Telephone");
278        Telephone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Telephone.png"))); // NOI18N
279        Telephone.addActionListener(new java.awt.event.ActionListener()
280        {
281            public void actionPerformed(java.awt.event.ActionEvent evt)
282            {
283                optionalChange(evt);
284            }
285        });
286        JMenu2.add(Telephone);
287
288        jMenuBar1.add(JMenu2);
289
290        jMenu3.setText("Automated Data");
291
292        Audio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
293        Audio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Audio.png"))); // NOI18N
294        Audio.setText("Audio");
295        jMenu3.add(Audio);
296
297        CADLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
298        CADLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CAD.png"))); // NOI18N
299        CADLog.setText("CAD Log");
300        jMenu3.add(CADLog);
301
302        CCTV.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
303        CCTV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CCTV.png"))); // NOI18N
304        CCTV.setText("CCTV");
305        jMenu3.add(CCTV);
306
307        CHPRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
308        CHPRadio.setText("CHP Radio");
309        CHPRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CHPRadio.png"))); // NOI18N
310        CHPRadio.addActionListener(new java.awt.event.ActionListener()
311        {
312            public void actionPerformed(java.awt.event.ActionEvent evt)
313            {
314                optionalChange(evt);
315            }
316        });
317        jMenu3.add(CHPRadio);
318
319        Paramics.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
320        Paramics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Paramics.png"))); // NOI18N
321        Paramics.setText("Paramics");
322        jMenu3.add(Paramics);
323
324        Tow.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
325        Tow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Tow.png"))); // NOI18N
326        Tow.setText("Tow");
327        jMenu3.add(Tow);
328
329        Unit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
330        Unit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unit.png"))); // NOI18N
331        Unit.setText("Unit");
332        jMenu3.add(Unit);
333
334        Witness.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
335        Witness.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Witness.png"))); // NOI18N
336        Witness.setText("Witness");
337        jMenu3.add(Witness);
338
339        jMenuBar1.add(jMenu3);
340
341        setJMenuBar(jMenuBar1);
342
343        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
344        getContentPane().setLayout(layout);
345        layout.setHorizontalGroup(
346            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
347            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTabbedPane1)
348            .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
349        );
350        layout.setVerticalGroup(
351            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
352            .add(layout.createSequentialGroup()
353                .addContainerGap()
354                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)
355                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
356                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
357        );
358
359        pack();
360    }// </editor-fold>//GEN-END:initComponents
361
362    private void multipleChangeListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_multipleChangeListener
363
364    }//GEN-LAST:event_multipleChangeListener
365
366    private void multipleChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleChange
367
368    }//GEN-LAST:event_multipleChange
369
370    private void optionalChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionalChange
371
372    }//GEN-LAST:event_optionalChange
373
374    private void btnRemoveCurrentEventActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnRemoveCurrentEventActionPerformed
375    {//GEN-HEADEREND:event_btnRemoveCurrentEventActionPerformed
376
377        int index = jTabbedPane1.getSelectedIndex();
378
379        if (index > 0 && jTabbedPane1.getTabComponentAt(index) != null)
380        {
381            JPanel removable = (JPanel) jTabbedPane1
382                    .getSelectedComponent();
383            this.model.properties.removeProperty(removable);
384        }
385
386    }//GEN-LAST:event_btnRemoveCurrentEventActionPerformed
387
388    /**
389     * @param args the command line arguments
390     */
391    public static void main(String args[])
392    {
393        java.awt.EventQueue.invokeLater(new Runnable()
394        {
395            public void run()
396            {
397                new Editor(new IncidentEditorFrame(new ScriptIncident(100, null, null, null))).setVisible(true);
398            }
399        });
400    }
401
402    // Variables declaration - do not modify//GEN-BEGIN:variables
403    private javax.swing.JCheckBoxMenuItem ATMS;
404    private javax.swing.JCheckBoxMenuItem ActivityLog;
405    private javax.swing.JMenuItem Audio;
406    private javax.swing.JCheckBoxMenuItem CAD;
407    private javax.swing.JMenuItem CADLog;
408    private javax.swing.JMenuItem CCTV;
409    private javax.swing.JCheckBoxMenuItem CHPRadio;
410    private javax.swing.JMenuItem CMS;
411    private javax.swing.JCheckBoxMenuItem Facilitator;
412    private javax.swing.JMenu JMenu2;
413    private javax.swing.JCheckBoxMenuItem MaintenanceRadio;
414    private javax.swing.JMenuItem Paramics;
415    private javax.swing.JCheckBoxMenuItem Radio;
416    private javax.swing.JCheckBoxMenuItem TMTRadio;
417    private javax.swing.JCheckBoxMenuItem Telephone;
418    private javax.swing.JMenuItem Tow;
419    private javax.swing.JMenuItem Unit;
420    private javax.swing.JMenuItem Witness;
421    private javax.swing.JButton btnRemoveCurrentEvent;
422    private javax.swing.JMenu jMenu1;
423    private javax.swing.JMenu jMenu3;
424    private javax.swing.JMenuBar jMenuBar1;
425    private javax.swing.JPanel jPanel1;
426    private javax.swing.JPanel jPanel2;
427    private javax.swing.JTabbedPane jTabbedPane1;
428    // End of variables declaration//GEN-END:variables
429
430    @Override
431    public void update(Observable o, Object arg)
432    {
433
434        final PropertyUpdate update = (PropertyUpdate) arg;
435        final ImageIcon image = update.getPanel().getProperty().getImage();
436        final String caption = update.getPanel().title();
437
438        final JLabel title = new JLabel(caption, image, JLabel.CENTER);
439
440        /*
441         final BorderLayout layout = new BorderLayout();
442         final JPanel title = new JPanel(layout);
443         title.setOpaque(false);
444         title.add(new JLabel(image), BorderLayout.WEST);
445         title.add(new JLabel(caption), BorderLayout.EAST);
446         */
447        if (update.getType() == UpdateType.Add)
448        {
449            jTabbedPane1.insertTab(null, null,
450                    update.getPanel().getPanel(), null, update.getPosition());
451            jTabbedPane1.setTabComponentAt(update.getPosition(), title);
452            jTabbedPane1.setSelectedIndex(update.getPosition());
453            topFrame.repaint();
454        }
455        else if (update.getType() == UpdateType.Remove)
456        {
457            jTabbedPane1.remove(update.getPanel().getPanel());
458            if (update.getPanel().getPanel() instanceof I_ScriptEventEditorPanel)
459            {
460                ((I_ScriptEventEditorPanel) update.getPanel().getPanel()).removeAssociatedEvent();
461            }
462            topFrame.repaint();
463        }
464        else if (update.getType() == UpdateType.TitleChange)
465        {
466            final int index = jTabbedPane1.indexOfComponent(
467                    update.getPanel().getPanel());
468
469            new Thread(new Runnable()
470            {
471                public void run()
472                {
473                    Color c = jTabbedPane1.getForegroundAt(index);
474                    jTabbedPane1.setForegroundAt(index, Color.blue);
475                    try
476                    {
477                        Thread.sleep(350);
478                    }
479                    catch (Exception e)
480                    {
481                    }
482                    jTabbedPane1.setTabComponentAt(index, title);
483                    try
484                    {
485                        Thread.sleep(350);
486                    }
487                    catch (Exception e)
488                    {
489                    }
490                    jTabbedPane1.setForegroundAt(index, c);
491                }
492            }).start();
493        }
494        else
495        {
496            throw new RuntimeException("UpdateType not accounted for");
497        }
498    }
499
500}
Note: See TracBrowser for help on using the repository browser.