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


Ignore:
Timestamp:
11/18/2019 03:51:55 PM (6 years ago)
Author:
sdanthin
Message:

IncidentTimelinePanel?.java added right-click menu popup functionality to add time
ScriptIncident?.java Added moveAllFollowingEvents function
ScriptIncidentTest?.java Added test to test moveAllFollowingEvents - may need better edge cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/panels/IncidentTimelinePanel.java

    r145 r150  
    1818import javax.swing.JPanel; 
    1919import javax.swing.JPopupMenu; 
     20import javax.swing.SwingUtilities; 
    2021import javax.swing.event.MouseInputAdapter; 
    2122import scriptbuilder.gui.IncidentEditorFrame; 
     
    6364     */ 
    6465    private boolean hasPopupAccess; 
    65  
     66     
    6667    int cursorTime, lastSlice, x, y; 
    6768 
     
    126127        { 
    127128            JPopupMenu menu = new JPopupMenu(); 
    128             JMenuItem eventsMenuItem = new JMenuItem("Events"); 
    129             JMenuItem propsMenuItem = new JMenuItem("Properties"); 
    130             eventsMenuItem.setActionCommand("Edit Events"); 
    131             propsMenuItem.setActionCommand("Modify Incident Properties"); 
    132  
    133129            PopupMenuItemListener menuItemListener = new PopupMenuItemListener(); 
    134  
    135             eventsMenuItem.addActionListener(menuItemListener); 
    136             propsMenuItem.addActionListener(menuItemListener); 
    137  
    138             menu.add(eventsMenuItem); 
    139             menu.add(propsMenuItem); 
     130            if(getTopLevelAncestor() instanceof ScriptBuilderFrame) 
     131            { 
     132                JMenuItem eventsMenuItem = new JMenuItem("Events"); 
     133                JMenuItem propsMenuItem = new JMenuItem("Properties"); 
     134                eventsMenuItem.setActionCommand("Edit Events"); 
     135                propsMenuItem.setActionCommand("Modify Incident Properties"); 
     136 
     137                 
     138 
     139                eventsMenuItem.addActionListener(menuItemListener); 
     140                propsMenuItem.addActionListener(menuItemListener); 
     141 
     142                menu.add(eventsMenuItem); 
     143                menu.add(propsMenuItem); 
     144            } 
     145             
     146             
     147             
     148            return menu; 
     149        } 
     150        private JPopupMenu createPopup(int x, int y) 
     151        { 
     152            JPopupMenu menu = new JPopupMenu(); 
     153            PopupMenuItemListener menuItemListener = new PopupMenuItemListener(); 
     154            if(getTopLevelAncestor() instanceof IncidentEditorFrame) 
     155            { 
     156                JMenuItem addTimeMenuItem = new JMenuItem("Add time here"); 
     157                JMenuItem removeTimeMenuItem = new JMenuItem("Remove time here"); 
     158                cursorTime =x; 
     159                 
     160       
     161                //logic that follows is used to "snap" the cursor location to the lines displayed on the timeline panel 
     162                if (x % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
     163                        > ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK / 2) 
     164                { 
     165                    cursorTime += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
     166                            - x 
     167                            % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK; 
     168                } 
     169                else 
     170                { 
     171                    cursorTime -= x 
     172                            % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK; 
     173                } 
     174 
     175                int newSlice = (cursorTime / ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK); 
     176 
     177                newSlice *= ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION; 
     178                 
     179                    addTimeMenuItem.setActionCommand("Add Time " + newSlice); 
     180                    removeTimeMenuItem.setActionCommand("Remove Time " + newSlice); 
     181                    removeTimeMenuItem.addActionListener(menuItemListener); 
     182                    addTimeMenuItem.addActionListener(menuItemListener); 
     183                    menu.add(addTimeMenuItem); 
     184                    menu.add(removeTimeMenuItem); 
     185            } 
    140186            return menu; 
    141187        } 
     
    163209                    } 
    164210                } 
     211                if(topFrame instanceof IncidentEditorFrame) 
     212                { 
     213                    if(e.getActionCommand().substring(0,8).equals("Add Time")) 
     214                    { 
     215                        int offset = Integer.parseInt(e.getActionCommand().substring(9,e.getActionCommand().length())); 
     216                        String addTimeInput = JOptionPane.showInputDialog("Add time(rounded to lowest 20s): "); 
     217                        int addTime = 0; 
     218                         
     219                        try 
     220                        { 
     221                            addTime = Integer.parseInt(addTimeInput); 
     222                        }catch(NumberFormatException exception){ 
     223                            addTime = 0; 
     224                            System.err.print("an invalid number was inputted"); 
     225                        } 
     226                         
     227                         
     228                        addTime = addTime-(addTime%20); 
     229                         
     230                        if(offset<=incident.offset+incident.length) 
     231                        { 
     232                            incident.moveAllFollowingEvents(offset, addTime); 
     233                        } 
     234                    } 
     235                    if(e.getActionCommand().substring(0,11).equals("Remove Time")) 
     236                    { 
     237                        //does addTime but with a negative time 
     238                        int offset = Integer.parseInt(e.getActionCommand().substring(11,e.getActionCommand().length()).trim()); 
     239                        String addTimeInput = JOptionPane.showInputDialog("Remove time(rounded to lowest 20s): "); 
     240                        int addTime = 0; 
     241                         
     242                        try 
     243                        { 
     244                            addTime = Integer.parseInt(addTimeInput); 
     245                        }catch(NumberFormatException exception){ 
     246                            addTime = 0; 
     247                            System.err.print("an invalid number was inputted"); 
     248                        } 
     249                         
     250                         
     251                        addTime = -(addTime-(addTime%20)); 
     252                         
     253                        if(offset<=incident.offset+incident.length) 
     254                        { 
     255                            incident.moveAllFollowingEvents(offset, addTime); 
     256                        } 
     257                    } 
     258                    //add my own handling of click menu here  
     259                } 
    165260                topFrame.repaint(); 
    166261            } 
     
    181276            if (e.isPopupTrigger() && hasPopupAccess) 
    182277            { 
    183                 JPopupMenu popup = createPopup(); 
    184                 popup.show(e.getComponent(), currentMouseX, currentMouseY); 
     278                if(getTopLevelAncestor() instanceof IncidentEditorFrame) 
     279                { 
     280                    JPopupMenu popup = createPopup(currentMouseX,currentMouseY); 
     281                    popup.show(e.getComponent(), currentMouseX, currentMouseY); 
     282                }else 
     283                { 
     284                    JPopupMenu popup = createPopup(); 
     285                    popup.show(e.getComponent(), currentMouseX, currentMouseY); 
     286                } 
     287                 
     288                 
     289                 
    185290            } 
    186291        } 
     
    297402                } 
    298403            } 
     404//            //code below may be useless 
     405//            if(SwingUtilities.isRightMouseButton(clickEvent)) 
     406//            { 
     407//                if (getTopLevelAncestor() instanceof IncidentEditorFrame && false) 
     408//                { 
     409//                    incidentEditFrameCurrent = (IncidentEditorFrame) getTopLevelAncestor(); 
     410//                    if(incidentEditFrameCurrent.currentEventType == null) 
     411//                    { 
     412//                        JPopupMenu timeAddMenu = new JPopupMenu(); 
     413//                        JMenuItem addTimeButton = new JMenuItem("Add time here"); 
     414//                        //addTimeButton.addActionListener(al); 
     415//                        timeAddMenu.add(addTimeButton); 
     416//                        timeAddMenu.show(clickEvent.getComponent(),clickEvent.getX(),clickEvent.getY()); 
     417//                         
     418//                    } 
     419//                     
     420//                } 
     421//            } 
    299422 
    300423            if (editor != null) 
     
    516639            if (this.getTopLevelAncestor() instanceof ScriptBuilderFrame) 
    517640            { 
     641                  
    518642                if (((ScriptBuilderFrame) this.getTopLevelAncestor()).currentEventType != null) 
    519643                { 
     
    530654                            ((IncidentEditorFrame) this.getTopLevelAncestor()).currentEventType, 
    531655                            x + 5, y + 10); 
     656                     
     657                }else 
     658                { 
     659                    //when we aren't selecting one of the incident adding buttons, this. 
     660                     
     661                    //this.selectMode = ((IncidentEditorFrame)this.getTopLevelAncestor()).selectMode; 
     662                     
     663                    if(((IncidentEditorFrame)this.getTopLevelAncestor()).selectMode) 
     664                    { 
     665                        //cursorTime dictates where we are in the x direction 
     666                        //there seems to be no way to tell where we are in the y direction 
     667                        //implement something? 
     668                         
     669                    } 
    532670                } 
    533671            } 
Note: See TracChangeset for help on using the changeset viewer.