Changeset 145 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui/panels


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/panels/IncidentTimelinePanel.java

    r133 r145  
    202202         * Determine if the mouse click happened within a valid timeSlice on 
    203203         * this incident; if so, activate the Editor window for that timeSlice. 
    204          * 
    205          * @param e the mouse event 
     204         *todo: fix bug where the event editor window appears even when a event type is not selected. 
     205         * @param clickEvent the mouse event 
    206206         */ 
    207207        @Override 
    208         public void mouseClicked(MouseEvent e) 
    209         { 
    210             Editor ed = null; 
    211             ScriptBuilderFrame f = null; 
    212             IncidentEditorFrame g = null; 
     208        public void mouseClicked(MouseEvent clickEvent) 
     209        { 
     210            Editor editor = null; 
     211            ScriptBuilderFrame scriptBuilderFrameCurrent = null; 
     212            IncidentEditorFrame incidentEditFrameCurrent = null; 
    213213            if (getTopLevelAncestor() instanceof ScriptBuilderFrame) 
    214214            { 
    215                 f = (ScriptBuilderFrame) getTopLevelAncestor(); 
     215                scriptBuilderFrameCurrent = (ScriptBuilderFrame) getTopLevelAncestor(); 
    216216 
    217217            } 
    218218            else if (getTopLevelAncestor() instanceof IncidentEditorFrame) 
    219219            { 
    220                 g = (IncidentEditorFrame) getTopLevelAncestor(); 
    221                 ed = new Editor(g); 
    222             } 
    223  
    224             x = cursorTime = e.getX(); 
    225             y = e.getY(); 
    226  
    227             if (e.getX() % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
     220                incidentEditFrameCurrent = (IncidentEditorFrame) getTopLevelAncestor(); 
     221                editor = new Editor(incidentEditFrameCurrent); 
     222            } 
     223 
     224            x = cursorTime = clickEvent.getX(); 
     225            y = clickEvent.getY(); 
     226            //System.out.println(cursorTime); 
     227            //logic that follows is used to "snap" the cursor location to the lines displayed on the timeline panel 
     228            if (clickEvent.getX() % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
    228229                    > ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK / 2) 
    229230            { 
    230231                cursorTime += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
    231                         - e.getX() 
     232                        - clickEvent.getX() 
    232233                        % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK; 
    233234            } 
    234235            else 
    235236            { 
    236                 cursorTime -= e.getX() 
     237                cursorTime -= clickEvent.getX() 
    237238                        % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK; 
    238239            } 
    239240 
    240241            int newSlice = (cursorTime / ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK); 
     242             
    241243            newSlice *= ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION; 
    242244            /** 
     
    248250            } 
    249251 
    250             if (ed != null) 
    251             { 
    252                 ed.setSlice(incident.slices.get(newSlice)); 
    253             } 
     252             
    254253 
    255254            /** 
    256              * Add a new icon if left mouse button was clicked * 
     255             * Add a new icon if left mouse button was clicked  
    257256             */ 
    258             if (e.getButton() == MouseEvent.BUTTON1) 
    259             { 
    260  
     257            if (clickEvent.getButton() == MouseEvent.BUTTON1) 
     258            { 
     259                 
    261260                if (getTopLevelAncestor() instanceof IncidentEditorFrame) 
    262261                { 
    263                     if (incident.slices.size() == 0 && newSlice != 0) 
     262                     
     263                    if (incidentEditFrameCurrent.currentEventType != null) 
    264264                    { 
    265                         JOptionPane.showMessageDialog(g, "This is the first event in the incident.\n" 
    266                                 + "Therefore, it will be automatically positioned at time 00:00:00,\n" 
    267                                 + "relative to the start of the incident.", "Event will be moved", JOptionPane.INFORMATION_MESSAGE); 
    268                         newSlice = 0; 
    269                     } 
    270                     if (g.currentEventType != null) 
    271                     { 
    272                         I_ScriptEvent s = ScriptEvent.factoryByType(g.currentEventType); 
    273                         if (ed != null) 
     265                        if ((incident.slices.size() == 0 && newSlice != 0)||(incident.slices.get(0).events.isEmpty())) 
    274266                        { 
    275                             ed.addEvent(eventTypeToPropertyMap.get(g.currentEventType), s); 
     267                             
     268                            JOptionPane.showMessageDialog(incidentEditFrameCurrent, "This is the first event in the incident.\n" 
     269                                    + "Therefore, it will be automatically positioned at time 00:00:00,\n" 
     270                                    + "relative to the start of the incident.", "Event will be moved", JOptionPane.INFORMATION_MESSAGE); 
     271                            newSlice = 0; 
    276272                        } 
    277                         if (incident.slices.get(newSlice) == null) 
     273                        //add the time of addition to be passed through to the event itself somewhere in here? Stored in newSlice 
     274                        I_ScriptEvent newScriptEvent = ScriptEvent.factoryByType(incidentEditFrameCurrent.currentEventType); 
     275//                        if (editor != null) 
     276//                        { 
     277//                            //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. 
     278//                            //this adds a new event to the existing editor window 
     279//                            editor.addEvent(eventTypeToPropertyMap.get(incidentEditFrameCurrent.currentEventType), newScriptEvent); 
     280//                        } 
     281                        if (incident.slices.get(newSlice) == null || incident.slices.get(newSlice).events.isEmpty()) 
    278282                        { 
    279                             incident.addNewEvent(s, newSlice); 
     283                            //if there is no slice at the newSlice time, then create a new event with a new slice at that time 
     284                             
     285                            incident.addNewEvent(newScriptEvent, newSlice); 
     286                            //find out where the new slice is added and then make it 
     287                            //possible to  
     288                            //editor.setSlice(incident.getSlices().get(newSlice)); 
    280289                        } 
    281290                        else 
    282291                        { 
    283                             incident.slices.get(newSlice).addEvent(s); 
     292                            //if there is already a slice there, just add the event to the  
     293                            incident.slices.get(newSlice).addEvent(newScriptEvent); 
    284294                        } 
    285                         g.update(null, g.getIncident()); 
     295                        incidentEditFrameCurrent.update(null, incidentEditFrameCurrent.getIncident()); 
    286296                    } 
    287297                } 
    288298            } 
    289299 
     300            if (editor != null) 
     301            { 
     302                editor.setSlice(incident.slices.get(newSlice)); 
     303            } 
    290304            if (incident.slices.get(newSlice) != null 
    291305                    && getTopLevelAncestor() instanceof IncidentEditorFrame) 
    292306            { 
    293                 ed.setVisible(true); 
     307                editor.setVisible(true); 
    294308            } 
    295309        } 
     
    498512        if (focused) 
    499513        { 
     514            //System.out.println("Cursor Time: " + cursorTime); 
    500515            CursorDrawer.DrawCursor(g2d, cursorTime, false); 
    501516            if (this.getTopLevelAncestor() instanceof ScriptBuilderFrame) 
Note: See TracChangeset for help on using the changeset viewer.