Index: trunk/src/scriptbuilder/gui/panels/IncidentTimelinePanel.java
===================================================================
--- trunk/src/scriptbuilder/gui/panels/IncidentTimelinePanel.java	(revision 133)
+++ trunk/src/scriptbuilder/gui/panels/IncidentTimelinePanel.java	(revision 145)
@@ -202,41 +202,43 @@
          * Determine if the mouse click happened within a valid timeSlice on
          * this incident; if so, activate the Editor window for that timeSlice.
-         *
-         * @param e the mouse event
+         *todo: fix bug where the event editor window appears even when a event type is not selected.
+         * @param clickEvent the mouse event
          */
         @Override
-        public void mouseClicked(MouseEvent e)
-        {
-            Editor ed = null;
-            ScriptBuilderFrame f = null;
-            IncidentEditorFrame g = null;
+        public void mouseClicked(MouseEvent clickEvent)
+        {
+            Editor editor = null;
+            ScriptBuilderFrame scriptBuilderFrameCurrent = null;
+            IncidentEditorFrame incidentEditFrameCurrent = null;
             if (getTopLevelAncestor() instanceof ScriptBuilderFrame)
             {
-                f = (ScriptBuilderFrame) getTopLevelAncestor();
+                scriptBuilderFrameCurrent = (ScriptBuilderFrame) getTopLevelAncestor();
 
             }
             else if (getTopLevelAncestor() instanceof IncidentEditorFrame)
             {
-                g = (IncidentEditorFrame) getTopLevelAncestor();
-                ed = new Editor(g);
-            }
-
-            x = cursorTime = e.getX();
-            y = e.getY();
-
-            if (e.getX() % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
+                incidentEditFrameCurrent = (IncidentEditorFrame) getTopLevelAncestor();
+                editor = new Editor(incidentEditFrameCurrent);
+            }
+
+            x = cursorTime = clickEvent.getX();
+            y = clickEvent.getY();
+            //System.out.println(cursorTime);
+            //logic that follows is used to "snap" the cursor location to the lines displayed on the timeline panel
+            if (clickEvent.getX() % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
                     > ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK / 2)
             {
                 cursorTime += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK
-                        - e.getX()
+                        - clickEvent.getX()
                         % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK;
             }
             else
             {
-                cursorTime -= e.getX()
+                cursorTime -= clickEvent.getX()
                         % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK;
             }
 
             int newSlice = (cursorTime / ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK);
+            
             newSlice *= ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION;
             /**
@@ -248,48 +250,60 @@
             }
 
-            if (ed != null)
-            {
-                ed.setSlice(incident.slices.get(newSlice));
-            }
+            
 
             /**
-             * Add a new icon if left mouse button was clicked *
+             * Add a new icon if left mouse button was clicked 
              */
-            if (e.getButton() == MouseEvent.BUTTON1)
-            {
-
+            if (clickEvent.getButton() == MouseEvent.BUTTON1)
+            {
+                
                 if (getTopLevelAncestor() instanceof IncidentEditorFrame)
                 {
-                    if (incident.slices.size() == 0 && newSlice != 0)
+                    
+                    if (incidentEditFrameCurrent.currentEventType != null)
                     {
-                        JOptionPane.showMessageDialog(g, "This is the first event in the incident.\n"
-                                + "Therefore, it will be automatically positioned at time 00:00:00,\n"
-                                + "relative to the start of the incident.", "Event will be moved", JOptionPane.INFORMATION_MESSAGE);
-                        newSlice = 0;
-                    }
-                    if (g.currentEventType != null)
-                    {
-                        I_ScriptEvent s = ScriptEvent.factoryByType(g.currentEventType);
-                        if (ed != null)
+                        if ((incident.slices.size() == 0 && newSlice != 0)||(incident.slices.get(0).events.isEmpty()))
                         {
-                            ed.addEvent(eventTypeToPropertyMap.get(g.currentEventType), s);
+                            
+                            JOptionPane.showMessageDialog(incidentEditFrameCurrent, "This is the first event in the incident.\n"
+                                    + "Therefore, it will be automatically positioned at time 00:00:00,\n"
+                                    + "relative to the start of the incident.", "Event will be moved", JOptionPane.INFORMATION_MESSAGE);
+                            newSlice = 0;
                         }
-                        if (incident.slices.get(newSlice) == null)
+                        //add the time of addition to be passed through to the event itself somewhere in here? Stored in newSlice
+                        I_ScriptEvent newScriptEvent = ScriptEvent.factoryByType(incidentEditFrameCurrent.currentEventType);
+//                        if (editor != null)
+//                        {
+//                            //this is not necessary if we just load the slices after we create a new one in the window, creates some extra dummy slice for no reason.
+//                            //this adds a new event to the existing editor window
+//                            editor.addEvent(eventTypeToPropertyMap.get(incidentEditFrameCurrent.currentEventType), newScriptEvent);
+//                        }
+                        if (incident.slices.get(newSlice) == null || incident.slices.get(newSlice).events.isEmpty())
                         {
-                            incident.addNewEvent(s, newSlice);
+                            //if there is no slice at the newSlice time, then create a new event with a new slice at that time
+                            
+                            incident.addNewEvent(newScriptEvent, newSlice);
+                            //find out where the new slice is added and then make it
+                            //possible to 
+                            //editor.setSlice(incident.getSlices().get(newSlice));
                         }
                         else
                         {
-                            incident.slices.get(newSlice).addEvent(s);
+                            //if there is already a slice there, just add the event to the 
+                            incident.slices.get(newSlice).addEvent(newScriptEvent);
                         }
-                        g.update(null, g.getIncident());
+                        incidentEditFrameCurrent.update(null, incidentEditFrameCurrent.getIncident());
                     }
                 }
             }
 
+            if (editor != null)
+            {
+                editor.setSlice(incident.slices.get(newSlice));
+            }
             if (incident.slices.get(newSlice) != null
                     && getTopLevelAncestor() instanceof IncidentEditorFrame)
             {
-                ed.setVisible(true);
+                editor.setVisible(true);
             }
         }
@@ -498,4 +512,5 @@
         if (focused)
         {
+            //System.out.println("Cursor Time: " + cursorTime);
             CursorDrawer.DrawCursor(g2d, cursorTime, false);
             if (this.getTopLevelAncestor() instanceof ScriptBuilderFrame)
