~tapaal-contributor/tapaal/autodetect-lens-check2

« back to all changes in this revision

Viewing changes to src/dk/aau/cs/gui/TabContent.java

  • Committer: Jiri Srba
  • Date: 2020-08-24 09:50:07 UTC
  • mfrom: (1071.5.13 game-shortcut)
  • Revision ID: srba.jiri@gmail.com-20200824095007-94smlnnaod0sbr6r
merged in lp:~tapaal-contributor/tapaal/game-shortcuts adding shortcuts U/E/L for drawing uncontrolalble and urgent transitions

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import dk.aau.cs.gui.components.BugHandledJXMultisplitPane;
19
19
import dk.aau.cs.gui.components.StatisticsPanel;
20
20
import dk.aau.cs.gui.components.TransitionFireingComponent;
21
 
import dk.aau.cs.gui.undo.Command;
22
 
import dk.aau.cs.gui.undo.DeleteQueriesCommand;
23
 
import dk.aau.cs.gui.undo.TimedPlaceMarkingEdit;
 
21
import dk.aau.cs.gui.undo.*;
24
22
import dk.aau.cs.io.*;
25
23
import dk.aau.cs.io.queries.SUMOQueryLoader;
26
24
import dk.aau.cs.io.queries.XMLQueryLoader;
171
169
            return new Result<>(pnObject);
172
170
        }
173
171
 
174
 
        public Result<TimedTransitionComponent, ModelViolation> addNewTimedTransitions(DataLayer c, Point p) {
 
172
        public Result<TimedTransitionComponent, ModelViolation> addNewTimedTransitions(DataLayer c, Point p, boolean isUncontrollable) {
175
173
            dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(drawingSurface.getNameGenerator().getNewTransitionName(guiModelToModel.get(c)));
176
174
 
 
175
            transition.setUncontrollable(isUncontrollable);
177
176
            TimedTransitionComponent pnObject = new TimedTransitionComponent(p.x, p.y, transition, lens);
178
177
 
179
178
            guiModelToModel.get(c).add(transition);
542
541
            }
543
542
        }
544
543
 
 
544
        public void toggleUncontrollableTrans() {
 
545
            ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection();
 
546
            TabContent currentTab = TabContent.this;
 
547
            getUndoManager().newEdit();
 
548
 
 
549
            for (PetriNetObject o : selection) {
 
550
                if (o instanceof TimedTransitionComponent) {
 
551
                    TimedTransitionComponent transition = (TimedTransitionComponent) o;
 
552
                    Command cmd = new ToggleTransitionUncontrollable(transition.underlyingTransition(), currentTab);
 
553
 
 
554
                    cmd.redo();
 
555
                    getUndoManager().addEdit(cmd);
 
556
                }
 
557
            }
 
558
            repaint();
 
559
        }
 
560
 
 
561
        public void toggleUrgentTrans() {
 
562
            ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection();
 
563
            TabContent currentTab = TabContent.this;
 
564
            getUndoManager().newEdit();
 
565
 
 
566
            for (PetriNetObject o : selection) {
 
567
                if (o instanceof TimedTransitionComponent) {
 
568
                    TimedTransitionComponent transition = (TimedTransitionComponent) o;
 
569
                    Command cmd = new ToggleTransitionUrgent(transition.underlyingTransition(), currentTab);
 
570
 
 
571
                    cmd.redo();
 
572
                    getUndoManager().addEdit(cmd);
 
573
                }
 
574
            }
 
575
            repaint();
 
576
        }
 
577
 
545
578
 
546
579
    }
547
580
 
1785
1818
            case TAPNTRANS:
1786
1819
                setManager(new CanvasTransitionDrawController());
1787
1820
                break;
 
1821
            case UNCONTROLLABLETRANS:
 
1822
                setManager(new CanvasUncontrollableTransitionDrawController());
 
1823
                break;
1788
1824
            case ANNOTATION:
1789
1825
                setManager(new CanvasAnnotationNoteDrawController());
1790
1826
                break;
2145
2181
        public void drawingSurfaceMousePressed(MouseEvent e) {
2146
2182
            Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom());
2147
2183
 
2148
 
            guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p);
 
2184
            guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p, false);
 
2185
        }
 
2186
 
 
2187
        @Override
 
2188
        public void registerEvents() {
 
2189
 
 
2190
        }
 
2191
    }
 
2192
 
 
2193
    class CanvasUncontrollableTransitionDrawController extends AbstractDrawingSurfaceManager {
 
2194
 
 
2195
        @Override
 
2196
        public void drawingSurfaceMousePressed(MouseEvent e) {
 
2197
            Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom());
 
2198
 
 
2199
            guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p, true);
2149
2200
        }
2150
2201
 
2151
2202
        @Override
2282
2333
                        var r = guiModelManager.addNewTimedPlace(getModel(), p);
2283
2334
                        placeClicked(r.result, e);
2284
2335
                    } else { //Transition
2285
 
                        var r = guiModelManager.addNewTimedTransitions(getModel(), p);
 
2336
                        var r = guiModelManager.addNewTimedTransitions(getModel(), p, false);
2286
2337
                        transitionClicked(r.result, e);
2287
2338
                    }
2288
2339
                }
2703
2754
        }
2704
2755
    }
