Merge lp:~tapaal-contributor/tapaal/game-shortcuts into lp:tapaal

Proposed by Lena Ernstsen
Status: Merged
Approved by: Jiri Srba
Approved revision: 1112
Merged at revision: 1086
Proposed branch: lp:~tapaal-contributor/tapaal/game-shortcuts
Merge into: lp:tapaal
Diff against target: 284 lines (+95/-19)
5 files modified
src/dk/aau/cs/gui/TabContent.java (+88/-10)
src/net/tapaal/swinghelpers/ToggleButtonWithoutText.java (+5/-3)
src/pipe/gui/GuiFrame.java (+0/-1)
src/pipe/gui/Pipe.java (+1/-1)
src/pipe/gui/handler/TransitionHandler.java (+1/-4)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/game-shortcuts
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Kenneth Yrke Jørgensen Approve
Review via email: mp+389584@code.launchpad.net

Commit message

Added game shortcuts

Description of the change

When a transition is selected it is possible to toggle between a controlled/uncontrolled transition by pressing E and an urgent/non-urgent transition by pressing U

The shortcuts are only possible if the lens allows it

If the net is game, then it is possible to draw an uncontrollable transition by pressing L and clicking on the drawing surface

To post a comment you must log in.
1109. By Lena Ernstsen

Added annotation to toolbar

1110. By Lena Ernstsen

Moved the transition toggle shortcuts to be a guiAction

1111. By Lena Ernstsen

guiModelManager handles the toggle functionality

1112. By Lena Ernstsen

Added undo to the toggle

Revision history for this message
Kenneth Yrke Jørgensen (yrke) wrote :

Looks good

review: Approve
Revision history for this message
Jiri Srba (srba) wrote :

