Index: trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java
===================================================================
--- trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java	(revision 139)
+++ trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java	(revision 145)
@@ -13,6 +13,9 @@
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 import java.io.File;
 import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.net.URI;
 import java.util.Observable;
@@ -38,4 +41,5 @@
 import scriptbuilder.structures.TimeSlice;
 import scriptbuilder.structures.events.I_ScriptEvent;
+import scriptbuilder.structures.CadData;
 
 /**
@@ -152,4 +156,9 @@
         script.addObserver(this);
         initComponents();
+        addCustomListeners();
+        //add to listener helper method
+        
+        
+        
         //We don't currently want the button to be present in this window
         btnAddTime.setVisible(false);
@@ -162,14 +171,6 @@
          */
         // Set listener for scroll pane
-        String t = "Script Builder: ";
-        if (script.saveFile == null)
-        {
-            t += "untitled1.xml";
-        }
-        else
-        {
-            t += script.saveFile.getName();
-        }
-        this.setTitle(t);
+        
+        
         AdjustmentListener listener = new MyAdjustmentListener();
         timelinesScrollPane.getHorizontalScrollBar().addAdjustmentListener(listener);
@@ -177,4 +178,56 @@
         repaint();
 
+    }
+    
+    /**
+     * Put all custom non-generated listeners in this method
+     */
+    private void addCustomListeners(){
+        
+        String fileName = "units.xml";
+        File unitFile = new File(fileName);
+        script.loadUnitsFromFile(unitFile);
+        //listener for window closing
+        this.addWindowListener(new WindowAdapter(){
+            @Override
+            public void windowClosing(WindowEvent e)
+            {
+                //System.out.println("Window is closing!" + saved);
+
+                if(!script.saved){
+                    //System.out.println("window was not saved!");
+                    Object[] options = {"Yes","No","Cancel"};
+                    int result = JOptionPane.showOptionDialog(null,"Would you like to save changes before exiting?",
+                            "Exit",
+                            JOptionPane.YES_NO_CANCEL_OPTION,
+                            JOptionPane.QUESTION_MESSAGE,
+                            null,
+                            options,
+                            options[2]);
+                    switch (result){
+                        //should save script then close
+                        case 0:
+                            fileSaveActionPerformed(null);
+                            //System.exit(0);
+                            break;
+                        // should just exit
+                        case 1:
+                            System.exit(0);
+                            break;
+                        // should do nothing
+                        case 2:
+                            break;
+                        default:
+                            break;
+                    }
+                    
+                    
+                    
+                }else{
+                    //should close current window since it is saved already
+                    System.exit(0);
+                }
+            }
+        });
     }
 
@@ -192,7 +245,8 @@
     public void update(Observable o, Object arg)
     {
-        //Three major update types: whole script, and 2 event updates
+        checkNeedsSave();
         if (arg instanceof SimulationScript)
         {
+            
             script = (SimulationScript) arg;
 
@@ -236,6 +290,8 @@
              * model.addElement(i); } gotoIncident.setModel(model);*
              */
+            
             this.setPreferredSize(this.getSize());
             pack();
+            
         }
         //Mouse has changed focus to a different timeslice
@@ -249,4 +305,7 @@
                 model.addElement(e);
             }
+            
+            
+            
         }
         //Mouse has changed focus to a different incident timeline panel 
@@ -256,4 +315,5 @@
 
             //gotoIncident.setSelectedItem(i);
+            
         }
 
@@ -267,18 +327,11 @@
         //scale the zoom slider such that the most zoomed-out point allows the
         //entire script to be visible at once
+        
+        //todo: interpret these two calls and make them so that they are more accurate to fit the entire window at once
         zoomSlider.setMinimum(((timelineTickPanel.getVisibleRect().width - 20)
                 * ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION)
                 / Math.max(script.absoluteLength(), ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH));
         zoomSlider.setMaximum(zoomSlider.getMinimum() + 20);
