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

Revision 165, 33.6 KB checked in by sdanthin, 6 years ago (diff)

Editor.java added a check to make moving an audioEvent possible - would still be nice to have some sort of greyed-out option.

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