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

Revision 119, 23.4 KB checked in by bmcguffin, 9 years ago (diff)

Fixed a bug which caused an event to be destroyed if it was the only event in its incident and the user attempted to change its start time. (See  http://git.tokomak.net:8888/ticket/20 for more details.)

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