-        String t = "Script Builder: ";
-        if (script.saveFile == null)
-        {
-            t += "untitled1.xml";
-        }
-        else
-        {
-            t += script.saveFile.getName();
-        }
-        this.setTitle(t);
+        
         repaint();
     }
@@ -291,6 +344,5 @@
     @SuppressWarnings("unchecked")
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
-    private void initComponents()
-    {
+    private void initComponents() {
 
         incidentPopupMenu = new javax.swing.JPopupMenu();
@@ -333,4 +385,8 @@
         incidentColorField = new javax.swing.JTextField();
         txtIncidentLength = new javax.swing.JLabel();
+        jLabel1 = new javax.swing.JLabel();
+        addIncidentLocation = new javax.swing.JTextField();
+        jLabel2 = new javax.swing.JLabel();
+        addIncidentType = new javax.swing.JTextField();
         addNoiseFrame = new javax.swing.JFrame();
         labelRadioChatter = new javax.swing.JLabel();
@@ -396,4 +452,5 @@
         newIncident = new javax.swing.JMenuItem();
         deleteIncident = new javax.swing.JMenuItem();
+        deleteIncident1 = new javax.swing.JMenuItem();
         jSeparator4 = new javax.swing.JPopupMenu.Separator();
         saveIncident = new javax.swing.JMenuItem();
@@ -401,4 +458,6 @@
         generateNoiseMenu = new javax.swing.JMenu();
         generateNoiseOption = new javax.swing.JMenuItem();
+        helpMenu1 = new javax.swing.JMenu();
+        loadUnits = new javax.swing.JMenuItem();
         helpMenu = new javax.swing.JMenu();
         helpTutorial = new javax.swing.JMenuItem();
@@ -406,22 +465,22 @@
 
         popupDeleteIncident.setText("Delete Incident...");
+        popupDeleteIncident.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                popupDeleteIncidentActionPerformed(evt);
+            }
+        });
         incidentPopupMenu.add(popupDeleteIncident);
 
         cadEvent.setText("CAD Event");
-        cadEvent.addMouseListener(new java.awt.event.MouseAdapter()
-        {
-            public void mousePressed(java.awt.event.MouseEvent evt)
-            {
+        cadEvent.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mousePressed(java.awt.event.MouseEvent evt) {
                 cadEventMousePressed(evt);
             }
-            public void mouseReleased(java.awt.event.MouseEvent evt)
-            {
+            public void mouseReleased(java.awt.event.MouseEvent evt) {
                 cadEventMouseReleased(evt);
             }
         });
-        cadEvent.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        cadEvent.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 cadEventActionPerformed(evt);
             }
@@ -433,8 +492,6 @@
 
         radioEvent.setText("Radio Event");
-        radioEvent.addMouseListener(new java.awt.event.MouseAdapter()
-        {
-            public void mousePressed(java.awt.event.MouseEvent evt)
-            {
+        radioEvent.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mousePressed(java.awt.event.MouseEvent evt) {
                 radioEventMousePressed(evt);
             }
@@ -490,8 +547,6 @@
 
         okButton.setText("OK");
-        okButton.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        okButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 okButtonActionPerformed(evt);
             }
@@ -499,8 +554,6 @@
 
         cancelButton.setText("Cancel");
-        cancelButton.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        cancelButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 cancelButtonActionPerformed(evt);
             }
@@ -545,8 +598,6 @@
 
         editEventList.setText("Edit...");
-        editEventList.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        editEventList.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 editEventListActionPerformed(evt);
             }
@@ -578,8 +629,6 @@
 
         incidentOkButton.setText("OK");
-        incidentOkButton.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        incidentOkButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 incidentOkButtonActionPerformed(evt);
             }
@@ -587,13 +636,17 @@
 
         incidentCancelButton.setText("Cancel");
-        incidentCancelButton.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        incidentCancelButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 incidentCancelButtonActionPerformed(evt);
             }
         });
 
-        addIncidentNumber.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(101), Integer.valueOf(101), null, Integer.valueOf(1)));
+        addIncidentNumber.setModel(new javax.swing.SpinnerNumberModel(101, 101, null, 1));
+
+        addIncidentName.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                addIncidentNameActionPerformed(evt);
+            }
+        });
 
         labelIncidentLength.setText("Incident Length in Minutes: ");
