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

Revision 93, 20.1 KB checked in by bmcguffin, 9 years ago (diff)

Moved classes which represent elements of the main event editor frame to their own package, for clarity' sake.

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