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

Revision 145, 33.1 KB checked in by sdanthin, 7 years ago (diff)

Move from Git to Svn (LARGE COMMIT)

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
347        jLabel1.setText("Hour");
348
349        jLabel2.setText("Minute");
350
351        jLabel3.setText("Second");
352
353        menuEvaluations.setText("Evaluations");
354
355        ATMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
356        ATMS.setText("ATMS");
357        ATMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ATMSEval.png"))); // NOI18N
358        ATMS.addActionListener(new java.awt.event.ActionListener() {
359            public void actionPerformed(java.awt.event.ActionEvent evt) {
360                multipleChange(evt);
361            }
362        });
363        menuEvaluations.add(ATMS);
364
365        ActivityLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
366        ActivityLog.setText("Activity Log");
367        ActivityLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ActivityLogEval.png"))); // NOI18N
368        ActivityLog.addActionListener(new java.awt.event.ActionListener() {
369            public void actionPerformed(java.awt.event.ActionEvent evt) {
370                multipleChange(evt);
371            }
372        });
373        menuEvaluations.add(ActivityLog);
374
375        CAD.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
376        CAD.setText("CAD");
377        CAD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CADEval.png"))); // NOI18N
378        CAD.addActionListener(new java.awt.event.ActionListener() {
379            public void actionPerformed(java.awt.event.ActionEvent evt) {
380                multipleChange(evt);
381            }
382        });
383        menuEvaluations.add(CAD);
384
385        CMS.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
386        CMS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CMSEval.png"))); // NOI18N
387        CMS.setText("CMS");
388        CMS.addMouseListener(new java.awt.event.MouseAdapter() {
389            public void mouseClicked(java.awt.event.MouseEvent evt) {
390                multipleChangeListener(evt);
391            }
392        });
393        CMS.addActionListener(new java.awt.event.ActionListener() {
394            public void actionPerformed(java.awt.event.ActionEvent evt) {
395                multipleChange(evt);
396            }
397        });
398        menuEvaluations.add(CMS);
399
400        Facilitator.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
401        Facilitator.setText("Facilitator");
402        Facilitator.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FacilitatorEval.png"))); // NOI18N
403        Facilitator.addActionListener(new java.awt.event.ActionListener() {
404            public void actionPerformed(java.awt.event.ActionEvent evt) {
405                optionalChange(evt);
406            }
407        });
408        menuEvaluations.add(Facilitator);
409
410        Radio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
411        Radio.setText("Radio");
412        Radio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/RadioEval.png"))); // NOI18N
413        Radio.addActionListener(new java.awt.event.ActionListener() {
414            public void actionPerformed(java.awt.event.ActionEvent evt) {
415                optionalChange(evt);
416            }
417        });
418        menuEvaluations.add(Radio);
419
420        editorMenuBar.add(menuEvaluations);
421
422        menuInstructor.setText("Instructor Actions");
423
424        MaintenanceRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
425        MaintenanceRadio.setText("Maintenance Radio");
426        MaintenanceRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/MaintenanceRadio.png"))); // NOI18N
427        MaintenanceRadio.addActionListener(new java.awt.event.ActionListener() {
428            public void actionPerformed(java.awt.event.ActionEvent evt) {
429                optionalChange(evt);
430            }
431        });
432        menuInstructor.add(MaintenanceRadio);
433
434        TMTRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
435        TMTRadio.setText("TMT Radio");
436        TMTRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/TMTRadio.png"))); // NOI18N
437        TMTRadio.addActionListener(new java.awt.event.ActionListener() {
438            public void actionPerformed(java.awt.event.ActionEvent evt) {
439                optionalChange(evt);
440            }
441        });
442        menuInstructor.add(TMTRadio);
443
444        Telephone.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
445        Telephone.setText("Telephone");
446        Telephone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Telephone.png"))); // NOI18N
447        Telephone.addActionListener(new java.awt.event.ActionListener() {
448            public void actionPerformed(java.awt.event.ActionEvent evt) {
449                optionalChange(evt);
450            }
451        });
452        menuInstructor.add(Telephone);
453
454        editorMenuBar.add(menuInstructor);
455
456        menuAutoData.setText("Automated Data");
457
458        Audio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
459        Audio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Audio.png"))); // NOI18N
460        Audio.setText("Audio");
461        Audio.addActionListener(new java.awt.event.ActionListener() {
462            public void actionPerformed(java.awt.event.ActionEvent evt) {
463                AudioActionPerformed(evt);
464            }
465        });
466        menuAutoData.add(Audio);
467
468        CADLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
469        CADLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CAD.png"))); // NOI18N
470        CADLog.setText("CAD Log");
471        menuAutoData.add(CADLog);
472
473        CCTV.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
474        CCTV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CCTV.png"))); // NOI18N
475        CCTV.setText("CCTV");
476        menuAutoData.add(CCTV);
477
478        CHPRadio.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
479        CHPRadio.setText("CHP Radio");
480        CHPRadio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/CHPRadio.png"))); // NOI18N
481        CHPRadio.addActionListener(new java.awt.event.ActionListener() {
482            public void actionPerformed(java.awt.event.ActionEvent evt) {
483                optionalChange(evt);
484            }
485        });
486        menuAutoData.add(CHPRadio);
487
488        Paramics.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
489        Paramics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Paramics.png"))); // NOI18N
490        Paramics.setText("Paramics");
491        menuAutoData.add(Paramics);
492
493        Tow.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
494        Tow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Tow.png"))); // NOI18N
495        Tow.setText("Tow");
496        menuAutoData.add(Tow);
497
498        Unit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
499        Unit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unit.png"))); // NOI18N
500        Unit.setText("Unit");
501        menuAutoData.add(Unit);
502
503        Witness.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
504        Witness.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Witness.png"))); // NOI18N
505        Witness.setText("Witness");
506        menuAutoData.add(Witness);
507
508        editorMenuBar.add(menuAutoData);
509
510        setJMenuBar(editorMenuBar);
511
512        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
513        getContentPane().setLayout(layout);
514        layout.setHorizontalGroup(
515            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
516            .add(org.jdesktop.layout.GroupLayout.TRAILING, eventTabsPane)
517            .add(layout.createSequentialGroup()
518                .addContainerGap()
519                .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
520                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
521                .add(jLabel1)
522                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
523                .add(timeHourComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
524                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
525                .add(jLabel2)
526                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
527                .add(timeMinuteComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
528                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
529                .add(jLabel3)
530                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
531                .add(timeSecondComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
532                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
533                .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
534                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
535                .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
536                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
537                .add(saveCloseBtn)
538                .addContainerGap())
539        );
540        layout.setVerticalGroup(
541            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
542            .add(layout.createSequentialGroup()
543                .addContainerGap()
544                .add(eventTabsPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 523, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
545                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
546                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
547                    .add(bottomFramePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
548                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
549                        .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
550                        .add(timeSecondComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
551                        .add(timeMinuteComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
552                        .add(timeHourComboSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
553                        .add(jLabel1)
554                        .add(jLabel2)
555                        .add(jLabel3))
556                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
557                        .add(saveCloseBtn)
558                        .add(btnRemoveCurrentEvent))))
559        );
560
561        pack();
562    }// </editor-fold>//GEN-END:initComponents
563
564    private void multipleChangeListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_multipleChangeListener
565
566    }//GEN-LAST:event_multipleChangeListener
567
568    private void multipleChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleChange
569
570    }//GEN-LAST:event_multipleChange
571
572    private void optionalChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionalChange
573
574    }//GEN-LAST:event_optionalChange
575
576    private void btnRemoveCurrentEventActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnRemoveCurrentEventActionPerformed
577    {//GEN-HEADEREND:event_btnRemoveCurrentEventActionPerformed
578
579        int index = eventTabsPane.getSelectedIndex();
580
581        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
582        {
583            JPanel removable = (JPanel) eventTabsPane
584                    .getSelectedComponent();
585            PropertyPanel update = this.model.properties.removeProperty(removable);
586
587            ((I_ScriptEventEditorPanel) update.getPanel()).removeAssociatedEvent();
588
589        }
590
591    }//GEN-LAST:event_btnRemoveCurrentEventActionPerformed
592
593    private void AudioActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_AudioActionPerformed
594    {//GEN-HEADEREND:event_AudioActionPerformed
595        // TODO add your handling code here:
596    }//GEN-LAST:event_AudioActionPerformed
597
598    private void saveCloseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCloseBtnActionPerformed
599        // TODO add your handling code here:
600        //closes the current frame
601       
602        //updateEventTime();
603        if(!txtEventStart.getText().equals(""))
604        {
605            updateEventTime();
606        }
607        model.closePanels();
608        closeWindow();
609        //this.dispatchEvent(new WindowEvent(this,WindowEvent.WINDOW_CLOSING));
610    }//GEN-LAST:event_saveCloseBtnActionPerformed
611
612    private void timeSecondComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeSecondComboSelectorActionPerformed
613        // TODO add your handling code here:
614    }//GEN-LAST:event_timeSecondComboSelectorActionPerformed
615
616    private void timeMinuteComboSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeMinuteComboSelectorActionPerformed
617        // TODO add your handling code here:
618    }//GEN-LAST:event_timeMinuteComboSelectorActionPerformed
619
620    private void txtEventStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEventStartActionPerformed
621        // TODO add your handling code here:
622    }//GEN-LAST:event_txtEventStartActionPerformed
623
624    private void updateEventTime()
625    {
626       
627//        String[] tokens = txtEventStart.getText().split(":");
628//       
629//        int hrs = Integer.parseInt(tokens[0]);
630//        int mins = Integer.parseInt(tokens[1]);
631//        int secs = Integer.parseInt(tokens[2]);
632        int hrs = Integer.parseInt(timeHourComboSelector.getSelectedItem().toString());
633        int mins = Integer.parseInt(timeMinuteComboSelector.getSelectedItem().toString());
634        int secs = Integer.parseInt(timeSecondComboSelector.getSelectedItem().toString());
635       
636
637        int newTime = (3600 * hrs) + (60 * mins) + secs;
638
639        int index = eventTabsPane.getSelectedIndex();
640
641        if (index >= 0 && eventTabsPane.getTabComponentAt(index) != null)
642        {
643            JPanel removable = (JPanel) eventTabsPane
644                    .getSelectedComponent();
645            I_ScriptEvent ise = this.model.eventMap.get(removable);
646            if (newTime != slice.getTime() && incident.changeEventStart(ise, slice.getTime(), newTime))
647            {
648                this.model.properties.removeProperty(removable);
649
650            }
651//            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
652//            df.setTimeZone(TimeZone.getTimeZone("GMT"));
653//            String eventTime = df.format(new Date(slice.getTime() * 1000));
654//            txtEventStart.setText(eventTime);
655        }
656    }
657//
658//    /**
659//     * @param args the command line arguments
660//     */
661//    public static void main(String args[])
662//    {
663//        java.awt.EventQueue.invokeLater(new Runnable()
664//        {
665//            public void run()
666//            {
667//                new Editor(new IncidentEditorFrame(
668//                        new ScriptIncident(100, null, null, null),
669//                        new ScriptBuilderFrame())).setVisible(true);
670//            }
671//        });
672//    }
673
674    // Variables declaration - do not modify//GEN-BEGIN:variables
675    private javax.swing.JCheckBoxMenuItem ATMS;
676    private javax.swing.JCheckBoxMenuItem ActivityLog;
677    private javax.swing.JMenuItem Audio;
678    private javax.swing.JCheckBoxMenuItem CAD;
679    private javax.swing.JMenuItem CADLog;
680    private javax.swing.JMenuItem CCTV;
681    private javax.swing.JCheckBoxMenuItem CHPRadio;
682    private javax.swing.JMenuItem CMS;
683    private javax.swing.JCheckBoxMenuItem Facilitator;
684    private javax.swing.JCheckBoxMenuItem MaintenanceRadio;
685    private javax.swing.JMenuItem Paramics;
686    private javax.swing.JCheckBoxMenuItem Radio;
687    private javax.swing.JCheckBoxMenuItem TMTRadio;
688    private javax.swing.JCheckBoxMenuItem Telephone;
689    private javax.swing.JMenuItem Tow;
690    private javax.swing.JMenuItem Unit;
691    private javax.swing.JMenuItem Witness;
692    private javax.swing.JPanel bottomFramePanel;
693    private javax.swing.JButton btnRemoveCurrentEvent;
694    private javax.swing.JMenuBar editorMenuBar;
695    private javax.swing.JTabbedPane eventTabsPane;
696    private javax.swing.JLabel jLabel1;
697    private javax.swing.JLabel jLabel2;
698    private javax.swing.JLabel jLabel3;
699    private javax.swing.JMenu menuAutoData;
700    private javax.swing.JMenu menuEvaluations;
701    private javax.swing.JMenu menuInstructor;
702    private javax.swing.JButton saveCloseBtn;
703    private javax.swing.JComboBox<String> timeHourComboSelector;
704    private javax.swing.JComboBox<String> timeMinuteComboSelector;
705    private javax.swing.JComboBox<String> timeSecondComboSelector;
706    private javax.swing.JTextField txtEventStart;
707    // End of variables declaration//GEN-END:variables
708
709    @Override
710    public void update(Observable o, Object arg)
711    {
712
713        final PropertyUpdate update = (PropertyUpdate) arg;
714        final ImageIcon image = update.getPanel().getProperty().getImage();
715        final String caption = update.getPanel().title();
716
717        final JLabel title = new JLabel(caption, image, JLabel.CENTER);
718
719        /*
720         final BorderLayout layout = new BorderLayout();
721         final JPanel title = new JPanel(layout);
722         title.setOpaque(false);
723         title.add(new JLabel(image), BorderLayout.WEST);
724         title.add(new JLabel(caption), BorderLayout.EAST);
725         */
726        if (update.getType() == UpdateType.Add)
727        {
728            eventTabsPane.insertTab(null, null,
729                    update.getPanel().getPanel(), null, update.getPosition());
730            eventTabsPane.setTabComponentAt(update.getPosition(), title);
731            eventTabsPane.setSelectedIndex(update.getPosition());
732            topFrame.repaint();
733        }
734        else if (update.getType() == UpdateType.Remove)
735        {
736            eventTabsPane.remove(update.getPanel().getPanel());
737            topFrame.repaint();
738        }
739        else if (update.getType() == UpdateType.TitleChange)
740        {
741            final int index = eventTabsPane.indexOfComponent(
742                    update.getPanel().getPanel());
743
744            new Thread(new Runnable()
745            {
746                public void run()
747                {
748                    Color c = eventTabsPane.getForegroundAt(index);
749                    eventTabsPane.setForegroundAt(index, Color.blue);
750                    try
751                    {
752                        Thread.sleep(350);
753                    }
754                    catch (Exception e)
755                    {
756                    }
757                    if (index < eventTabsPane.getTabCount())
758                    {
759                        eventTabsPane.setTabComponentAt(index, title);
760                    }
761                    try
762                    {
763                        Thread.sleep(350);
764                    }
765                    catch (Exception e)
766                    {
767                    }
768                    if (index < eventTabsPane.getTabCount())
769                    {
770                        eventTabsPane.setForegroundAt(index, c);
771                    }
772                }
773            }).start();
774        }
775        else
776        {
777            throw new RuntimeException("UpdateType not accounted for");
778        }
779    }
780
781}
Note: See TracBrowser for help on using the repository browser.