@@ -601,11 +654,9 @@
         labelIncidentStart.setText("Incident Start Time in Minutes:");
 
-        addIncidentStart.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
+        addIncidentStart.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1));
 
         btnChooseColor.setText("Choose...");
-        btnChooseColor.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        btnChooseColor.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 btnChooseColorActionPerformed(evt);
             }
@@ -618,4 +669,14 @@
         txtIncidentLength.setText("0");
         txtIncidentLength.setToolTipText("");
+
+        jLabel1.setText("Incident Location:");
+
+        addIncidentLocation.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                addIncidentLocationActionPerformed(evt);
+            }
+        });
+
+        jLabel2.setText("Incident Type:");
 
         javax.swing.GroupLayout incidentFrameLayout = new javax.swing.GroupLayout(incidentFrame.getContentPane());
@@ -623,27 +684,26 @@
         incidentFrameLayout.setHorizontalGroup(
             incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, incidentFrameLayout.createSequentialGroup()
+            .addGroup(incidentFrameLayout.createSequentialGroup()
                 .addContainerGap()
-                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
-                    .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
-                    .addComponent(labelIncidentDescription, javax.swing.GroupLayout.Alignment.LEADING)
-                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, incidentFrameLayout.createSequentialGroup()
+                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
+                    .addGroup(incidentFrameLayout.createSequentialGroup()
                         .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                             .addComponent(labelIncidentNumber)
                             .addComponent(labelIncidentName)
                             .addComponent(labelIncidentColor))
-                        .addGap(18, 18, 18)
+                        .addGap(66, 66, 66)
                         .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-                            .addComponent(addIncidentName, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
-                            .addComponent(addIncidentNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
+                            .addComponent(addIncidentName, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
+                            .addComponent(addIncidentNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, incidentFrameLayout.createSequentialGroup()
-                                .addComponent(incidentColorField, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
+                                .addComponent(incidentColorField, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                 .addComponent(btnChooseColor, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))))
-                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, incidentFrameLayout.createSequentialGroup()
+                    .addGroup(incidentFrameLayout.createSequentialGroup()
                         .addComponent(incidentCancelButton)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 188, Short.MAX_VALUE)
                         .addComponent(incidentOkButton, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
-                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, incidentFrameLayout.createSequentialGroup()
+                    .addGroup(incidentFrameLayout.createSequentialGroup()
                         .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                             .addComponent(labelIncidentStart)
@@ -655,5 +715,16 @@
                                 .addComponent(txtIncidentLength, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                 .addGap(22, 22, 22))
-                            .addComponent(addIncidentStart, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))))
+                            .addComponent(addIncidentStart, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)))
+                    .addGroup(incidentFrameLayout.createSequentialGroup()
+                        .addComponent(jLabel2)
+                        .addGap(93, 93, 93)
+                        .addComponent(addIncidentType))
+                    .addGroup(incidentFrameLayout.createSequentialGroup()
+                        .addComponent(labelIncidentDescription)
+                        .addGap(0, 0, Short.MAX_VALUE))
+                    .addGroup(incidentFrameLayout.createSequentialGroup()
+                        .addComponent(jLabel1)
+                        .addGap(69, 69, 69)
+                        .addComponent(addIncidentLocation)))
                 .addContainerGap())
         );
@@ -675,7 +746,15 @@
                     .addComponent(incidentColorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(jLabel1)
+                    .addComponent(addIncidentLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(jLabel2)
+                    .addComponent(addIncidentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(labelIncidentDescription)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
+                .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
@@ -726,8 +805,6 @@
 
         btnCancelNoise.setText("Cancel");
-        btnCancelNoise.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        btnCancelNoise.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 btnCancelNoiseActionPerformed(evt);
             }
@@ -735,8 +812,6 @@
 
         btnGenerateNoise.setText("Generate");
-        btnGenerateNoise.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        btnGenerateNoise.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 btnGenerateNoiseActionPerformed(evt);
             }
@@ -817,5 +892,5 @@
         );
 