Works very nice! Great usability addition.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/dk/aau/cs/gui/TabContent.java'
--- src/dk/aau/cs/gui/TabContent.java 2020-08-17 08:18:13 +0000
+++ src/dk/aau/cs/gui/TabContent.java 2020-08-21 08:37:32 +0000
@@ -16,9 +16,7 @@
16import dk.aau.cs.gui.components.BugHandledJXMultisplitPane;16import dk.aau.cs.gui.components.BugHandledJXMultisplitPane;
17import dk.aau.cs.gui.components.StatisticsPanel;17import dk.aau.cs.gui.components.StatisticsPanel;
18import dk.aau.cs.gui.components.TransitionFireingComponent;18import dk.aau.cs.gui.components.TransitionFireingComponent;
19import dk.aau.cs.gui.undo.Command;19import dk.aau.cs.gui.undo.*;
20import dk.aau.cs.gui.undo.DeleteQueriesCommand;
21import dk.aau.cs.gui.undo.TimedPlaceMarkingEdit;
22import dk.aau.cs.io.*;20import dk.aau.cs.io.*;
23import dk.aau.cs.io.queries.SUMOQueryLoader;21import dk.aau.cs.io.queries.SUMOQueryLoader;
24import dk.aau.cs.io.queries.XMLQueryLoader;22import dk.aau.cs.io.queries.XMLQueryLoader;
@@ -168,9 +166,10 @@
168 return new Result<>(pnObject);166 return new Result<>(pnObject);
169 }167 }
170168
171 public Result<TimedTransitionComponent, ModelViolation> addNewTimedTransitions(DataLayer c, Point p) {169 public Result<TimedTransitionComponent, ModelViolation> addNewTimedTransitions(DataLayer c, Point p, boolean isUncontrollable) {
172 dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(drawingSurface.getNameGenerator().getNewTransitionName(guiModelToModel.get(c)));170 dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(drawingSurface.getNameGenerator().getNewTransitionName(guiModelToModel.get(c)));
173171
172 transition.setUncontrollable(isUncontrollable);
174 TimedTransitionComponent pnObject = new TimedTransitionComponent(p.x, p.y, transition, lens);173 TimedTransitionComponent pnObject = new TimedTransitionComponent(p.x, p.y, transition, lens);
175174
176 guiModelToModel.get(c).add(transition);175 guiModelToModel.get(c).add(transition);
@@ -539,6 +538,40 @@
539 }538 }
540 }539 }
541540
541 public void toggleUncontrollableTrans() {
542 ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection();
543 TabContent currentTab = TabContent.this;
544 getUndoManager().newEdit();
545
546 for (PetriNetObject o : selection) {
547 if (o instanceof TimedTransitionComponent) {
548 TimedTransitionComponent transition = (TimedTransitionComponent) o;
549 Command cmd = new ToggleTransitionUncontrollable(transition.underlyingTransition(), currentTab);
550
551 cmd.redo();
552 getUndoManager().addEdit(cmd);
553 }
554 }
555 repaint();
556 }
557
558 public void toggleUrgentTrans() {
559 ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection();
560 TabContent currentTab = TabContent.this;
561 getUndoManager().newEdit();
562
563 for (PetriNetObject o : selection) {
564 if (o instanceof TimedTransitionComponent) {
565 TimedTransitionComponent transition = (TimedTransitionComponent) o;
566 Command cmd = new ToggleTransitionUrgent(transition.underlyingTransition(), currentTab);
567
568 cmd.redo();
569 getUndoManager().addEdit(cmd);
570 }
571 }
572 repaint();
573 }
574
542575
543 }576 }
544577
@@ -1749,6 +1782,9 @@
1749 case TAPNTRANS:1782 case TAPNTRANS:
1750 setManager(new CanvasTransitionDrawController());1783 setManager(new CanvasTransitionDrawController());
1751 break;1784 break;
1785 case UNCONTROLLABLETRANS:
1786 setManager(new CanvasUncontrollableTransitionDrawController());
1787 break;
1752 case ANNOTATION:1788 case ANNOTATION:
1753 setManager(new CanvasAnnotationNoteDrawController());1789 setManager(new CanvasAnnotationNoteDrawController());
1754 break;1790 break;
@@ -2109,7 +2145,22 @@
2109 public void drawingSurfaceMousePressed(MouseEvent e) {2145 public void drawingSurfaceMousePressed(MouseEvent e) {
2110 Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom());2146 Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom());
21112147
2112 guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p);2148 guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p, false);
2149 }
2150
2151 @Override
2152 public void registerEvents() {
2153
2154 }
2155 }
2156
2157 class CanvasUncontrollableTransitionDrawController extends AbstractDrawingSurfaceManager {
2158
2159 @Override
2160 public void drawingSurfaceMousePressed(MouseEvent e) {
2161 Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom());
2162
2163 guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p, true);
2113 }2164 }
21142165
2115 @Override2166 @Override
@@ -2246,7 +2297,7 @@
2246 var r = guiModelManager.addNewTimedPlace(getModel(), p);2297 var r = guiModelManager.addNewTimedPlace(getModel(), p);
2247 placeClicked(r.result, e);2298 placeClicked(r.result, e);
2248 } else { //Transition2299 } else { //Transition
2249 var r = guiModelManager.addNewTimedTransitions(getModel(), p);2300 var r = guiModelManager.addNewTimedTransitions(getModel(), p, false);
2250 transitionClicked(r.result, e);2301 transitionClicked(r.result, e);
2251 }2302 }
2252 }2303 }
@@ -2667,10 +2718,14 @@
2667 }2718 }
2668 }2719 }
2669 public List<GuiAction> getAvailableDrawActions(){2720 public List<GuiAction> getAvailableDrawActions(){
2670 if(lens.isTimed()){2721 if (lens.isTimed() && !lens.isGame()) {
2671 return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction));2722 return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUrgentAction));
2672 } else{2723 } else if (lens.isTimed()) {
2673 return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction));2724 return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, uncontrollableTransAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUrgentAction, toggleUncontrollableAction));
2725 } else if (lens.isGame()){
2726 return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, uncontrollableTransAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUncontrollableAction));
2727 } else {
2728 return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction));
2674 }2729 }
2675 }2730 }
26762731
@@ -2704,6 +2759,11 @@
2704 setMode(Pipe.ElementType.TAPNTRANS);2759 setMode(Pipe.ElementType.TAPNTRANS);
2705 }2760 }
2706 };2761 };
2762 private final GuiAction uncontrollableTransAction = new GuiAction("Uncontrollable transition", "Add an uncontrollable transition (L)", "L", true) {
2763 public void actionPerformed(ActionEvent e) {
2764 setMode(Pipe.ElementType.UNCONTROLLABLETRANS);
2765 }
2766 };
2707 private final GuiAction tokenAction = new GuiAction("Add token", "Add a token (+)", "typed +", true) {2767 private final GuiAction tokenAction = new GuiAction("Add token", "Add a token (+)", "typed +", true) {
2708 public void actionPerformed(ActionEvent e) {2768 public void actionPerformed(ActionEvent e) {
2709 setMode(Pipe.ElementType.ADDTOKEN);2769 setMode(Pipe.ElementType.ADDTOKEN);
@@ -2731,6 +2791,16 @@
2731 setMode(Pipe.ElementType.TRANSPORTARC);2791 setMode(Pipe.ElementType.TRANSPORTARC);
2732 }2792 }
2733 };2793 };
2794 private final GuiAction toggleUncontrollableAction = new GuiAction("Toggle uncontrollable transition", "Toggle between control/environment transition", "E", true) {
2795 public void actionPerformed(ActionEvent e) {
2796 guiModelManager.toggleUncontrollableTrans();
2797 }
2798 };
2799 private final GuiAction toggleUrgentAction = new GuiAction("Toggle urgent transition", "Toggle between urgent/non-urgent transition", "U", true) {
2800 public void actionPerformed(ActionEvent e) {
2801 guiModelManager.toggleUrgentTrans();
2802 }
2803 };
2734 private final GuiAction timeAction = new GuiAction("Delay one time unit", "Let time pass one time unit", "W") {2804 private final GuiAction timeAction = new GuiAction("Delay one time unit", "Let time pass one time unit", "W") {
2735 public void actionPerformed(ActionEvent e) {2805 public void actionPerformed(ActionEvent e) {
2736 timeDelay();2806 timeDelay();
@@ -2746,6 +2816,7 @@
2746 // deselect other actions2816 // deselect other actions
2747 selectAction.setSelected(CreateGui.guiMode == Pipe.ElementType.SELECT);2817 selectAction.setSelected(CreateGui.guiMode == Pipe.ElementType.SELECT);
2748 transAction.setSelected(editorMode == Pipe.ElementType.TAPNTRANS);2818 transAction.setSelected(editorMode == Pipe.ElementType.TAPNTRANS);
2819 uncontrollableTransAction.setSelected(editorMode == Pipe.ElementType.UNCONTROLLABLETRANS);
2749 timedPlaceAction.setSelected(editorMode == Pipe.ElementType.TAPNPLACE);2820 timedPlaceAction.setSelected(editorMode == Pipe.ElementType.TAPNPLACE);
2750 timedArcAction.setSelected(editorMode == Pipe.ElementType.TAPNARC);2821 timedArcAction.setSelected(editorMode == Pipe.ElementType.TAPNARC);
2751 transportArcAction.setSelected(editorMode == Pipe.ElementType.TRANSPORTARC);2822 transportArcAction.setSelected(editorMode == Pipe.ElementType.TRANSPORTARC);
@@ -2760,6 +2831,7 @@
2760 case draw:2831 case draw:
2761 selectAction.setEnabled(true);2832 selectAction.setEnabled(true);
2762 transAction.setEnabled(true);2833 transAction.setEnabled(true);
2834 uncontrollableTransAction.setEnabled(true);
2763 timedPlaceAction.setEnabled(true);2835 timedPlaceAction.setEnabled(true);
2764 timedArcAction.setEnabled(true);2836 timedArcAction.setEnabled(true);
2765 transportArcAction.setEnabled(true);2837 transportArcAction.setEnabled(true);
@@ -2773,6 +2845,7 @@
2773 case noNet:2845 case noNet:
2774 selectAction.setEnabled(false);2846 selectAction.setEnabled(false);
2775 transAction.setEnabled(false);2847 transAction.setEnabled(false);
2848 uncontrollableTransAction.setEnabled(false);
2776 timedPlaceAction.setEnabled(false);2849 timedPlaceAction.setEnabled(false);
2777 timedArcAction.setEnabled(false);2850 timedArcAction.setEnabled(false);
2778 transportArcAction.setEnabled(false);2851 transportArcAction.setEnabled(false);
@@ -2785,6 +2858,7 @@
2785 case animation:2858 case animation:
2786 selectAction.setEnabled(false);2859 selectAction.setEnabled(false);
2787 transAction.setEnabled(false);2860 transAction.setEnabled(false);
2861 uncontrollableTransAction.setEnabled(false);
2788 timedPlaceAction.setEnabled(false);2862 timedPlaceAction.setEnabled(false);
2789 timedArcAction.setEnabled(false);2863 timedArcAction.setEnabled(false);
2790 transportArcAction.setEnabled(false);2864 transportArcAction.setEnabled(false);
@@ -2805,6 +2879,7 @@
2805 public static final String textforTAPNPlace = "Place Mode: Right click on a place to see menu options ";2879 public static final String textforTAPNPlace = "Place Mode: Right click on a place to see menu options ";
2806 public static final String textforTrans = "Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";2880 public static final String textforTrans = "Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
2807 public static final String textforTimedTrans = "Timed Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";2881 public static final String textforTimedTrans = "Timed Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
2882 public static final String textforUncontrollableTrans = "Uncontrollable Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
2808 public static final String textforAddtoken = "Add Token Mode: Click on a place to add a token";2883 public static final String textforAddtoken = "Add Token Mode: Click on a place to add a token";
2809 public static final String textforDeltoken = "Delete Token Mode: Click on a place to delete a token ";2884 public static final String textforDeltoken = "Delete Token Mode: Click on a place to delete a token ";
2810 public static final String textforAnimation = "Simulation Mode: Red transitions are enabled, click a transition to fire it";2885 public static final String textforAnimation = "Simulation Mode: Red transitions are enabled, click a transition to fire it";
@@ -2817,6 +2892,9 @@
28172892
2818 public void changeStatusbarText(Pipe.ElementType type) {2893 public void changeStatusbarText(Pipe.ElementType type) {
2819 switch (type) {2894 switch (type) {
2895 case UNCONTROLLABLETRANS:
2896 app.ifPresent(o14 -> o14.setStatusBarText(textforUncontrollableTrans));
2897
2820 case PLACE:2898 case PLACE:
2821 app.ifPresent(o13 -> o13.setStatusBarText(textforPlace));2899 app.ifPresent(o13 -> o13.setStatusBarText(textforPlace));
2822 break;2900 break;
28232901
=== modified file 'src/net/tapaal/swinghelpers/ToggleButtonWithoutText.java'
--- src/net/tapaal/swinghelpers/ToggleButtonWithoutText.java 2019-11-05 12:19:17 +0000
+++ src/net/tapaal/swinghelpers/ToggleButtonWithoutText.java 2020-08-21 08:37:32 +0000
@@ -1,6 +1,7 @@
1package net.tapaal.swinghelpers;1package net.tapaal.swinghelpers;
22
3import javax.swing.*;3import javax.swing.*;
4import java.awt.*;
45
5/**6/**
6 * A JToggleButton that without any text7 * A JToggleButton that without any text
@@ -9,10 +10,11 @@
910
10 public ToggleButtonWithoutText(Action a) {11 public ToggleButtonWithoutText(Action a) {
11 super(a);12 super(a);
12 if (a.getValue(Action.SMALL_ICON) != null) {13 if (a.getValue(Action.SMALL_ICON) == null) {
13 // toggle buttons like to have images *and* text, nasty14 setVisible(false);
14 setText(null);
15 }15 }
16 setText(null);
17
16 this.setRequestFocusEnabled(false);18 this.setRequestFocusEnabled(false);
17 }19 }
1820
1921
=== modified file 'src/pipe/gui/GuiFrame.java'
--- src/pipe/gui/GuiFrame.java 2020-08-14 09:41:34 +0000
+++ src/pipe/gui/GuiFrame.java 2020-08-21 08:37:32 +0000
@@ -1167,7 +1167,6 @@
1167 drawMenu.add(action);1167 drawMenu.add(action);
1168 }1168 }
11691169
1170 drawingToolBar.addSeparator();
1171 drawingToolBar.add(featureInfoText);1170 drawingToolBar.add(featureInfoText);
1172 } else {1171 } else {
1173 drawMenu.setEnabled(false);1172 drawMenu.setEnabled(false);
11741173
=== modified file 'src/pipe/gui/Pipe.java'
--- src/pipe/gui/Pipe.java 2020-07-16 10:02:06 +0000
+++ src/pipe/gui/Pipe.java 2020-08-21 08:37:32 +0000
@@ -8,7 +8,7 @@
8 public enum ElementType {8 public enum ElementType {
9 PLACE, IMMTRANS, TIMEDTRANS, ANNOTATION, ARC, INHIBARC, 9 PLACE, IMMTRANS, TIMEDTRANS, ANNOTATION, ARC, INHIBARC,
10 //TAPN Elements10 //TAPN Elements
11 TAPNPLACE, TAPNTRANS, TAPNARC, TRANSPORTARC, TAPNINHIBITOR_ARC,11 TAPNPLACE, TAPNTRANS, UNCONTROLLABLETRANS, TAPNARC, TRANSPORTARC, TAPNINHIBITOR_ARC,
12 //Others (might refactore)12 //Others (might refactore)
13 ADDTOKEN, DELTOKEN, SELECT, DRAW, DRAG,13 ADDTOKEN, DELTOKEN, SELECT, DRAW, DRAG,
14 }14 }
1515
=== modified file 'src/pipe/gui/handler/TransitionHandler.java'
--- src/pipe/gui/handler/TransitionHandler.java 2020-07-20 07:19:51 +0000
+++ src/pipe/gui/handler/TransitionHandler.java 2020-08-21 08:37:32 +0000
@@ -11,8 +11,7 @@
11/**11/**
12 * Class used to implement methods corresponding to mouse events on transitions.12 * Class used to implement methods corresponding to mouse events on transitions.
13 */13 */
14public class TransitionHandler extends PlaceTransitionObjectHandler implements14public class TransitionHandler extends PlaceTransitionObjectHandler implements java.awt.event.MouseWheelListener {
15 java.awt.event.MouseWheelListener {
1615
17 public TransitionHandler(Transition obj) {16 public TransitionHandler(Transition obj) {
18 super(obj);17 super(obj);
@@ -42,6 +41,4 @@
4241
43 return popup;42 return popup;
44 }43 }
45
46
47}44}
4845
=== added file 'src/resources/Images/Uncontrollable transition.png'
49Binary files src/resources/Images/Uncontrollable transition.png 1970-01-01 00:00:00 +0000 and src/resources/Images/Uncontrollable transition.png 2020-08-21 08:37:32 +0000 differ46Binary files src/resources/Images/Uncontrollable transition.png 1970-01-01 00:00:00 +0000 and src/resources/Images/Uncontrollable transition.png 2020-08-21 08:37:32 +0000 differ

Subscribers

People subscribed via source and target branches