Changeset 145 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java


Ignore:
Timestamp:
11/04/2019 08:14:32 AM (6 years ago)
Author:
sdanthin
Message:

Move from Git to Svn (LARGE COMMIT)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java

    r139 r145  
    1313import java.awt.event.KeyEvent; 
    1414import java.awt.event.KeyListener; 
     15import java.awt.event.WindowAdapter; 
     16import java.awt.event.WindowEvent; 
    1517import java.io.File; 
    1618import java.io.IOException; 
     19import java.io.FileNotFoundException; 
    1720import java.net.URI; 
    1821import java.util.Observable; 
     
    3841import scriptbuilder.structures.TimeSlice; 
    3942import scriptbuilder.structures.events.I_ScriptEvent; 
     43import scriptbuilder.structures.CadData; 
    4044 
    4145/** 
     
    152156        script.addObserver(this); 
    153157        initComponents(); 
     158        addCustomListeners(); 
     159        //add to listener helper method 
     160         
     161         
     162         
    154163        //We don't currently want the button to be present in this window 
    155164        btnAddTime.setVisible(false); 
     
    162171         */ 
    163172        // Set listener for scroll pane 
    164         String t = "Script Builder: "; 
    165         if (script.saveFile == null) 
    166         { 
    167             t += "untitled1.xml"; 
    168         } 
    169         else 
    170         { 
    171             t += script.saveFile.getName(); 
    172         } 
    173         this.setTitle(t); 
     173         
     174         
    174175        AdjustmentListener listener = new MyAdjustmentListener(); 
    175176        timelinesScrollPane.getHorizontalScrollBar().addAdjustmentListener(listener); 
     
    177178        repaint(); 
    178179 
     180    } 
     181     
     182    /** 
     183     * Put all custom non-generated listeners in this method 
     184     */ 
     185    private void addCustomListeners(){ 
     186         
     187        String fileName = "units.xml"; 
     188        File unitFile = new File(fileName); 
     189        script.loadUnitsFromFile(unitFile); 
     190        //listener for window closing 
     191        this.addWindowListener(new WindowAdapter(){ 
     192            @Override 
     193            public void windowClosing(WindowEvent e) 
     194            { 
     195                //System.out.println("Window is closing!" + saved); 
     196 
     197                if(!script.saved){ 
     198                    //System.out.println("window was not saved!"); 
     199                    Object[] options = {"Yes","No","Cancel"}; 
     200                    int result = JOptionPane.showOptionDialog(null,"Would you like to save changes before exiting?", 
     201                            "Exit", 
     202                            JOptionPane.YES_NO_CANCEL_OPTION, 
     203                            JOptionPane.QUESTION_MESSAGE, 
     204                            null, 
     205                            options, 
     206                            options[2]); 
     207                    switch (result){ 
     208                        //should save script then close 
     209                        case 0: 
     210                            fileSaveActionPerformed(null); 
     211                            //System.exit(0); 
     212                            break; 
     213                        // should just exit 
     214                        case 1: 
     215                            System.exit(0); 
     216                            break; 
     217                        // should do nothing 
     218                        case 2: 
     219                            break; 
     220                        default: 
     221                            break; 
     222                    } 
     223                     
     224                     
     225                     
     226                }else{ 
     227                    //should close current window since it is saved already 
     228                    System.exit(0); 
     229                } 
     230            } 
     231        }); 
    179232    } 
    180233 
     
    192245    public void update(Observable o, Object arg) 
    193246    { 
    194         //Three major update types: whole script, and 2 event updates 
     247        checkNeedsSave(); 
    195248        if (arg instanceof SimulationScript) 
    196249        { 
     250             
    197251            script = (SimulationScript) arg; 
    198252 
     
    236290             * model.addElement(i); } gotoIncident.setModel(model);* 
    237291             */ 
     292             
    238293            this.setPreferredSize(this.getSize()); 
    239294            pack(); 
     295             
    240296        } 
    241297        //Mouse has changed focus to a different timeslice 
     
    249305                model.addElement(e); 
    250306            } 
     307             
     308             
     309             
    251310        } 
    252311        //Mouse has changed focus to a different incident timeline panel  
     
    256315 
    257316            //gotoIncident.setSelectedItem(i); 
     317             
    258318        } 
    259319 
     
    267327        //scale the zoom slider such that the most zoomed-out point allows the 
    268328        //entire script to be visible at once 
     329         
     330        //todo: interpret these two calls and make them so that they are more accurate to fit the entire window at once 
    269331        zoomSlider.setMinimum(((timelineTickPanel.getVisibleRect().width - 20) 
    270332                * ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION) 
    271333                / Math.max(script.absoluteLength(), ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH)); 
    272334        zoomSlider.setMaximum(zoomSlider.getMinimum() + 20); 
    273         String t = "Script Builder: "; 
    274         if (script.saveFile == null) 
    275         { 
    276             t += "untitled1.xml"; 
    277         } 
    278         else 
    279         { 
    280             t += script.saveFile.getName(); 
    281         } 
    282         this.setTitle(t); 
     335         
    283336        repaint(); 
    284337    } 
     
    291344    @SuppressWarnings("unchecked") 
    292345    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 
    293     private void initComponents() 
    294     { 
     346    private void initComponents() { 
    295347 
    296348        incidentPopupMenu = new javax.swing.JPopupMenu(); 
     
    333385        incidentColorField = new javax.swing.JTextField(); 
    334386        txtIncidentLength = new javax.swing.JLabel(); 
     387        jLabel1 = new javax.swing.JLabel(); 
     388        addIncidentLocation = new javax.swing.JTextField(); 
     389        jLabel2 = new javax.swing.JLabel(); 
     390        addIncidentType = new javax.swing.JTextField(); 
    335391        addNoiseFrame = new javax.swing.JFrame(); 
    336392        labelRadioChatter = new javax.swing.JLabel(); 
     
    396452        newIncident = new javax.swing.JMenuItem(); 
    397453        deleteIncident = new javax.swing.JMenuItem(); 
     454        deleteIncident1 = new javax.swing.JMenuItem(); 
    398455        jSeparator4 = new javax.swing.JPopupMenu.Separator(); 
    399456        saveIncident = new javax.swing.JMenuItem(); 
     
    401458        generateNoiseMenu = new javax.swing.JMenu(); 
    402459        generateNoiseOption = new javax.swing.JMenuItem(); 
     460        helpMenu1 = new javax.swing.JMenu(); 
     461        loadUnits = new javax.swing.JMenuItem(); 
    403462        helpMenu = new javax.swing.JMenu(); 
    404463        helpTutorial = new javax.swing.JMenuItem(); 
     
    406465 
    407466        popupDeleteIncident.setText("Delete Incident..."); 
     467        popupDeleteIncident.addActionListener(new java.awt.event.ActionListener() { 
     468            public void actionPerformed(java.awt.event.ActionEvent evt) { 
     469                popupDeleteIncidentActionPerformed(evt); 
     470            } 
     471        }); 
    408472        incidentPopupMenu.add(popupDeleteIncident); 
    409473 
    410474        cadEvent.setText("CAD Event"); 
    411         cadEvent.addMouseListener(new java.awt.event.MouseAdapter() 
    412         { 
    413             public void mousePressed(java.awt.event.MouseEvent evt) 
    414             { 
     475        cadEvent.addMouseListener(new java.awt.event.MouseAdapter() { 
     476            public void mousePressed(java.awt.event.MouseEvent evt) { 
    415477                cadEventMousePressed(evt); 
    416478            } 
    417             public void mouseReleased(java.awt.event.MouseEvent evt) 
    418             { 
     479            public void mouseReleased(java.awt.event.MouseEvent evt) { 
    419480                cadEventMouseReleased(evt); 
    420481            } 
    421482        }); 
    422         cadEvent.addActionListener(new java.awt.event.ActionListener() 
    423         { 
    424             public void actionPerformed(java.awt.event.ActionEvent evt) 
    425             { 
     483        cadEvent.addActionListener(new java.awt.event.ActionListener() { 
     484            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    426485                cadEventActionPerformed(evt); 
    427486            } 
     
    433492 
    434493        radioEvent.setText("Radio Event"); 
    435         radioEvent.addMouseListener(new java.awt.event.MouseAdapter() 
    436         { 
    437             public void mousePressed(java.awt.event.MouseEvent evt) 
    438             { 
     494        radioEvent.addMouseListener(new java.awt.event.MouseAdapter() { 
     495            public void mousePressed(java.awt.event.MouseEvent evt) { 
    439496                radioEventMousePressed(evt); 
    440497            } 
     
    490547 
    491548        okButton.setText("OK"); 
    492         okButton.addActionListener(new java.awt.event.ActionListener() 
    493         { 
    494             public void actionPerformed(java.awt.event.ActionEvent evt) 
    495             { 
     549        okButton.addActionListener(new java.awt.event.ActionListener() { 
     550            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    496551                okButtonActionPerformed(evt); 
    497552            } 
     
    499554 
    500555        cancelButton.setText("Cancel"); 
    501         cancelButton.addActionListener(new java.awt.event.ActionListener() 
    502         { 
    503             public void actionPerformed(java.awt.event.ActionEvent evt) 
    504             { 
     556        cancelButton.addActionListener(new java.awt.event.ActionListener() { 
     557            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    505558                cancelButtonActionPerformed(evt); 
    506559            } 
     
    545598 
    546599        editEventList.setText("Edit..."); 
    547         editEventList.addActionListener(new java.awt.event.ActionListener() 
    548         { 
    549             public void actionPerformed(java.awt.event.ActionEvent evt) 
    550             { 
     600        editEventList.addActionListener(new java.awt.event.ActionListener() { 
     601            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    551602                editEventListActionPerformed(evt); 
    552603            } 
     
    578629 
    579630        incidentOkButton.setText("OK"); 
    580         incidentOkButton.addActionListener(new java.awt.event.ActionListener() 
    581         { 
    582             public void actionPerformed(java.awt.event.ActionEvent evt) 
    583             { 
     631        incidentOkButton.addActionListener(new java.awt.event.ActionListener() { 
     632            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    584633                incidentOkButtonActionPerformed(evt); 
    585634            } 
     
    587636 
    588637        incidentCancelButton.setText("Cancel"); 
    589         incidentCancelButton.addActionListener(new java.awt.event.ActionListener() 
    590         { 
    591             public void actionPerformed(java.awt.event.ActionEvent evt) 
    592             { 
     638        incidentCancelButton.addActionListener(new java.awt.event.ActionListener() { 
     639            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    593640                incidentCancelButtonActionPerformed(evt); 
    594641            } 
    595642        }); 
    596643 
    597         addIncidentNumber.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(101), Integer.valueOf(101), null, Integer.valueOf(1))); 
     644        addIncidentNumber.setModel(new javax.swing.SpinnerNumberModel(101, 101, null, 1)); 
     645 
     646        addIncidentName.addActionListener(new java.awt.event.ActionListener() { 
     647            public void actionPerformed(java.awt.event.ActionEvent evt) { 
     648                addIncidentNameActionPerformed(evt); 
     649            } 
     650        }); 
    598651 
    599652        labelIncidentLength.setText("Incident Length in Minutes: "); 
     
    601654        labelIncidentStart.setText("Incident Start Time in Minutes:"); 
    602655 
    603         addIncidentStart.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1))); 
     656        addIncidentStart.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1)); 
    604657 
    605658        btnChooseColor.setText("Choose..."); 
    606         btnChooseColor.addActionListener(new java.awt.event.ActionListener() 
    607         { 
    608             public void actionPerformed(java.awt.event.ActionEvent evt) 
    609             { 
     659        btnChooseColor.addActionListener(new java.awt.event.ActionListener() { 
     660            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    610661                btnChooseColorActionPerformed(evt); 
    611662            } 
     
    618669        txtIncidentLength.setText("0"); 
    619670        txtIncidentLength.setToolTipText(""); 
     671 
     672        jLabel1.setText("Incident Location:"); 
     673 
     674        addIncidentLocation.addActionListener(new java.awt.event.ActionListener() { 
     675            public void actionPerformed(java.awt.event.ActionEvent evt) { 
     676                addIncidentLocationActionPerformed(evt); 
     677            } 
     678        }); 
     679 
     680        jLabel2.setText("Incident Type:"); 
    620681 
    621682        javax.swing.GroupLayout incidentFrameLayout = new javax.swing.GroupLayout(incidentFrame.getContentPane()); 
     
    623684        incidentFrameLayout.setHorizontalGroup( 
    624685            incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    625             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, incidentFrameLayout.createSequentialGroup() 
     686            .addGroup(incidentFrameLayout.createSequentialGroup() 
    626687                .addContainerGap() 
    627                 .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 
    628                     .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE) 
    629                     .addComponent(labelIncidentDescription, javax.swing.GroupLayout.Alignment.LEADING) 
    630                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, incidentFrameLayout.createSequentialGroup() 
     688                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     689                    .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE) 
     690                    .addGroup(incidentFrameLayout.createSequentialGroup() 
    631691                        .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    632692                            .addComponent(labelIncidentNumber) 
    633693                            .addComponent(labelIncidentName) 
    634694                            .addComponent(labelIncidentColor)) 
    635                         .addGap(18, 18, 18) 
     695                        .addGap(66, 66, 66) 
    636696                        .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    637                             .addComponent(addIncidentName, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE) 
    638                             .addComponent(addIncidentNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE) 
     697                            .addComponent(addIncidentName, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) 
     698                            .addComponent(addIncidentNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) 
    639699                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, incidentFrameLayout.createSequentialGroup() 
    640                                 .addComponent(incidentColorField, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE) 
     700                                .addComponent(incidentColorField, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE) 
    641701                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    642702                                .addComponent(btnChooseColor, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))) 
    643                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, incidentFrameLayout.createSequentialGroup() 
     703                    .addGroup(incidentFrameLayout.createSequentialGroup() 
    644704                        .addComponent(incidentCancelButton) 
    645705                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 188, Short.MAX_VALUE) 
    646706                        .addComponent(incidentOkButton, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)) 
    647                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, incidentFrameLayout.createSequentialGroup() 
     707                    .addGroup(incidentFrameLayout.createSequentialGroup() 
    648708                        .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
    649709                            .addComponent(labelIncidentStart) 
     
    655715                                .addComponent(txtIncidentLength, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
    656716                                .addGap(22, 22, 22)) 
    657                             .addComponent(addIncidentStart, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)))) 
     717                            .addComponent(addIncidentStart, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))) 
     718                    .addGroup(incidentFrameLayout.createSequentialGroup() 
     719                        .addComponent(jLabel2) 
     720                        .addGap(93, 93, 93) 
     721                        .addComponent(addIncidentType)) 
     722                    .addGroup(incidentFrameLayout.createSequentialGroup() 
     723                        .addComponent(labelIncidentDescription) 
     724                        .addGap(0, 0, Short.MAX_VALUE)) 
     725                    .addGroup(incidentFrameLayout.createSequentialGroup() 
     726                        .addComponent(jLabel1) 
     727                        .addGap(69, 69, 69) 
     728                        .addComponent(addIncidentLocation))) 
    658729                .addContainerGap()) 
    659730        ); 
     
    675746                    .addComponent(incidentColorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
    676747                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
     748                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
     749                    .addComponent(jLabel1) 
     750                    .addComponent(addIncidentLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
     751                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
     752                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
     753                    .addComponent(jLabel2) 
     754                    .addComponent(addIncidentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
     755                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    677756                .addComponent(labelIncidentDescription) 
    678757                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    679                 .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE) 
     758                .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE) 
    680759                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    681760                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
     
    726805 
    727806        btnCancelNoise.setText("Cancel"); 
    728         btnCancelNoise.addActionListener(new java.awt.event.ActionListener() 
    729         { 
    730             public void actionPerformed(java.awt.event.ActionEvent evt) 
    731             { 
     807        btnCancelNoise.addActionListener(new java.awt.event.ActionListener() { 
     808            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    732809                btnCancelNoiseActionPerformed(evt); 
    733810            } 
     
    735812 
    736813        btnGenerateNoise.setText("Generate"); 
    737         btnGenerateNoise.addActionListener(new java.awt.event.ActionListener() 
    738         { 
    739             public void actionPerformed(java.awt.event.ActionEvent evt) 
    740             { 
     814        btnGenerateNoise.addActionListener(new java.awt.event.ActionListener() { 
     815            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    741816                btnGenerateNoiseActionPerformed(evt); 
    742817            } 
     
    817892        ); 
    818893 
    819         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
     894        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 
    820895        setTitle("Script Builder"); 
    821896        setBounds(new java.awt.Rectangle(0, 23, 800, 700)); 
     
    11871262        zoomSlider.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); 
    11881263        zoomSlider.setFocusable(false); 
    1189         zoomSlider.addChangeListener(new javax.swing.event.ChangeListener() 
    1190         { 
    1191             public void stateChanged(javax.swing.event.ChangeEvent evt) 
    1192             { 
     1264        zoomSlider.addChangeListener(new javax.swing.event.ChangeListener() { 
     1265            public void stateChanged(javax.swing.event.ChangeEvent evt) { 
    11931266                zoomSliderStateChanged(evt); 
    11941267            } 
     
    11971270        zoomInIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ZoomIn.png"))); // NOI18N 
    11981271        zoomInIcon.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); 
    1199         zoomInIcon.addMouseListener(new java.awt.event.MouseAdapter() 
    1200         { 
    1201             public void mouseClicked(java.awt.event.MouseEvent evt) 
    1202             { 
     1272        zoomInIcon.addMouseListener(new java.awt.event.MouseAdapter() { 
     1273            public void mouseClicked(java.awt.event.MouseEvent evt) { 
    12031274                zoomInIconMouseClicked(evt); 
    12041275            } 
     
    12071278        zoomOutIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ZoomOut.png"))); // NOI18N 
    12081279        zoomOutIcon.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); 
    1209         zoomOutIcon.addMouseListener(new java.awt.event.MouseAdapter() 
    1210         { 
    1211             public void mouseClicked(java.awt.event.MouseEvent evt) 
    1212             { 
     1280        zoomOutIcon.addMouseListener(new java.awt.event.MouseAdapter() { 
     1281            public void mouseClicked(java.awt.event.MouseEvent evt) { 
    12131282                zoomOutIconMouseClicked(evt); 
    12141283            } 
     
    12331302 
    12341303        btnAddTime.setText("+15:00"); 
    1235         btnAddTime.addActionListener(new java.awt.event.ActionListener() 
    1236         { 
    1237             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1238             { 
     1304        btnAddTime.addActionListener(new java.awt.event.ActionListener() { 
     1305            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    12391306                btnAddTimeActionPerformed(evt); 
     1307            } 
     1308        }); 
     1309 
     1310        scriptBuilderMenuBar.addAncestorListener(new javax.swing.event.AncestorListener() { 
     1311            public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 
     1312            } 
     1313            public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 
     1314                scriptBuilderMenuBarAncestorAdded(evt); 
     1315            } 
     1316            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 
    12401317            } 
    12411318        }); 
     
    12431320        fileMenu.setText("File"); 
    12441321        fileMenu.setMargin(new java.awt.Insets(0, 10, 0, 10)); 
    1245         fileMenu.addActionListener(new java.awt.event.ActionListener() 
    1246         { 
    1247             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1248             { 
     1322        fileMenu.addActionListener(new java.awt.event.ActionListener() { 
     1323            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    12491324                fileMenuActionPerformed(evt); 
    12501325            } 
     
    12531328        fileNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    12541329        fileNew.setText("New"); 
    1255         fileNew.addActionListener(new java.awt.event.ActionListener() 
    1256         { 
    1257             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1258             { 
     1330        fileNew.addActionListener(new java.awt.event.ActionListener() { 
     1331            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    12591332                fileNewActionPerformed(evt); 
    12601333            } 
     
    12651338        fileOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    12661339        fileOpen.setText("Open..."); 
    1267         fileOpen.addActionListener(new java.awt.event.ActionListener() 
    1268         { 
    1269             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1270             { 
     1340        fileOpen.addActionListener(new java.awt.event.ActionListener() { 
     1341            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    12711342                fileOpenActionPerformed(evt); 
    12721343            } 
     
    12771348        fileSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); 
    12781349        fileSave.setText("Save"); 
    1279         fileSave.addActionListener(new java.awt.event.ActionListener() 
    1280         { 
    1281             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1282             { 
     1350        fileSave.addActionListener(new java.awt.event.ActionListener() { 
     1351            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    12831352                fileSaveActionPerformed(evt); 
    12841353            } 
     
    12881357        fileSaveAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    12891358        fileSaveAs.setText("Save as..."); 
    1290         fileSaveAs.addActionListener(new java.awt.event.ActionListener() 
    1291         { 
    1292             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1293             { 
     1359        fileSaveAs.addActionListener(new java.awt.event.ActionListener() { 
     1360            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    12941361                fileSaveAsActionPerformed(evt); 
    12951362            } 
     
    13041371        generateNotebooks.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    13051372        generateNotebooks.setText("Generate Notebooks..."); 
    1306         generateNotebooks.addActionListener(new java.awt.event.ActionListener() 
    1307         { 
    1308             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1309             { 
     1373        generateNotebooks.addActionListener(new java.awt.event.ActionListener() { 
     1374            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13101375                generateNotebooksActionPerformed(evt); 
    13111376            } 
     
    13151380        generateWebNotebook.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    13161381        generateWebNotebook.setText("Generate Web Notebook..."); 
    1317         generateWebNotebook.addActionListener(new java.awt.event.ActionListener() 
    1318         { 
    1319             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1320             { 
     1382        generateWebNotebook.addActionListener(new java.awt.event.ActionListener() { 
     1383            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13211384                generateWebNotebookActionPerformed(evt); 
    13221385            } 
     
    13261389        generateScorecards.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    13271390        generateScorecards.setText("Generate Scorecards..."); 
    1328         generateScorecards.addActionListener(new java.awt.event.ActionListener() 
    1329         { 
    1330             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1331             { 
     1391        generateScorecards.addActionListener(new java.awt.event.ActionListener() { 
     1392            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13321393                generateScorecardsActionPerformed(evt); 
    13331394            } 
     
    13371398        generateOrganizationChart.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    13381399        generateOrganizationChart.setText("Generate D14 TMC Org Chart..."); 
    1339         generateOrganizationChart.addActionListener(new java.awt.event.ActionListener() 
    1340         { 
    1341             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1342             { 
     1400        generateOrganizationChart.addActionListener(new java.awt.event.ActionListener() { 
     1401            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13431402                generateOrganizationChartActionPerformed(evt); 
    13441403            } 
     
    13491408        generateProjectRequirements.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); 
    13501409        generateProjectRequirements.setText("Generate Project Worklist..."); 
    1351         generateProjectRequirements.addActionListener(new java.awt.event.ActionListener() 
    1352         { 
    1353             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1354             { 
     1410        generateProjectRequirements.addActionListener(new java.awt.event.ActionListener() { 
     1411            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13551412                generateProjectRequirementsActionPerformed(evt); 
    13561413            } 
     
    13641421 
    13651422        newIncident.setText("New Incident..."); 
    1366         newIncident.addActionListener(new java.awt.event.ActionListener() 
    1367         { 
    1368             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1369             { 
     1423        newIncident.addActionListener(new java.awt.event.ActionListener() { 
     1424            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13701425                newIncidentActionPerformed(evt); 
    13711426            } 
     
    13741429 
    13751430        deleteIncident.setText("Delete Incident"); 
    1376         deleteIncident.addActionListener(new java.awt.event.ActionListener() 
    1377         { 
    1378             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1379             { 
     1431        deleteIncident.addActionListener(new java.awt.event.ActionListener() { 
     1432            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13801433                deleteIncidentActionPerformed(evt); 
    13811434            } 
    13821435        }); 
    13831436        incidentMenu.add(deleteIncident); 
     1437 
     1438        deleteIncident1.setText("Edit Incident..."); 
     1439        deleteIncident1.addActionListener(new java.awt.event.ActionListener() { 
     1440            public void actionPerformed(java.awt.event.ActionEvent evt) { 
     1441                incidentDetailsActionPerformed(evt); 
     1442            } 
     1443        }); 
     1444        incidentMenu.add(deleteIncident1); 
    13841445        incidentMenu.add(jSeparator4); 
    13851446 
    13861447        saveIncident.setText("Save Incident..."); 
    1387         saveIncident.addActionListener(new java.awt.event.ActionListener() 
    1388         { 
    1389             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1390             { 
     1448        saveIncident.addActionListener(new java.awt.event.ActionListener() { 
     1449            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    13911450                saveIncidentActionPerformed(evt); 
    13921451            } 
     
    13951454 
    13961455        loadIncident.setText("Load Incident..."); 
    1397         loadIncident.addActionListener(new java.awt.event.ActionListener() 
    1398         { 
    1399             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1400             { 
     1456        loadIncident.addActionListener(new java.awt.event.ActionListener() { 
     1457            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    14011458                loadIncidentActionPerformed(evt); 
    14021459            } 
     
    14091466 
    14101467        generateNoiseOption.setText("Generate Noise..."); 
    1411         generateNoiseOption.addActionListener(new java.awt.event.ActionListener() 
    1412         { 
    1413             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1414             { 
     1468        generateNoiseOption.addActionListener(new java.awt.event.ActionListener() { 
     1469            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    14151470                generateNoiseOptionActionPerformed(evt); 
    14161471            } 
     
    14191474 
    14201475        scriptBuilderMenuBar.add(generateNoiseMenu); 
     1476 
     1477        helpMenu1.setText("Unit"); 
     1478        helpMenu1.setMargin(new java.awt.Insets(0, 10, 0, 10)); 
     1479 
     1480        loadUnits.setText("Load Units..."); 
     1481        loadUnits.addActionListener(new java.awt.event.ActionListener() { 
     1482            public void actionPerformed(java.awt.event.ActionEvent evt) { 
     1483                loadUnitsActionPerformed(evt); 
     1484            } 
     1485        }); 
     1486        helpMenu1.add(loadUnits); 
     1487 
     1488        scriptBuilderMenuBar.add(helpMenu1); 
    14211489 
    14221490        helpMenu.setText("Help"); 
     
    14251493        helpTutorial.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0)); 
    14261494        helpTutorial.setText("Tutorial..."); 
    1427         helpTutorial.addActionListener(new java.awt.event.ActionListener() 
    1428         { 
    1429             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1430             { 
     1495        helpTutorial.addActionListener(new java.awt.event.ActionListener() { 
     1496            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    14311497                helpTutorialActionPerformed(evt); 
    14321498            } 
     
    14351501 
    14361502        helpAbout.setText("About..."); 
    1437         helpAbout.addActionListener(new java.awt.event.ActionListener() 
    1438         { 
    1439             public void actionPerformed(java.awt.event.ActionEvent evt) 
    1440             { 
     1503        helpAbout.addActionListener(new java.awt.event.ActionListener() { 
     1504            public void actionPerformed(java.awt.event.ActionEvent evt) { 
    14411505                helpAboutActionPerformed(evt); 
    14421506            } 
     
    15741638            SimulationScript.incidentColors[indx] = selectedColor; 
    15751639            // Add the new incident to the list 
     1640            //todo: need to add new data to the ScriptIncident Object here 
    15761641            script.incidents.add(indx, 
    15771642                    new ScriptIncident(SimulationScript.incidentColors[indx], 
    15781643                            (Integer) addIncidentNumber.getValue(), addIncidentName.getText(), addIncidentDescription.getText(), 
    1579                             script)); 
     1644                            script,0)); 
     1645             
    15801646            script.incidents.get(indx).setOffset((Integer) addIncidentStart.getValue() * 60); 
     1647            script.incidents.get(indx).insertCadData((Integer) addIncidentStart.getValue(), new CadData(addIncidentType.getText(),addIncidentLocation.getText())); 
    15811648            script.numberOfIncidents++; 
     1649             
    15821650            IncidentEditorFrame editor = new IncidentEditorFrame(script.incidents.get(indx), this); 
    15831651 
     
    15941662            //change offset of incident 
    15951663            script.incidents.get(oldIncidentIndex).setOffset(((int) addIncidentStart.getValue()) * 60); 
     1664             
     1665            script.incidents.get(oldIncidentIndex).insertCadData((int) addIncidentStart.getValue() * 60, new CadData(addIncidentType.getText(),addIncidentLocation.getText())); 
    15961666            //update incident number, if it was changed 
    15971667            if ((int) addIncidentNumber.getValue() == script.incidents.get(oldIncidentIndex).number 
     
    16131683        repaint(); 
    16141684    }//GEN-LAST:event_incidentOkButtonActionPerformed 
    1615  
    1616     /** 
     1685    /** 
     1686     * Calling this will check to see if the model has been updated.  
     1687     * @param save indicated whether or not the file needs to be saved 
     1688     */ 
     1689    private void checkNeedsSave(){ 
     1690         
     1691        if(!script.saved){ 
     1692            changeFrameTitle("*"); 
     1693        }else{ 
     1694            changeFrameTitle(""); 
     1695        } 
     1696    } 
     1697    /** 
     1698     *  
     1699     * @param ext changes title by putting ext after current title.  
     1700     */ 
     1701    private void changeFrameTitle(String ext){ 
     1702        String t = "Script Builder: "; 
     1703        if (script.saveFile == null) 
     1704        { 
     1705            t += "untitled1.xml"; 
     1706        } 
     1707        else 
     1708        { 
     1709            t += script.saveFile.getName(); 
     1710        } 
     1711        t+= ext; 
     1712        this.setTitle(t); 
     1713    } 
     1714    /** 
     1715     *  
    16171716     * Determine if the given incident number is already present in the script. 
    16181717     * 
     
    16531752 
    16541753        addIncidentName.setText(""); 
    1655  
    16561754        int newLogNum = 100; 
    16571755        boolean found = false; 
     
    16821780        selectedColor = Color.BLACK; 
    16831781        addIncidentDescription.setText(""); 
     1782        addIncidentLocation.setText(""); 
     1783        addIncidentType.setText(""); 
    16841784 
    16851785        incidentFrame.setVisible(true); 
     
    17111811            script.saveFile = fc.getSelectedFile(); 
    17121812        } 
     1813         
    17131814        this.update(script, script); 
    17141815        //zoom out all the way so that the whole imported script is visible 
     
    17361837            } 
    17371838            script.saveFile = new File("" + fName + untitledCount + ".xml"); 
     1839             
    17381840        } 
    17391841 
     
    17551857            script.saveScriptToFile(new File(filename)); 
    17561858            script.saveFile = new File(filename); 
     1859             
    17571860        } 
    17581861        else 
     
    17631866            } 
    17641867        } 
     1868         
    17651869        this.update(script, 0); 
    17661870    }//GEN-LAST:event_fileSaveAsActionPerformed 
     
    17821886        else 
    17831887        { 
     1888             
    17841889            script.saveScriptToFile(script.saveFile); 
    17851890        } 
     1891        //TODO: TEST TO MAKE SURE THIS DOES NOT CREATE BADDIES 
     1892        this.update(script, 0); 
    17861893    }//GEN-LAST:event_fileSaveActionPerformed 
    17871894 
     
    18091916        addIncidentName.setText(i.name); 
    18101917        addIncidentNumber.setValue(i.number); 
     1918        addIncidentLocation.setText(i.getCadData(i.offset).Header_FullLoc); 
     1919        addIncidentType.setText(i.getCadData(i.offset).Header_Type); 
    18111920        addIncidentStart.setValue(i.offset / 60); 
    18121921        txtIncidentLength.setText("" + (i.length / 60)); 
     
    21062215    {//GEN-HEADEREND:event_fileNewActionPerformed 
    21072216        script = new SimulationScript(); 
     2217        String fileName = "units.xml"; 
     2218        File f = new File(fileName); 
     2219        script.loadUnitsFromFile(f); 
    21082220        script.update(); 
    21092221        this.update(null, script); 
     
    21572269                    script.incidents.add(null); 
    21582270                    script.numberOfIncidents--; 
     2271                     
    21592272                } 
    21602273            } 
    21612274        } 
     2275        //since delete is the only method in this class that actually edits the data model, needs .update() 
     2276        script.update(); 
    21622277        //Refresh 
    21632278        this.update(script, script); 
     2279         
     2280         
    21642281        repaint(); 
    21652282    }//GEN-LAST:event_deleteIncidentActionPerformed 
     
    22202337// TODO add your handling code here: 
    22212338    }//GEN-LAST:event_helpTutorialActionPerformed 
     2339 
     2340    private void addIncidentLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addIncidentLocationActionPerformed 
     2341        // TODO add your handling code here: 
     2342    }//GEN-LAST:event_addIncidentLocationActionPerformed 
     2343 
     2344    private void addIncidentNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addIncidentNameActionPerformed 
     2345        // TODO add your handling code here: 
     2346    }//GEN-LAST:event_addIncidentNameActionPerformed 
     2347 
     2348    private void incidentDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_incidentDetailsActionPerformed 
     2349        // TODO add your handling code here: 
     2350        Object[] incidentList = script.incidents.toArray(); 
     2351        ScriptIncident i = (ScriptIncident) JOptionPane.showInputDialog( 
     2352                this, 
     2353                "Select Incident:", 
     2354                "Edit Incident", 
     2355                JOptionPane.PLAIN_MESSAGE, 
     2356                null, 
     2357                incidentList, 
     2358                script.incidents.get(0)); 
     2359 
     2360        // If a valid incident was selected 
     2361        if (i != null) 
     2362        { 
     2363            editingIncident = true; 
     2364            oldIncidentIndex = script.incidents.indexOf(i); 
     2365 
     2366            addIncidentName.setText(i.name); 
     2367            addIncidentNumber.setValue(i.number); 
     2368             
     2369            addIncidentLocation.setText(i.getCadData(i.offset).Header_FullLoc); 
     2370            addIncidentType.setText(i.getCadData(i.offset).Header_Type); 
     2371            addIncidentStart.setValue(i.offset / 60); 
     2372            //addIncidentLength.setValue(i.length / 60); 
     2373            incidentColorField.setBackground(i.color); 
     2374            selectedColor = i.color; 
     2375            addIncidentDescription.setText(i.description); 
     2376 
     2377            incidentFrame.setVisible(true); 
     2378        } 
     2379    }//GEN-LAST:event_incidentDetailsActionPerformed 
     2380 
     2381    private void popupDeleteIncidentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_popupDeleteIncidentActionPerformed 
     2382        // TODO add your handling code here: 
     2383    }//GEN-LAST:event_popupDeleteIncidentActionPerformed 
     2384 
     2385    private void loadUnitsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadUnitsActionPerformed 
     2386        // TODO: needs to have testing performed 
     2387        JFileChooser fc = new JFileChooser(); 
     2388 
     2389        //Search for .xml files 
     2390        fc.setFileFilter(new ExtensionFileFilter("Simulation Script XML (.xml)", 
     2391                new String[] 
     2392                { 
     2393                    "xml" 
     2394                })); 
     2395        if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 
     2396        { 
     2397            //load script with values from the selected file 
     2398            script.loadUnitsFromFile(fc.getSelectedFile()); 
     2399        } 
     2400    }//GEN-LAST:event_loadUnitsActionPerformed 
     2401 
     2402    private void scriptBuilderMenuBarAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_scriptBuilderMenuBarAncestorAdded 
     2403        //loads in the initial unit file 
     2404//        String fileName = "units.xml"; 
     2405//         
     2406//        File f = new File(fileName); 
     2407//         
     2408//        script.loadUnitsFromFile(f); 
     2409    }//GEN-LAST:event_scriptBuilderMenuBarAncestorAdded 
    22222410 
    22232411    /** 
     
    22922480    private javax.swing.JSlider TMCALSlider; 
    22932481    private javax.swing.JTextArea addIncidentDescription; 
     2482    private javax.swing.JTextField addIncidentLocation; 
    22942483    private javax.swing.JTextField addIncidentName; 
    22952484    private javax.swing.JSpinner addIncidentNumber; 
    22962485    private javax.swing.JSpinner addIncidentStart; 
     2486    private javax.swing.JTextField addIncidentType; 
    22972487    private javax.swing.JFrame addNoiseFrame; 
    22982488    private javax.swing.JSlider backgroundNoiseSlider; 
     
    23062496    private javax.swing.JMenuItem deleteEventList; 
    23072497    private javax.swing.JMenuItem deleteIncident; 
     2498    private javax.swing.JMenuItem deleteIncident1; 
    23082499    private javax.swing.JMenuItem editEventList; 
    23092500    private javax.swing.JPopupMenu eventListPopupMenu; 
     
    23242515    private javax.swing.JMenuItem helpAbout; 
    23252516    private javax.swing.JMenu helpMenu; 
     2517    private javax.swing.JMenu helpMenu1; 
    23262518    private javax.swing.JMenuItem helpTutorial; 
    23272519    private javax.swing.JButton incidentCancelButton; 
     
    23532545    private scriptbuilder.gui.panels.IncidentTimelinePanel incidentTimelinePanel8; 
    23542546    private scriptbuilder.gui.panels.IncidentTimelinePanel incidentTimelinePanel9; 
     2547    private javax.swing.JLabel jLabel1; 
     2548    private javax.swing.JLabel jLabel2; 
    23552549    private javax.swing.JMenuItem jMenuItem2; 
    23562550    private javax.swing.JMenuItem jMenuItem4; 
     
    23792573    private javax.swing.JSlider laneClosuresSlider; 
    23802574    private javax.swing.JMenuItem loadIncident; 
     2575    private javax.swing.JMenuItem loadUnits; 
    23812576    private javax.swing.JSlider minorEventsSlider; 
    23822577    private javax.swing.JMenuItem newIncident; 
Note: See TracChangeset for help on using the changeset viewer.