-        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
         setTitle("Script Builder");
         setBounds(new java.awt.Rectangle(0, 23, 800, 700));
@@ -1187,8 +1262,6 @@
         zoomSlider.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
         zoomSlider.setFocusable(false);
-        zoomSlider.addChangeListener(new javax.swing.event.ChangeListener()
-        {
-            public void stateChanged(javax.swing.event.ChangeEvent evt)
-            {
+        zoomSlider.addChangeListener(new javax.swing.event.ChangeListener() {
+            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                 zoomSliderStateChanged(evt);
             }
@@ -1197,8 +1270,6 @@
         zoomInIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ZoomIn.png"))); // NOI18N
         zoomInIcon.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
-        zoomInIcon.addMouseListener(new java.awt.event.MouseAdapter()
-        {
-            public void mouseClicked(java.awt.event.MouseEvent evt)
-            {
+        zoomInIcon.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mouseClicked(java.awt.event.MouseEvent evt) {
                 zoomInIconMouseClicked(evt);
             }
@@ -1207,8 +1278,6 @@
         zoomOutIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ZoomOut.png"))); // NOI18N
         zoomOutIcon.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
-        zoomOutIcon.addMouseListener(new java.awt.event.MouseAdapter()
-        {
-            public void mouseClicked(java.awt.event.MouseEvent evt)
-            {
+        zoomOutIcon.addMouseListener(new java.awt.event.MouseAdapter() {
+            public void mouseClicked(java.awt.event.MouseEvent evt) {
                 zoomOutIconMouseClicked(evt);
             }
@@ -1233,9 +1302,17 @@
 
         btnAddTime.setText("+15:00");
-        btnAddTime.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        btnAddTime.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 btnAddTimeActionPerformed(evt);
+            }
+        });
+
+        scriptBuilderMenuBar.addAncestorListener(new javax.swing.event.AncestorListener() {
+            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
+            }
+            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
+                scriptBuilderMenuBarAncestorAdded(evt);
+            }
+            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
             }
         });
@@ -1243,8 +1320,6 @@
         fileMenu.setText("File");
         fileMenu.setMargin(new java.awt.Insets(0, 10, 0, 10));
-        fileMenu.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        fileMenu.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 fileMenuActionPerformed(evt);
             }
@@ -1253,8 +1328,6 @@
         fileNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         fileNew.setText("New");
-        fileNew.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        fileNew.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 fileNewActionPerformed(evt);
             }
@@ -1265,8 +1338,6 @@
         fileOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         fileOpen.setText("Open...");
-        fileOpen.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        fileOpen.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 fileOpenActionPerformed(evt);
             }
@@ -1277,8 +1348,6 @@
         fileSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
         fileSave.setText("Save");
-        fileSave.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        fileSave.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 fileSaveActionPerformed(evt);
             }
@@ -1288,8 +1357,6 @@
         fileSaveAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         fileSaveAs.setText("Save as...");
-        fileSaveAs.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        fileSaveAs.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 fileSaveAsActionPerformed(evt);
             }
@@ -1304,8 +1371,6 @@
         generateNotebooks.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         generateNotebooks.setText("Generate Notebooks...");
-        generateNotebooks.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        generateNotebooks.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 generateNotebooksActionPerformed(evt);
             }
@@ -1315,8 +1380,6 @@
         generateWebNotebook.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         generateWebNotebook.setText("Generate Web Notebook...");
-        generateWebNotebook.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        generateWebNotebook.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 generateWebNotebookActionPerformed(evt);
             }
@@ -1326,8 +1389,6 @@
         generateScorecards.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         generateScorecards.setText("Generate Scorecards...");
-        generateScorecards.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        generateScorecards.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 generateScorecardsActionPerformed(evt);
             }
@@ -1337,8 +1398,6 @@
         generateOrganizationChart.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         generateOrganizationChart.setText("Generate D14 TMC Org Chart...");
