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

Revision 134, 24.3 KB checked in by bmcguffin, 9 years ago (diff)

The event-add dropdown menus in the event editor window now function correctly. Clicking on an event in the dropdown list adds it to that timeslice.

Line 
1package event.editor.frame;
2
3import event.editor.I_ScriptEventEditorPanel;
4import java.awt.BorderLayout;
5import java.awt.Color;
6import java.awt.FlowLayout;
7import javax.swing.*;
8import java.util.*;
9import java.awt.event.*;
10import java.text.SimpleDateFormat;
11import scriptbuilder.gui.IncidentEditorFrame;
12import scriptbuilder.gui.ScriptBuilderFrame;
13import scriptbuilder.gui.panels.IncidentTimelinePanel;
14import scriptbuilder.structures.ScriptEvent;
15import scriptbuilder.structures.ScriptIncident;
16import scriptbuilder.structures.TimeSlice;
17import scriptbuilder.structures.events.*;
18
19public class Editor extends javax.swing.JFrame implements Observer
20{
21
22    IncidentEditorFrame topFrame = null;
23
24    ScriptIncident incident = null;
25
26    TimeSlice slice = null;
27
28    private PropertyModel model = new PropertyModel();
29
30    public void addEvent(Properties property, I_ScriptEvent se)
31    {
32        model.addEventPanel(property, se);
33    }
34
35    public void setSlice(TimeSlice ts)
36    {
37        slice = ts;
38
39        if (slice != null)
40
41        {
42            for (I_ScriptEvent se : slice.events)
43            {
44
45                this.addEvent(IncidentTimelinePanel.eventTypeToPropertyMap.get(se.getScriptEventType()), se);
46
47            }
48            System.out.println("Current time = " + slice.getTime() + " seconds");
49            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
50            df.setTimeZone(TimeZone.getTimeZone("GMT"));
51            String eventTime = df.format(new Date(slice.getTime() * 1000));
52            System.out.println("[" + eventTime + "]");
53            txtEventStart.setText(eventTime);
54        }
55
56    }
57
58    private ActionListener optionalChangeListener = new ActionListener()
59    {
60        public void actionPerformed(ActionEvent evt)
61        {
62            JCheckBoxMenuItem src = (JCheckBoxMenuItem) evt.getSource();
63            Properties property = Properties.valueOf(src.getText().replaceAll(" ", ""));
64
65            if (src.isSelected())
66            {
67                model.addEventFromDropdown(property, incident, slice);
68            }
69            else
70            {
71                model.removeProperty(property);
72            }
73        }
74    };
75
76    private ActionListener multipleChangeListener = new ActionListener()
77    {
78        public void actionPerformed(ActionEvent evt)
79        {
80            JMenuItem src = (JMenuItem) evt.getSource();
81            Properties property = Properties.valueOf(src.getText().replaceAll(" ", ""));
82            model.addEventFromDropdown(property, incident, slice);
83        }
84    };
85
86    /**
87     * Blank constructor for a new editor.
88     */
89    public Editor(IncidentEditorFrame frame)
90    {
91        topFrame = frame;
92        initComponents();
93
94        incident = frame.getIncident();
95
96        model.addObserver(this);
97
98        // For each menu
99        for (int menuCtr = 0; menuCtr < editorMenuBar.getMenuCount(); menuCtr++)
100        {
101            // for each menu item
102            for (java.awt.Component comp : editorMenuBar.getMenu(menuCtr).getMenuComponents())
103            {
104                JMenuItem item = (JMenuItem) comp;
105
106                String itemName = item.getText().replaceAll(" ", "");
107
108                Properties property = Properties.valueOf(itemName);
109
110                if (property.getType() == PropertyTypes.Multiple)
111                {
112                    item.addActionListener(multipleChangeListener);
113                }
114                else if (property.getType() == PropertyTypes.Optional)
115                {
116                    item.addActionListener(optionalChangeListener);
117                }
118                else
119                {
120                    throw new RuntimeException("Property type not accounted for");
121                }
122            }
123
124        }
125
126        String eventTime = "";
127
128        txtEventStart.setText(eventTime);
129
130        txtEventStart.addKeyListener(new KeyListener()
131        {
132
133            @Override
134            public void keyTyped(KeyEvent e)
135            {
136            }
137
138            @Override
139            public void keyPressed(KeyEvent e)
140            {
141                if (e.getKeyCode() == KeyEvent.VK_ENTER)
142                {
143                    updateEventTime();
144                }
145            }
146
147            @Override
148            public void keyReleased(KeyEvent e)
149            {
150            }
151        });
152        this.addWindowListener(new WindowAdapter()
153        {
154            @Override
155            public void windowClosing(WindowEvent e)
156            {
157                //Add previous offset back in
158                //If we didn't adjust the offset, this will just set it to the old value
159                //If we deleted the first event(s), this will add the offsets,
160                //to ensure that events stay at the correct times
161                model.closePanels();
162            }
163        });
164    }
165
166    /**
167     * This method is called from within the constructor to initialize the form.
168     * WARNING: Do NOT modify this code. The content of this method is always
169     * regenerated by the Form Editor.
170     */
171    @SuppressWarnings("unchecked")
172    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
173    private void initComponents()
174    {
175
176        eventTabsPane = new javax.swing.JTabbedPane();
177        bottomFramePanel = new javax.swing.JPanel();
178        txtEventStart = new javax.swing.JTextField();
179        btnRemoveCurrentEvent = new javax.swing.JButton();
180        editorMenuBar = new javax.swing.JMenuBar();
181        menuEvaluations = new javax.swing.JMenu();
182        ATMS = new javax.swing.JCheckBoxMenuItem();
183        ActivityLog = new javax.swing.JCheckBoxMenuItem();
184        CAD = new javax.swing.JCheckBoxMenuItem();
185        CMS = new javax.swing.JMenuItem();
186        Facilitator = new javax.swing.JCheckBoxMenuItem();
187        Radio = new javax.swing.JCheckBoxMenuItem();
188        menuInstructor = new javax.swing.JMenu();
189        MaintenanceRadio = new javax.swing.JCheckBoxMenuItem();
190        TMTRadio = new javax.swing.JCheckBoxMenuItem();
191        Telephone = new javax.swing.JCheckBoxMenuItem();
192        menuAutoData = new javax.swing.JMenu();
193        Audio = new javax.swing.JMenuItem();
194        CADLog = new javax.swing.JMenuItem();
195        CCTV = new javax.swing.JMenuItem();
196        CHPRadio = new javax.swing.JCheckBoxMenuItem();
197        Paramics = new javax.swing.JMenuItem();
198        Tow = new javax.swing.JMenuItem();
199        Unit = new javax.swing.JMenuItem();
200        Witness = new javax.swing.JMenuItem();
201
202        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
203        setTitle("Event Editor");
204
205        org.jdesktop.layout.GroupLayout bottomFramePanelLayout = new org.jdesktop.layout.GroupLayout(bottomFramePanel);
206        bottomFramePanel.setLayout(bottomFramePanelLayout);
207        bottomFramePanelLayout.setHorizontalGroup(
208            bottomFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
209            .add(0, 613, Short.MAX_VALUE)
210        );
211        bottomFramePanelLayout.setVerticalGroup(
212            bottomFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
213            .add(0, 34, Short.MAX_VALUE)
214        );
215
216        txtEventStart.setText("00:00:00");
217
218        btnRemoveCurrentEvent.setText("Remove This Event");
219        btnRemoveCurrentEvent.addActionListener(new java.awt.event.ActionListener()
220        {
221            public void actionPerformed(java.awt.event.ActionEvent evt)
222            {
223                btnRemoveCurrentEventActionPerformed(evt);
224            }
225        });
226
227        menuEvaluations.setText("Evaluations");
228
229        ATMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
230        ATMS.setText("ATMS");
231        ATMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ATMSEval.png"))); // NOI18N
232        ATMS.addActionListener(new java.awt.event.ActionListener()
233        {
234            public void actionPerformed(java.awt.event.ActionEvent evt)
235            {
236                multipleChange(evt);
237            }
238        });
239        menuEvaluations.add(ATMS);
240
241        ActivityLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
242        ActivityLog.setText("Activity Log");
243        ActivityLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ActivityLogEval.png"))); // NOI18N
244        ActivityLog.addActionListener(new java.awt.event.ActionListener()
245        {
246            public void actionPerformed(java.awt.event.ActionEvent evt)
247            {
248                multipleChange(evt);
249            }
250        });
251        menuEvaluations.add(ActivityLog);
252
253        CAD.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
254        CAD.setText("CAD");
255        CAD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CADEval.png"))); // NOI18N
256        CAD.addActionListener(new java.awt.event.ActionListener()
257        {
258            public void actionPerformed(java.awt.event.ActionEvent evt)
259            {
260                multipleChange(evt);
261            }
262        });
263        menuEvaluations.add(CAD);
264
265        CMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
266        CMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CMSEval.png"))); // NOI18N
267        CMS.setText("CMS");
268        CMS.addMouseListener(new java.awt.event.MouseAdapter()
269        {
270            public void mouseClicked(java.awt.event.MouseEvent evt)
271            {
272                multipleChangeListener(evt);
273            }
274        });
275        CMS.addActionListener(new java.awt.event.ActionListener()
276        {
277            public void actionPerformed(java.awt.event.ActionEvent evt)
278            {
279                multipleChange(evt);
280            }
281        });
282        menuEvaluations.add(CMS);
283
284        Facilitator.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
285        Facilitator.setText("Facilitator");
286        Facilitator.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FacilitatorEval.png"))); // NOI18N
287        Facilitator.addActionListener(new java.awt.event.ActionListener()
288        {
289            public void actionPerformed(java.awt.event.ActionEvent evt)
290            {
291                optionalChange(evt);
292            }
293        });
294        menuEvaluations.add(Facilitator);
295
296        Radio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
297        Radio.setText("Radio");
298        Radio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/RadioEval.png"))); // NOI18N
299        Radio.addActionListener(new java.awt.event.ActionListener()
300        {
301            public void actionPerformed(java.awt.event.ActionEvent evt)
302            {
303                optionalChange(evt);
304            }
305        });
306        menuEvaluations.add(Radio);
307
308        editorMenuBar.add(menuEvaluations);
309
310        menuInstructor.setText("Instructor Actions");
311
312        MaintenanceRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
313        MaintenanceRadio.setText("Maintenance Radio");
314        MaintenanceRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MaintenanceRadio.png"))); // NOI18N
315        MaintenanceRadio.addActionListener(new java.awt.event.ActionListener()
316        {
317            public void actionPerformed(java.awt.event.ActionEvent evt)
318            {
319                optionalChange(evt);
320            }
321        });
322        menuInstructor.add(MaintenanceRadio);
323
324        TMTRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
325        TMTRadio.setText("TMT Radio");
326        TMTRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TMTRadio.png"))); // NOI18N
327        TMTRadio.addActionListener(new java.awt.event.ActionListener()
328        {
329            public void actionPerformed(java.awt.event.ActionEvent evt)
330            {
331                optionalChange(evt);
332            }
333        });
334        menuInstructor.add(TMTRadio);
335
336        Telephone.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
337        Telephone.setText("Telephone");
338        Telephone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Telephone.png"))); // NOI18N
339        Telephone.addActionListener(new java.awt.event.ActionListener()
340        {
341            public void actionPerformed(java.awt.event.ActionEvent evt)
342            {
343                optionalChange(evt);
344            }
345        });
346        menuInstructor.add(Telephone);
347
348        editorMenuBar.add(menuInstructor);
349
350        menuAutoData.setText("Automated Data");
351
352        Audio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
353        Audio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Audio.png"))); // NOI18N
354        Audio.setText("Audio");
355        Audio.addActionListener(new java.awt.event.ActionListener()
356        {
357            public void actionPerformed(java.awt.event.ActionEvent evt)
358            {
359                AudioActionPerformed(evt);
360            }
361        });
362        menuAutoData.add(Audio);
363
364        CADLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
365        CADLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CAD.png"))); // NOI18N
366        CADLog.setText("CAD Log");
367        menuAutoData.add(CADLog);
368
369        CCTV.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
370        CCTV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CCTV.png"))); // NOI18N
371        CCTV.setText("CCTV");
372        menuAutoData.add(CCTV);
373
374        CHPRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
375        CHPRadio.setText("CHP Radio");
376        CHPRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CHPRadio.png"))); // NOI18N
377        CHPRadio.addActionListener(new java.awt.event.ActionListener()
378        {
379            public void actionPerformed(java.awt.event.ActionEvent evt)
380            {
381                optionalChange(evt);
382            }
383        });
384        menuAutoData.add(CHPRadio);
385
386        Paramics.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
387        Paramics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Paramics.png"))); // NOI18N
388        Paramics.setText("Paramics");
389        menuAutoData.add(Paramics);
390
391        Tow.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
392        Tow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Tow.png"))); // NOI18N
393        Tow.setText("Tow");
394        menuAutoData.add(Tow);
395
396        Unit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
397        Unit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unit.png"))); // NOI18N
398        Unit.setText("Unit");
399        menuAutoData.add(Unit);
400
401        Witness.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
402        Witness.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Witness.png"))); // NOI18N
403        Witness.setText("Witness");
404        menuAutoData.add(Witness);
405
406        editorMenuBar.add(menuAutoData);
407
408        setJMenuBar(editorMenuBar);
409
410        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
411        getContentPane().setLayout(layout);
412        layout.setHorizontalGroup(
413            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
414            .add(org.jdesktop.layout.GroupLayout.TRAILING, eventTabsPane)
415            .add(layout.createSequentialGroup()
416                .addContainerGap()
417                .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
418                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
419                .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
420                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
421                .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
422                .addContainerGap())
423        );
424        layout.setVerticalGroup(
425            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
426            .add(layout.createSequentialGroup()
427                .addContainerGap()
428                .add(eventTabsPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 534, Short.MAX_VALUE)
429                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
430                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
431                    .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
432                    .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
433                    .add(btnRemoveCurrentEvent)))
434        );
435
436        pack();
437    }// </editor-fold>//GEN-END:initComponents
438
439    private void multipleChangeListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_multipleChangeListener
440
441    }//GEN-LAST:event_multipleChangeListener
442
443    private void multipleChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleChange
444
445    }//GEN-LAST:event_multipleChange
446
447    private void optionalChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionalChange
448
449    }//GEN-LAST:event_optionalChange
450
451    private void btnRemoveCurrentEventActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnRemoveCurrentEventActionPerformed
452    {//GEN-HEADEREND:event_btnRemoveCurrentEventActionPerformed
453
454        int index = eventTabsPane.getSelectedIndex();
455
456        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
457        {
458            JPanel removable = (JPanel) eventTabsPane
459                    .getSelectedComponent();
460            PropertyPanel update = this.model.properties.removeProperty(removable);
461
462            ((I_ScriptEventEditorPanel) update.getPanel()).removeAssociatedEvent();
463
464        }
465
466    }//GEN-LAST:event_btnRemoveCurrentEventActionPerformed
467
468    private void AudioActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_AudioActionPerformed
469    {//GEN-HEADEREND:event_AudioActionPerformed
470        // TODO add your handling code here:
471    }//GEN-LAST:event_AudioActionPerformed
472
473    private void updateEventTime()
474    {
475        String[] tokens = txtEventStart.getText().split(":");
476
477        int hrs = Integer.parseInt(tokens[0]);
478        int mins = Integer.parseInt(tokens[1]);
479        int secs = Integer.parseInt(tokens[2]);
480
481        int newTime = (3600 * hrs) + (60 * mins) + secs;
482
483        int index = eventTabsPane.getSelectedIndex();
484
485        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
486        {
487            JPanel removable = (JPanel) eventTabsPane
488                    .getSelectedComponent();
489            I_ScriptEvent ise = this.model.eventMap.get(removable);
490            if (newTime != slice.getTime() && incident.changeEventStart(ise, slice.getTime(), newTime))
491            {
492                this.model.properties.removeProperty(removable);
493
494            }
495            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
496            df.setTimeZone(TimeZone.getTimeZone("GMT"));
497            String eventTime = df.format(new Date(slice.getTime() * 1000));
498            txtEventStart.setText(eventTime);
499        }
500    }
501//
502//    /**
503//     * @param args the command line arguments
504//     */
505//    public static void main(String args[])
506//    {
507//        java.awt.EventQueue.invokeLater(new Runnable()
508//        {
509//            public void run()
510//            {
511//                new Editor(new IncidentEditorFrame(
512//                        new ScriptIncident(100, null, null, null),
513//                        new ScriptBuilderFrame())).setVisible(true);
514//            }
515//        });
516//    }
517
518    // Variables declaration - do not modify//GEN-BEGIN:variables
519    private javax.swing.JCheckBoxMenuItem ATMS;
520    private javax.swing.JCheckBoxMenuItem ActivityLog;
521    private javax.swing.JMenuItem Audio;
522    private javax.swing.JCheckBoxMenuItem CAD;
523    private javax.swing.JMenuItem CADLog;
524    private javax.swing.JMenuItem CCTV;
525    private javax.swing.JCheckBoxMenuItem CHPRadio;
526    private javax.swing.JMenuItem CMS;
527    private javax.swing.JCheckBoxMenuItem Facilitator;
528    private javax.swing.JCheckBoxMenuItem MaintenanceRadio;
529    private javax.swing.JMenuItem Paramics;
530    private javax.swing.JCheckBoxMenuItem Radio;
531    private javax.swing.JCheckBoxMenuItem TMTRadio;
532    private javax.swing.JCheckBoxMenuItem Telephone;
533    private javax.swing.JMenuItem Tow;
534    private javax.swing.JMenuItem Unit;
535    private javax.swing.JMenuItem Witness;
536    private javax.swing.JPanel bottomFramePanel;
537    private javax.swing.JButton btnRemoveCurrentEvent;
538    private javax.swing.JMenuBar editorMenuBar;
539    private javax.swing.JTabbedPane eventTabsPane;
540    private javax.swing.JMenu menuAutoData;
541    private javax.swing.JMenu menuEvaluations;
542    private javax.swing.JMenu menuInstructor;
543    private javax.swing.JTextField txtEventStart;
544    // End of variables declaration//GEN-END:variables
545
546    @Override
547    public void update(Observable o, Object arg)
548    {
549
550        final PropertyUpdate update = (PropertyUpdate) arg;
551        final ImageIcon image = update.getPanel().getProperty().getImage();
552        final String caption = update.getPanel().title();
553
554        final JLabel title = new JLabel(caption, image, JLabel.CENTER);
555
556        /*
557         final BorderLayout layout = new BorderLayout();
558         final JPanel title = new JPanel(layout);
559         title.setOpaque(false);
560         title.add(new JLabel(image), BorderLayout.WEST);
561         title.add(new JLabel(caption), BorderLayout.EAST);
562         */
563        if (update.getType() == UpdateType.Add)
564        {
565            eventTabsPane.insertTab(null, null,
566                    update.getPanel().getPanel(), null, update.getPosition());
567            eventTabsPane.setTabComponentAt(update.getPosition(), title);
568            eventTabsPane.setSelectedIndex(update.getPosition());
569            topFrame.repaint();
570        }
571        else if (update.getType() == UpdateType.Remove)
572        {
573            eventTabsPane.remove(update.getPanel().getPanel());
574            topFrame.repaint();
575        }
576        else if (update.getType() == UpdateType.TitleChange)
577        {
578            final int index = eventTabsPane.indexOfComponent(
579                    update.getPanel().getPanel());
580
581            new Thread(new Runnable()
582            {
583                public void run()
584                {
585                    Color c = eventTabsPane.getForegroundAt(index);
586                    eventTabsPane.setForegroundAt(index, Color.blue);
587                    try
588                    {
589                        Thread.sleep(350);
590                    }
591                    catch (Exception e)
592                    {
593                    }
594                    if (index < eventTabsPane.getTabCount())
595                    {
596                        eventTabsPane.setTabComponentAt(index, title);
597                    }
598                    try
599                    {
600                        Thread.sleep(350);
601                    }
602                    catch (Exception e)
603                    {
604                    }
605                    if (index < eventTabsPane.getTabCount())
606                    {
607                        eventTabsPane.setForegroundAt(index, c);
608                    }
609                }
610            }).start();
611        }
612        else
613        {
614            throw new RuntimeException("UpdateType not accounted for");
615        }
616    }
617
618}
Note: See TracBrowser for help on using the repository browser.