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

Revision 102, 23.8 KB checked in by bmcguffin, 9 years ago (diff)

Commented out main() method.

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 < jMenuBar1.getMenuCount(); menuCtr++)
103        {
104            // for each menu item
105            for (java.awt.Component comp : jMenuBar1.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        jPanel1 = new javax.swing.JPanel();
167        jTabbedPane1 = new javax.swing.JTabbedPane();
168        jPanel2 = new javax.swing.JPanel();
169        txtEventStart = new javax.swing.JTextField();
170        btnRemoveCurrentEvent = new javax.swing.JButton();
171        jMenuBar1 = new javax.swing.JMenuBar();
172        jMenu1 = new javax.swing.JMenu();
173        ATMS = new javax.swing.JCheckBoxMenuItem();
174        ActivityLog = new javax.swing.JCheckBoxMenuItem();
175        CAD = new javax.swing.JCheckBoxMenuItem();
176        CMS = new javax.swing.JMenuItem();
177        Facilitator = new javax.swing.JCheckBoxMenuItem();
178        Radio = new javax.swing.JCheckBoxMenuItem();
179        JMenu2 = new javax.swing.JMenu();
180        MaintenanceRadio = new javax.swing.JCheckBoxMenuItem();
181        TMTRadio = new javax.swing.JCheckBoxMenuItem();
182        Telephone = new javax.swing.JCheckBoxMenuItem();
183        jMenu3 = new javax.swing.JMenu();
184        Audio = new javax.swing.JMenuItem();
185        CADLog = new javax.swing.JMenuItem();
186        CCTV = new javax.swing.JMenuItem();
187        CHPRadio = new javax.swing.JCheckBoxMenuItem();
188        Paramics = new javax.swing.JMenuItem();
189        Tow = new javax.swing.JMenuItem();
190        Unit = new javax.swing.JMenuItem();
191        Witness = new javax.swing.JMenuItem();
192
193        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
194        jPanel1.setLayout(jPanel1Layout);
195        jPanel1Layout.setHorizontalGroup(
196            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
197            .add(0, 100, Short.MAX_VALUE)
198        );
199        jPanel1Layout.setVerticalGroup(
200            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
201            .add(0, 100, Short.MAX_VALUE)
202        );
203
204        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
205        setTitle("Event Editor");
206
207        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
208        jPanel2.setLayout(jPanel2Layout);
209        jPanel2Layout.setHorizontalGroup(
210            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
211            .add(0, 613, Short.MAX_VALUE)
212        );
213        jPanel2Layout.setVerticalGroup(
214            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
215            .add(0, 34, Short.MAX_VALUE)
216        );
217
218        txtEventStart.setText("00:00:00");
219
220        btnRemoveCurrentEvent.setText("Remove This Event");
221        btnRemoveCurrentEvent.addActionListener(new java.awt.event.ActionListener()
222        {
223            public void actionPerformed(java.awt.event.ActionEvent evt)
224            {
225                btnRemoveCurrentEventActionPerformed(evt);
226            }
227        });
228
229        jMenu1.setText("Evaluations");
230
231        ATMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
232        ATMS.setText("ATMS");
233        ATMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ATMSEval.png"))); // NOI18N
234        ATMS.addActionListener(new java.awt.event.ActionListener()
235        {
236            public void actionPerformed(java.awt.event.ActionEvent evt)
237            {
238                multipleChange(evt);
239            }
240        });
241        jMenu1.add(ATMS);
242
243        ActivityLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
244        ActivityLog.setText("Activity Log");
245        ActivityLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ActivityLogEval.png"))); // NOI18N
246        ActivityLog.addActionListener(new java.awt.event.ActionListener()
247        {
248            public void actionPerformed(java.awt.event.ActionEvent evt)
249            {
250                multipleChange(evt);
251            }
252        });
253        jMenu1.add(ActivityLog);
254
255        CAD.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
256        CAD.setText("CAD");
257        CAD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CADEval.png"))); // NOI18N
258        CAD.addActionListener(new java.awt.event.ActionListener()
259        {
260            public void actionPerformed(java.awt.event.ActionEvent evt)
261            {
262                multipleChange(evt);
263            }
264        });
265        jMenu1.add(CAD);
266
267        CMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
268        CMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CMSEval.png"))); // NOI18N
269        CMS.setText("CMS");
270        CMS.addMouseListener(new java.awt.event.MouseAdapter()
271        {
272            public void mouseClicked(java.awt.event.MouseEvent evt)
273            {
274                multipleChangeListener(evt);
275            }
276        });
277        CMS.addActionListener(new java.awt.event.ActionListener()
278        {
279            public void actionPerformed(java.awt.event.ActionEvent evt)
280            {
281                multipleChange(evt);
282            }
283        });
284        jMenu1.add(CMS);
285
286        Facilitator.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
287        Facilitator.setText("Facilitator");
288        Facilitator.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FacilitatorEval.png"))); // NOI18N
289        Facilitator.addActionListener(new java.awt.event.ActionListener()
290        {
291            public void actionPerformed(java.awt.event.ActionEvent evt)
292            {
293                optionalChange(evt);
294            }
295        });
296        jMenu1.add(Facilitator);
297
298        Radio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
299        Radio.setText("Radio");
300        Radio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/RadioEval.png"))); // NOI18N
301        Radio.addActionListener(new java.awt.event.ActionListener()
302        {
303            public void actionPerformed(java.awt.event.ActionEvent evt)
304            {
305                optionalChange(evt);
306            }
307        });
308        jMenu1.add(Radio);
309
310        jMenuBar1.add(jMenu1);
311
312        JMenu2.setText("Instructor Actions");
313
314        MaintenanceRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
315        MaintenanceRadio.setText("Maintenance Radio");
316        MaintenanceRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MaintenanceRadio.png"))); // NOI18N
317        MaintenanceRadio.addActionListener(new java.awt.event.ActionListener()
318        {
319            public void actionPerformed(java.awt.event.ActionEvent evt)
320            {
321                optionalChange(evt);
322            }
323        });
324        JMenu2.add(MaintenanceRadio);
325
326        TMTRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
327        TMTRadio.setText("TMT Radio");
328        TMTRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TMTRadio.png"))); // NOI18N
329        TMTRadio.addActionListener(new java.awt.event.ActionListener()
330        {
331            public void actionPerformed(java.awt.event.ActionEvent evt)
332            {
333                optionalChange(evt);
334            }
335        });
336        JMenu2.add(TMTRadio);
337
338        Telephone.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
339        Telephone.setText("Telephone");
340        Telephone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Telephone.png"))); // NOI18N
341        Telephone.addActionListener(new java.awt.event.ActionListener()
342        {
343            public void actionPerformed(java.awt.event.ActionEvent evt)
344            {
345                optionalChange(evt);
346            }
347        });
348        JMenu2.add(Telephone);
349
350        jMenuBar1.add(JMenu2);
351
352        jMenu3.setText("Automated Data");
353
354        Audio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
355        Audio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Audio.png"))); // NOI18N
356        Audio.setText("Audio");
357        jMenu3.add(Audio);
358
359        CADLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
360        CADLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CAD.png"))); // NOI18N
361        CADLog.setText("CAD Log");
362        jMenu3.add(CADLog);
363
364        CCTV.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
365        CCTV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CCTV.png"))); // NOI18N
366        CCTV.setText("CCTV");
367        jMenu3.add(CCTV);
368
369        CHPRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
370        CHPRadio.setText("CHP Radio");
371        CHPRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CHPRadio.png"))); // NOI18N
372        CHPRadio.addActionListener(new java.awt.event.ActionListener()
373        {
374            public void actionPerformed(java.awt.event.ActionEvent evt)
375            {
376                optionalChange(evt);
377            }
378        });
379        jMenu3.add(CHPRadio);
380
381        Paramics.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
382        Paramics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Paramics.png"))); // NOI18N
383        Paramics.setText("Paramics");
384        jMenu3.add(Paramics);
385
386        Tow.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
387        Tow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Tow.png"))); // NOI18N
388        Tow.setText("Tow");
389        jMenu3.add(Tow);
390
391        Unit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
392        Unit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unit.png"))); // NOI18N
393        Unit.setText("Unit");
394        jMenu3.add(Unit);
395
396        Witness.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
397        Witness.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Witness.png"))); // NOI18N
398        Witness.setText("Witness");
399        jMenu3.add(Witness);
400
401        jMenuBar1.add(jMenu3);
402
403        setJMenuBar(jMenuBar1);
404
405        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
406        getContentPane().setLayout(layout);
407        layout.setHorizontalGroup(
408            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
409            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTabbedPane1)
410            .add(layout.createSequentialGroup()
411                .addContainerGap()
412                .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
413                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
414                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
415                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
416                .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
417                .addContainerGap())
418        );
419        layout.setVerticalGroup(
420            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
421            .add(layout.createSequentialGroup()
422                .addContainerGap()
423                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 534, Short.MAX_VALUE)
424                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
425                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
426                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
427                    .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
428                    .add(btnRemoveCurrentEvent)))
429        );
430
431        pack();
432    }// </editor-fold>//GEN-END:initComponents
433
434    private void multipleChangeListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_multipleChangeListener
435
436    }//GEN-LAST:event_multipleChangeListener
437
438    private void multipleChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleChange
439
440    }//GEN-LAST:event_multipleChange
441
442    private void optionalChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionalChange
443
444    }//GEN-LAST:event_optionalChange
445
446    private void btnRemoveCurrentEventActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnRemoveCurrentEventActionPerformed
447    {//GEN-HEADEREND:event_btnRemoveCurrentEventActionPerformed
448
449        int index = jTabbedPane1.getSelectedIndex();
450
451        if (index >= 0 && jTabbedPane1.getTabComponentAt(index) != null)
452        {
453            JPanel removable = (JPanel) jTabbedPane1
454                    .getSelectedComponent();
455            this.model.properties.removeProperty(removable);
456        }
457
458    }//GEN-LAST:event_btnRemoveCurrentEventActionPerformed
459
460    private void updateEventTime()
461    {
462        String[] tokens = txtEventStart.getText().split(":");
463
464        int hrs = Integer.parseInt(tokens[0]);
465        int mins = Integer.parseInt(tokens[1]);
466        int secs = Integer.parseInt(tokens[2]);
467
468        int time = (3600 * hrs) + (60 * mins) + secs;
469
470        int index = jTabbedPane1.getSelectedIndex();
471
472        if (index >= 0 && jTabbedPane1.getTabComponentAt(index) != null)
473        {
474            JPanel removable = (JPanel) jTabbedPane1
475                    .getSelectedComponent();
476            I_ScriptEvent ise = this.model.eventMap.get(removable);
477            if (time != slice.getTime())
478            {
479                System.out.println("New time = " + time);
480                this.model.properties.removeProperty(removable);
481                incident.addNewEvent(ise, time);
482                SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
483                df.setTimeZone(TimeZone.getTimeZone("GMT"));
484                String eventTime = df.format(new Date(slice.getTime() * 1000));
485                txtEventStart.setText(eventTime);
486            }
487        }
488    }
489//
490//    /**
491//     * @param args the command line arguments
492//     */
493//    public static void main(String args[])
494//    {
495//        java.awt.EventQueue.invokeLater(new Runnable()
496//        {
497//            public void run()
498//            {
499//                new Editor(new IncidentEditorFrame(
500//                        new ScriptIncident(100, null, null, null),
501//                        new ScriptBuilderFrame())).setVisible(true);
502//            }
503//        });
504//    }
505
506    // Variables declaration - do not modify//GEN-BEGIN:variables
507    private javax.swing.JCheckBoxMenuItem ATMS;
508    private javax.swing.JCheckBoxMenuItem ActivityLog;
509    private javax.swing.JMenuItem Audio;
510    private javax.swing.JCheckBoxMenuItem CAD;
511    private javax.swing.JMenuItem CADLog;
512    private javax.swing.JMenuItem CCTV;
513    private javax.swing.JCheckBoxMenuItem CHPRadio;
514    private javax.swing.JMenuItem CMS;
515    private javax.swing.JCheckBoxMenuItem Facilitator;
516    private javax.swing.JMenu JMenu2;
517    private javax.swing.JCheckBoxMenuItem MaintenanceRadio;
518    private javax.swing.JMenuItem Paramics;
519    private javax.swing.JCheckBoxMenuItem Radio;
520    private javax.swing.JCheckBoxMenuItem TMTRadio;
521    private javax.swing.JCheckBoxMenuItem Telephone;
522    private javax.swing.JMenuItem Tow;
523    private javax.swing.JMenuItem Unit;
524    private javax.swing.JMenuItem Witness;
525    private javax.swing.JButton btnRemoveCurrentEvent;
526    private javax.swing.JMenu jMenu1;
527    private javax.swing.JMenu jMenu3;
528    private javax.swing.JMenuBar jMenuBar1;
529    private javax.swing.JPanel jPanel1;
530    private javax.swing.JPanel jPanel2;
531    private javax.swing.JTabbedPane jTabbedPane1;
532    private javax.swing.JTextField txtEventStart;
533    // End of variables declaration//GEN-END:variables
534
535    @Override
536    public void update(Observable o, Object arg)
537    {
538
539        final PropertyUpdate update = (PropertyUpdate) arg;
540        final ImageIcon image = update.getPanel().getProperty().getImage();
541        final String caption = update.getPanel().title();
542
543        final JLabel title = new JLabel(caption, image, JLabel.CENTER);
544
545        /*
546         final BorderLayout layout = new BorderLayout();
547         final JPanel title = new JPanel(layout);
548         title.setOpaque(false);
549         title.add(new JLabel(image), BorderLayout.WEST);
550         title.add(new JLabel(caption), BorderLayout.EAST);
551         */
552        if (update.getType() == UpdateType.Add)
553        {
554            jTabbedPane1.insertTab(null, null,
555                    update.getPanel().getPanel(), null, update.getPosition());
556            jTabbedPane1.setTabComponentAt(update.getPosition(), title);
557            jTabbedPane1.setSelectedIndex(update.getPosition());
558            topFrame.repaint();
559        }
560        else if (update.getType() == UpdateType.Remove)
561        {
562            jTabbedPane1.remove(update.getPanel().getPanel());
563            if (update.getPanel().getPanel() instanceof I_ScriptEventEditorPanel)
564            {
565                ((I_ScriptEventEditorPanel) update.getPanel().getPanel()).removeAssociatedEvent();
566            }
567            topFrame.repaint();
568        }
569        else if (update.getType() == UpdateType.TitleChange)
570        {
571            final int index = jTabbedPane1.indexOfComponent(
572                    update.getPanel().getPanel());
573
574            new Thread(new Runnable()
575            {
576                public void run()
577                {
578                    Color c = jTabbedPane1.getForegroundAt(index);
579                    jTabbedPane1.setForegroundAt(index, Color.blue);
580                    try
581                    {
582                        Thread.sleep(350);
583                    }
584                    catch (Exception e)
585                    {
586                    }
587                    if (index < jTabbedPane1.getTabCount())
588                    {
589                        jTabbedPane1.setTabComponentAt(index, title);
590                    }
591                    try
592                    {
593                        Thread.sleep(350);
594                    }
595                    catch (Exception e)
596                    {
597                    }
598                    if (index < jTabbedPane1.getTabCount())
599                    {
600                        jTabbedPane1.setForegroundAt(index, c);
601                    }
602                }
603            }).start();
604        }
605        else
606        {
607            throw new RuntimeException("UpdateType not accounted for");
608        }
609    }
610
611}
Note: See TracBrowser for help on using the repository browser.