-        generateOrganizationChart.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        generateOrganizationChart.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 generateOrganizationChartActionPerformed(evt);
             }
@@ -1349,8 +1408,6 @@
         generateProjectRequirements.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
         generateProjectRequirements.setText("Generate Project Worklist...");
-        generateProjectRequirements.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        generateProjectRequirements.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 generateProjectRequirementsActionPerformed(evt);
             }
@@ -1364,8 +1421,6 @@
 
         newIncident.setText("New Incident...");
-        newIncident.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        newIncident.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 newIncidentActionPerformed(evt);
             }
@@ -1374,19 +1429,23 @@
 
         deleteIncident.setText("Delete Incident");
-        deleteIncident.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        deleteIncident.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 deleteIncidentActionPerformed(evt);
             }
         });
         incidentMenu.add(deleteIncident);
+
+        deleteIncident1.setText("Edit Incident...");
+        deleteIncident1.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                incidentDetailsActionPerformed(evt);
+            }
+        });
+        incidentMenu.add(deleteIncident1);
         incidentMenu.add(jSeparator4);
 
         saveIncident.setText("Save Incident...");
-        saveIncident.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        saveIncident.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 saveIncidentActionPerformed(evt);
             }
@@ -1395,8 +1454,6 @@
 
         loadIncident.setText("Load Incident...");
-        loadIncident.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        loadIncident.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 loadIncidentActionPerformed(evt);
             }
@@ -1409,8 +1466,6 @@
 
         generateNoiseOption.setText("Generate Noise...");
-        generateNoiseOption.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        generateNoiseOption.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 generateNoiseOptionActionPerformed(evt);
             }
@@ -1419,4 +1474,17 @@
 
         scriptBuilderMenuBar.add(generateNoiseMenu);
+
+        helpMenu1.setText("Unit");
+        helpMenu1.setMargin(new java.awt.Insets(0, 10, 0, 10));
+
+        loadUnits.setText("Load Units...");
+        loadUnits.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                loadUnitsActionPerformed(evt);
+            }
+        });
+        helpMenu1.add(loadUnits);
+
+        scriptBuilderMenuBar.add(helpMenu1);
 
         helpMenu.setText("Help");
@@ -1425,8 +1493,6 @@
         helpTutorial.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
         helpTutorial.setText("Tutorial...");
-        helpTutorial.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        helpTutorial.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 helpTutorialActionPerformed(evt);
             }
@@ -1435,8 +1501,6 @@
 
         helpAbout.setText("About...");
-        helpAbout.addActionListener(new java.awt.event.ActionListener()
-        {
-            public void actionPerformed(java.awt.event.ActionEvent evt)
-            {
+        helpAbout.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
                 helpAboutActionPerformed(evt);
             }
@@ -1574,10 +1638,14 @@
             SimulationScript.incidentColors[indx] = selectedColor;
             // Add the new incident to the list
+            //todo: need to add new data to the ScriptIncident Object here
             script.incidents.add(indx,
                     new ScriptIncident(SimulationScript.incidentColors[indx],
                             (Integer) addIncidentNumber.getValue(), addIncidentName.getText(), addIncidentDescription.getText(),
-                            script));
+                            script,0));
+            
             script.incidents.get(indx).setOffset((Integer) addIncidentStart.getValue() * 60);
+            script.incidents.get(indx).insertCadData((Integer) addIncidentStart.getValue(), new CadData(addIncidentType.getText(),addIncidentLocation.getText()));
             script.numberOfIncidents++;
+            
             IncidentEditorFrame editor = new IncidentEditorFrame(script.incidents.get(indx), this);
 
@@ -1594,4 +1662,6 @@
             //change offset of incident
             script.incidents.get(oldIncidentIndex).setOffset(((int) addIncidentStart.getValue()) * 60);
+            
+            script.incidents.get(oldIncidentIndex).insertCadData((int) addIncidentStart.getValue() * 60, new CadData(addIncidentType.getText(),addIncidentLocation.getText()));
             //update incident number, if it was changed
             if ((int) addIncidentNumber.getValue() == script.incidents.get(oldIncidentIndex).number
@@ -1613,6 +1683,35 @@
         repaint();
     }//GEN-LAST:event_incidentOkButtonActionPerformed
