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

Revision 186, 32.4 KB checked in by jdalbey, 6 years ago (diff)

event.editor.frame.Editor.java change names and order of items in main menu to be consistent with panels in Incident Editor

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 = {"Cancel","OK"};
202                int result = JOptionPane.showOptionDialog(null,
203                        "Are you sure you want to exit without saving?",
204                        "Confirm Exit",
205                        JOptionPane.OK_CANCEL_OPTION,
206                        JOptionPane.QUESTION_MESSAGE,
207                        null,
208                        options,
209                        options[1]);
210                // Take action depending on user choice
211                switch (result)
212                {
213                    //OK: should just close
214                    case 1:
215                        closeWindow();
216                        break;
217                    // Cancel: should do nothing
218                    case 0:                           
219                        break;
220                    default:
221                        break;
222                }
223            }
224        });
225    }
226    private void closeWindow(){
227        this.dispose();
228    }
229
230    /**
231     * This method is called from within the constructor to initialize the form.
232     * WARNING: Do NOT modify this code. The content of this method is always
233     * regenerated by the Form Editor.
234     */
235    @SuppressWarnings("unchecked")
236    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
237    private void initComponents() {
238
239        eventTabsPane = new javax.swing.JTabbedPane();
240        bottomFramePanel = new javax.swing.JPanel();
241        saveCloseBtn = new javax.swing.JButton();
242        btnRemoveCurrentEvent = new javax.swing.JButton();
243        timeSecondComboSelector = new javax.swing.JComboBox<>();
244        timeMinuteComboSelector = new javax.swing.JComboBox<>();
245        timeHourComboSelector = new javax.swing.JComboBox<>();
246        jLabel1 = new javax.swing.JLabel();
247        jLabel2 = new javax.swing.JLabel();
248        jLabel3 = new javax.swing.JLabel();
249        editorMenuBar = new javax.swing.JMenuBar();
250        menuAutoData = new javax.swing.JMenu();
251        Audio = new javax.swing.JMenuItem();
252        CADLog = new javax.swing.JMenuItem();
253        CCTV = new javax.swing.JMenuItem();
254        CHPRadio = new javax.swing.JCheckBoxMenuItem();
255        Paramics = new javax.swing.JMenuItem();
256        Tow = new javax.swing.JMenuItem();
257        Unit = new javax.swing.JMenuItem();
258        Witness = new javax.swing.JMenuItem();
259        menuInstructor = new javax.swing.JMenu();
260        MaintenanceRadio = new javax.swing.JCheckBoxMenuItem();
261        TMTRadio = new javax.swing.JCheckBoxMenuItem();
262        Telephone = new javax.swing.JCheckBoxMenuItem();
263        menuEvaluations = new javax.swing.JMenu();
264        ATMS = new javax.swing.JCheckBoxMenuItem();
265        ActivityLog = new javax.swing.JCheckBoxMenuItem();
266        CAD = new javax.swing.JCheckBoxMenuItem();
267        CMS = new javax.swing.JMenuItem();
268        Facilitator = new javax.swing.JCheckBoxMenuItem();
269        Radio = new javax.swing.JCheckBoxMenuItem();
270
271        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
272        setTitle("Event Editor");
273
274        org.jdesktop.layout.GroupLayout bottomFramePanelLayout = new org.jdesktop.layout.GroupLayout(bottomFramePanel);
275        bottomFramePanel.setLayout(bottomFramePanelLayout);
276        bottomFramePanelLayout.setHorizontalGroup(
277            bottomFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
278            .add(0, 70, Short.MAX_VALUE)
279        );
280        bottomFramePanelLayout.setVerticalGroup(
281            bottomFramePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
282            .add(0, 45, Short.MAX_VALUE)
283        );
284
285        saveCloseBtn.setText("Save and Close");
286        saveCloseBtn.addActionListener(new java.awt.event.ActionListener() {
287            public void actionPerformed(java.awt.event.ActionEvent evt) {
288                saveCloseBtnActionPerformed(evt);
289            }
290        });
291
292        btnRemoveCurrentEvent.setText("Remove This Event");
293        btnRemoveCurrentEvent.addActionListener(new java.awt.event.ActionListener() {
294            public void actionPerformed(java.awt.event.ActionEvent evt) {
295                btnRemoveCurrentEventActionPerformed(evt);
296            }
297        });
298
299        timeSecondComboSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Second" }));
300        timeSecondComboSelector.addActionListener(new java.awt.event.ActionListener() {
301            public void actionPerformed(java.awt.event.ActionEvent evt) {
302                timeSecondComboSelectorActionPerformed(evt);
303            }
304        });
305
306        timeMinuteComboSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Minute" }));
307        timeMinuteComboSelector.addActionListener(new java.awt.event.ActionListener() {
308            public void actionPerformed(java.awt.event.ActionEvent evt) {
309                timeMinuteComboSelectorActionPerformed(evt);
310            }
311        });
312
313        timeHourComboSelector.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Hour" }));
314        timeHourComboSelector.addActionListener(new java.awt.event.ActionListener() {
315            public void actionPerformed(java.awt.event.ActionEvent evt) {
316                timeHourComboSelectorActionPerformed(evt);
317            }
318        });
319
320        jLabel1.setText("Hour");
321
322        jLabel2.setText("Minute");
323
324        jLabel3.setText("Second");
325
326        menuAutoData.setText("Automated Events");
327
328        Audio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
329        Audio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Audio.png"))); // NOI18N
330        Audio.setText("Audio");
331        Audio.addActionListener(new java.awt.event.ActionListener() {
332            public void actionPerformed(java.awt.event.ActionEvent evt) {
333                AudioActionPerformed(evt);
334            }
335        });
336        menuAutoData.add(Audio);
337
338        CADLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
339        CADLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CAD.png"))); // NOI18N
340        CADLog.setText("CAD Log");
341        menuAutoData.add(CADLog);
342
343        CCTV.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
344        CCTV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CCTV.png"))); // NOI18N
345        CCTV.setText("CCTV");
346        menuAutoData.add(CCTV);
347
348        CHPRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
349        CHPRadio.setText("CHP Radio");
350        CHPRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CHPRadio.png"))); // NOI18N
351        CHPRadio.addActionListener(new java.awt.event.ActionListener() {
352            public void actionPerformed(java.awt.event.ActionEvent evt) {
353                optionalChange(evt);
354            }
355        });
356        menuAutoData.add(CHPRadio);
357
358        Paramics.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
359        Paramics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Paramics.png"))); // NOI18N
360        Paramics.setText("Paramics");
361        menuAutoData.add(Paramics);
362
363        Tow.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
364        Tow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Tow.png"))); // NOI18N
365        Tow.setText("Tow");
366        menuAutoData.add(Tow);
367
368        Unit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
369        Unit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unit.png"))); // NOI18N
370        Unit.setText("Unit");
371        menuAutoData.add(Unit);
372
373        Witness.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
374        Witness.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Witness.png"))); // NOI18N
375        Witness.setText("Witness");
376        menuAutoData.add(Witness);
377
378        editorMenuBar.add(menuAutoData);
379
380        menuInstructor.setText("Instructor Actions");
381
382        MaintenanceRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
383        MaintenanceRadio.setText("Maintenance Radio");
384        MaintenanceRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MaintenanceRadio.png"))); // NOI18N
385        MaintenanceRadio.addActionListener(new java.awt.event.ActionListener() {
386            public void actionPerformed(java.awt.event.ActionEvent evt) {
387                optionalChange(evt);
388            }
389        });
390        menuInstructor.add(MaintenanceRadio);
391
392        TMTRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
393        TMTRadio.setText("TMT Radio");
394        TMTRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TMTRadio.png"))); // NOI18N
395        TMTRadio.addActionListener(new java.awt.event.ActionListener() {
396            public void actionPerformed(java.awt.event.ActionEvent evt) {
397                optionalChange(evt);
398            }
399        });
400        menuInstructor.add(TMTRadio);
401
402        Telephone.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
403        Telephone.setText("Telephone");
404        Telephone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Telephone.png"))); // NOI18N
405        Telephone.addActionListener(new java.awt.event.ActionListener() {
406            public void actionPerformed(java.awt.event.ActionEvent evt) {
407                optionalChange(evt);
408            }
409        });
410        menuInstructor.add(Telephone);
411
412        editorMenuBar.add(menuInstructor);
413
414        menuEvaluations.setText("Evaluation Actions");
415
416        ATMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
417        ATMS.setText("ATMS");
418        ATMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ATMSEval.png"))); // NOI18N
419        ATMS.addActionListener(new java.awt.event.ActionListener() {
420            public void actionPerformed(java.awt.event.ActionEvent evt) {
421                multipleChange(evt);
422            }
423        });
424        menuEvaluations.add(ATMS);
425
426        ActivityLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
427        ActivityLog.setText("Activity Log");
428        ActivityLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ActivityLogEval.png"))); // NOI18N
429        ActivityLog.addActionListener(new java.awt.event.ActionListener() {
430            public void actionPerformed(java.awt.event.ActionEvent evt) {
431                multipleChange(evt);
432            }
433        });
434        menuEvaluations.add(ActivityLog);
435
436        CAD.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
437        CAD.setText("CAD");
438        CAD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CADEval.png"))); // NOI18N
439        CAD.addActionListener(new java.awt.event.ActionListener() {
440            public void actionPerformed(java.awt.event.ActionEvent evt) {
441                multipleChange(evt);
442            }
443        });
444        menuEvaluations.add(CAD);
445
446        CMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
447        CMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CMSEval.png"))); // NOI18N
448        CMS.setText("CMS");
449        CMS.addMouseListener(new java.awt.event.MouseAdapter() {
450            public void mouseClicked(java.awt.event.MouseEvent evt) {
451                multipleChangeListener(evt);
452            }
453        });
454        CMS.addActionListener(new java.awt.event.ActionListener() {
455            public void actionPerformed(java.awt.event.ActionEvent evt) {
456                multipleChange(evt);
457            }
458        });
459        menuEvaluations.add(CMS);
460
461        Facilitator.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
462        Facilitator.setText("Facilitator");
463        Facilitator.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FacilitatorEval.png"))); // NOI18N
464        Facilitator.addActionListener(new java.awt.event.ActionListener() {
465            public void actionPerformed(java.awt.event.ActionEvent evt) {
466                optionalChange(evt);
467            }
468        });
469        menuEvaluations.add(Facilitator);
470
471        Radio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
472        Radio.setText("Radio");
473        Radio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/RadioEval.png"))); // NOI18N
474        Radio.addActionListener(new java.awt.event.ActionListener() {
475            public void actionPerformed(java.awt.event.ActionEvent evt) {
476                optionalChange(evt);
477            }
478        });
479        menuEvaluations.add(Radio);
480
481        editorMenuBar.add(menuEvaluations);
482
483        setJMenuBar(editorMenuBar);
484
485        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
486        getContentPane().setLayout(layout);
487        layout.setHorizontalGroup(
488            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
489            .add(org.jdesktop.layout.GroupLayout.TRAILING, eventTabsPane)
490            .add(layout.createSequentialGroup()
491                .add(84, 84, 84)
492                .add(jLabel1)
493                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
494                .add(timeHourComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
495                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
496                .add(jLabel2)
497                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
498                .add(timeMinuteComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
499                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
500                .add(jLabel3)
501                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
502                .add(timeSecondComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
503                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
504                .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
505                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
506                .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
507                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
508                .add(saveCloseBtn)
509                .addContainerGap())
510        );
511        layout.setVerticalGroup(
512            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
513            .add(layout.createSequentialGroup()
514                .addContainerGap()
515                .add(eventTabsPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 523, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
516                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
517                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
518                    .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
519                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
520                        .add(timeSecondComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
521                        .add(timeMinuteComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
522                        .add(timeHourComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
523                        .add(jLabel1)
524                        .add(jLabel2)
525                        .add(jLabel3))
526                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
527                        .add(saveCloseBtn)
528                        .add(btnRemoveCurrentEvent))))
529        );
530
531        pack();
532    }// </editor-fold>//GEN-END:initComponents
533
534    private void multipleChangeListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_multipleChangeListener
535
536    }//GEN-LAST:event_multipleChangeListener
537
538    private void multipleChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleChange
539
540    }//GEN-LAST:event_multipleChange
541
542    private void optionalChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionalChange
543
544    }//GEN-LAST:event_optionalChange
545
546    private void btnRemoveCurrentEventActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnRemoveCurrentEventActionPerformed
547    {//GEN-HEADEREND:event_btnRemoveCurrentEventActionPerformed
548
549        int index = eventTabsPane.getSelectedIndex();
550        //checks if there is a component at the tab selected, if so, then remove the associated event from the data model,
551        //and if it is removed, then remove the associated editor window.
552        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
553        {
554            JPanel removable = (JPanel) eventTabsPane
555                    .getSelectedComponent();
556            PropertyPanel removedProperty = this.model.properties.getProperty(removable);
557           
558            if(((I_ScriptEventEditorPanel) removedProperty.getPanel()).removeAssociatedEvent())
559            {
560                this.model.properties.removeProperty(removable);
561            }
562
563        }
564       
565        //prevents an "empty editor" from appearing
566        if(eventTabsPane.getSelectedComponent() == null)
567        {
568            updateEventTime();
569            this.closeWindow();
570        }
571
572    }//GEN-LAST:event_btnRemoveCurrentEventActionPerformed
573
574    private void AudioActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_AudioActionPerformed
575    {//GEN-HEADEREND:event_AudioActionPerformed
576        // TODO add your handling code here:
577    }//GEN-LAST:event_AudioActionPerformed
578
579    private void saveCloseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCloseBtnActionPerformed
580        // TODO add your handling code here:
581        //closes the current frame
582       
583        //updateEventTime();
584       
585        updateEventTime();
586       
587        model.closePanels();
588        closeWindow();
589        //this.dispatchEvent(new WindowEvent(this,WindowEvent.WINDOW_CLOSING));
590    }//GEN-LAST:event_saveCloseBtnActionPerformed
591
592    private void timeSecondComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeSecondComboSelectorActionPerformed
593        // TODO add your handling code here:
594    }//GEN-LAST:event_timeSecondComboSelectorActionPerformed
595
596    private void timeMinuteComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeMinuteComboSelectorActionPerformed
597        // TODO add your handling code here:
598    }//GEN-LAST:event_timeMinuteComboSelectorActionPerformed
599
600    private void timeHourComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeHourComboSelectorActionPerformed
601        // TODO add your handling code here:
602    }//GEN-LAST:event_timeHourComboSelectorActionPerformed
603
604    private void updateEventTime()
605    {
606       
607//        String[] tokens = txtEventStart.getText().split(":");
608//       
609//        int hrs = Integer.parseInt(tokens[0]);
610//        int mins = Integer.parseInt(tokens[1]);
611//        int secs = Integer.parseInt(tokens[2]);
612        int hrs = Integer.parseInt(timeHourComboSelector.getSelectedItem().toString());
613        int mins = Integer.parseInt(timeMinuteComboSelector.getSelectedItem().toString());
614        int secs = Integer.parseInt(timeSecondComboSelector.getSelectedItem().toString());
615       
616
617        int newTime = (3600 * hrs) + (60 * mins) + secs;
618
619        int index = eventTabsPane.getSelectedIndex();
620
621        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
622        {
623            JPanel removable = (JPanel) eventTabsPane
624                    .getSelectedComponent();
625            I_ScriptEvent ise = this.model.eventMap.get(removable);
626            if (newTime != slice.getTime() && !(ise instanceof AudioEvent) && incident.changeEventStart(ise, slice.getTime(), newTime))
627            {
628                this.model.properties.removeProperty(removable);
629
630            }
631//            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
632//            df.setTimeZone(TimeZone.getTimeZone("GMT"));
633//            String eventTime = df.format(new Date(slice.getTime() * 1000));
634//            txtEventStart.setText(eventTime);
635        }
636        slice.checkEmpty();
637    }
638//
639//    /**
640//     * @param args the command line arguments
641//     */
642//    public static void main(String args[])
643//    {
644//        java.awt.EventQueue.invokeLater(new Runnable()
645//        {
646//            public void run()
647//            {
648//                new Editor(new IncidentEditorFrame(
649//                        new ScriptIncident(100, null, null, null),
650//                        new ScriptBuilderFrame())).setVisible(true);
651//            }
652//        });
653//    }
654
655    // Variables declaration - do not modify//GEN-BEGIN:variables
656    private javax.swing.JCheckBoxMenuItem ATMS;
657    private javax.swing.JCheckBoxMenuItem ActivityLog;
658    private javax.swing.JMenuItem Audio;
659    private javax.swing.JCheckBoxMenuItem CAD;
660    private javax.swing.JMenuItem CADLog;
661    private javax.swing.JMenuItem CCTV;
662    private javax.swing.JCheckBoxMenuItem CHPRadio;
663    private javax.swing.JMenuItem CMS;
664    private javax.swing.JCheckBoxMenuItem Facilitator;
665    private javax.swing.JCheckBoxMenuItem MaintenanceRadio;
666    private javax.swing.JMenuItem Paramics;
667    private javax.swing.JCheckBoxMenuItem Radio;
668    private javax.swing.JCheckBoxMenuItem TMTRadio;
669    private javax.swing.JCheckBoxMenuItem Telephone;
670    private javax.swing.JMenuItem Tow;
671    private javax.swing.JMenuItem Unit;
672    private javax.swing.JMenuItem Witness;
673    private javax.swing.JPanel bottomFramePanel;
674    private javax.swing.JButton btnRemoveCurrentEvent;
675    private javax.swing.JMenuBar editorMenuBar;
676    private javax.swing.JTabbedPane eventTabsPane;
677    private javax.swing.JLabel jLabel1;
678    private javax.swing.JLabel jLabel2;
679    private javax.swing.JLabel jLabel3;
680    private javax.swing.JMenu menuAutoData;
681    private javax.swing.JMenu menuEvaluations;
682    private javax.swing.JMenu menuInstructor;
683    private javax.swing.JButton saveCloseBtn;
684    private javax.swing.JComboBox<String> timeHourComboSelector;
685    private javax.swing.JComboBox<String> timeMinuteComboSelector;
686    private javax.swing.JComboBox<String> timeSecondComboSelector;
687    // End of variables declaration//GEN-END:variables
688
689    @Override
690    public void update(Observable o, Object arg)
691    {
692
693        final PropertyUpdate update = (PropertyUpdate) arg;
694        final ImageIcon image = update.getPanel().getProperty().getImage();
695        final String caption = update.getPanel().title();
696
697        final JLabel title = new JLabel(caption, image, JLabel.CENTER);
698
699        /*
700         final BorderLayout layout = new BorderLayout();
701         final JPanel title = new JPanel(layout);
702         title.setOpaque(false);
703         title.add(new JLabel(image), BorderLayout.WEST);
704         title.add(new JLabel(caption), BorderLayout.EAST);
705         */
706        if (update.getType() == UpdateType.Add)
707        {
708            eventTabsPane.insertTab(null, null,
709                    update.getPanel().getPanel(), null, update.getPosition());
710            eventTabsPane.setTabComponentAt(update.getPosition(), title);
711            eventTabsPane.setSelectedIndex(update.getPosition());
712            topFrame.repaint();
713        }
714        else if (update.getType() == UpdateType.Remove)
715        {
716            eventTabsPane.remove(update.getPanel().getPanel());
717            topFrame.repaint();
718        }
719        else if (update.getType() == UpdateType.TitleChange)
720        {
721            final int index = eventTabsPane.indexOfComponent(
722                    update.getPanel().getPanel());
723
724            new Thread(new Runnable()
725            {
726                public void run()
727                {
728                    Color c = eventTabsPane.getForegroundAt(index);
729                    eventTabsPane.setForegroundAt(index, Color.blue);
730                    try
731                    {
732                        Thread.sleep(350);
733                    }
734                    catch (Exception e)
735                    {
736                    }
737                    if (index < eventTabsPane.getTabCount())
738                    {
739                        eventTabsPane.setTabComponentAt(index, title);
740                    }
741                    try
742                    {
743                        Thread.sleep(350);
744                    }
745                    catch (Exception e)
746                    {
747                    }
748                    if (index < eventTabsPane.getTabCount())
749                    {
750                        eventTabsPane.setForegroundAt(index, c);
751                    }
752                }
753            }).start();
754        }
755        else
756        {
757            throw new RuntimeException("UpdateType not accounted for");
758        }
759    }
760
761}
Note: See TracBrowser for help on using the repository browser.