2705
2756
    public List<GuiAction> getAvailableDrawActions(){
2706
 
        if(lens.isTimed()){
2707
 
            return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction));
2708
 
        } else{
2709
 
            return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction));
 
2757
        if (lens.isTimed() && !lens.isGame()) {
 
2758
            return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUrgentAction));
 
2759
        } else if (lens.isTimed()) {
 
2760
            return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, uncontrollableTransAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUrgentAction, toggleUncontrollableAction));
 
2761
        } else if (lens.isGame()){
 
2762
            return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, uncontrollableTransAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUncontrollableAction));
 
2763
        } else {
 
2764
            return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction));
2710
2765
        }
2711
2766
    }
2712
2767
 
2740
2795
            setMode(Pipe.ElementType.TAPNTRANS);
2741
2796
        }
2742
2797
    };
 
2798
    private final GuiAction uncontrollableTransAction = new GuiAction("Uncontrollable transition", "Add an uncontrollable transition (L)", "L", true) {
 
2799
        public void actionPerformed(ActionEvent e) {
 
2800
            setMode(Pipe.ElementType.UNCONTROLLABLETRANS);
 
2801
        }
 
2802
    };
2743
2803
    private final GuiAction tokenAction = new GuiAction("Add token", "Add a token (+)", "typed +", true) {
2744
2804
        public void actionPerformed(ActionEvent e) {
2745
2805
            setMode(Pipe.ElementType.ADDTOKEN);
2767
2827
            setMode(Pipe.ElementType.TRANSPORTARC);
2768
2828
        }
2769
2829
    };
 
2830
    private final GuiAction toggleUncontrollableAction = new GuiAction("Toggle uncontrollable transition", "Toggle between control/environment transition", "E", true) {
 
2831
        public void actionPerformed(ActionEvent e) {
 
2832
            guiModelManager.toggleUncontrollableTrans();
 
2833
        }
 
2834
    };
 
2835
    private final GuiAction toggleUrgentAction = new GuiAction("Toggle urgent transition", "Toggle between urgent/non-urgent transition", "U", true) {
 
2836
        public void actionPerformed(ActionEvent e) {
 
2837
            guiModelManager.toggleUrgentTrans();
 
2838
        }
 
2839
    };
2770
2840
    private final GuiAction timeAction = new GuiAction("Delay one time unit", "Let time pass one time unit", "W") {
2771
2841
        public void actionPerformed(ActionEvent e) {
2772
2842
            timeDelay();
2782
2852
        // deselect other actions
2783
2853
        selectAction.setSelected(CreateGui.guiMode == Pipe.ElementType.SELECT);
2784
2854
        transAction.setSelected(editorMode == Pipe.ElementType.TAPNTRANS);
 
2855
        uncontrollableTransAction.setSelected(editorMode == Pipe.ElementType.UNCONTROLLABLETRANS);
2785
2856
        timedPlaceAction.setSelected(editorMode == Pipe.ElementType.TAPNPLACE);
2786
2857
        timedArcAction.setSelected(editorMode == Pipe.ElementType.TAPNARC);
2787
2858
        transportArcAction.setSelected(editorMode == Pipe.ElementType.TRANSPORTARC);
2796
2867
            case draw:
2797
2868
                selectAction.setEnabled(true);
2798
2869
                transAction.setEnabled(true);
 
2870
                uncontrollableTransAction.setEnabled(true);
2799
2871
                timedPlaceAction.setEnabled(true);
2800
2872
                timedArcAction.setEnabled(true);
2801
2873
                transportArcAction.setEnabled(true);
2809
2881
            case noNet:
2810
2882
                selectAction.setEnabled(false);
2811
2883
                transAction.setEnabled(false);
 
2884
                uncontrollableTransAction.setEnabled(false);
2812
2885
                timedPlaceAction.setEnabled(false);
2813
2886
                timedArcAction.setEnabled(false);
2814
2887
                transportArcAction.setEnabled(false);
2821
2894
            case animation:
2822
2895
                selectAction.setEnabled(false);
2823
2896
                transAction.setEnabled(false);
 
2897
                uncontrollableTransAction.setEnabled(false);
2824
2898
                timedPlaceAction.setEnabled(false);
2825
2899
                timedArcAction.setEnabled(false);
2826
2900
                transportArcAction.setEnabled(false);
2841
2915
    public static final String textforTAPNPlace = "Place Mode: Right click on a place to see menu options ";
2842
2916
    public static final String textforTrans = "Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
2843
2917
    public static final String textforTimedTrans = "Timed Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
 
2918
    public static final String textforUncontrollableTrans = "Uncontrollable Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
2844
2919
    public static final String textforAddtoken = "Add Token Mode: Click on a place to add a token";
2845
2920
    public static final String textforDeltoken = "Delete Token Mode: Click on a place to delete a token ";
2846
2921
    public static final String textforAnimation = "Simulation Mode: Red transitions are enabled, click a transition to fire it";
2853
2928
 
2854
2929
    public void changeStatusbarText(Pipe.ElementType type) {
2855
2930
        switch (type) {
 
2931
            case UNCONTROLLABLETRANS:
 
2932
                app.ifPresent(o14 -> o14.setStatusBarText(textforUncontrollableTrans));
 
2933
 
2856
2934
            case PLACE:
2857
2935
                app.ifPresent(o13 -> o13.setStatusBarText(textforPlace));
2858
2936
                break;