-
-    /**
+    /**
+     * Calling this will check to see if the model has been updated. 
+     * @param save indicated whether or not the file needs to be saved
+     */
+    private void checkNeedsSave(){
+        
+        if(!script.saved){
+            changeFrameTitle("*");
+        }else{
+            changeFrameTitle("");
+        }
+    }
+    /**
+     * 
+     * @param ext changes title by putting ext after current title. 
+     */
+    private void changeFrameTitle(String ext){
+        String t = "Script Builder: ";
+        if (script.saveFile == null)
+        {
+            t += "untitled1.xml";
+        }
+        else
+        {
+            t += script.saveFile.getName();
+        }
+        t+= ext;
+        this.setTitle(t);
+    }
+    /**
+     * 
      * Determine if the given incident number is already present in the script.
      *
@@ -1653,5 +1752,4 @@
 
         addIncidentName.setText("");
-
         int newLogNum = 100;
         boolean found = false;
@@ -1682,4 +1780,6 @@
         selectedColor = Color.BLACK;
         addIncidentDescription.setText("");
+        addIncidentLocation.setText("");
+        addIncidentType.setText("");
 
         incidentFrame.setVisible(true);
@@ -1711,4 +1811,5 @@
             script.saveFile = fc.getSelectedFile();
         }
+        
         this.update(script, script);
         //zoom out all the way so that the whole imported script is visible
@@ -1736,4 +1837,5 @@
             }
             script.saveFile = new File("" + fName + untitledCount + ".xml");
+            
         }
 
@@ -1755,4 +1857,5 @@
             script.saveScriptToFile(new File(filename));
             script.saveFile = new File(filename);
+            
         }
         else
@@ -1763,4 +1866,5 @@
             }
         }
+        
         this.update(script, 0);
     }//GEN-LAST:event_fileSaveAsActionPerformed
@@ -1782,6 +1886,9 @@
         else
         {
+            
             script.saveScriptToFile(script.saveFile);
         }
+        //TODO: TEST TO MAKE SURE THIS DOES NOT CREATE BADDIES
+        this.update(script, 0);
     }//GEN-LAST:event_fileSaveActionPerformed
 
@@ -1809,4 +1916,6 @@
         addIncidentName.setText(i.name);
         addIncidentNumber.setValue(i.number);
+        addIncidentLocation.setText(i.getCadData(i.offset).Header_FullLoc);
+        addIncidentType.setText(i.getCadData(i.offset).Header_Type);
         addIncidentStart.setValue(i.offset / 60);
         txtIncidentLength.setText("" + (i.length / 60));
@@ -2106,4 +2215,7 @@
     {//GEN-HEADEREND:event_fileNewActionPerformed
         script = new SimulationScript();
+        String fileName = "units.xml";
+        File f = new File(fileName);
+        script.loadUnitsFromFile(f);
         script.update();
         this.update(null, script);
@@ -2157,9 +2269,14 @@
                     script.incidents.add(null);
                     script.numberOfIncidents--;
+                    
                 }
             }
         }
+        //since delete is the only method in this class that actually edits the data model, needs .update()
+        script.update();
         //Refresh
         this.update(script, script);
+        
+        
         repaint();
     }//GEN-LAST:event_deleteIncidentActionPerformed
@@ -2220,4 +2337,75 @@
 // TODO add your handling code here:
     }//GEN-LAST:event_helpTutorialActionPerformed
+
+    private void addIncidentLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addIncidentLocationActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_addIncidentLocationActionPerformed
+
+    private void addIncidentNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addIncidentNameActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_addIncidentNameActionPerformed
+
+    private void incidentDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_incidentDetailsActionPerformed
+        // TODO add your handling code here:
+        Object[] incidentList = script.incidents.toArray();
+        ScriptIncident i = (ScriptIncident) JOptionPane.showInputDialog(
+                this,
+                "Select Incident:",
+                "Edit Incident",
+                JOptionPane.PLAIN_MESSAGE,
+                null,
+                incidentList,
+                script.incidents.get(0));
+
+        // If a valid incident was selected
+        if (i != null)
+        {
+            editingIncident = true;
+            oldIncidentIndex = script.incidents.indexOf(i);
+
+            addIncidentName.setText(i.name);
+            addIncidentNumber.setValue(i.number);
+            
+            addIncidentLocation.setText(i.getCadData(i.offset).Header_FullLoc);
+            addIncidentType.setText(i.getCadData(i.offset).Header_Type);
+            addIncidentStart.setValue(i.offset / 60);
+            //addIncidentLength.setValue(i.length / 60);
+            incidentColorField.setBackground(i.color);
+            selectedColor = i.color;
+            addIncidentDescription.setText(i.description);
+
+            incidentFrame.setVisible(true);
+        }
+    }//GEN-LAST:event_incidentDetailsActionPerformed
+
+    private void popupDeleteIncidentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_popupDeleteIncidentActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_popupDeleteIncidentActionPerformed
+
+    private void loadUnitsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadUnitsActionPerformed
+        // TODO: needs to have testing performed
+        JFileChooser fc = new JFileChooser();
+
+        //Search for .xml files
+        fc.setFileFilter(new ExtensionFileFilter("Simulation Script XML (.xml)",
+                new String[]
+                {
+                    "xml"
+                }));
+        if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
+        {
+            //load script with values from the selected file
+            script.loadUnitsFromFile(fc.getSelectedFile());
+        }
+    }//GEN-LAST:event_loadUnitsActionPerformed
+
+    private void scriptBuilderMenuBarAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_scriptBuilderMenuBarAncestorAdded
+        //loads in the initial unit file
+//        String fileName = "units.xml";
+//        
+//        File f = new File(fileName);
+//        
+//        script.loadUnitsFromFile(f);
+    }//GEN-LAST:event_scriptBuilderMenuBarAncestorAdded
 
     /**
@@ -2292,7 +2480,9 @@
     private javax.swing.JSlider TMCALSlider;
     private javax.swing.JTextArea addIncidentDescription;
+    private javax.swing.JTextField addIncidentLocation;
     private javax.swing.JTextField addIncidentName;
     private javax.swing.JSpinner addIncidentNumber;
     private javax.swing.JSpinner addIncidentStart;
+    private javax.swing.JTextField addIncidentType;
     private javax.swing.JFrame addNoiseFrame;
     private javax.swing.JSlider backgroundNoiseSlider;
@@ -2306,4 +2496,5 @@
     private javax.swing.JMenuItem deleteEventList;
     private javax.swing.JMenuItem deleteIncident;
+    private javax.swing.JMenuItem deleteIncident1;
     private javax.swing.JMenuItem editEventList;
     private javax.swing.JPopupMenu eventListPopupMenu;
@@ -2324,4 +2515,5 @@
     private javax.swing.JMenuItem helpAbout;
     private javax.swing.JMenu helpMenu;
+    private javax.swing.JMenu helpMenu1;
     private javax.swing.JMenuItem helpTutorial;
     private javax.swing.JButton incidentCancelButton;
@@ -2353,4 +2545,6 @@
     private scriptbuilder.gui.panels.IncidentTimelinePanel incidentTimelinePanel8;
     private scriptbuilder.gui.panels.IncidentTimelinePanel incidentTimelinePanel9;
+    private javax.swing.JLabel jLabel1;
+    private javax.swing.JLabel jLabel2;
     private javax.swing.JMenuItem jMenuItem2;
     private javax.swing.JMenuItem jMenuItem4;
@@ -2379,4 +2573,5 @@
     private javax.swing.JSlider laneClosuresSlider;
     private javax.swing.JMenuItem loadIncident;
+    private javax.swing.JMenuItem loadUnits;
     private javax.swing.JSlider minorEventsSlider;
     private javax.swing.JMenuItem newIncident;
