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

Revision 180, 32.5 KB checked in by sdanthin, 6 years ago (diff)

PropertyPanels?.java added a function to get properties from a certain jPanel.
Editor.java used above function to auto-close the editor window when it has no more events contained.
AudioPanel?.java modified to NOT allow audioEvents in the Event Editor to be deleted.

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.ScriptBuilderGuiConstants;
14import scriptbuilder.gui.panels.IncidentTimelinePanel;
15import scriptbuilder.structures.ScriptEvent;
16import scriptbuilder.structures.ScriptIncident;
17import scriptbuilder.structures.TimeSlice;
18import scriptbuilder.structures.events.*;
19
20public class Editor extends javax.swing.JFrame implements Observer
21{
22
23    IncidentEditorFrame topFrame = null;
24
25    ScriptIncident incident = null;
26
27    TimeSlice slice = null;
28
29    private PropertyModel model = new PropertyModel();
30
31    public void addEvent(Properties property, I_ScriptEvent se)
32    {
33        model.addEventPanel(property, se);
34    }
35    /**
36     * adds all of the events from the timeslice to the incidentTimelinePanel
37     * @param ts the timeslice to be added
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           
58            List<Integer> timesS = timeGenerator(eventTime,"s");
59            List<Integer> timesM = timeGenerator(eventTime,"m");
60            List<Integer> timesH = timeGenerator(eventTime,"h");
61            timeHourComboSelector.setModel(new DefaultComboBoxModel(timesH.toArray()));
62            timeMinuteComboSelector.setModel(new DefaultComboBoxModel(timesM.toArray()));
63            timeSecondComboSelector.setModel(new DefaultComboBoxModel(timesS.toArray()));
64            timeHourComboSelector.setSelectedItem(slice.getTime()/3600);
65            timeMinuteComboSelector.setSelectedItem((slice.getTime()%3600)/60);
66            timeSecondComboSelector.setSelectedItem(slice.getTime()%60);
67        }
68
69    }
70   
71    private List<Integer> timeGenerator(String time,String type)
72    {
73        List<Integer> times = new ArrayList<Integer>();
74        String[] timeArray = time.split(":");
75        int currTime = 0;
76        switch(type)
77        {
78            case "h":
79            {
80                currTime = Integer.parseInt(timeArray[0]);
81                for(int i = 0;i< ScriptBuilderGuiConstants.MAX_SIMULATION_LENGTH/3600;i++)
82                {
83                    times.add(i);
84                }
85                break;
86            }
87            case "m":
88            {
89                currTime = Integer.parseInt(timeArray[1]);
90                for(int i = 0; i<60;i++)
91                {
92                    times.add(i);
93                }
94               
95                break;
96            }
97            case "s":
98            {
99                //includes times 0,20,40,80
100                currTime = Integer.parseInt(timeArray[2]); 
101                for(int i = 0; i<60;i+=ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION)
102                {
103                    times.add(i);
104                }
105                break;
106            }
107            default:
108            {
109            }
110               
111        }
112       
113       
114        //times.add(time);
115       
116        return times;
117    }
118   
119   
120
121    private ActionListener optionalChangeListener = new ActionListener()
122    {
123        public void actionPerformed(ActionEvent evt)
124        {
125            JCheckBoxMenuItem src = (JCheckBoxMenuItem) evt.getSource();
126            Properties property = Properties.valueOf(src.getText().replaceAll(" ", ""));
127
128            if (src.isSelected())
129            {
130                model.addEventFromDropdown(property, incident, slice);
131            }
132            else
133            {
134                model.removeProperty(property);
135            }
136        }
137    };
138
139    private ActionListener multipleChangeListener = new ActionListener()
140    {
141        public void actionPerformed(ActionEvent evt)
142        {
143            JMenuItem src = (JMenuItem) evt.getSource();
144            Properties property = Properties.valueOf(src.getText().replaceAll(" ", ""));
145            model.addEventFromDropdown(property, incident, slice);
146        }
147    };
148
149    /**
150     * Blank constructor for a new editor.
151     */
152    public Editor(IncidentEditorFrame frame)
153    {
154        topFrame = frame;
155        initComponents();
156
157        incident = frame.getIncident();
158
159        model.addObserver(this);
160
161        // For each menu
162        for (int menuCtr = 0; menuCtr < editorMenuBar.getMenuCount(); menuCtr++)
163        {
164            // for each menu item
165            for (java.awt.Component comp : editorMenuBar.getMenu(menuCtr).getMenuComponents())
166            {
167                JMenuItem item = (JMenuItem) comp;
168
169                String itemName = item.getText().replaceAll(" ", "");
170
171                Properties property = Properties.valueOf(itemName);
172
173                if (property.getType() == PropertyTypes.Multiple)
174                {
175                    item.addActionListener(multipleChangeListener);
176                }
177                else if (property.getType() == PropertyTypes.Optional)
178                {
179                    item.addActionListener(optionalChangeListener);
180                }
181                else
182                {
183                    throw new RuntimeException("Property type not accounted for");
184                }
185            }
186
187        }
188        //this eventTime might need to be initialized to the correct time
189        String eventTime = "";
190
191       
192        this.addWindowListener(new WindowAdapter()
193        {
194            @Override
195            public void windowClosing(WindowEvent e)
196            {
197                //Add previous offset back in
198                //If we didn't adjust the offset, this will just set it to the old value
199                //If we deleted the first event(s), this will add the offsets,
200                //to ensure that events stay at the correct times
201                Object[] options = {"Yes","Cancel"};
202                    int result = JOptionPane.showOptionDialog(null,"Are you sure you want to exit without saving?",
203                            "Exit",
204                            JOptionPane.YES_NO_OPTION,
205                            JOptionPane.QUESTION_MESSAGE,
206                            null,
207                            options,
208                            options[1]);
209                    switch (result){
210                        //should just close
211                        case 0:
212                            closeWindow();
213                            //this.setVisible(true);
214                            break;
215                        // should do nothing
216                        case 1:
217                           
218                            break;
219                        default:
220                            break;
221                    }
222                //add a do you want to close without saving popup window here
223               
224            }
225        });
226    }
227    private void closeWindow(){
228        this.dispose();
229    }
230
231    /**
232     * This method is called from within the constructor to initialize the form.
233     * WARNING: Do NOT modify this code. The content of this method is always
234     * regenerated by the Form Editor.
235     */
236    @SuppressWarnings("unchecked")
237    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
238    private void initComponents() {
239
240        eventTabsPane = new javax.swing.JTabbedPane();
241        bottomFramePanel = new javax.swing.JPanel();
242        saveCloseBtn = new javax.swing.JButton();
243        btnRemoveCurrentEvent = new javax.swing.JButton();
244        timeSecondComboSelector = new javax.swing.JComboBox<>();
245        timeMinuteComboSelector = new javax.swing.JComboBox<>();
246        timeHourComboSelector = new javax.swing.JComboBox<>();
247        jLabel1 = new javax.swing.JLabel();
248        jLabel2 = new javax.swing.JLabel();
249        jLabel3 = new javax.swing.JLabel();
250        editorMenuBar = new javax.swing.JMenuBar();
251        menuEvaluations = new javax.swing.JMenu();
252        ATMS = new javax.swing.JCheckBoxMenuItem();
253        ActivityLog = new javax.swing.JCheckBoxMenuItem();
254        CAD = new javax.swing.JCheckBoxMenuItem();
255        CMS = new javax.swing.JMenuItem();
256        Facilitator = new javax.swing.JCheckBoxMenuItem();
257        Radio = new javax.swing.JCheckBoxMenuItem();
258        menuInstructor = new javax.swing.JMenu();
259        MaintenanceRadio = new javax.swing.JCheckBoxMenuItem();
260        TMTRadio = new javax.swing.JCheckBoxMenuItem();
261        Telephone = new javax.swing.JCheckBoxMenuItem();
262        menuAutoData = new javax.swing.JMenu();
263        Audio = new javax.swing.JMenuItem();
264        CADLog = new javax.swing.JMenuItem();
265        CCTV = new javax.swing.JMenuItem();
266        CHPRadio = new javax.swing.JCheckBoxMenuItem();
267        Paramics = new javax.swing.JMenuItem();
268        Tow = new javax.swing.JMenuItem();
269        Unit = new javax.swing.JMenuItem();
270        Witness = new javax.swing.JMenuItem();
271
272        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
273        setTitle("Event Editor");
274
275        org.jdesktop.layout.GroupLayout bottomFramePanelLayout = new org.jdesktop.layout.GroupLayout(bottomFramePanel);
276        bottomFramePanel.setLayout(bottomFramePanelLayout);
277        bottomFramePanelLayout.setHorizontalGroup(
278            bottomFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
279            .add(0, 70, Short.MAX_VALUE)
280        );
281        bottomFramePanelLayout.setVerticalGroup(
282            bottomFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
283            .add(0, 45, Short.MAX_VALUE)
284        );
285
286        saveCloseBtn.setText("Save and Close");
287        saveCloseBtn.addActionListener(new java.awt.event.ActionListener() {
288            public void actionPerformed(java.awt.event.ActionEvent evt) {
289                saveCloseBtnActionPerformed(evt);
290            }
291        });
292
293        btnRemoveCurrentEvent.setText("Remove This Event");
294        btnRemoveCurrentEvent.addActionListener(new java.awt.event.ActionListener() {
295            public void actionPerformed(java.awt.event.ActionEvent evt) {
296                btnRemoveCurrentEventActionPerformed(evt);
297            }
298        });
299
300        timeSecondComboSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Second" }));
301        timeSecondComboSelector.addActionListener(new java.awt.event.ActionListener() {
302            public void actionPerformed(java.awt.event.ActionEvent evt) {
303                timeSecondComboSelectorActionPerformed(evt);
304            }
305        });
306
307        timeMinuteComboSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Minute" }));
308        timeMinuteComboSelector.addActionListener(new java.awt.event.ActionListener() {
309            public void actionPerformed(java.awt.event.ActionEvent evt) {
310                timeMinuteComboSelectorActionPerformed(evt);
311            }
312        });
313
314        timeHourComboSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Hour" }));
315        timeHourComboSelector.addActionListener(new java.awt.event.ActionListener() {
316            public void actionPerformed(java.awt.event.ActionEvent evt) {
317                timeHourComboSelectorActionPerformed(evt);
318            }
319        });
320
321        jLabel1.setText("Hour");
322
323        jLabel2.setText("Minute");
324
325        jLabel3.setText("Second");
326
327        menuEvaluations.setText("Evaluations");
328
329        ATMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
330        ATMS.setText("ATMS");
331        ATMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ATMSEval.png"))); // NOI18N
332        ATMS.addActionListener(new java.awt.event.ActionListener() {
333            public void actionPerformed(java.awt.event.ActionEvent evt) {
334                multipleChange(evt);
335            }
336        });
337        menuEvaluations.add(ATMS);
338
339        ActivityLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
340        ActivityLog.setText("Activity Log");
341        ActivityLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ActivityLogEval.png"))); // NOI18N
342        ActivityLog.addActionListener(new java.awt.event.ActionListener() {
343            public void actionPerformed(java.awt.event.ActionEvent evt) {
344                multipleChange(evt);
345            }
346        });
347        menuEvaluations.add(ActivityLog);
348
349        CAD.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
350        CAD.setText("CAD");
351        CAD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CADEval.png"))); // NOI18N
352        CAD.addActionListener(new java.awt.event.ActionListener() {
353            public void actionPerformed(java.awt.event.ActionEvent evt) {
354                multipleChange(evt);
355            }
356        });
357        menuEvaluations.add(CAD);
358
359        CMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
360        CMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CMSEval.png"))); // NOI18N
361        CMS.setText("CMS");
362        CMS.addMouseListener(new java.awt.event.MouseAdapter() {
363            public void mouseClicked(java.awt.event.MouseEvent evt) {
364                multipleChangeListener(evt);
365            }
366        });
367        CMS.addActionListener(new java.awt.event.ActionListener() {
368            public void actionPerformed(java.awt.event.ActionEvent evt) {
369                multipleChange(evt);
370            }
371        });
372        menuEvaluations.add(CMS);
373
374        Facilitator.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
375        Facilitator.setText("Facilitator");
376        Facilitator.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FacilitatorEval.png"))); // NOI18N
377        Facilitator.addActionListener(new java.awt.event.ActionListener() {
378            public void actionPerformed(java.awt.event.ActionEvent evt) {
379                optionalChange(evt);
380            }
381        });
382        menuEvaluations.add(Facilitator);
383
384        Radio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
385        Radio.setText("Radio");
386        Radio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/RadioEval.png"))); // NOI18N
387        Radio.addActionListener(new java.awt.event.ActionListener() {
388            public void actionPerformed(java.awt.event.ActionEvent evt) {
389                optionalChange(evt);
390            }
391        });
392        menuEvaluations.add(Radio);
393
394        editorMenuBar.add(menuEvaluations);
395
396        menuInstructor.setText("Instructor Actions");
397
398        MaintenanceRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
399        MaintenanceRadio.setText("Maintenance Radio");
400        MaintenanceRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MaintenanceRadio.png"))); // NOI18N
401        MaintenanceRadio.addActionListener(new java.awt.event.ActionListener() {
402            public void actionPerformed(java.awt.event.ActionEvent evt) {
403                optionalChange(evt);
404            }
405        });
406        menuInstructor.add(MaintenanceRadio);
407
408        TMTRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
409        TMTRadio.setText("TMT Radio");
410        TMTRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TMTRadio.png"))); // NOI18N
411        TMTRadio.addActionListener(new java.awt.event.ActionListener() {
412            public void actionPerformed(java.awt.event.ActionEvent evt) {
413                optionalChange(evt);
414            }
415        });
416        menuInstructor.add(TMTRadio);
417
418        Telephone.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
419        Telephone.setText("Telephone");
420        Telephone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Telephone.png"))); // NOI18N
421        Telephone.addActionListener(new java.awt.event.ActionListener() {
422            public void actionPerformed(java.awt.event.ActionEvent evt) {
423                optionalChange(evt);
424            }
425        });
426        menuInstructor.add(Telephone);
427
428        editorMenuBar.add(menuInstructor);
429
430        menuAutoData.setText("Automated Data");
431
432        Audio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
433        Audio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Audio.png"))); // NOI18N
434        Audio.setText("Audio");
435        Audio.addActionListener(new java.awt.event.ActionListener() {
436            public void actionPerformed(java.awt.event.ActionEvent evt) {
437                AudioActionPerformed(evt);
438            }
439        });
440        menuAutoData.add(Audio);
441
442        CADLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
443        CADLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CAD.png"))); // NOI18N
444        CADLog.setText("CAD Log");
445        menuAutoData.add(CADLog);
446
447        CCTV.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
448        CCTV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CCTV.png"))); // NOI18N
449        CCTV.setText("CCTV");
450        menuAutoData.add(CCTV);
451
452        CHPRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
453        CHPRadio.setText("CHP Radio");
454        CHPRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CHPRadio.png"))); // NOI18N
455        CHPRadio.addActionListener(new java.awt.event.ActionListener() {
456            public void actionPerformed(java.awt.event.ActionEvent evt) {
457                optionalChange(evt);
458            }
459        });
460        menuAutoData.add(CHPRadio);
461
462        Paramics.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
463        Paramics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Paramics.png"))); // NOI18N
464        Paramics.setText("Paramics");
465        menuAutoData.add(Paramics);
466
467        Tow.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
468        Tow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Tow.png"))); // NOI18N
469        Tow.setText("Tow");
470        menuAutoData.add(Tow);
471
472        Unit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
473        Unit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unit.png"))); // NOI18N
474        Unit.setText("Unit");
475        menuAutoData.add(Unit);
476
477        Witness.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
478        Witness.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Witness.png"))); // NOI18N
479        Witness.setText("Witness");
480        menuAutoData.add(Witness);
481
482        editorMenuBar.add(menuAutoData);
483
484        setJMenuBar(editorMenuBar);
485
486        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
487        getContentPane().setLayout(layout);
488        layout.setHorizontalGroup(
489            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
490            .add(org.jdesktop.layout.GroupLayout.TRAILING, eventTabsPane)
491            .add(layout.createSequentialGroup()
492                .add(84, 84, 84)
493                .add(jLabel1)
494                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
495                .add(timeHourComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
496                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
497                .add(jLabel2)
498                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
499                .add(timeMinuteComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
500                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
501                .add(jLabel3)
502                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
503                .add(timeSecondComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
504                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
505                .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
506                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
507                .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
508                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
509                .add(saveCloseBtn)
510                .addContainerGap())
511        );
512        layout.setVerticalGroup(
513            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
514            .add(layout.createSequentialGroup()
515                .addContainerGap()
516                .add(eventTabsPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 523, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
517                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
518                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
519                    .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
520                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
521                        .add(timeSecondComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
522                        .add(timeMinuteComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
523                        .add(timeHourComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
524                        .add(jLabel1)
525                        .add(jLabel2)
526                        .add(jLabel3))
527                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
528                        .add(saveCloseBtn)
529                        .add(btnRemoveCurrentEvent))))
530        );
531
532        pack();
533    }// </editor-fold>//GEN-END:initComponents
534
535    private void multipleChangeListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_multipleChangeListener
536
537    }//GEN-LAST:event_multipleChangeListener
538
539    private void multipleChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleChange
540
541    }//GEN-LAST:event_multipleChange
542
543    private void optionalChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionalChange
544
545    }//GEN-LAST:event_optionalChange
546
547    private void btnRemoveCurrentEventActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnRemoveCurrentEventActionPerformed
548    {//GEN-HEADEREND:event_btnRemoveCurrentEventActionPerformed
549
550        int index = eventTabsPane.getSelectedIndex();
551        //checks if there is a component at the tab selected, if so, then remove the associated event from the data model,
552        //and if it is removed, then remove the associated editor window.
553        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
554        {
555            JPanel removable = (JPanel) eventTabsPane
556                    .getSelectedComponent();
557            PropertyPanel removedProperty = this.model.properties.getProperty(removable);
558           
559            if(((I_ScriptEventEditorPanel) removedProperty.getPanel()).removeAssociatedEvent())
560            {
561                this.model.properties.removeProperty(removable);
562            }
563
564        }
565       
566        //prevents an "empty editor" from appearing
567        if(eventTabsPane.getSelectedComponent() == null)
568        {
569            updateEventTime();
570            this.closeWindow();
571        }
572
573    }//GEN-LAST:event_btnRemoveCurrentEventActionPerformed
574
575    private void AudioActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_AudioActionPerformed
576    {//GEN-HEADEREND:event_AudioActionPerformed
577        // TODO add your handling code here:
578    }//GEN-LAST:event_AudioActionPerformed
579
580    private void saveCloseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCloseBtnActionPerformed
581        // TODO add your handling code here:
582        //closes the current frame
583       
584        //updateEventTime();
585       
586        updateEventTime();
587       
588        model.closePanels();
589        closeWindow();
590        //this.dispatchEvent(new WindowEvent(this,WindowEvent.WINDOW_CLOSING));
591    }//GEN-LAST:event_saveCloseBtnActionPerformed
592
593    private void timeSecondComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeSecondComboSelectorActionPerformed
594        // TODO add your handling code here:
595    }//GEN-LAST:event_timeSecondComboSelectorActionPerformed
596
597    private void timeMinuteComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeMinuteComboSelectorActionPerformed
598        // TODO add your handling code here:
599    }//GEN-LAST:event_timeMinuteComboSelectorActionPerformed
600
601    private void timeHourComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeHourComboSelectorActionPerformed
602        // TODO add your handling code here:
603    }//GEN-LAST:event_timeHourComboSelectorActionPerformed
604
605    private void updateEventTime()
606    {
607       
608//        String[] tokens = txtEventStart.getText().split(":");
609//       
610//        int hrs = Integer.parseInt(tokens[0]);
611//        int mins = Integer.parseInt(tokens[1]);
612//        int secs = Integer.parseInt(tokens[2]);
613        int hrs = Integer.parseInt(timeHourComboSelector.getSelectedItem().toString());
614        int mins = Integer.parseInt(timeMinuteComboSelector.getSelectedItem().toString());
615        int secs = Integer.parseInt(timeSecondComboSelector.getSelectedItem().toString());
616       
617
618        int newTime = (3600 * hrs) + (60 * mins) + secs;
619
620        int index = eventTabsPane.getSelectedIndex();
621
622        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
623        {
624            JPanel removable = (JPanel) eventTabsPane
625                    .getSelectedComponent();
626            I_ScriptEvent ise = this.model.eventMap.get(removable);
627            if (newTime != slice.getTime() && !(ise instanceof AudioEvent) && incident.changeEventStart(ise, slice.getTime(), newTime))
628            {
629                this.model.properties.removeProperty(removable);
630
631            }
632//            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
633//            df.setTimeZone(TimeZone.getTimeZone("GMT"));
634//            String eventTime = df.format(new Date(slice.getTime() * 1000));
635//            txtEventStart.setText(eventTime);
636        }
637        slice.checkEmpty();
638    }
639//
640//    /**
641//     * @param args the command line arguments
642//     */
643//    public static void main(String args[])
644//    {
645//        java.awt.EventQueue.invokeLater(new Runnable()
646//        {
647//            public void run()
648//            {
649//                new Editor(new IncidentEditorFrame(
650//                        new ScriptIncident(100, null, null, null),
651//                        new ScriptBuilderFrame())).setVisible(true);
652//            }
653//        });
654//    }
655
656    // Variables declaration - do not modify//GEN-BEGIN:variables
657    private javax.swing.JCheckBoxMenuItem ATMS;
658    private javax.swing.JCheckBoxMenuItem ActivityLog;
659    private javax.swing.JMenuItem Audio;
660    private javax.swing.JCheckBoxMenuItem CAD;
661    private javax.swing.JMenuItem CADLog;
662    private javax.swing.JMenuItem CCTV;
663    private javax.swing.JCheckBoxMenuItem CHPRadio;
664    private javax.swing.JMenuItem CMS;
665    private javax.swing.JCheckBoxMenuItem Facilitator;
666    private javax.swing.JCheckBoxMenuItem MaintenanceRadio;
667    private javax.swing.JMenuItem Paramics;
668    private javax.swing.JCheckBoxMenuItem Radio;
669    private javax.swing.JCheckBoxMenuItem TMTRadio;
670    private javax.swing.JCheckBoxMenuItem Telephone;
671    private javax.swing.JMenuItem Tow;
672    private javax.swing.JMenuItem Unit;
673    private javax.swing.JMenuItem Witness;
674    private javax.swing.JPanel bottomFramePanel;
675    private javax.swing.JButton btnRemoveCurrentEvent;
676    private javax.swing.JMenuBar editorMenuBar;
677    private javax.swing.JTabbedPane eventTabsPane;
678    private javax.swing.JLabel jLabel1;
679    private javax.swing.JLabel jLabel2;
680    private javax.swing.JLabel jLabel3;
681    private javax.swing.JMenu menuAutoData;
682    private javax.swing.JMenu menuEvaluations;
683    private javax.swing.JMenu menuInstructor;
684    private javax.swing.JButton saveCloseBtn;
685    private javax.swing.JComboBox<String> timeHourComboSelector;
686    private javax.swing.JComboBox<String> timeMinuteComboSelector;
687    private javax.swing.JComboBox<String> timeSecondComboSelector;
688    // End of variables declaration//GEN-END:variables
689
690    @Override
691    public void update(Observable o, Object arg)
692    {
693
694        final PropertyUpdate update = (PropertyUpdate) arg;
695        final ImageIcon image = update.getPanel().getProperty().getImage();
696        final String caption = update.getPanel().title();
697
698        final JLabel title = new JLabel(caption, image, JLabel.CENTER);
699
700        /*
701         final BorderLayout layout = new BorderLayout();
702         final JPanel title = new JPanel(layout);
703         title.setOpaque(false);
704         title.add(new JLabel(image), BorderLayout.WEST);
705         title.add(new JLabel(caption), BorderLayout.EAST);
706         */
707        if (update.getType() == UpdateType.Add)
708        {
709            eventTabsPane.insertTab(null, null,
710                    update.getPanel().getPanel(), null, update.getPosition());
711            eventTabsPane.setTabComponentAt(update.getPosition(), title);
712            eventTabsPane.setSelectedIndex(update.getPosition());
713            topFrame.repaint();
714        }
715        else if (update.getType() == UpdateType.Remove)
716        {
717            eventTabsPane.remove(update.getPanel().getPanel());
718            topFrame.repaint();
719        }
720        else if (update.getType() == UpdateType.TitleChange)
721        {
722            final int index = eventTabsPane.indexOfComponent(
723                    update.getPanel().getPanel());
724
725            new Thread(new Runnable()
726            {
727                public void run()
728                {
729                    Color c = eventTabsPane.getForegroundAt(index);
730                    eventTabsPane.setForegroundAt(index, Color.blue);
731                    try
732                    {
733                        Thread.sleep(350);
734                    }
735                    catch (Exception e)
736                    {
737                    }
738                    if (index < eventTabsPane.getTabCount())
739                    {
740                        eventTabsPane.setTabComponentAt(index, title);
741                    }
742                    try
743                    {
744                        Thread.sleep(350);
745                    }
746                    catch (Exception e)
747                    {
748                    }
749                    if (index < eventTabsPane.getTabCount())
750                    {
751                        eventTabsPane.setForegroundAt(index, c);
752                    }
753                }
754            }).start();
755        }
756        else
757        {
758            throw new RuntimeException("UpdateType not accounted for");
759        }
760    }
761
762}
Note: See TracBrowser for help on using the repository browser.