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

Proposed by Lena Said on 2020-08-20
Status: Merged
Approved by: Jiri Srba on 2020-08-24
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 2020-08-20 Approve on 2020-08-24
Kenneth Yrke Jørgensen Approve on 2020-08-21
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 Said on 2020-08-20

Added annotation to toolbar

1110. By Lena Said on 2020-08-20

Moved the transition toggle shortcuts to be a guiAction

1111. By Lena Said on 2020-08-21

guiModelManager handles the toggle functionality

1112. By Lena Said on 2020-08-21

Added undo to the toggle

Kenneth Yrke Jørgensen (yrke) wrote :

Looks good

review: Approve
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
1=== modified file 'src/dk/aau/cs/gui/TabContent.java'
2--- src/dk/aau/cs/gui/TabContent.java 2020-08-17 08:18:13 +0000
3+++ src/dk/aau/cs/gui/TabContent.java 2020-08-21 08:37:32 +0000
4@@ -16,9 +16,7 @@
5 import dk.aau.cs.gui.components.BugHandledJXMultisplitPane;
6 import dk.aau.cs.gui.components.StatisticsPanel;
7 import dk.aau.cs.gui.components.TransitionFireingComponent;
8-import dk.aau.cs.gui.undo.Command;
9-import dk.aau.cs.gui.undo.DeleteQueriesCommand;
10-import dk.aau.cs.gui.undo.TimedPlaceMarkingEdit;
11+import dk.aau.cs.gui.undo.*;
12 import dk.aau.cs.io.*;
13 import dk.aau.cs.io.queries.SUMOQueryLoader;
14 import dk.aau.cs.io.queries.XMLQueryLoader;
15@@ -168,9 +166,10 @@
16 return new Result<>(pnObject);
17 }
18
19- public Result<TimedTransitionComponent, ModelViolation> addNewTimedTransitions(DataLayer c, Point p) {
20+ public Result<TimedTransitionComponent, ModelViolation> addNewTimedTransitions(DataLayer c, Point p, boolean isUncontrollable) {
21 dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(drawingSurface.getNameGenerator().getNewTransitionName(guiModelToModel.get(c)));
22
23+ transition.setUncontrollable(isUncontrollable);
24 TimedTransitionComponent pnObject = new TimedTransitionComponent(p.x, p.y, transition, lens);
25
26 guiModelToModel.get(c).add(transition);
27@@ -539,6 +538,40 @@
28 }
29 }
30
31+ public void toggleUncontrollableTrans() {
32+ ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection();
33+ TabContent currentTab = TabContent.this;
34+ getUndoManager().newEdit();
35+
36+ for (PetriNetObject o : selection) {
37+ if (o instanceof TimedTransitionComponent) {
38+ TimedTransitionComponent transition = (TimedTransitionComponent) o;
39+ Command cmd = new ToggleTransitionUncontrollable(transition.underlyingTransition(), currentTab);
40+
41+ cmd.redo();
42+ getUndoManager().addEdit(cmd);
43+ }
44+ }
45+ repaint();
46+ }
47+
48+ public void toggleUrgentTrans() {
49+ ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection();
50+ TabContent currentTab = TabContent.this;
51+ getUndoManager().newEdit();
52+
53+ for (PetriNetObject o : selection) {
54+ if (o instanceof TimedTransitionComponent) {
55+ TimedTransitionComponent transition = (TimedTransitionComponent) o;
56+ Command cmd = new ToggleTransitionUrgent(transition.underlyingTransition(), currentTab);
57+
58+ cmd.redo();
59+ getUndoManager().addEdit(cmd);
60+ }
61+ }
62+ repaint();
63+ }
64+
65
66 }
67
68@@ -1749,6 +1782,9 @@
69 case TAPNTRANS:
70 setManager(new CanvasTransitionDrawController());
71 break;
72+ case UNCONTROLLABLETRANS:
73+ setManager(new CanvasUncontrollableTransitionDrawController());
74+ break;
75 case ANNOTATION:
76 setManager(new CanvasAnnotationNoteDrawController());
77 break;
78@@ -2109,7 +2145,22 @@
79 public void drawingSurfaceMousePressed(MouseEvent e) {
80 Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom());
81
82- guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p);
83+ guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p, false);
84+ }
85+
86+ @Override
87+ public void registerEvents() {
88+
89+ }
90+ }
91+
92+ class CanvasUncontrollableTransitionDrawController extends AbstractDrawingSurfaceManager {
93+
94+ @Override
95+ public void drawingSurfaceMousePressed(MouseEvent e) {
96+ Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom());
97+
98+ guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p, true);
99 }
100
101 @Override
102@@ -2246,7 +2297,7 @@
103 var r = guiModelManager.addNewTimedPlace(getModel(), p);
104 placeClicked(r.result, e);
105 } else { //Transition
106- var r = guiModelManager.addNewTimedTransitions(getModel(), p);
107+ var r = guiModelManager.addNewTimedTransitions(getModel(), p, false);
108 transitionClicked(r.result, e);
109 }
110 }
111@@ -2667,10 +2718,14 @@
112 }
113 }
114 public List<GuiAction> getAvailableDrawActions(){
115- if(lens.isTimed()){
116- return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction));
117- } else{
118- return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction));
119+ if (lens.isTimed() && !lens.isGame()) {
120+ return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUrgentAction));
121+ } else if (lens.isTimed()) {
122+ return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, uncontrollableTransAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUrgentAction, toggleUncontrollableAction));
123+ } else if (lens.isGame()){
124+ return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, uncontrollableTransAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction, toggleUncontrollableAction));
125+ } else {
126+ return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction, transAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction, annotationAction));
127 }
128 }
129
130@@ -2704,6 +2759,11 @@
131 setMode(Pipe.ElementType.TAPNTRANS);
132 }
133 };
134+ private final GuiAction uncontrollableTransAction = new GuiAction("Uncontrollable transition", "Add an uncontrollable transition (L)", "L", true) {
135+ public void actionPerformed(ActionEvent e) {
136+ setMode(Pipe.ElementType.UNCONTROLLABLETRANS);
137+ }
138+ };
139 private final GuiAction tokenAction = new GuiAction("Add token", "Add a token (+)", "typed +", true) {
140 public void actionPerformed(ActionEvent e) {
141 setMode(Pipe.ElementType.ADDTOKEN);
142@@ -2731,6 +2791,16 @@
143 setMode(Pipe.ElementType.TRANSPORTARC);
144 }
145 };
146+ private final GuiAction toggleUncontrollableAction = new GuiAction("Toggle uncontrollable transition", "Toggle between control/environment transition", "E", true) {
147+ public void actionPerformed(ActionEvent e) {
148+ guiModelManager.toggleUncontrollableTrans();
149+ }
150+ };
151+ private final GuiAction toggleUrgentAction = new GuiAction("Toggle urgent transition", "Toggle between urgent/non-urgent transition", "U", true) {
152+ public void actionPerformed(ActionEvent e) {
153+ guiModelManager.toggleUrgentTrans();
154+ }
155+ };
156 private final GuiAction timeAction = new GuiAction("Delay one time unit", "Let time pass one time unit", "W") {
157 public void actionPerformed(ActionEvent e) {
158 timeDelay();
159@@ -2746,6 +2816,7 @@
160 // deselect other actions
161 selectAction.setSelected(CreateGui.guiMode == Pipe.ElementType.SELECT);
162 transAction.setSelected(editorMode == Pipe.ElementType.TAPNTRANS);
163+ uncontrollableTransAction.setSelected(editorMode == Pipe.ElementType.UNCONTROLLABLETRANS);
164 timedPlaceAction.setSelected(editorMode == Pipe.ElementType.TAPNPLACE);
165 timedArcAction.setSelected(editorMode == Pipe.ElementType.TAPNARC);
166 transportArcAction.setSelected(editorMode == Pipe.ElementType.TRANSPORTARC);
167@@ -2760,6 +2831,7 @@
168 case draw:
169 selectAction.setEnabled(true);
170 transAction.setEnabled(true);
171+ uncontrollableTransAction.setEnabled(true);
172 timedPlaceAction.setEnabled(true);
173 timedArcAction.setEnabled(true);
174 transportArcAction.setEnabled(true);
175@@ -2773,6 +2845,7 @@
176 case noNet:
177 selectAction.setEnabled(false);
178 transAction.setEnabled(false);
179+ uncontrollableTransAction.setEnabled(false);
180 timedPlaceAction.setEnabled(false);
181 timedArcAction.setEnabled(false);
182 transportArcAction.setEnabled(false);
183@@ -2785,6 +2858,7 @@
184 case animation:
185 selectAction.setEnabled(false);
186 transAction.setEnabled(false);
187+ uncontrollableTransAction.setEnabled(false);
188 timedPlaceAction.setEnabled(false);
189 timedArcAction.setEnabled(false);
190 transportArcAction.setEnabled(false);
191@@ -2805,6 +2879,7 @@
192 public static final String textforTAPNPlace = "Place Mode: Right click on a place to see menu options ";
193 public static final String textforTrans = "Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
194 public static final String textforTimedTrans = "Timed Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
195+ public static final String textforUncontrollableTrans = "Uncontrollable Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
196 public static final String textforAddtoken = "Add Token Mode: Click on a place to add a token";
197 public static final String textforDeltoken = "Delete Token Mode: Click on a place to delete a token ";
198 public static final String textforAnimation = "Simulation Mode: Red transitions are enabled, click a transition to fire it";
199@@ -2817,6 +2892,9 @@
200
201 public void changeStatusbarText(Pipe.ElementType type) {
202 switch (type) {
203+ case UNCONTROLLABLETRANS:
204+ app.ifPresent(o14 -> o14.setStatusBarText(textforUncontrollableTrans));
205+
206 case PLACE:
207 app.ifPresent(o13 -> o13.setStatusBarText(textforPlace));
208 break;
209
210=== modified file 'src/net/tapaal/swinghelpers/ToggleButtonWithoutText.java'
211--- src/net/tapaal/swinghelpers/ToggleButtonWithoutText.java 2019-11-05 12:19:17 +0000
212+++ src/net/tapaal/swinghelpers/ToggleButtonWithoutText.java 2020-08-21 08:37:32 +0000
213@@ -1,6 +1,7 @@
214 package net.tapaal.swinghelpers;
215
216 import javax.swing.*;
217+import java.awt.*;
218
219 /**
220 * A JToggleButton that without any text
221@@ -9,10 +10,11 @@
222
223 public ToggleButtonWithoutText(Action a) {
224 super(a);
225- if (a.getValue(Action.SMALL_ICON) != null) {
226- // toggle buttons like to have images *and* text, nasty
227- setText(null);
228+ if (a.getValue(Action.SMALL_ICON) == null) {
229+ setVisible(false);
230 }
231+ setText(null);
232+
233 this.setRequestFocusEnabled(false);
234 }
235
236
237=== modified file 'src/pipe/gui/GuiFrame.java'
238--- src/pipe/gui/GuiFrame.java 2020-08-14 09:41:34 +0000
239+++ src/pipe/gui/GuiFrame.java 2020-08-21 08:37:32 +0000
240@@ -1167,7 +1167,6 @@
241 drawMenu.add(action);
242 }
243
244- drawingToolBar.addSeparator();
245 drawingToolBar.add(featureInfoText);
246 } else {
247 drawMenu.setEnabled(false);
248
249=== modified file 'src/pipe/gui/Pipe.java'
250--- src/pipe/gui/Pipe.java 2020-07-16 10:02:06 +0000
251+++ src/pipe/gui/Pipe.java 2020-08-21 08:37:32 +0000
252@@ -8,7 +8,7 @@
253 public enum ElementType {
254 PLACE, IMMTRANS, TIMEDTRANS, ANNOTATION, ARC, INHIBARC,
255 //TAPN Elements
256- TAPNPLACE, TAPNTRANS, TAPNARC, TRANSPORTARC, TAPNINHIBITOR_ARC,
257+ TAPNPLACE, TAPNTRANS, UNCONTROLLABLETRANS, TAPNARC, TRANSPORTARC, TAPNINHIBITOR_ARC,
258 //Others (might refactore)
259 ADDTOKEN, DELTOKEN, SELECT, DRAW, DRAG,
260 }
261
262=== modified file 'src/pipe/gui/handler/TransitionHandler.java'
263--- src/pipe/gui/handler/TransitionHandler.java 2020-07-20 07:19:51 +0000
264+++ src/pipe/gui/handler/TransitionHandler.java 2020-08-21 08:37:32 +0000
265@@ -11,8 +11,7 @@
266 /**
267 * Class used to implement methods corresponding to mouse events on transitions.
268 */
269-public class TransitionHandler extends PlaceTransitionObjectHandler implements
270- java.awt.event.MouseWheelListener {
271+public class TransitionHandler extends PlaceTransitionObjectHandler implements java.awt.event.MouseWheelListener {
272
273 public TransitionHandler(Transition obj) {
274 super(obj);
275@@ -42,6 +41,4 @@
276
277 return popup;
278 }
279-
280-
281 }
282
283=== added file 'src/resources/Images/Uncontrollable transition.png'
284Binary 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