Merge lp:~yrke/tapaal/cleanup-PNO-namingAndInterface into lp:tapaal
- cleanup-PNO-namingAndInterface
- Merge into trunk
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Jiri Srba | ||||||||||||
Approved revision: | 1211 | ||||||||||||
Merged at revision: | 1067 | ||||||||||||
Proposed branch: | lp:~yrke/tapaal/cleanup-PNO-namingAndInterface | ||||||||||||
Merge into: | lp:tapaal | ||||||||||||
Diff against target: |
11415 lines (+4524/-4480) 68 files modified
src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java (+14/-16) src/dk/aau/cs/gui/TabContent.java (+1097/-180) src/dk/aau/cs/gui/TemplateExplorer.java (+56/-58) src/dk/aau/cs/gui/components/EnabledTransitionsList.java (+9/-83) src/dk/aau/cs/gui/components/NonsearchableJList.java (+1/-1) src/dk/aau/cs/gui/components/TransitionFireingComponent.java (+12/-6) src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java (+9/-13) src/dk/aau/cs/gui/undo/TimedPlaceMarkingEdit.java (+5/-5) src/dk/aau/cs/io/TapnXmlLoader.java (+2/-3) src/dk/aau/cs/model/tapn/LocalTimedPlace.java (+1/-118) src/dk/aau/cs/model/tapn/NetworkMarking.java (+5/-4) src/dk/aau/cs/model/tapn/SharedPlace.java (+6/-122) src/dk/aau/cs/model/tapn/TimedArcPetriNet.java (+8/-13) src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java (+7/-8) src/dk/aau/cs/model/tapn/TimedInhibitorArc.java (+6/-2) src/dk/aau/cs/model/tapn/TimedPlace.java (+114/-31) src/dk/aau/cs/model/tapn/TimedToken.java (+2/-8) src/dk/aau/cs/model/tapn/TimedTransition.java (+5/-5) src/dk/aau/cs/model/tapn/TransportArc.java (+6/-2) src/net/tapaal/gui/DrawingSurfaceManager/AbstractDrawingSurfaceManager.java (+14/-4) src/net/tapaal/swinghelpers/DispatchEventsToParentHandler.java (+58/-0) src/pipe/dataLayer/DataLayer.java (+158/-197) src/pipe/dataLayer/Template.java (+3/-8) src/pipe/gui/AnimationHistoryList.java (+1/-1) src/pipe/gui/Animator.java (+610/-622) src/pipe/gui/CreateGui.java (+7/-8) src/pipe/gui/DelayEnabledTransitionControl.java (+7/-8) src/pipe/gui/GuiFrame.java (+1554/-1575) src/pipe/gui/GuiFrameController.java (+1/-1) src/pipe/gui/SelectionManager.java (+43/-27) src/pipe/gui/SimulationControl.java (+11/-21) src/pipe/gui/action/SplitArcAction.java (+6/-2) src/pipe/gui/canvas/Canvas.java (+3/-2) src/pipe/gui/canvas/DrawingSurfaceImpl.java (+49/-222) src/pipe/gui/canvas/PrototypeCanvas.java (+3/-2) src/pipe/gui/graphicElements/AnnotationNote.java (+5/-4) src/pipe/gui/graphicElements/Arc.java (+34/-34) src/pipe/gui/graphicElements/ArcPath.java (+34/-32) src/pipe/gui/graphicElements/ArcPathPoint.java (+35/-32) src/pipe/gui/graphicElements/Drawable.java (+7/-0) src/pipe/gui/graphicElements/GraphicalElement.java (+162/-0) src/pipe/gui/graphicElements/Note.java (+1/-4) src/pipe/gui/graphicElements/PetriNetObject.java (+15/-62) src/pipe/gui/graphicElements/PetriNetObjectWithLabel.java (+6/-33) src/pipe/gui/graphicElements/Place.java (+2/-5) src/pipe/gui/graphicElements/PlaceTransitionObject.java (+26/-48) src/pipe/gui/graphicElements/Transition.java (+53/-122) src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java (+9/-1) src/pipe/gui/graphicElements/tapn/TimedInputArcComponent.java (+9/-0) src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java (+11/-3) src/pipe/gui/graphicElements/tapn/TimedPlaceComponent.java (+13/-31) src/pipe/gui/graphicElements/tapn/TimedTransitionComponent.java (+21/-11) src/pipe/gui/graphicElements/tapn/TimedTransportArcComponent.java (+22/-0) src/pipe/gui/handler/AnnotationNoteHandler.java (+0/-15) src/pipe/gui/handler/ArcHandler.java (+42/-36) src/pipe/gui/handler/ArcPathPointHandler.java (+0/-1) src/pipe/gui/handler/LabelHandler.java (+10/-10) src/pipe/gui/handler/NoteHandler.java (+0/-1) src/pipe/gui/handler/PetriNetObjectHandler.java (+11/-10) src/pipe/gui/handler/PlaceHandler.java (+12/-69) src/pipe/gui/handler/PlaceTransitionObjectHandler.java (+34/-480) src/pipe/gui/handler/TimedArcHandler.java (+0/-5) src/pipe/gui/handler/TransitionHandler.java (+0/-28) src/pipe/gui/handler/TransportArcHandler.java (+1/-1) src/pipe/gui/undo/TranslatePetriNetObjectEdit.java (+7/-8) src/pipe/gui/undo/UndoManager.java (+3/-14) src/pipe/gui/widgets/ArcTokenSelector.java (+1/-1) tests/dk/aau/cs/io/TapnXmlLoaderTest.kt (+45/-1) |
||||||||||||
To merge this branch: | bzr merge lp:~yrke/tapaal/cleanup-PNO-namingAndInterface | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Approve | ||
Peter Haahr Taankvist (community) | Approve | ||
Lena Ernstsen (community) | Approve | ||
Kenneth Yrke Jørgensen | Needs Resubmitting | ||
Review via email: mp+386803@code.launchpad.net |
Commit message
Description of the change
Kenneth Yrke Jørgensen (yrke) wrote : | # |
- 1206. By Kenneth Yrke Jørgensen
-
Merged changes from other computer
- 1207. By Kenneth Yrke Jørgensen
-
Removed color
- 1208. By Kenneth Yrke Jørgensen
-
Corrected spelling
Peter Haahr Taankvist (ptaank) wrote : | # |
Open alternating-
Peter Haahr Taankvist (ptaank) wrote : | # |
The problem with pressing shift+U many times still persists:
Open alternating-
press shift+U 23 times
now press ctrl+U some times
The spacing will not increase, rather the places will all stay on top of each other and arcpathpoints will fly everywhere.
Peter Haahr Taankvist (ptaank) wrote : | # |
> The problem with pressing shift+U many times still persists:
>
> Open alternating-
>
> press shift+U 23 times
>
> now press ctrl+U some times
>
> The spacing will not increase, rather the places will all stay on top of each
> other and arcpathpoints will fly everywhere.
What's worse is that the same happens with ctrl+z
Peter Haahr Taankvist (ptaank) wrote : | # |
It is not possible to undo resizing of annotation notes
Lena Ernstsen (lsaid) wrote : | # |
1)
When I select ‘place’ and want to add it to the the component I sometimes have to click several times before it registers and adds the ‘place’. Same goes for transitions, tokens, and the different arcs.
2)
The positions of the different arcs are shown as ‘X:0 Y:0’. But I'm not sure if this is relevant or not.
3)
There is a weird behaviour when moving an arc with extra inserted points. When moving such and arc a little to the right, then it moves very fast by itself to the far right and goes off screen. When undoing, the arc does not return to how it was setup before moving it, but rather it stays to the far right and removes the extra points.
The same thing happens if you move the end point of an arc with an extra point a little down.
Peter Haahr Taankvist (ptaank) wrote : | # |
> 1)
> When I select ‘place’ and want to add it to the the component I sometimes have
> to click several times before it registers and adds the ‘place’. Same goes for
> transitions, tokens, and the different arcs.
>
> 2)
> The positions of the different arcs are shown as ‘X:0 Y:0’. But I'm not sure
> if this is relevant or not.
>
> 3)
> There is a weird behaviour when moving an arc with extra inserted points. When
> moving such and arc a little to the right, then it moves very fast by itself
> to the far right and goes off screen. When undoing, the arc does not return to
> how it was setup before moving it, but rather it stays to the far right and
> removes the extra points.
> The same thing happens if you move the end point of an arc with an extra point
> a little down.
How to reproduce #3
Place a place and a transition and draw an arc between them. Now drag at one of the endpoints and the arcs will fly all over.
Peter Haahr Taankvist (ptaank) wrote : | # |
> 1)
> When I select ‘place’ and want to add it to the the component I sometimes have
> to click several times before it registers and adds the ‘place’. Same goes for
> transitions, tokens, and the different arcs.
>
> 2)
> The positions of the different arcs are shown as ‘X:0 Y:0’. But I'm not sure
> if this is relevant or not.
>
> 3)
> There is a weird behaviour when moving an arc with extra inserted points. When
> moving such and arc a little to the right, then it moves very fast by itself
> to the far right and goes off screen. When undoing, the arc does not return to
> how it was setup before moving it, but rather it stays to the far right and
> removes the extra points.
> The same thing happens if you move the end point of an arc with an extra point
> a little down.
4)
#1 To add to this it also seems that it has a hard time registering a click on an enabled transition in animation mode.
Peter Haahr Taankvist (ptaank) wrote : | # |
5)
Adding text to an annotation note and then undoing does not undo the size of the annotation note.
- 1209. By Kenneth Yrke Jørgensen
-
Changed mouse clicked events to mouse down
- 1210. By Kenneth Yrke Jørgensen
-
Disabled dragging arcs
Current implementation does not support this
- 1211. By Kenneth Yrke Jørgensen
-
Moved adding of arcpath point with doubleclick to new controller
Kenneth Yrke Jørgensen (yrke) wrote : | # |
Changed draw from click to mouse down, addresses #1,4. #2 is as expected, #3 is also in trunk but added a fix so you can't draw on an arc.
Lena Ernstsen (lsaid) : | # |
Peter Haahr Taankvist (ptaank) : | # |
Jiri Srba (srba) : | # |
Preview Diff
1 | === modified file 'src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java' | |||
2 | --- src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java 2020-05-27 13:15:44 +0000 | |||
3 | +++ src/dk/aau/cs/gui/SharedPlacesAndTransitionsPanel.java 2020-07-09 12:55:48 +0000 | |||
4 | @@ -45,17 +45,17 @@ | |||
5 | 45 | private static final String TRANSITIONS = "Transitions"; | 45 | private static final String TRANSITIONS = "Transitions"; |
6 | 46 | private static final String PLACES = "Places"; | 46 | private static final String PLACES = "Places"; |
7 | 47 | 47 | ||
15 | 48 | private JList list; | 48 | private final JList list = new NonsearchableJList(); |
16 | 49 | private SharedPlacesListModel sharedPlacesListModel; | 49 | private final SharedPlacesListModel sharedPlacesListModel; |
17 | 50 | private SharedTransitionsListModel sharedTransitionsListModel; | 50 | private final SharedTransitionsListModel sharedTransitionsListModel; |
18 | 51 | private JComboBox placesTransitionsComboBox; | 51 | private final JComboBox placesTransitionsComboBox = new JComboBox(new String[]{ PLACES, TRANSITIONS }); |
19 | 52 | private UndoManager undoManager; | 52 | private final UndoManager undoManager; |
20 | 53 | private NameGenerator nameGenerator; | 53 | private final NameGenerator nameGenerator; |
21 | 54 | private TabContent tab; | 54 | private final TabContent tab; |
22 | 55 | 55 | ||
26 | 56 | private JButton renameButton = new JButton("Rename"); | 56 | private final JButton renameButton = new JButton("Rename"); |
27 | 57 | private JButton removeButton = new JButton("Remove"); | 57 | private final JButton removeButton = new JButton("Remove"); |
28 | 58 | private JButton addButton = new JButton("New"); | 58 | private final JButton addButton = new JButton("New"); |
29 | 59 | private JButton moveUpButton; | 59 | private JButton moveUpButton; |
30 | 60 | private JButton moveDownButton; | 60 | private JButton moveDownButton; |
31 | 61 | private JButton sortButton; | 61 | private JButton sortButton; |
32 | @@ -128,9 +128,8 @@ | |||
33 | 128 | 128 | ||
34 | 129 | private void initComponents() { | 129 | private void initComponents() { |
35 | 130 | JPanel listPanel = new JPanel(new GridBagLayout()); | 130 | JPanel listPanel = new JPanel(new GridBagLayout()); |
39 | 131 | 131 | ||
40 | 132 | list = new NonsearchableJList(); | 132 | list.addListSelectionListener(new ListSelectionListener() { |
38 | 133 | list.addListSelectionListener(new ListSelectionListener() { | ||
41 | 134 | public void valueChanged(ListSelectionEvent e) { | 133 | public void valueChanged(ListSelectionEvent e) { |
42 | 135 | if(!e.getValueIsAdjusting()){ | 134 | if(!e.getValueIsAdjusting()){ |
43 | 136 | JList source = (JList)e.getSource(); | 135 | JList source = (JList)e.getSource(); |
44 | @@ -262,9 +261,8 @@ | |||
45 | 262 | gbc.fill = GridBagConstraints.HORIZONTAL; | 261 | gbc.fill = GridBagConstraints.HORIZONTAL; |
46 | 263 | gbc.anchor = GridBagConstraints.NORTH; | 262 | gbc.anchor = GridBagConstraints.NORTH; |
47 | 264 | listPanel.add(sortButton,gbc); | 263 | listPanel.add(sortButton,gbc); |
51 | 265 | 264 | ||
52 | 266 | placesTransitionsComboBox = new JComboBox(new String[]{ PLACES, TRANSITIONS }); | 265 | placesTransitionsComboBox.setToolTipText(toolTipChangeBetweenPlacesAndTransitions); |
50 | 267 | placesTransitionsComboBox.setToolTipText(toolTipChangeBetweenPlacesAndTransitions); | ||
53 | 268 | placesTransitionsComboBox.addActionListener(e -> { | 266 | placesTransitionsComboBox.addActionListener(e -> { |
54 | 269 | JComboBox source = (JComboBox)e.getSource(); | 267 | JComboBox source = (JComboBox)e.getSource(); |
55 | 270 | String selectedItem = (String)source.getSelectedItem(); | 268 | String selectedItem = (String)source.getSelectedItem(); |
56 | 271 | 269 | ||
57 | === modified file 'src/dk/aau/cs/gui/TabContent.java' | |||
58 | --- src/dk/aau/cs/gui/TabContent.java 2020-06-22 07:41:12 +0000 | |||
59 | +++ src/dk/aau/cs/gui/TabContent.java 2020-07-09 12:55:48 +0000 | |||
60 | @@ -3,6 +3,7 @@ | |||
61 | 3 | import java.awt.*; | 3 | import java.awt.*; |
62 | 4 | import java.awt.event.MouseAdapter; | 4 | import java.awt.event.MouseAdapter; |
63 | 5 | import java.awt.event.MouseEvent; | 5 | import java.awt.event.MouseEvent; |
64 | 6 | import java.awt.geom.Point2D; | ||
65 | 6 | import java.io.*; | 7 | import java.io.*; |
66 | 7 | import java.math.BigDecimal; | 8 | import java.math.BigDecimal; |
67 | 8 | import java.util.*; | 9 | import java.util.*; |
68 | @@ -11,12 +12,11 @@ | |||
69 | 11 | import javax.swing.*; | 12 | import javax.swing.*; |
70 | 12 | import javax.swing.border.BevelBorder; | 13 | import javax.swing.border.BevelBorder; |
71 | 13 | 14 | ||
72 | 14 | import dk.aau.cs.approximation.OverApproximation; | ||
73 | 15 | import dk.aau.cs.approximation.UnderApproximation; | ||
74 | 16 | import dk.aau.cs.debug.Logger; | 15 | import dk.aau.cs.debug.Logger; |
75 | 17 | import dk.aau.cs.gui.components.StatisticsPanel; | 16 | import dk.aau.cs.gui.components.StatisticsPanel; |
76 | 18 | import dk.aau.cs.gui.undo.Command; | 17 | import dk.aau.cs.gui.undo.Command; |
77 | 19 | import dk.aau.cs.gui.undo.DeleteQueriesCommand; | 18 | import dk.aau.cs.gui.undo.DeleteQueriesCommand; |
78 | 19 | import dk.aau.cs.gui.undo.TimedPlaceMarkingEdit; | ||
79 | 20 | import dk.aau.cs.io.*; | 20 | import dk.aau.cs.io.*; |
80 | 21 | import dk.aau.cs.io.queries.SUMOQueryLoader; | 21 | import dk.aau.cs.io.queries.SUMOQueryLoader; |
81 | 22 | import dk.aau.cs.io.queries.XMLQueryLoader; | 22 | import dk.aau.cs.io.queries.XMLQueryLoader; |
82 | @@ -35,12 +35,13 @@ | |||
83 | 35 | import pipe.gui.*; | 35 | import pipe.gui.*; |
84 | 36 | import pipe.gui.canvas.DrawingSurfaceImpl; | 36 | import pipe.gui.canvas.DrawingSurfaceImpl; |
85 | 37 | import pipe.gui.graphicElements.*; | 37 | import pipe.gui.graphicElements.*; |
89 | 38 | import pipe.gui.graphicElements.tapn.TimedPlaceComponent; | 38 | import pipe.gui.graphicElements.tapn.*; |
90 | 39 | import pipe.gui.graphicElements.tapn.TimedTransitionComponent; | 39 | import pipe.gui.undo.*; |
91 | 40 | import pipe.gui.handler.PlaceTransitionObjectHandler; | 40 | import pipe.gui.widgets.ConstantsPane; |
92 | 41 | import pipe.gui.undo.ChangeSpacingEdit; | 41 | import pipe.gui.undo.ChangeSpacingEdit; |
93 | 42 | import pipe.gui.undo.UndoManager; | 42 | import pipe.gui.undo.UndoManager; |
94 | 43 | import pipe.gui.widgets.*; | 43 | import pipe.gui.widgets.*; |
95 | 44 | |||
96 | 44 | import net.tapaal.swinghelpers.JSplitPaneFix; | 45 | import net.tapaal.swinghelpers.JSplitPaneFix; |
97 | 45 | import dk.aau.cs.gui.components.BugHandledJXMultisplitPane; | 46 | import dk.aau.cs.gui.components.BugHandledJXMultisplitPane; |
98 | 46 | import dk.aau.cs.gui.components.TransitionFireingComponent; | 47 | import dk.aau.cs.gui.components.TransitionFireingComponent; |
99 | @@ -49,37 +50,443 @@ | |||
100 | 49 | 50 | ||
101 | 50 | public class TabContent extends JSplitPane implements TabContentActions{ | 51 | public class TabContent extends JSplitPane implements TabContentActions{ |
102 | 51 | 52 | ||
103 | 53 | static class TAPNLens { | ||
104 | 54 | public boolean isTimed() { | ||
105 | 55 | return timed; | ||
106 | 56 | } | ||
107 | 57 | |||
108 | 58 | public boolean isGame() { | ||
109 | 59 | return game; | ||
110 | 60 | } | ||
111 | 61 | |||
112 | 62 | private final boolean timed; | ||
113 | 63 | private final boolean game; | ||
114 | 64 | |||
115 | 65 | TAPNLens(boolean timed, boolean game) { | ||
116 | 66 | this.timed = timed; | ||
117 | 67 | this.game = game; | ||
118 | 68 | } | ||
119 | 69 | } | ||
120 | 70 | private final TAPNLens lens; | ||
121 | 71 | |||
122 | 52 | //Model and state | 72 | //Model and state |
129 | 53 | private TimedArcPetriNetNetwork tapnNetwork = new TimedArcPetriNetNetwork(); | 73 | private final TimedArcPetriNetNetwork tapnNetwork; |
130 | 54 | private HashMap<TimedArcPetriNet, DataLayer> guiModels = new HashMap<TimedArcPetriNet, DataLayer>(); | 74 | |
131 | 55 | private HashMap<TimedArcPetriNet, Zoomer> zoomLevels = new HashMap<TimedArcPetriNet, Zoomer>(); | 75 | //XXX: Replace with bi-map |
132 | 56 | 76 | private final HashMap<TimedArcPetriNet, DataLayer> guiModels = new HashMap<TimedArcPetriNet, DataLayer>(); | |
133 | 57 | 77 | private final HashMap<DataLayer, TimedArcPetriNet> guiModelToModel = new HashMap<>(); | |
134 | 58 | private UndoManager undoManager = new UndoManager(); | 78 | |
135 | 79 | private final HashMap<TimedArcPetriNet, Zoomer> zoomLevels = new HashMap<TimedArcPetriNet, Zoomer>(); | ||
136 | 80 | |||
137 | 81 | |||
138 | 82 | private final UndoManager undoManager = new UndoManager(); | ||
139 | 83 | |||
140 | 84 | public final GuiModelManager guiModelManager = new GuiModelManager(); | ||
141 | 85 | public class GuiModelManager { | ||
142 | 86 | public GuiModelManager(){ | ||
143 | 87 | |||
144 | 88 | } | ||
145 | 89 | |||
146 | 90 | public void addNewTimedPlace(DataLayer c, Point p){ | ||
147 | 91 | Require.notNull(c, "datalyer can't be null"); | ||
148 | 92 | Require.notNull(p, "Point can't be null"); | ||
149 | 93 | |||
150 | 94 | dk.aau.cs.model.tapn.LocalTimedPlace tp = new dk.aau.cs.model.tapn.LocalTimedPlace(drawingSurface.getNameGenerator().getNewPlaceName(guiModelToModel.get(c))); | ||
151 | 95 | TimedPlaceComponent pnObject = new TimedPlaceComponent(p.x, p.y, tp); | ||
152 | 96 | guiModelToModel.get(c).add(tp); | ||
153 | 97 | c.addPetriNetObject(pnObject); | ||
154 | 98 | |||
155 | 99 | getUndoManager().addNewEdit(new AddTimedPlaceCommand(pnObject, guiModelToModel.get(c), c)); | ||
156 | 100 | |||
157 | 101 | } | ||
158 | 102 | |||
159 | 103 | public void addNewTimedTransitions(DataLayer c, Point p) { | ||
160 | 104 | dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(drawingSurface.getNameGenerator().getNewTransitionName(guiModelToModel.get(c))); | ||
161 | 105 | |||
162 | 106 | TimedTransitionComponent pnObject = new TimedTransitionComponent(p.x, p.y, transition); | ||
163 | 107 | |||
164 | 108 | guiModelToModel.get(c).add(transition); | ||
165 | 109 | c.addPetriNetObject(pnObject); | ||
166 | 110 | |||
167 | 111 | getUndoManager().addNewEdit(new AddTimedTransitionCommand(pnObject, guiModelToModel.get(c), c)); | ||
168 | 112 | } | ||
169 | 113 | |||
170 | 114 | public void addAnnotationNote(DataLayer c, Point p) { | ||
171 | 115 | AnnotationNote pnObject = new AnnotationNote(p.x, p.y); | ||
172 | 116 | |||
173 | 117 | //enableEditMode open editor, retuns true of text added, else false | ||
174 | 118 | //If no text is added,dont add it to model | ||
175 | 119 | if (pnObject.enableEditMode(true)) { | ||
176 | 120 | c.addPetriNetObject(pnObject); | ||
177 | 121 | getUndoManager().addEdit(new AddAnnotationNoteCommand(pnObject, c)); | ||
178 | 122 | } | ||
179 | 123 | } | ||
180 | 124 | |||
181 | 125 | public void addTimedInputArc(DataLayer c, TimedPlaceComponent p, TimedTransitionComponent t, ArcPath path) { | ||
182 | 126 | Require.notNull(c, "DataLayer can't be null"); | ||
183 | 127 | Require.notNull(p, "Place can't be null"); | ||
184 | 128 | Require.notNull(t, "Transitions can't be null"); | ||
185 | 129 | |||
186 | 130 | TimedArcPetriNet modelNet = guiModelToModel.get(c); | ||
187 | 131 | |||
188 | 132 | if (!modelNet.hasArcFromPlaceToTransition(p.underlyingPlace(), t.underlyingTransition())) { | ||
189 | 133 | |||
190 | 134 | TimedInputArc tia = new TimedInputArc( | ||
191 | 135 | p.underlyingPlace(), | ||
192 | 136 | t.underlyingTransition(), | ||
193 | 137 | TimeInterval.ZERO_INF | ||
194 | 138 | ); | ||
195 | 139 | |||
196 | 140 | TimedInputArcComponent tiac = new TimedInputArcComponent(p,t,tia); | ||
197 | 141 | |||
198 | 142 | if (path != null) { | ||
199 | 143 | tiac.setArcPath(new ArcPath(tiac, path)); | ||
200 | 144 | } | ||
201 | 145 | |||
202 | 146 | Command edit = new AddTimedInputArcCommand( | ||
203 | 147 | tiac, | ||
204 | 148 | modelNet, | ||
205 | 149 | c | ||
206 | 150 | ); | ||
207 | 151 | edit.redo(); | ||
208 | 152 | |||
209 | 153 | undoManager.addNewEdit(edit); | ||
210 | 154 | |||
211 | 155 | } else { | ||
212 | 156 | //TODO: can't have two arcs between place and transition | ||
213 | 157 | JOptionPane.showMessageDialog( | ||
214 | 158 | CreateGui.getApp(), | ||
215 | 159 | "There was an error drawing the arc. Possible problems:\n" | ||
216 | 160 | + " - There is already an arc between the selected place and transition\n" | ||
217 | 161 | + " - You are attempting to draw an arc between a shared transition and a shared place", | ||
218 | 162 | "Error", JOptionPane.ERROR_MESSAGE | ||
219 | 163 | ); | ||
220 | 164 | } | ||
221 | 165 | } | ||
222 | 166 | |||
223 | 167 | public void addTimedOutputArc(DataLayer c, TimedTransitionComponent t, TimedPlaceComponent p, ArcPath path) { | ||
224 | 168 | Require.notNull(c, "DataLayer can't be null"); | ||
225 | 169 | Require.notNull(p, "Place can't be null"); | ||
226 | 170 | Require.notNull(t, "Transitions can't be null"); | ||
227 | 171 | |||
228 | 172 | TimedArcPetriNet modelNet = guiModelToModel.get(c); | ||
229 | 173 | |||
230 | 174 | if (!modelNet.hasArcFromTransitionToPlace(t.underlyingTransition(), p.underlyingPlace())) { | ||
231 | 175 | |||
232 | 176 | TimedOutputArc toa = new TimedOutputArc( | ||
233 | 177 | t.underlyingTransition(), | ||
234 | 178 | p.underlyingPlace() | ||
235 | 179 | ); | ||
236 | 180 | |||
237 | 181 | TimedOutputArcComponent toac = new TimedOutputArcComponent(t, p, toa); | ||
238 | 182 | |||
239 | 183 | if (path != null) { | ||
240 | 184 | toac.setArcPath(new ArcPath(toac, path)); | ||
241 | 185 | } | ||
242 | 186 | |||
243 | 187 | Command edit = new AddTimedOutputArcCommand( | ||
244 | 188 | toac, | ||
245 | 189 | modelNet, | ||
246 | 190 | c | ||
247 | 191 | ); | ||
248 | 192 | edit.redo(); | ||
249 | 193 | undoManager.addNewEdit(edit); | ||
250 | 194 | |||
251 | 195 | } else { | ||
252 | 196 | |||
253 | 197 | JOptionPane.showMessageDialog( | ||
254 | 198 | CreateGui.getApp(), | ||
255 | 199 | "There was an error drawing the arc. Possible problems:\n" | ||
256 | 200 | + " - There is already an arc between the selected place and transition\n" | ||
257 | 201 | + " - You are attempting to draw an arc between a shared transition and a shared place", | ||
258 | 202 | "Error", JOptionPane.ERROR_MESSAGE | ||
259 | 203 | ); | ||
260 | 204 | |||
261 | 205 | } | ||
262 | 206 | |||
263 | 207 | |||
264 | 208 | } | ||
265 | 209 | |||
266 | 210 | public void addInhibitorArc(DataLayer c, TimedPlaceComponent p, TimedTransitionComponent t, ArcPath path) { | ||
267 | 211 | Require.notNull(c, "DataLayer can't be null"); | ||
268 | 212 | Require.notNull(p, "Place can't be null"); | ||
269 | 213 | Require.notNull(t, "Transitions can't be null"); | ||
270 | 214 | |||
271 | 215 | TimedArcPetriNet modelNet = guiModelToModel.get(c); | ||
272 | 216 | |||
273 | 217 | if (!modelNet.hasArcFromPlaceToTransition(p.underlyingPlace(), t.underlyingTransition())) { | ||
274 | 218 | |||
275 | 219 | TimedInhibitorArc tiha = new TimedInhibitorArc( | ||
276 | 220 | p.underlyingPlace(), | ||
277 | 221 | t.underlyingTransition() | ||
278 | 222 | ); | ||
279 | 223 | |||
280 | 224 | TimedInhibitorArcComponent tihac = new TimedInhibitorArcComponent(p, t, tiha); | ||
281 | 225 | |||
282 | 226 | if (path != null) { | ||
283 | 227 | tihac.setArcPath(new ArcPath(tihac, path)); | ||
284 | 228 | } | ||
285 | 229 | |||
286 | 230 | Command edit = new AddTimedInhibitorArcCommand( | ||
287 | 231 | tihac, | ||
288 | 232 | modelNet, | ||
289 | 233 | c | ||
290 | 234 | ); | ||
291 | 235 | edit.redo(); | ||
292 | 236 | undoManager.addNewEdit(edit); | ||
293 | 237 | |||
294 | 238 | } else { | ||
295 | 239 | |||
296 | 240 | JOptionPane.showMessageDialog( | ||
297 | 241 | CreateGui.getApp(), | ||
298 | 242 | "There was an error drawing the arc. Possible problems:\n" | ||
299 | 243 | + " - There is already an arc between the selected place and transition\n" | ||
300 | 244 | + " - You are attempting to draw an arc between a shared transition and a shared place", | ||
301 | 245 | "Error", JOptionPane.ERROR_MESSAGE | ||
302 | 246 | ); | ||
303 | 247 | |||
304 | 248 | } | ||
305 | 249 | |||
306 | 250 | } | ||
307 | 251 | |||
308 | 252 | public void addTimedTransportArc(DataLayer c, TimedPlaceComponent p1, TimedTransitionComponent t, TimedPlaceComponent p2, ArcPath path1, ArcPath path2) { | ||
309 | 253 | Require.notNull(c, "DataLayer can't be null"); | ||
310 | 254 | Require.notNull(p1, "Place1 can't be null"); | ||
311 | 255 | Require.notNull(t, "Transitions can't be null"); | ||
312 | 256 | Require.notNull(p2, "Place2 can't be null"); | ||
313 | 257 | |||
314 | 258 | TimedArcPetriNet modelNet = guiModelToModel.get(c); | ||
315 | 259 | |||
316 | 260 | if ( | ||
317 | 261 | !modelNet.hasArcFromPlaceToTransition(p1.underlyingPlace(), t.underlyingTransition()) && | ||
318 | 262 | !modelNet.hasArcFromTransitionToPlace(t.underlyingTransition(), p2.underlyingPlace()) | ||
319 | 263 | ) { | ||
320 | 264 | |||
321 | 265 | int groupNr = getNextTransportArcMaxGroupNumber(p1, t); | ||
322 | 266 | |||
323 | 267 | TransportArc tta = new TransportArc(p1.underlyingPlace(), t.underlyingTransition(), p2.underlyingPlace()); | ||
324 | 268 | |||
325 | 269 | TimedTransportArcComponent ttac1 = new TimedTransportArcComponent(p1, t, tta, groupNr); | ||
326 | 270 | TimedTransportArcComponent ttac2 = new TimedTransportArcComponent(t, p2, tta, groupNr); | ||
327 | 271 | |||
328 | 272 | ttac1.setConnectedTo(ttac2); | ||
329 | 273 | ttac2.setConnectedTo(ttac1); | ||
330 | 274 | |||
331 | 275 | if (path1 != null) { | ||
332 | 276 | ttac1.setArcPath(new ArcPath(ttac1, path1)); | ||
333 | 277 | } | ||
334 | 278 | if (path2 != null) { | ||
335 | 279 | ttac2.setArcPath(new ArcPath(ttac2, path2)); | ||
336 | 280 | } | ||
337 | 281 | |||
338 | 282 | //XXX: the Command should take both arcs | ||
339 | 283 | Command edit = new AddTransportArcCommand( | ||
340 | 284 | ttac2, | ||
341 | 285 | tta, | ||
342 | 286 | modelNet, | ||
343 | 287 | c | ||
344 | 288 | ); | ||
345 | 289 | edit.redo(); | ||
346 | 290 | undoManager.addNewEdit(edit); | ||
347 | 291 | |||
348 | 292 | } else { | ||
349 | 293 | JOptionPane.showMessageDialog( | ||
350 | 294 | CreateGui.getApp(), | ||
351 | 295 | "There was an error drawing the arc. Possible problems:\n" | ||
352 | 296 | + " - There is already an arc between the source place and transition\n" | ||
353 | 297 | + " - There is already an arc between the transtion and the target place\n" | ||
354 | 298 | + " - You are attempting to draw an arc between a shared transition and a shared place", | ||
355 | 299 | "Error", JOptionPane.ERROR_MESSAGE | ||
356 | 300 | ); | ||
357 | 301 | } | ||
358 | 302 | |||
359 | 303 | } | ||
360 | 304 | |||
361 | 305 | private int getNextTransportArcMaxGroupNumber(TimedPlaceComponent p, TimedTransitionComponent t) { | ||
362 | 306 | int groupMaxCounter = 0; | ||
363 | 307 | |||
364 | 308 | for (Arc a : t.getPreset()) { | ||
365 | 309 | if (a instanceof TimedTransportArcComponent && a.getTarget().equals(t)) { | ||
366 | 310 | if (((TimedTransportArcComponent) a).getGroupNr() > groupMaxCounter) { | ||
367 | 311 | groupMaxCounter = ((TimedTransportArcComponent) a).getGroupNr(); | ||
368 | 312 | } | ||
369 | 313 | } | ||
370 | 314 | } | ||
371 | 315 | |||
372 | 316 | return groupMaxCounter+1; | ||
373 | 317 | } | ||
374 | 318 | |||
375 | 319 | |||
376 | 320 | public void deleteSelection() { | ||
377 | 321 | // check if queries need to be removed | ||
378 | 322 | ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection(); | ||
379 | 323 | Iterable<TAPNQuery> queries = queries(); | ||
380 | 324 | HashSet<TAPNQuery> queriesToDelete = new HashSet<TAPNQuery>(); | ||
381 | 325 | |||
382 | 326 | boolean queriesAffected = false; | ||
383 | 327 | for (PetriNetObject pn : selection) { | ||
384 | 328 | if (pn instanceof TimedPlaceComponent) { | ||
385 | 329 | TimedPlaceComponent place = (TimedPlaceComponent)pn; | ||
386 | 330 | if(!place.underlyingPlace().isShared()){ | ||
387 | 331 | for (TAPNQuery q : queries) { | ||
388 | 332 | if (q.getProperty().containsAtomicPropositionWithSpecificPlaceInTemplate(((LocalTimedPlace)place.underlyingPlace()).model().name(),place.underlyingPlace().name())) { | ||
389 | 333 | queriesAffected = true; | ||
390 | 334 | queriesToDelete.add(q); | ||
391 | 335 | } | ||
392 | 336 | } | ||
393 | 337 | } | ||
394 | 338 | } else if (pn instanceof TimedTransitionComponent){ | ||
395 | 339 | TimedTransitionComponent transition = (TimedTransitionComponent)pn; | ||
396 | 340 | if(!transition.underlyingTransition().isShared()){ | ||
397 | 341 | for (TAPNQuery q : queries) { | ||
398 | 342 | if (q.getProperty().containsAtomicPropositionWithSpecificTransitionInTemplate((transition.underlyingTransition()).model().name(),transition.underlyingTransition().name())) { | ||
399 | 343 | queriesAffected = true; | ||
400 | 344 | queriesToDelete.add(q); | ||
401 | 345 | } | ||
402 | 346 | } | ||
403 | 347 | } | ||
404 | 348 | } | ||
405 | 349 | } | ||
406 | 350 | StringBuilder s = new StringBuilder(); | ||
407 | 351 | s.append("The following queries are associated with the currently selected objects:\n\n"); | ||
408 | 352 | for (TAPNQuery q : queriesToDelete) { | ||
409 | 353 | s.append(q.getName()); | ||
410 | 354 | s.append('\n'); | ||
411 | 355 | } | ||
412 | 356 | s.append("\nAre you sure you want to remove the current selection and all associated queries?"); | ||
413 | 357 | |||
414 | 358 | int choice = queriesAffected ? JOptionPane.showConfirmDialog( | ||
415 | 359 | CreateGui.getApp(), s.toString(), "Warning", | ||
416 | 360 | JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) | ||
417 | 361 | : JOptionPane.YES_OPTION; | ||
418 | 362 | |||
419 | 363 | if (choice == JOptionPane.YES_OPTION) { | ||
420 | 364 | getUndoManager().newEdit(); // new "transaction"" | ||
421 | 365 | if (queriesAffected) { | ||
422 | 366 | TabContent currentTab = TabContent.this; | ||
423 | 367 | for (TAPNQuery q : queriesToDelete) { | ||
424 | 368 | Command cmd = new DeleteQueriesCommand(currentTab, Arrays.asList(q)); | ||
425 | 369 | cmd.redo(); | ||
426 | 370 | getUndoManager().addEdit(cmd); | ||
427 | 371 | } | ||
428 | 372 | } | ||
429 | 373 | |||
430 | 374 | deleteSelection(selection); | ||
431 | 375 | network().buildConstraints(); | ||
432 | 376 | } | ||
433 | 377 | } | ||
434 | 378 | |||
435 | 379 | //XXX: function moved from undoManager --kyrke - 2019-07-06 | ||
436 | 380 | private void deleteObject(PetriNetObject pnObject) { | ||
437 | 381 | if (pnObject instanceof ArcPathPoint) { | ||
438 | 382 | |||
439 | 383 | ArcPathPoint arcPathPoint = (ArcPathPoint)pnObject; | ||
440 | 384 | |||
441 | 385 | //If the arc is marked for deletion, skip deleting individual arcpathpoint | ||
442 | 386 | if (!(arcPathPoint.getArcPath().getArc().isSelected())) { | ||
443 | 387 | |||
444 | 388 | //Don't delete the two last arc path points | ||
445 | 389 | if (arcPathPoint.isDeleteable()) { | ||
446 | 390 | Command cmd = new DeleteArcPathPointEdit( | ||
447 | 391 | arcPathPoint.getArcPath().getArc(), | ||
448 | 392 | arcPathPoint, | ||
449 | 393 | arcPathPoint.getIndex(), | ||
450 | 394 | getModel() | ||
451 | 395 | ); | ||
452 | 396 | cmd.redo(); | ||
453 | 397 | getUndoManager().addEdit(cmd); | ||
454 | 398 | } | ||
455 | 399 | } | ||
456 | 400 | }else{ | ||
457 | 401 | //The list of selected objects is not updated when a element is deleted | ||
458 | 402 | //We might delete the same object twice, which will give an error | ||
459 | 403 | //Eg. a place with output arc is deleted (deleted also arc) while arc is also selected. | ||
460 | 404 | //There is properly a better way to track this (check model?) but while refactoring we will keeps it close | ||
461 | 405 | //to the orginal code -- kyrke 2019-06-27 | ||
462 | 406 | if (!pnObject.isDeleted()) { | ||
463 | 407 | Command cmd = null; | ||
464 | 408 | if(pnObject instanceof TimedPlaceComponent){ | ||
465 | 409 | TimedPlaceComponent tp = (TimedPlaceComponent)pnObject; | ||
466 | 410 | cmd = new DeleteTimedPlaceCommand(tp, guiModelToModel.get(getModel()), getModel()); | ||
467 | 411 | }else if(pnObject instanceof TimedTransitionComponent){ | ||
468 | 412 | TimedTransitionComponent transition = (TimedTransitionComponent)pnObject; | ||
469 | 413 | cmd = new DeleteTimedTransitionCommand(transition, transition.underlyingTransition().model(), getModel()); | ||
470 | 414 | }else if(pnObject instanceof TimedTransportArcComponent){ | ||
471 | 415 | TimedTransportArcComponent transportArc = (TimedTransportArcComponent)pnObject; | ||
472 | 416 | cmd = new DeleteTransportArcCommand(transportArc, transportArc.underlyingTransportArc(), transportArc.underlyingTransportArc().model(), getModel()); | ||
473 | 417 | }else if(pnObject instanceof TimedInhibitorArcComponent){ | ||
474 | 418 | TimedInhibitorArcComponent tia = (TimedInhibitorArcComponent)pnObject; | ||
475 | 419 | cmd = new DeleteTimedInhibitorArcCommand(tia, tia.underlyingTimedInhibitorArc().model(), getModel()); | ||
476 | 420 | }else if(pnObject instanceof TimedInputArcComponent){ | ||
477 | 421 | TimedInputArcComponent tia = (TimedInputArcComponent)pnObject; | ||
478 | 422 | cmd = new DeleteTimedInputArcCommand(tia, tia.underlyingTimedInputArc().model(), getModel()); | ||
479 | 423 | }else if(pnObject instanceof TimedOutputArcComponent){ | ||
480 | 424 | TimedOutputArcComponent toa = (TimedOutputArcComponent)pnObject; | ||
481 | 425 | cmd = new DeleteTimedOutputArcCommand(toa, toa.underlyingArc().model(), getModel()); | ||
482 | 426 | }else if(pnObject instanceof AnnotationNote){ | ||
483 | 427 | cmd = new DeleteAnnotationNoteCommand((AnnotationNote)pnObject, getModel()); | ||
484 | 428 | }else{ | ||
485 | 429 | throw new RuntimeException("This should not be possible"); | ||
486 | 430 | } | ||
487 | 431 | cmd.redo(); | ||
488 | 432 | getUndoManager().addEdit(cmd); | ||
489 | 433 | } | ||
490 | 434 | } | ||
491 | 435 | } | ||
492 | 436 | |||
493 | 437 | |||
494 | 438 | private void deleteSelection(PetriNetObject pnObject) { | ||
495 | 439 | if(pnObject instanceof PlaceTransitionObject){ | ||
496 | 440 | PlaceTransitionObject pto = (PlaceTransitionObject)pnObject; | ||
497 | 441 | |||
498 | 442 | ArrayList<Arc> arcsToDelete = new ArrayList<>(); | ||
499 | 443 | |||
500 | 444 | //Notice since we delte elements from the collection we can't do this while iterating, we need to | ||
501 | 445 | // capture the arcs and delete them later. | ||
502 | 446 | for(Arc arc : pto.getPreset()){ | ||
503 | 447 | arcsToDelete.add(arc); | ||
504 | 448 | } | ||
505 | 449 | |||
506 | 450 | for(Arc arc : pto.getPostset()){ | ||
507 | 451 | arcsToDelete.add(arc); | ||
508 | 452 | } | ||
509 | 453 | |||
510 | 454 | arcsToDelete.forEach(this::deleteObject); | ||
511 | 455 | } | ||
512 | 456 | |||
513 | 457 | deleteObject(pnObject); | ||
514 | 458 | } | ||
515 | 459 | |||
516 | 460 | public void deleteSelection(ArrayList<PetriNetObject> selection) { | ||
517 | 461 | for (PetriNetObject pnObject : selection) { | ||
518 | 462 | deleteSelection(pnObject); | ||
519 | 463 | } | ||
520 | 464 | } | ||
521 | 465 | |||
522 | 466 | |||
523 | 467 | } | ||
524 | 468 | |||
525 | 59 | 469 | ||
526 | 60 | /** | 470 | /** |
527 | 61 | * Creates a new tab with the selected file, or a new file if filename==null | 471 | * Creates a new tab with the selected file, or a new file if filename==null |
528 | 62 | */ | 472 | */ |
529 | 63 | public static TabContent createNewTabFromInputStream(InputStream file, String name) throws Exception { | 473 | public static TabContent createNewTabFromInputStream(InputStream file, String name) throws Exception { |
530 | 64 | TabContent tab = new TabContent(); | ||
531 | 65 | tab.setInitialName(name); | ||
532 | 66 | 474 | ||
534 | 67 | try { | 475 | try { |
535 | 68 | ModelLoader loader = new ModelLoader(); | 476 | ModelLoader loader = new ModelLoader(); |
536 | 69 | LoadedModel loadedModel = loader.load(file); | 477 | LoadedModel loadedModel = loader.load(file); |
537 | 70 | 478 | ||
541 | 71 | tab.setNetwork(loadedModel.network(), loadedModel.templates()); | 479 | TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries()); |
542 | 72 | tab.setQueries(loadedModel.queries()); | 480 | tab.setInitialName(name); |
540 | 73 | tab.setConstants(loadedModel.network().constants()); | ||
543 | 74 | 481 | ||
544 | 75 | tab.selectFirstElements(); | 482 | tab.selectFirstElements(); |
545 | 76 | 483 | ||
546 | 77 | tab.setFile(null); | 484 | tab.setFile(null); |
547 | 485 | return tab; | ||
548 | 78 | } catch (Exception e) { | 486 | } catch (Exception e) { |
549 | 79 | throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString()); | 487 | throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString()); |
550 | 80 | } | 488 | } |
551 | 81 | 489 | ||
552 | 82 | return tab; | ||
553 | 83 | } | 490 | } |
554 | 84 | 491 | ||
555 | 85 | public static TabContent createNewEmptyTab(String name){ | 492 | public static TabContent createNewEmptyTab(String name){ |
556 | @@ -89,7 +496,7 @@ | |||
557 | 89 | //Set Default Template | 496 | //Set Default Template |
558 | 90 | String templateName = tab.drawingSurface().getNameGenerator().getNewTemplateName(); | 497 | String templateName = tab.drawingSurface().getNameGenerator().getNewTemplateName(); |
559 | 91 | Template template = new Template(new TimedArcPetriNet(templateName), new DataLayer(), new Zoomer()); | 498 | Template template = new Template(new TimedArcPetriNet(templateName), new DataLayer(), new Zoomer()); |
561 | 92 | tab.addTemplate(template, false); | 499 | tab.addTemplate(template); |
562 | 93 | 500 | ||
563 | 94 | return tab; | 501 | return tab; |
564 | 95 | } | 502 | } |
565 | @@ -99,14 +506,6 @@ | |||
566 | 99 | */ | 506 | */ |
567 | 100 | 507 | ||
568 | 101 | public static TabContent createNewTabFromPNMLFile(File file) throws Exception { | 508 | public static TabContent createNewTabFromPNMLFile(File file) throws Exception { |
569 | 102 | TabContent tab = new TabContent(); | ||
570 | 103 | |||
571 | 104 | String name = null; | ||
572 | 105 | |||
573 | 106 | if (file != null) { | ||
574 | 107 | name = file.getName().replaceAll(".pnml", ".tapn"); | ||
575 | 108 | } | ||
576 | 109 | tab.setInitialName(name); | ||
577 | 110 | 509 | ||
578 | 111 | if (file != null) { | 510 | if (file != null) { |
579 | 112 | try { | 511 | try { |
580 | @@ -116,24 +515,28 @@ | |||
581 | 116 | PNMLoader loader = new PNMLoader(); | 515 | PNMLoader loader = new PNMLoader(); |
582 | 117 | loadedModel = loader.load(file); | 516 | loadedModel = loader.load(file); |
583 | 118 | 517 | ||
588 | 119 | 518 | TabContent tab = new TabContent(loadedModel.network(), loadedModel.templates(), loadedModel.queries()); | |
589 | 120 | tab.setNetwork(loadedModel.network(), loadedModel.templates()); | 519 | |
590 | 121 | tab.setQueries(loadedModel.queries()); | 520 | String name = null; |
591 | 122 | tab.setConstants(loadedModel.network().constants()); | 521 | |
592 | 522 | if (file != null) { | ||
593 | 523 | name = file.getName().replaceAll(".pnml", ".tapn"); | ||
594 | 524 | } | ||
595 | 525 | tab.setInitialName(name); | ||
596 | 123 | 526 | ||
597 | 124 | tab.selectFirstElements(); | 527 | tab.selectFirstElements(); |
598 | 125 | 528 | ||
599 | 126 | tab.setMode(Pipe.ElementType.SELECT); | 529 | tab.setMode(Pipe.ElementType.SELECT); |
600 | 127 | 530 | ||
601 | 531 | //appView.updatePreferredSize(); //XXX 2018-05-23 kyrke seems not to be needed | ||
602 | 532 | name = name.replace(".pnml",".tapn"); // rename .pnml input file to .tapn | ||
603 | 533 | return tab; | ||
604 | 128 | 534 | ||
605 | 129 | } catch (Exception e) { | 535 | } catch (Exception e) { |
606 | 130 | throw new Exception("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nPossible explanations:\n - " + e.toString()); | 536 | throw new Exception("TAPAAL encountered an error while loading the file: " + file.getName() + "\n\nPossible explanations:\n - " + e.toString()); |
607 | 131 | } | 537 | } |
608 | 132 | } | 538 | } |
613 | 133 | 539 | return null; | |
610 | 134 | //appView.updatePreferredSize(); //XXX 2018-05-23 kyrke seems not to be needed | ||
611 | 135 | name = name.replace(".pnml",".tapn"); // rename .pnml input file to .tapn | ||
612 | 136 | return tab; | ||
614 | 137 | } | 540 | } |
615 | 138 | 541 | ||
616 | 139 | /** | 542 | /** |
617 | @@ -227,49 +630,72 @@ | |||
618 | 227 | 630 | ||
619 | 228 | private WorkflowDialog workflowDialog = null; | 631 | private WorkflowDialog workflowDialog = null; |
620 | 229 | 632 | ||
664 | 230 | public TabContent() { | 633 | |
665 | 231 | for (TimedArcPetriNet net : tapnNetwork.allTemplates()) { | 634 | private TabContent() { |
666 | 232 | guiModels.put(net, new DataLayer()); | 635 | this(new TimedArcPetriNetNetwork(), new ArrayList<>(), new TAPNLens(true,false)); |
667 | 233 | zoomLevels.put(net, new Zoomer()); | 636 | } |
668 | 234 | hasPositionalInfos.put(net, Boolean.FALSE); | 637 | |
669 | 235 | } | 638 | private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, TAPNLens lens) { |
670 | 236 | 639 | ||
671 | 237 | drawingSurface = new DrawingSurfaceImpl(new DataLayer(), this, managerRef); | 640 | Require.that(network != null, "network cannot be null"); |
672 | 238 | drawingSurfaceScroller = new JScrollPane(drawingSurface); | 641 | Require.notNull(lens, "Lens can't be null"); |
673 | 239 | // make it less bad on XP | 642 | this.lens = lens; |
674 | 240 | drawingSurfaceScroller.setBorder(new BevelBorder(BevelBorder.LOWERED)); | 643 | tapnNetwork = network; |
675 | 241 | drawingSurfaceScroller.setWheelScrollingEnabled(true); | 644 | |
676 | 242 | drawingSurfaceScroller.getVerticalScrollBar().setUnitIncrement(10); | 645 | guiModels.clear(); |
677 | 243 | drawingSurfaceScroller.getHorizontalScrollBar().setUnitIncrement(10); | 646 | for (Template template : templates) { |
678 | 244 | 647 | addGuiModel(template.model(), template.guiModel()); | |
679 | 245 | // Make clicking the drawing area move focus to GuiFrame | 648 | zoomLevels.put(template.model(), template.zoomer()); |
680 | 246 | drawingSurface.addMouseListener(new MouseAdapter() { | 649 | hasPositionalInfos.put(template.model(), template.getHasPositionalInfo()); |
681 | 247 | @Override | 650 | } |
682 | 248 | public void mouseClicked(MouseEvent e) { | 651 | |
683 | 249 | CreateGui.getApp().requestFocus(); | 652 | drawingSurface = new DrawingSurfaceImpl(new DataLayer(), this, managerRef); |
684 | 250 | } | 653 | drawingSurfaceScroller = new JScrollPane(drawingSurface); |
685 | 251 | }); | 654 | // make it less bad on XP |
686 | 252 | 655 | drawingSurfaceScroller.setBorder(new BevelBorder(BevelBorder.LOWERED)); | |
687 | 253 | drawingSurfaceDummy = new JPanel(new GridBagLayout()); | 656 | drawingSurfaceScroller.setWheelScrollingEnabled(true); |
688 | 254 | GridBagConstraints gc=new GridBagConstraints(); | 657 | drawingSurfaceScroller.getVerticalScrollBar().setUnitIncrement(10); |
689 | 255 | gc.fill=GridBagConstraints.HORIZONTAL; | 658 | drawingSurfaceScroller.getHorizontalScrollBar().setUnitIncrement(10); |
690 | 256 | gc.gridx=0; | 659 | |
691 | 257 | gc.gridy=0; | 660 | // Make clicking the drawing area move focus to GuiFrame |
692 | 258 | drawingSurfaceDummy.add(new JLabel("The net is too big to be drawn"), gc); | 661 | drawingSurface.addMouseListener(new MouseAdapter() { |
693 | 259 | 662 | @Override | |
694 | 260 | createEditorLeftPane(); | 663 | public void mouseClicked(MouseEvent e) { |
695 | 261 | createAnimatorSplitPane(); | 664 | CreateGui.getApp().requestFocus(); |
696 | 262 | 665 | } | |
697 | 263 | this.setOrientation(HORIZONTAL_SPLIT); | 666 | }); |
698 | 264 | this.setLeftComponent(editorSplitPaneScroller); | 667 | |
699 | 265 | this.setRightComponent(drawingSurfaceScroller); | 668 | drawingSurfaceDummy = new JPanel(new GridBagLayout()); |
700 | 266 | 669 | GridBagConstraints gc=new GridBagConstraints(); | |
701 | 267 | this.setContinuousLayout(true); | 670 | gc.fill=GridBagConstraints.HORIZONTAL; |
702 | 268 | this.setOneTouchExpandable(true); | 671 | gc.gridx=0; |
703 | 269 | this.setBorder(null); // avoid multiple borders | 672 | gc.gridy=0; |
704 | 270 | this.setDividerSize(8); | 673 | drawingSurfaceDummy.add(new JLabel("The net is too big to be drawn"), gc); |
705 | 271 | //XXX must be after the animationcontroller is created | 674 | |
706 | 272 | animationModeController = new CanvasAnimationController(getAnimator()); | 675 | createEditorLeftPane(); |
707 | 676 | createAnimatorSplitPane(); | ||
708 | 677 | |||
709 | 678 | this.setOrientation(HORIZONTAL_SPLIT); | ||
710 | 679 | this.setLeftComponent(editorSplitPaneScroller); | ||
711 | 680 | this.setRightComponent(drawingSurfaceScroller); | ||
712 | 681 | |||
713 | 682 | this.setContinuousLayout(true); | ||
714 | 683 | this.setOneTouchExpandable(true); | ||
715 | 684 | this.setBorder(null); // avoid multiple borders | ||
716 | 685 | this.setDividerSize(8); | ||
717 | 686 | //XXX must be after the animationcontroller is created | ||
718 | 687 | animationModeController = new CanvasAnimationController(getAnimator()); | ||
719 | 688 | } | ||
720 | 689 | |||
721 | 690 | private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries) { | ||
722 | 691 | this(network, templates, tapnqueries, new TAPNLens(true, false)); | ||
723 | 692 | } | ||
724 | 693 | private TabContent(TimedArcPetriNetNetwork network, Collection<Template> templates, Iterable<TAPNQuery> tapnqueries, TAPNLens lens) { | ||
725 | 694 | this(network, templates, lens); | ||
726 | 695 | |||
727 | 696 | setNetwork(network, templates); | ||
728 | 697 | setQueries(tapnqueries); | ||
729 | 698 | setConstants(network().constants()); | ||
730 | 273 | } | 699 | } |
731 | 274 | 700 | ||
732 | 275 | public SharedPlacesAndTransitionsPanel getSharedPlacesAndTransitionsPanel(){ | 701 | public SharedPlacesAndTransitionsPanel getSharedPlacesAndTransitionsPanel(){ |
733 | @@ -706,34 +1132,24 @@ | |||
734 | 706 | return count; | 1132 | return count; |
735 | 707 | } | 1133 | } |
736 | 708 | 1134 | ||
745 | 709 | /* | 1135 | public void addTemplate(Template template) { |
738 | 710 | XXX: 2018-05-07 kyrke, added a version of addTemplate that does not call templatExplorer.updatTemplateList | ||
739 | 711 | used in createNewTab (as updateTamplateList expects the current tab to be selected) | ||
740 | 712 | this needs to be refactored asap. but the is the only way I could get it to work for now. | ||
741 | 713 | The code is very unclean on what is a template, TimeArcPetriNetNetwork, seems to mix concerns about | ||
742 | 714 | gui/controller/model. Further refactoring is needed to clean up this mess. | ||
743 | 715 | */ | ||
744 | 716 | public void addTemplate(Template template, boolean updateTemplateExplorer) { | ||
746 | 717 | tapnNetwork.add(template.model()); | 1136 | tapnNetwork.add(template.model()); |
747 | 718 | guiModels.put(template.model(), template.guiModel()); | 1137 | guiModels.put(template.model(), template.guiModel()); |
748 | 1138 | guiModelToModel.put(template.guiModel(), template.model()); | ||
749 | 719 | zoomLevels.put(template.model(), template.zoomer()); | 1139 | zoomLevels.put(template.model(), template.zoomer()); |
750 | 720 | hasPositionalInfos.put(template.model(), template.getHasPositionalInfo()); | 1140 | hasPositionalInfos.put(template.model(), template.getHasPositionalInfo()); |
758 | 721 | if (updateTemplateExplorer) { | 1141 | templateExplorer.updateTemplateList(); |
752 | 722 | templateExplorer.updateTemplateList(); | ||
753 | 723 | } | ||
754 | 724 | } | ||
755 | 725 | |||
756 | 726 | public void addTemplate(Template template) { | ||
757 | 727 | addTemplate(template, true); | ||
759 | 728 | } | 1142 | } |
760 | 729 | 1143 | ||
761 | 730 | public void addGuiModel(TimedArcPetriNet net, DataLayer guiModel) { | 1144 | public void addGuiModel(TimedArcPetriNet net, DataLayer guiModel) { |
762 | 731 | guiModels.put(net, guiModel); | 1145 | guiModels.put(net, guiModel); |
763 | 1146 | guiModelToModel.put(guiModel, net); | ||
764 | 732 | } | 1147 | } |
765 | 733 | 1148 | ||
766 | 734 | public void removeTemplate(Template template) { | 1149 | public void removeTemplate(Template template) { |
767 | 735 | tapnNetwork.remove(template.model()); | 1150 | tapnNetwork.remove(template.model()); |
768 | 736 | guiModels.remove(template.model()); | 1151 | guiModels.remove(template.model()); |
769 | 1152 | guiModelToModel.remove(template.guiModel()); | ||
770 | 737 | zoomLevels.remove(template.model()); | 1153 | zoomLevels.remove(template.model()); |
771 | 738 | hasPositionalInfos.remove(template.model()); | 1154 | hasPositionalInfos.remove(template.model()); |
772 | 739 | templateExplorer.updateTemplateList(); | 1155 | templateExplorer.updateTemplateList(); |
773 | @@ -747,7 +1163,7 @@ | |||
774 | 747 | return queries.getQueries(); | 1163 | return queries.getQueries(); |
775 | 748 | } | 1164 | } |
776 | 749 | 1165 | ||
778 | 750 | public void setQueries(Iterable<TAPNQuery> queries) { | 1166 | private void setQueries(Iterable<TAPNQuery> queries) { |
779 | 751 | this.queries.setQueries(queries); | 1167 | this.queries.setQueries(queries); |
780 | 752 | } | 1168 | } |
781 | 753 | 1169 | ||
782 | @@ -759,20 +1175,12 @@ | |||
783 | 759 | queries.addQuery(query); | 1175 | queries.addQuery(query); |
784 | 760 | } | 1176 | } |
785 | 761 | 1177 | ||
787 | 762 | public void setConstants(Iterable<Constant> constants) { | 1178 | private void setConstants(Iterable<Constant> constants) { |
788 | 763 | tapnNetwork.setConstants(constants); | 1179 | tapnNetwork.setConstants(constants); |
789 | 764 | } | 1180 | } |
790 | 765 | 1181 | ||
794 | 766 | public void setNetwork(TimedArcPetriNetNetwork network, Collection<Template> templates) { | 1182 | private void setNetwork(TimedArcPetriNetNetwork network, Collection<Template> templates) { |
792 | 767 | Require.that(network != null, "network cannot be null"); | ||
793 | 768 | tapnNetwork = network; | ||
795 | 769 | 1183 | ||
796 | 770 | guiModels.clear(); | ||
797 | 771 | for (Template template : templates) { | ||
798 | 772 | addGuiModel(template.model(), template.guiModel()); | ||
799 | 773 | zoomLevels.put(template.model(), template.zoomer()); | ||
800 | 774 | hasPositionalInfos.put(template.model(), template.getHasPositionalInfo()); | ||
801 | 775 | } | ||
802 | 776 | 1184 | ||
803 | 777 | sharedPTPanel.setNetwork(network); | 1185 | sharedPTPanel.setNetwork(network); |
804 | 778 | templateExplorer.updateTemplateList(); | 1186 | templateExplorer.updateTemplateList(); |
805 | @@ -1060,6 +1468,8 @@ | |||
806 | 1060 | animator.updateAnimationButtonsEnabled(); //Update stepBack/Forward | 1468 | animator.updateAnimationButtonsEnabled(); //Update stepBack/Forward |
807 | 1061 | } | 1469 | } |
808 | 1062 | 1470 | ||
809 | 1471 | private Pipe.ElementType editorMode = Pipe.ElementType.SELECT; | ||
810 | 1472 | |||
811 | 1063 | //XXX temp while refactoring, kyrke - 2019-07-25 | 1473 | //XXX temp while refactoring, kyrke - 2019-07-25 |
812 | 1064 | @Override | 1474 | @Override |
813 | 1065 | public void setMode(Pipe.ElementType mode) { | 1475 | public void setMode(Pipe.ElementType mode) { |
814 | @@ -1068,11 +1478,67 @@ | |||
815 | 1068 | 1478 | ||
816 | 1069 | //Disable selection and deselect current selection | 1479 | //Disable selection and deselect current selection |
817 | 1070 | drawingSurface().getSelectionObject().clearSelection(); | 1480 | drawingSurface().getSelectionObject().clearSelection(); |
823 | 1071 | 1481 | editorMode = mode; | |
824 | 1072 | //If pending arc draw, remove it | 1482 | switch (mode) { |
825 | 1073 | if (drawingSurface().createArc != null) { | 1483 | case ADDTOKEN: |
826 | 1074 | PlaceTransitionObjectHandler.cleanupArc(drawingSurface().createArc, drawingSurface()); | 1484 | setManager(new AbstractDrawingSurfaceManager() { |
827 | 1075 | } | 1485 | @Override |
828 | 1486 | public void registerEvents() { | ||
829 | 1487 | registerEvent( | ||
830 | 1488 | e -> e.pno instanceof TimedPlaceComponent && e.a == MouseAction.pressed, | ||
831 | 1489 | e -> placeClicked((TimedPlaceComponent) e.pno) | ||
832 | 1490 | ); | ||
833 | 1491 | } | ||
834 | 1492 | |||
835 | 1493 | public void placeClicked(TimedPlaceComponent pno) { | ||
836 | 1494 | Command command = new TimedPlaceMarkingEdit(pno, 1); | ||
837 | 1495 | command.redo(); | ||
838 | 1496 | undoManager.addNewEdit(command); | ||
839 | 1497 | } | ||
840 | 1498 | }); | ||
841 | 1499 | break; | ||
842 | 1500 | case DELTOKEN: | ||
843 | 1501 | setManager(new AbstractDrawingSurfaceManager() { | ||
844 | 1502 | @Override | ||
845 | 1503 | public void registerEvents() { | ||
846 | 1504 | registerEvent( | ||
847 | 1505 | e -> e.pno instanceof TimedPlaceComponent && e.a == MouseAction.pressed, | ||
848 | 1506 | e -> placeClicked((TimedPlaceComponent) e.pno) | ||
849 | 1507 | ); | ||
850 | 1508 | } | ||
851 | 1509 | |||
852 | 1510 | public void placeClicked(TimedPlaceComponent pno) { | ||
853 | 1511 | Command command = new TimedPlaceMarkingEdit(pno, -1); | ||
854 | 1512 | command.redo(); | ||
855 | 1513 | undoManager.addNewEdit(command); | ||
856 | 1514 | } | ||
857 | 1515 | }); | ||
858 | 1516 | break; | ||
859 | 1517 | case TAPNPLACE: | ||
860 | 1518 | setManager(new CanvasPlaceDrawController()); | ||
861 | 1519 | break; | ||
862 | 1520 | case TAPNTRANS: | ||
863 | 1521 | setManager(new CanvasTransitionDrawController()); | ||
864 | 1522 | break; | ||
865 | 1523 | case ANNOTATION: | ||
866 | 1524 | setManager(new CanvasAnnotationNoteDrawController()); | ||
867 | 1525 | break; | ||
868 | 1526 | case TAPNARC: | ||
869 | 1527 | setManager(new CanvasArcDrawController()); | ||
870 | 1528 | break; | ||
871 | 1529 | case TAPNINHIBITOR_ARC: | ||
872 | 1530 | setManager(new CanvasInhibitorarcDrawController()); | ||
873 | 1531 | break; | ||
874 | 1532 | case TRANSPORTARC: | ||
875 | 1533 | setManager(new CanvasTransportarcDrawController()); | ||
876 | 1534 | break; | ||
877 | 1535 | case SELECT: | ||
878 | 1536 | setManager(new CanvasGeneralDrawController()); | ||
879 | 1537 | break; | ||
880 | 1538 | default: | ||
881 | 1539 | setManager(notingManager); | ||
882 | 1540 | break; | ||
883 | 1541 | } | ||
884 | 1076 | 1542 | ||
885 | 1077 | if (mode == Pipe.ElementType.SELECT) { | 1543 | if (mode == Pipe.ElementType.SELECT) { |
886 | 1078 | drawingSurface().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); | 1544 | drawingSurface().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
887 | @@ -1221,63 +1687,7 @@ | |||
888 | 1221 | 1687 | ||
889 | 1222 | @Override | 1688 | @Override |
890 | 1223 | public void deleteSelection() { | 1689 | public void deleteSelection() { |
948 | 1224 | // check if queries need to be removed | 1690 | guiModelManager.deleteSelection(); |
892 | 1225 | ArrayList<PetriNetObject> selection = drawingSurface().getSelectionObject().getSelection(); | ||
893 | 1226 | Iterable<TAPNQuery> queries = queries(); | ||
894 | 1227 | HashSet<TAPNQuery> queriesToDelete = new HashSet<TAPNQuery>(); | ||
895 | 1228 | |||
896 | 1229 | boolean queriesAffected = false; | ||
897 | 1230 | for (PetriNetObject pn : selection) { | ||
898 | 1231 | if (pn instanceof TimedPlaceComponent) { | ||
899 | 1232 | TimedPlaceComponent place = (TimedPlaceComponent)pn; | ||
900 | 1233 | if(!place.underlyingPlace().isShared()){ | ||
901 | 1234 | for (TAPNQuery q : queries) { | ||
902 | 1235 | if (q.getProperty().containsAtomicPropositionWithSpecificPlaceInTemplate(((LocalTimedPlace)place.underlyingPlace()).model().name(),place.underlyingPlace().name())) { | ||
903 | 1236 | queriesAffected = true; | ||
904 | 1237 | queriesToDelete.add(q); | ||
905 | 1238 | } | ||
906 | 1239 | } | ||
907 | 1240 | } | ||
908 | 1241 | } else if (pn instanceof TimedTransitionComponent){ | ||
909 | 1242 | TimedTransitionComponent transition = (TimedTransitionComponent)pn; | ||
910 | 1243 | if(!transition.underlyingTransition().isShared()){ | ||
911 | 1244 | for (TAPNQuery q : queries) { | ||
912 | 1245 | if (q.getProperty().containsAtomicPropositionWithSpecificTransitionInTemplate((transition.underlyingTransition()).model().name(),transition.underlyingTransition().name())) { | ||
913 | 1246 | queriesAffected = true; | ||
914 | 1247 | queriesToDelete.add(q); | ||
915 | 1248 | } | ||
916 | 1249 | } | ||
917 | 1250 | } | ||
918 | 1251 | } | ||
919 | 1252 | } | ||
920 | 1253 | StringBuilder s = new StringBuilder(); | ||
921 | 1254 | s.append("The following queries are associated with the currently selected objects:\n\n"); | ||
922 | 1255 | for (TAPNQuery q : queriesToDelete) { | ||
923 | 1256 | s.append(q.getName()); | ||
924 | 1257 | s.append('\n'); | ||
925 | 1258 | } | ||
926 | 1259 | s.append("\nAre you sure you want to remove the current selection and all associated queries?"); | ||
927 | 1260 | |||
928 | 1261 | int choice = queriesAffected ? JOptionPane.showConfirmDialog( | ||
929 | 1262 | CreateGui.getApp(), s.toString(), "Warning", | ||
930 | 1263 | JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) | ||
931 | 1264 | : JOptionPane.YES_OPTION; | ||
932 | 1265 | |||
933 | 1266 | if (choice == JOptionPane.YES_OPTION) { | ||
934 | 1267 | getUndoManager().newEdit(); // new "transaction"" | ||
935 | 1268 | if (queriesAffected) { | ||
936 | 1269 | TabContent currentTab = this; | ||
937 | 1270 | for (TAPNQuery q : queriesToDelete) { | ||
938 | 1271 | Command cmd = new DeleteQueriesCommand(currentTab, Arrays.asList(q)); | ||
939 | 1272 | cmd.redo(); | ||
940 | 1273 | getUndoManager().addEdit(cmd); | ||
941 | 1274 | } | ||
942 | 1275 | } | ||
943 | 1276 | |||
944 | 1277 | drawingSurface().deleteSelection(drawingSurface().getSelectionObject().getSelection()); | ||
945 | 1278 | //getCurrentTab().drawingSurface().repaint(); | ||
946 | 1279 | network().buildConstraints(); | ||
947 | 1280 | } | ||
949 | 1281 | 1691 | ||
950 | 1282 | 1692 | ||
951 | 1283 | } | 1693 | } |
952 | @@ -1309,13 +1719,13 @@ | |||
953 | 1309 | 1719 | ||
954 | 1310 | //If arc is being drawn delete it | 1720 | //If arc is being drawn delete it |
955 | 1311 | 1721 | ||
957 | 1312 | if (drawingSurface().createArc == null) { | 1722 | if (editorMode == Pipe.ElementType.SELECT) { |
958 | 1313 | getUndoManager().undo(); | 1723 | getUndoManager().undo(); |
959 | 1314 | network().buildConstraints(); | 1724 | network().buildConstraints(); |
960 | 1315 | 1725 | ||
961 | 1316 | } else { | 1726 | } else { |
962 | 1317 | 1727 | ||
964 | 1318 | PlaceTransitionObjectHandler.cleanupArc(drawingSurface().createArc, drawingSurface()); | 1728 | setMode(Pipe.ElementType.SELECT); |
965 | 1319 | 1729 | ||
966 | 1320 | } | 1730 | } |
967 | 1321 | } | 1731 | } |
968 | @@ -1330,13 +1740,13 @@ | |||
969 | 1330 | 1740 | ||
970 | 1331 | //If arc is being drawn delete it | 1741 | //If arc is being drawn delete it |
971 | 1332 | 1742 | ||
973 | 1333 | if (drawingSurface().createArc == null) { | 1743 | if (editorMode == Pipe.ElementType.SELECT) { |
974 | 1334 | getUndoManager().redo(); | 1744 | getUndoManager().redo(); |
975 | 1335 | network().buildConstraints(); | 1745 | network().buildConstraints(); |
976 | 1336 | 1746 | ||
977 | 1337 | } else { | 1747 | } else { |
978 | 1338 | 1748 | ||
980 | 1339 | PlaceTransitionObjectHandler.cleanupArc(drawingSurface().createArc, drawingSurface()); | 1749 | setMode(Pipe.ElementType.SELECT); |
981 | 1340 | 1750 | ||
982 | 1341 | } | 1751 | } |
983 | 1342 | } | 1752 | } |
984 | @@ -1462,6 +1872,321 @@ | |||
985 | 1462 | return null; | 1872 | return null; |
986 | 1463 | } | 1873 | } |
987 | 1464 | 1874 | ||
988 | 1875 | class CanvasPlaceDrawController extends AbstractDrawingSurfaceManager { | ||
989 | 1876 | |||
990 | 1877 | @Override | ||
991 | 1878 | public void drawingSurfaceMousePressed(MouseEvent e) { | ||
992 | 1879 | Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom()); | ||
993 | 1880 | |||
994 | 1881 | guiModelManager.addNewTimedPlace(canvas.getGuiModel(), p); | ||
995 | 1882 | } | ||
996 | 1883 | |||
997 | 1884 | @Override | ||
998 | 1885 | public void registerEvents() { | ||
999 | 1886 | |||
1000 | 1887 | } | ||
1001 | 1888 | } | ||
1002 | 1889 | |||
1003 | 1890 | class CanvasTransitionDrawController extends AbstractDrawingSurfaceManager { | ||
1004 | 1891 | |||
1005 | 1892 | @Override | ||
1006 | 1893 | public void drawingSurfaceMousePressed(MouseEvent e) { | ||
1007 | 1894 | Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom()); | ||
1008 | 1895 | |||
1009 | 1896 | guiModelManager.addNewTimedTransitions(drawingSurface.getGuiModel(), p); | ||
1010 | 1897 | } | ||
1011 | 1898 | |||
1012 | 1899 | @Override | ||
1013 | 1900 | public void registerEvents() { | ||
1014 | 1901 | |||
1015 | 1902 | } | ||
1016 | 1903 | } | ||
1017 | 1904 | |||
1018 | 1905 | class CanvasAnnotationNoteDrawController extends AbstractDrawingSurfaceManager { | ||
1019 | 1906 | |||
1020 | 1907 | @Override | ||
1021 | 1908 | public void drawingSurfaceMousePressed(MouseEvent e) { | ||
1022 | 1909 | Point p = canvas.adjustPointToGridAndZoom(e.getPoint(), canvas.getZoom()); | ||
1023 | 1910 | |||
1024 | 1911 | guiModelManager.addAnnotationNote(drawingSurface.getGuiModel(), p); | ||
1025 | 1912 | } | ||
1026 | 1913 | |||
1027 | 1914 | @Override | ||
1028 | 1915 | public void registerEvents() { | ||
1029 | 1916 | |||
1030 | 1917 | } | ||
1031 | 1918 | } | ||
1032 | 1919 | |||
1033 | 1920 | class CanvasInhibitorarcDrawController extends AbstractDrawingSurfaceManager { | ||
1034 | 1921 | |||
1035 | 1922 | private TimedTransitionComponent transition; | ||
1036 | 1923 | private TimedPlaceComponent place; | ||
1037 | 1924 | private Arc arc; | ||
1038 | 1925 | |||
1039 | 1926 | @Override | ||
1040 | 1927 | public void registerEvents() { | ||
1041 | 1928 | registerEvent( | ||
1042 | 1929 | e->e.pno instanceof TimedPlaceComponent && e.a == MouseAction.pressed, | ||
1043 | 1930 | e->placeClicked(((TimedPlaceComponent) e.pno)) | ||
1044 | 1931 | ); | ||
1045 | 1932 | registerEvent( | ||
1046 | 1933 | e->e.pno instanceof TimedTransitionComponent && e.a == MouseAction.pressed, | ||
1047 | 1934 | e->transitionClicked(((TimedTransitionComponent) e.pno)) | ||
1048 | 1935 | ); | ||
1049 | 1936 | registerEvent( | ||
1050 | 1937 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.entered, | ||
1051 | 1938 | e->placetranstionMouseOver(((PlaceTransitionObject) e.pno)) | ||
1052 | 1939 | ); | ||
1053 | 1940 | registerEvent( | ||
1054 | 1941 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.exited, | ||
1055 | 1942 | e->placetranstionMouseExited(((PlaceTransitionObject) e.pno)) | ||
1056 | 1943 | ); | ||
1057 | 1944 | registerEvent( | ||
1058 | 1945 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.moved, | ||
1059 | 1946 | e->placetransitionMouseMoved(((PlaceTransitionObject) e.pno), e.e) | ||
1060 | 1947 | ); | ||
1061 | 1948 | } | ||
1062 | 1949 | |||
1063 | 1950 | private void placetransitionMouseMoved(PlaceTransitionObject pno, MouseEvent e) { | ||
1064 | 1951 | if (arc != null) { | ||
1065 | 1952 | if (arc.getSource() == pno || !arc.getSource().areNotSameType(pno)) { | ||
1066 | 1953 | //Dispatch event to parent (drawing surface) | ||
1067 | 1954 | e.translatePoint(pno.getX(),pno.getY()); | ||
1068 | 1955 | pno.getParent().dispatchEvent(e); | ||
1069 | 1956 | } | ||
1070 | 1957 | } | ||
1071 | 1958 | } | ||
1072 | 1959 | |||
1073 | 1960 | private void placetranstionMouseExited(PlaceTransitionObject pto) { | ||
1074 | 1961 | if (arc != null) { | ||
1075 | 1962 | arc.setTarget(null); | ||
1076 | 1963 | //XXX this is bad, we have to clean up internal state manually, should be refactored //kyrke - 2019-11-14 | ||
1077 | 1964 | // Relates to bug #1849786 | ||
1078 | 1965 | if (pto instanceof Transition) { | ||
1079 | 1966 | ((Transition)pto).removeArcCompareObject(arc); | ||
1080 | 1967 | } | ||
1081 | 1968 | arc.updateArcPosition(); | ||
1082 | 1969 | } | ||
1083 | 1970 | } | ||
1084 | 1971 | |||
1085 | 1972 | private void placetranstionMouseOver(PlaceTransitionObject pno) { | ||
1086 | 1973 | if (arc != null) { | ||
1087 | 1974 | if (arc.getSource() != pno && arc.getSource().areNotSameType(pno)) { | ||
1088 | 1975 | arc.setTarget(pno); | ||
1089 | 1976 | arc.updateArcPosition(); | ||
1090 | 1977 | } | ||
1091 | 1978 | } | ||
1092 | 1979 | } | ||
1093 | 1980 | |||
1094 | 1981 | private void transitionClicked(TimedTransitionComponent pno) { | ||
1095 | 1982 | if (place != null && transition == null) { | ||
1096 | 1983 | transition = pno; | ||
1097 | 1984 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1098 | 1985 | guiModelManager.addInhibitorArc(getModel(), place, transition, arc.getArcPath()); | ||
1099 | 1986 | clearPendingArc(); | ||
1100 | 1987 | } | ||
1101 | 1988 | } | ||
1102 | 1989 | |||
1103 | 1990 | private void placeClicked(TimedPlaceComponent pno) { | ||
1104 | 1991 | if (place == null && transition == null) { | ||
1105 | 1992 | place = pno; | ||
1106 | 1993 | arc = new TimedInhibitorArcComponent(pno); | ||
1107 | 1994 | //XXX calling zoomUpdate will set the endpoint to 0,0, drawing the arc from source to 0,0 | ||
1108 | 1995 | //to avoid this we change the endpoint to set the end point to the same as the end point | ||
1109 | 1996 | //needs further refactorings //kyrke 2019-09-05 | ||
1110 | 1997 | arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false); | ||
1111 | 1998 | CreateGui.getDrawingSurface().addPrototype(arc); | ||
1112 | 1999 | arc.requestFocusInWindow(); | ||
1113 | 2000 | arc.setSelectable(false); | ||
1114 | 2001 | arc.enableDrawingKeyBindings(this::clearPendingArc); | ||
1115 | 2002 | } else if (transition != null && place == null) { | ||
1116 | 2003 | place = pno; | ||
1117 | 2004 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1118 | 2005 | guiModelManager.addTimedOutputArc(getModel(), transition, place, arc.getArcPath()); | ||
1119 | 2006 | clearPendingArc(); | ||
1120 | 2007 | } | ||
1121 | 2008 | } | ||
1122 | 2009 | |||
1123 | 2010 | private void clearPendingArc() { | ||
1124 | 2011 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1125 | 2012 | place = null; | ||
1126 | 2013 | transition = null; | ||
1127 | 2014 | arc = null; | ||
1128 | 2015 | } | ||
1129 | 2016 | |||
1130 | 2017 | @Override | ||
1131 | 2018 | public void drawingSurfaceMouseMoved(MouseEvent e) { | ||
1132 | 2019 | if(arc!=null) { | ||
1133 | 2020 | arc.setEndPoint(e.getX(), e.getY(), e.isShiftDown()); | ||
1134 | 2021 | } | ||
1135 | 2022 | } | ||
1136 | 2023 | |||
1137 | 2024 | @Override | ||
1138 | 2025 | public void drawingSurfaceMousePressed(MouseEvent e) { | ||
1139 | 2026 | if (arc!=null) {; | ||
1140 | 2027 | Point p = e.getPoint(); | ||
1141 | 2028 | int x = Zoomer.getUnzoomedValue(p.x, CreateGui.getDrawingSurface().getZoom()); | ||
1142 | 2029 | int y = Zoomer.getUnzoomedValue(p.y, CreateGui.getDrawingSurface().getZoom()); | ||
1143 | 2030 | |||
1144 | 2031 | boolean shiftDown = e.isShiftDown(); | ||
1145 | 2032 | //XXX: x,y is ignored is overwritten when mouse is moved, this just add a new point to the end of list | ||
1146 | 2033 | arc.getArcPath().addPoint(arc.getArcPath().getEndIndex(), x,y, shiftDown); | ||
1147 | 2034 | } | ||
1148 | 2035 | } | ||
1149 | 2036 | |||
1150 | 2037 | @Override | ||
1151 | 2038 | public void registerManager(DrawingSurfaceImpl canvas) { | ||
1152 | 2039 | CreateGui.useExtendedBounds = true; | ||
1153 | 2040 | } | ||
1154 | 2041 | |||
1155 | 2042 | @Override | ||
1156 | 2043 | public void deregisterManager() { | ||
1157 | 2044 | clearPendingArc(); | ||
1158 | 2045 | CreateGui.useExtendedBounds = false; | ||
1159 | 2046 | } | ||
1160 | 2047 | |||
1161 | 2048 | |||
1162 | 2049 | } | ||
1163 | 2050 | class CanvasArcDrawController extends AbstractDrawingSurfaceManager { | ||
1164 | 2051 | private TimedTransitionComponent transition; | ||
1165 | 2052 | private TimedPlaceComponent place; | ||
1166 | 2053 | private Arc arc; | ||
1167 | 2054 | |||
1168 | 2055 | @Override | ||
1169 | 2056 | public void registerEvents() { | ||
1170 | 2057 | registerEvent( | ||
1171 | 2058 | e->e.pno instanceof TimedPlaceComponent && e.a == MouseAction.pressed, | ||
1172 | 2059 | e->placeClicked(((TimedPlaceComponent) e.pno)) | ||
1173 | 2060 | ); | ||
1174 | 2061 | registerEvent( | ||
1175 | 2062 | e->e.pno instanceof TimedTransitionComponent && e.a == MouseAction.pressed, | ||
1176 | 2063 | e->transitionClicked(((TimedTransitionComponent) e.pno)) | ||
1177 | 2064 | ); | ||
1178 | 2065 | registerEvent( | ||
1179 | 2066 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.entered, | ||
1180 | 2067 | e->placetranstionMouseOver(((PlaceTransitionObject) e.pno)) | ||
1181 | 2068 | ); | ||
1182 | 2069 | registerEvent( | ||
1183 | 2070 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.exited, | ||
1184 | 2071 | e->placetranstionMouseExited(((PlaceTransitionObject) e.pno)) | ||
1185 | 2072 | ); | ||
1186 | 2073 | registerEvent( | ||
1187 | 2074 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.moved, | ||
1188 | 2075 | e->placetransitionMouseMoved(((PlaceTransitionObject) e.pno), e.e) | ||
1189 | 2076 | ); | ||
1190 | 2077 | } | ||
1191 | 2078 | |||
1192 | 2079 | private void placetransitionMouseMoved(PlaceTransitionObject pno, MouseEvent e) { | ||
1193 | 2080 | if (arc != null) { | ||
1194 | 2081 | if (arc.getSource() == pno || !arc.getSource().areNotSameType(pno)) { | ||
1195 | 2082 | //Dispatch event to parent (drawing surface) | ||
1196 | 2083 | e.translatePoint(pno.getX(),pno.getY()); | ||
1197 | 2084 | pno.getParent().dispatchEvent(e); | ||
1198 | 2085 | } | ||
1199 | 2086 | } | ||
1200 | 2087 | } | ||
1201 | 2088 | |||
1202 | 2089 | private void placetranstionMouseExited(PlaceTransitionObject pto) { | ||
1203 | 2090 | if (arc != null) { | ||
1204 | 2091 | arc.setTarget(null); | ||
1205 | 2092 | //XXX this is bad, we have to clean up internal state manually, should be refactored //kyrke - 2019-11-14 | ||
1206 | 2093 | // Relates to bug #1849786 | ||
1207 | 2094 | if (pto instanceof Transition) { | ||
1208 | 2095 | ((Transition)pto).removeArcCompareObject(arc); | ||
1209 | 2096 | } | ||
1210 | 2097 | arc.updateArcPosition(); | ||
1211 | 2098 | } | ||
1212 | 2099 | } | ||
1213 | 2100 | |||
1214 | 2101 | private void placetranstionMouseOver(PlaceTransitionObject pno) { | ||
1215 | 2102 | if (arc != null) { | ||
1216 | 2103 | if (arc.getSource() != pno && arc.getSource().areNotSameType(pno)) { | ||
1217 | 2104 | arc.setTarget(pno); | ||
1218 | 2105 | arc.updateArcPosition(); | ||
1219 | 2106 | } | ||
1220 | 2107 | } | ||
1221 | 2108 | } | ||
1222 | 2109 | |||
1223 | 2110 | private void transitionClicked(TimedTransitionComponent pno) { | ||
1224 | 2111 | if (place == null && transition == null) { | ||
1225 | 2112 | transition = pno; | ||
1226 | 2113 | arc = new TimedOutputArcComponent(pno); | ||
1227 | 2114 | |||
1228 | 2115 | //XXX calling zoomUpdate will set the endpoint to 0,0, drawing the arc from source to 0,0 | ||
1229 | 2116 | //to avoid this we change the endpoint to set the end point to the same as the end point | ||
1230 | 2117 | //needs further refactorings //kyrke 2019-09-05 | ||
1231 | 2118 | arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false); | ||
1232 | 2119 | CreateGui.getDrawingSurface().addPrototype(arc); | ||
1233 | 2120 | arc.requestFocusInWindow(); | ||
1234 | 2121 | arc.setSelectable(false); | ||
1235 | 2122 | arc.enableDrawingKeyBindings(this::clearPendingArc); | ||
1236 | 2123 | } else if (place != null && transition == null) { | ||
1237 | 2124 | transition = pno; | ||
1238 | 2125 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1239 | 2126 | guiModelManager.addTimedInputArc(getModel(), place, transition, arc.getArcPath()); | ||
1240 | 2127 | clearPendingArc(); | ||
1241 | 2128 | } | ||
1242 | 2129 | } | ||
1243 | 2130 | |||
1244 | 2131 | private void placeClicked(TimedPlaceComponent pno) { | ||
1245 | 2132 | if (place == null && transition == null) { | ||
1246 | 2133 | place = pno; | ||
1247 | 2134 | arc = new TimedInputArcComponent(pno); | ||
1248 | 2135 | //XXX calling zoomUpdate will set the endpoint to 0,0, drawing the arc from source to 0,0 | ||
1249 | 2136 | //to avoid this we change the endpoint to set the end point to the same as the end point | ||
1250 | 2137 | //needs further refactorings //kyrke 2019-09-05 | ||
1251 | 2138 | arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false); | ||
1252 | 2139 | CreateGui.getDrawingSurface().addPrototype(arc); | ||
1253 | 2140 | arc.requestFocusInWindow(); | ||
1254 | 2141 | arc.setSelectable(false); | ||
1255 | 2142 | arc.enableDrawingKeyBindings(this::clearPendingArc); | ||
1256 | 2143 | } else if (transition != null && place == null) { | ||
1257 | 2144 | place = pno; | ||
1258 | 2145 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1259 | 2146 | guiModelManager.addTimedOutputArc(getModel(), transition, place, arc.getArcPath()); | ||
1260 | 2147 | clearPendingArc(); | ||
1261 | 2148 | } | ||
1262 | 2149 | } | ||
1263 | 2150 | |||
1264 | 2151 | private void clearPendingArc() { | ||
1265 | 2152 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1266 | 2153 | place = null; | ||
1267 | 2154 | transition = null; | ||
1268 | 2155 | arc = null; | ||
1269 | 2156 | } | ||
1270 | 2157 | |||
1271 | 2158 | @Override | ||
1272 | 2159 | public void drawingSurfaceMouseMoved(MouseEvent e) { | ||
1273 | 2160 | if(arc!=null) { | ||
1274 | 2161 | arc.setEndPoint(e.getX(), e.getY(), e.isShiftDown()); | ||
1275 | 2162 | } | ||
1276 | 2163 | } | ||
1277 | 2164 | |||
1278 | 2165 | @Override | ||
1279 | 2166 | public void drawingSurfaceMousePressed(MouseEvent e) { | ||
1280 | 2167 | if (arc!=null) {; | ||
1281 | 2168 | Point p = e.getPoint(); | ||
1282 | 2169 | int x = Zoomer.getUnzoomedValue(p.x, CreateGui.getDrawingSurface().getZoom()); | ||
1283 | 2170 | int y = Zoomer.getUnzoomedValue(p.y, CreateGui.getDrawingSurface().getZoom()); | ||
1284 | 2171 | |||
1285 | 2172 | boolean shiftDown = e.isShiftDown(); | ||
1286 | 2173 | //XXX: x,y is ignored is overwritten when mouse is moved, this just add a new point to the end of list | ||
1287 | 2174 | arc.getArcPath().addPoint(arc.getArcPath().getEndIndex(), x,y, shiftDown); | ||
1288 | 2175 | } | ||
1289 | 2176 | } | ||
1290 | 2177 | |||
1291 | 2178 | @Override | ||
1292 | 2179 | public void registerManager(DrawingSurfaceImpl canvas) { | ||
1293 | 2180 | CreateGui.useExtendedBounds = true; | ||
1294 | 2181 | } | ||
1295 | 2182 | |||
1296 | 2183 | @Override | ||
1297 | 2184 | public void deregisterManager() { | ||
1298 | 2185 | clearPendingArc(); | ||
1299 | 2186 | CreateGui.useExtendedBounds = false; | ||
1300 | 2187 | } | ||
1301 | 2188 | } | ||
1302 | 2189 | |||
1303 | 1465 | static class CanvasAnimationController extends AbstractDrawingSurfaceManager { | 2190 | static class CanvasAnimationController extends AbstractDrawingSurfaceManager { |
1304 | 1466 | 2191 | ||
1305 | 1467 | private final Animator animator; | 2192 | private final Animator animator; |
1306 | @@ -1473,7 +2198,7 @@ | |||
1307 | 1473 | @Override | 2198 | @Override |
1308 | 1474 | public void registerEvents() { | 2199 | public void registerEvents() { |
1309 | 1475 | registerEvent( | 2200 | registerEvent( |
1311 | 1476 | e -> e.a == MouseAction.clicked && e.pno instanceof TimedTransitionComponent && SwingUtilities.isLeftMouseButton(e.e), | 2201 | e -> e.a == MouseAction.pressed && e.pno instanceof TimedTransitionComponent && SwingUtilities.isLeftMouseButton(e.e), |
1312 | 1477 | e -> transitionLeftClicked((TimedTransitionComponent)e.pno) | 2202 | e -> transitionLeftClicked((TimedTransitionComponent)e.pno) |
1313 | 1478 | ); | 2203 | ); |
1314 | 1479 | registerEvent( | 2204 | registerEvent( |
1315 | @@ -1516,13 +2241,205 @@ | |||
1316 | 1516 | //De-register old manager | 2241 | //De-register old manager |
1317 | 1517 | managerRef.get().deregisterManager(); | 2242 | managerRef.get().deregisterManager(); |
1318 | 1518 | managerRef.setReference(newManager); | 2243 | managerRef.setReference(newManager); |
1328 | 1519 | managerRef.get().registerManager(); | 2244 | managerRef.get().registerManager(drawingSurface); |
1329 | 1520 | } | 2245 | } |
1330 | 1521 | 2246 | ||
1331 | 1522 | //XXX: A quick function made while refactoring to test if the tab is currently | 2247 | private final class CanvasTransportarcDrawController extends AbstractDrawingSurfaceManager { |
1332 | 1523 | // the tab selected, and is allowed to change gui the gui. Should be controlled an other way | 2248 | |
1333 | 1524 | // /kyrke 2019-11-10 | 2249 | private TimedTransitionComponent transition; |
1334 | 1525 | public boolean isTabInFocus(){ | 2250 | private TimedPlaceComponent place1; |
1335 | 1526 | return app.isPresent(); | 2251 | private TimedPlaceComponent place2; |
1336 | 1527 | } | 2252 | private Arc arc; |
1337 | 2253 | private Arc arc1; | ||
1338 | 2254 | private Arc arc2; | ||
1339 | 2255 | |||
1340 | 2256 | |||
1341 | 2257 | @Override | ||
1342 | 2258 | public void registerEvents() { | ||
1343 | 2259 | registerEvent( | ||
1344 | 2260 | e->e.pno instanceof TimedPlaceComponent && e.a == MouseAction.pressed, | ||
1345 | 2261 | e->placeClicked(((TimedPlaceComponent) e.pno)) | ||
1346 | 2262 | ); | ||
1347 | 2263 | registerEvent( | ||
1348 | 2264 | e->e.pno instanceof TimedTransitionComponent && e.a == MouseAction.pressed, | ||
1349 | 2265 | e->transitionClicked(((TimedTransitionComponent) e.pno)) | ||
1350 | 2266 | ); | ||
1351 | 2267 | registerEvent( | ||
1352 | 2268 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.entered, | ||
1353 | 2269 | e->placetranstionMouseOver(((PlaceTransitionObject) e.pno)) | ||
1354 | 2270 | ); | ||
1355 | 2271 | registerEvent( | ||
1356 | 2272 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.exited, | ||
1357 | 2273 | e->placetranstionMouseExited(((PlaceTransitionObject) e.pno)) | ||
1358 | 2274 | ); | ||
1359 | 2275 | registerEvent( | ||
1360 | 2276 | e->e.pno instanceof PlaceTransitionObject && e.a == MouseAction.moved, | ||
1361 | 2277 | e->placetransitionMouseMoved(((PlaceTransitionObject) e.pno), e.e) | ||
1362 | 2278 | ); | ||
1363 | 2279 | } | ||
1364 | 2280 | |||
1365 | 2281 | private void placetransitionMouseMoved(PlaceTransitionObject pno, MouseEvent e) { | ||
1366 | 2282 | if (arc != null) { | ||
1367 | 2283 | if (arc.getSource() == pno || !arc.getSource().areNotSameType(pno)) { | ||
1368 | 2284 | //Dispatch event to parent (drawing surface) | ||
1369 | 2285 | e.translatePoint(pno.getX(),pno.getY()); | ||
1370 | 2286 | pno.getParent().dispatchEvent(e); | ||
1371 | 2287 | } | ||
1372 | 2288 | } | ||
1373 | 2289 | } | ||
1374 | 2290 | |||
1375 | 2291 | private void placetranstionMouseExited(PlaceTransitionObject pto) { | ||
1376 | 2292 | if (arc != null) { | ||
1377 | 2293 | arc.setTarget(null); | ||
1378 | 2294 | //XXX this is bad, we have to clean up internal state manually, should be refactored //kyrke - 2019-11-14 | ||
1379 | 2295 | // Relates to bug #1849786 | ||
1380 | 2296 | if (pto instanceof Transition) { | ||
1381 | 2297 | ((Transition)pto).removeArcCompareObject(arc); | ||
1382 | 2298 | } | ||
1383 | 2299 | arc.updateArcPosition(); | ||
1384 | 2300 | } | ||
1385 | 2301 | } | ||
1386 | 2302 | |||
1387 | 2303 | private void placetranstionMouseOver(PlaceTransitionObject pno) { | ||
1388 | 2304 | if (arc != null) { | ||
1389 | 2305 | if (arc.getSource() != pno && arc.getSource().areNotSameType(pno)) { | ||
1390 | 2306 | arc.setTarget(pno); | ||
1391 | 2307 | arc.updateArcPosition(); | ||
1392 | 2308 | } | ||
1393 | 2309 | } | ||
1394 | 2310 | } | ||
1395 | 2311 | |||
1396 | 2312 | private void transitionClicked(TimedTransitionComponent pno) { | ||
1397 | 2313 | if (place1 != null && transition == null) { | ||
1398 | 2314 | transition = pno; | ||
1399 | 2315 | arc2 = arc = new TimedTransportArcComponent(pno, -1, false); | ||
1400 | 2316 | |||
1401 | 2317 | //XXX calling zoomUpdate will set the endpoint to 0,0, drawing the arc from source to 0,0 | ||
1402 | 2318 | //to avoid this we change the endpoint to set the end point to the same as the end point | ||
1403 | 2319 | //needs further refactorings //kyrke 2019-09-05 | ||
1404 | 2320 | arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false); | ||
1405 | 2321 | CreateGui.getDrawingSurface().addPrototype(arc); | ||
1406 | 2322 | arc.requestFocusInWindow(); | ||
1407 | 2323 | arc.setSelectable(false); | ||
1408 | 2324 | arc.enableDrawingKeyBindings(this::clearPendingArc); | ||
1409 | 2325 | } | ||
1410 | 2326 | } | ||
1411 | 2327 | |||
1412 | 2328 | private void placeClicked(TimedPlaceComponent pno) { | ||
1413 | 2329 | if (place1 == null && transition == null) { | ||
1414 | 2330 | place1 = pno; | ||
1415 | 2331 | arc1 = arc = new TimedTransportArcComponent(pno, -1, true); | ||
1416 | 2332 | //XXX calling zoomUpdate will set the endpoint to 0,0, drawing the arc from source to 0,0 | ||
1417 | 2333 | //to avoid this we change the endpoint to set the end point to the same as the end point | ||
1418 | 2334 | //needs further refactorings //kyrke 2019-09-05 | ||
1419 | 2335 | arc.setEndPoint(pno.getPositionX(), pno.getPositionY(), false); | ||
1420 | 2336 | CreateGui.getDrawingSurface().addPrototype(arc); | ||
1421 | 2337 | arc.requestFocusInWindow(); | ||
1422 | 2338 | arc.setSelectable(false); | ||
1423 | 2339 | arc.enableDrawingKeyBindings(this::clearPendingArc); | ||
1424 | 2340 | } else if (transition != null && place2 == null) { | ||
1425 | 2341 | place2 = pno; | ||
1426 | 2342 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1427 | 2343 | guiModelManager.addTimedTransportArc(getModel(), place1, transition, place2, arc1.getArcPath(), arc2.getArcPath()); | ||
1428 | 2344 | clearPendingArc(); | ||
1429 | 2345 | } | ||
1430 | 2346 | } | ||
1431 | 2347 | |||
1432 | 2348 | private void clearPendingArc() { | ||
1433 | 2349 | CreateGui.getDrawingSurface().clearAllPrototype(); | ||
1434 | 2350 | place1 = place2 = null; | ||
1435 | 2351 | transition = null; | ||
1436 | 2352 | arc = arc1 = arc2 = null; | ||
1437 | 2353 | } | ||
1438 | 2354 | |||
1439 | 2355 | @Override | ||
1440 | 2356 | public void drawingSurfaceMouseMoved(MouseEvent e) { | ||
1441 | 2357 | if(arc!=null) { | ||
1442 | 2358 | arc.setEndPoint(e.getX(), e.getY(), e.isShiftDown()); | ||
1443 | 2359 | } | ||
1444 | 2360 | } | ||
1445 | 2361 | |||
1446 | 2362 | @Override | ||
1447 | 2363 | public void drawingSurfaceMousePressed(MouseEvent e) { | ||
1448 | 2364 | if (arc!=null) { | ||
1449 | 2365 | Point p = e.getPoint(); | ||
1450 | 2366 | int x = Zoomer.getUnzoomedValue(p.x, CreateGui.getDrawingSurface().getZoom()); | ||
1451 | 2367 | int y = Zoomer.getUnzoomedValue(p.y, CreateGui.getDrawingSurface().getZoom()); | ||
1452 | 2368 | |||
1453 | 2369 | boolean shiftDown = e.isShiftDown(); | ||
1454 | 2370 | //XXX: x,y is ignored is overwritten when mouse is moved, this just add a new point to the end of list | ||
1455 | 2371 | arc.getArcPath().addPoint(arc.getArcPath().getEndIndex(), x,y, shiftDown); | ||
1456 | 2372 | } | ||
1457 | 2373 | } | ||
1458 | 2374 | |||
1459 | 2375 | @Override | ||
1460 | 2376 | public void registerManager(DrawingSurfaceImpl canvas) { | ||
1461 | 2377 | CreateGui.useExtendedBounds = true; | ||
1462 | 2378 | } | ||
1463 | 2379 | |||
1464 | 2380 | @Override | ||
1465 | 2381 | public void deregisterManager() { | ||
1466 | 2382 | clearPendingArc(); | ||
1467 | 2383 | CreateGui.useExtendedBounds = false; | ||
1468 | 2384 | } | ||
1469 | 2385 | } | ||
1470 | 2386 | |||
1471 | 2387 | private class CanvasGeneralDrawController extends AbstractDrawingSurfaceManager { | ||
1472 | 2388 | @Override | ||
1473 | 2389 | public void registerEvents() { | ||
1474 | 2390 | registerEvent( | ||
1475 | 2391 | e->e.pno instanceof TimedTransitionComponent && e.a == MouseAction.doubleClicked, | ||
1476 | 2392 | e-> ((TimedTransitionComponent) e.pno).showEditor() | ||
1477 | 2393 | ); | ||
1478 | 2394 | registerEvent( | ||
1479 | 2395 | e->e.pno instanceof TimedPlaceComponent && e.a == MouseAction.doubleClicked, | ||
1480 | 2396 | e-> ((TimedPlaceComponent) e.pno).showEditor() | ||
1481 | 2397 | ); | ||
1482 | 2398 | registerEvent( | ||
1483 | 2399 | e->e.pno instanceof TimedTransitionComponent && e.a == MouseAction.rightClicked, | ||
1484 | 2400 | e-> ((TimedTransitionComponent) e.pno).getMouseHandler().getPopup(e.e).show(e.pno, e.e.getX(), e.e.getY()) | ||
1485 | 2401 | ); | ||
1486 | 2402 | registerEvent( | ||
1487 | 2403 | e->e.pno instanceof TimedPlaceComponent && e.a == MouseAction.rightClicked, | ||
1488 | 2404 | e-> ((TimedPlaceComponent) e.pno).getMouseHandler().getPopup(e.e).show(e.pno, e.e.getX(), e.e.getY()) | ||
1489 | 2405 | ); | ||
1490 | 2406 | registerEvent( | ||
1491 | 2407 | e->e.pno instanceof Arc && e.a == MouseAction.rightClicked, | ||
1492 | 2408 | e-> ((Arc) e.pno).getMouseHandler().getPopup(e.e).show(e.pno, e.e.getX(), e.e.getY()) | ||
1493 | 2409 | ); | ||
1494 | 2410 | registerEvent( | ||
1495 | 2411 | e->e.pno instanceof AnnotationNote && e.a == MouseAction.doubleClicked, | ||
1496 | 2412 | e-> ((AnnotationNote) e.pno).enableEditMode() | ||
1497 | 2413 | ); | ||
1498 | 2414 | registerEvent( | ||
1499 | 2415 | e->e.pno instanceof AnnotationNote && e.a == MouseAction.rightClicked, | ||
1500 | 2416 | e-> ((AnnotationNote) e.pno).getMouseHandler().getPopup(e.e).show(e.pno, e.e.getX(), e.e.getY()) | ||
1501 | 2417 | ); | ||
1502 | 2418 | registerEvent( | ||
1503 | 2419 | e->e.pno instanceof Arc && e.a == MouseAction.entered, | ||
1504 | 2420 | e -> ((Arc)e.pno).getArcPath().showPoints() | ||
1505 | 2421 | ); | ||
1506 | 2422 | registerEvent( | ||
1507 | 2423 | e->e.pno instanceof Arc && e.a == MouseAction.exited, | ||
1508 | 2424 | e -> ((Arc)e.pno).getArcPath().hidePoints() | ||
1509 | 2425 | ); | ||
1510 | 2426 | registerEvent( | ||
1511 | 2427 | e->e.pno instanceof Arc && e.a == MouseAction.doubleClicked && e.e.isControlDown(), | ||
1512 | 2428 | e->arcDoubleClickedWithContrl(((Arc) e.pno), e.e) | ||
1513 | 2429 | ); | ||
1514 | 2430 | |||
1515 | 2431 | } | ||
1516 | 2432 | |||
1517 | 2433 | private void arcDoubleClickedWithContrl(Arc arc, MouseEvent e) { | ||
1518 | 2434 | CreateGui.getCurrentTab().getUndoManager().addNewEdit( | ||
1519 | 2435 | arc.getArcPath().insertPoint( | ||
1520 | 2436 | new Point2D.Double( | ||
1521 | 2437 | Zoomer.getUnzoomedValue(arc.getX() + e.getX(), arc.getZoom()), | ||
1522 | 2438 | Zoomer.getUnzoomedValue(arc.getY() + e.getY(), arc.getZoom()) | ||
1523 | 2439 | ), | ||
1524 | 2440 | e.isAltDown() | ||
1525 | 2441 | ) | ||
1526 | 2442 | ); | ||
1527 | 2443 | } | ||
1528 | 2444 | } | ||
1529 | 1528 | } | 2445 | } |
1530 | 1529 | 2446 | ||
1531 | === modified file 'src/dk/aau/cs/gui/TemplateExplorer.java' | |||
1532 | --- src/dk/aau/cs/gui/TemplateExplorer.java 2020-05-27 13:15:44 +0000 | |||
1533 | +++ src/dk/aau/cs/gui/TemplateExplorer.java 2020-07-09 12:55:48 +0000 | |||
1534 | @@ -81,12 +81,12 @@ | |||
1535 | 81 | private JButton renameButton; | 81 | private JButton renameButton; |
1536 | 82 | private JButton copyButton; | 82 | private JButton copyButton; |
1537 | 83 | 83 | ||
1540 | 84 | private TabContent parent; | 84 | private final TabContent parent; |
1541 | 85 | private UndoManager undoManager; | 85 | private final UndoManager undoManager; |
1542 | 86 | private boolean isInAnimationMode; | 86 | private boolean isInAnimationMode; |
1543 | 87 | 87 | ||
1546 | 88 | public JButton moveUpButton; | 88 | private JButton moveUpButton; |
1547 | 89 | public JButton moveDownButton; | 89 | private JButton moveDownButton; |
1548 | 90 | private JButton sortButton; | 90 | private JButton sortButton; |
1549 | 91 | 91 | ||
1550 | 92 | private static final String toolTipNewComponent ="Create a new component"; | 92 | private static final String toolTipNewComponent ="Create a new component"; |
1551 | @@ -188,7 +188,7 @@ | |||
1552 | 188 | 188 | ||
1553 | 189 | private void initExplorerPanel() { | 189 | private void initExplorerPanel() { |
1554 | 190 | templatePanel = new JPanel(new GridBagLayout()); | 190 | templatePanel = new JPanel(new GridBagLayout()); |
1556 | 191 | listModel = new DefaultListModel(); | 191 | listModel = new DefaultListModel<>(); |
1557 | 192 | for (Template net : parent.allTemplates()) { | 192 | for (Template net : parent.allTemplates()) { |
1558 | 193 | listModel.addElement(net); | 193 | listModel.addElement(net); |
1559 | 194 | } | 194 | } |
1560 | @@ -214,7 +214,7 @@ | |||
1561 | 214 | } | 214 | } |
1562 | 215 | }); | 215 | }); |
1563 | 216 | 216 | ||
1565 | 217 | templateList = new NonsearchableJList(listModel); | 217 | templateList = new NonsearchableJList<>(listModel); |
1566 | 218 | 218 | ||
1567 | 219 | templateList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | 219 | templateList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
1568 | 220 | templateList.setSelectedIndex(0); | 220 | templateList.setSelectedIndex(0); |
1569 | @@ -476,7 +476,7 @@ | |||
1570 | 476 | private void onOKRenameTemplate() { | 476 | private void onOKRenameTemplate() { |
1571 | 477 | Template template = selectedModel(); | 477 | Template template = selectedModel(); |
1572 | 478 | String newName = nameTextField.getText().trim(); | 478 | String newName = nameTextField.getText().trim(); |
1574 | 479 | if (newName == null || template.model().name().equals(newName)) { | 479 | if (template.model().name().equals(newName)) { |
1575 | 480 | exit(); | 480 | exit(); |
1576 | 481 | return; | 481 | return; |
1577 | 482 | } | 482 | } |
1578 | @@ -508,37 +508,34 @@ | |||
1579 | 508 | } | 508 | } |
1580 | 509 | 509 | ||
1581 | 510 | private void onOK() { | 510 | private void onOK() { |
1613 | 511 | Template template = null; | 511 | String templateName = nameTextField.getText().trim(); |
1614 | 512 | String templateName = nameTextField.getText().trim(); | 512 | if(!isNameAllowed(templateName)) { |
1615 | 513 | if (templateName != null) { | 513 | JOptionPane.showMessageDialog(parent.drawingSurface(), |
1616 | 514 | if(!isNameAllowed(templateName)) { | 514 | "Acceptable names for components are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nThe new component could not be created.", |
1617 | 515 | JOptionPane.showMessageDialog(parent.drawingSurface(), | 515 | "Error Creating Component", |
1618 | 516 | "Acceptable names for components are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nThe new component could not be created.", | 516 | JOptionPane.ERROR_MESSAGE); |
1619 | 517 | "Error Creating Component", | 517 | exit(); |
1620 | 518 | JOptionPane.ERROR_MESSAGE); | 518 | ShowNewTemplateDialog(templateName); |
1621 | 519 | exit(); | 519 | return; |
1622 | 520 | ShowNewTemplateDialog(templateName); | 520 | } |
1623 | 521 | return; | 521 | else if (parent.network().hasTAPNCalled(templateName)) { |
1624 | 522 | } | 522 | JOptionPane.showMessageDialog(parent.drawingSurface(), |
1625 | 523 | else if (parent.network().hasTAPNCalled(templateName)) { | 523 | "A component named \"" + templateName + "\" already exists.\n\nThe new component could not be created.", |
1626 | 524 | JOptionPane.showMessageDialog(parent.drawingSurface(), | 524 | "Error Creating Component", |
1627 | 525 | "A component named \"" + templateName + "\" already exists.\n\nThe new component could not be created.", | 525 | JOptionPane.ERROR_MESSAGE); |
1628 | 526 | "Error Creating Component", | 526 | exit(); |
1629 | 527 | JOptionPane.ERROR_MESSAGE); | 527 | ShowNewTemplateDialog(templateName); |
1630 | 528 | exit(); | 528 | return; |
1631 | 529 | ShowNewTemplateDialog(templateName); | 529 | } |
1632 | 530 | return; | 530 | else { |
1633 | 531 | } | 531 | Template template = createNewTemplate(templateName); |
1634 | 532 | else { | 532 | |
1635 | 533 | template = createNewTemplate(templateName); | 533 | int index = listModel.size(); |
1636 | 534 | 534 | undoManager.addNewEdit(new AddTemplateCommand(TemplateExplorer.this, template, index)); | |
1637 | 535 | int index = listModel.size(); | 535 | parent.addTemplate(template); |
1638 | 536 | undoManager.addNewEdit(new AddTemplateCommand(TemplateExplorer.this, template, index)); | 536 | } |
1639 | 537 | parent.addTemplate(template); | 537 | |
1640 | 538 | } | 538 | exit(); |
1610 | 539 | } | ||
1611 | 540 | |||
1612 | 541 | exit(); | ||
1641 | 542 | } | 539 | } |
1642 | 543 | 540 | ||
1643 | 544 | private void exit() { | 541 | private void exit() { |
1644 | @@ -639,8 +636,7 @@ | |||
1645 | 639 | } | 636 | } |
1646 | 640 | 637 | ||
1647 | 641 | private void ShowNewTemplateDialog(String nameToShow) { | 638 | private void ShowNewTemplateDialog(String nameToShow) { |
1650 | 642 | dialog = new EscapableDialog(CreateGui.getApp(), | 639 | dialog = new EscapableDialog(CreateGui.getApp(), "Enter Component Name", true); |
1649 | 643 | "Enter Component Name", true); | ||
1651 | 644 | initComponentsOfNewTemplateDialog(nameToShow); | 640 | initComponentsOfNewTemplateDialog(nameToShow); |
1652 | 645 | dialog.add(container); | 641 | dialog.add(container); |
1653 | 646 | dialog.setResizable(false); | 642 | dialog.setResizable(false); |
1654 | @@ -742,8 +738,7 @@ | |||
1655 | 742 | } | 738 | } |
1656 | 743 | 739 | ||
1657 | 744 | private void showRenameTemplateDialog(String nameToShow) { | 740 | private void showRenameTemplateDialog(String nameToShow) { |
1660 | 745 | dialog = new EscapableDialog(CreateGui.getApp(), | 741 | dialog = new EscapableDialog(CreateGui.getApp(), "Enter Component Name", true); |
1659 | 746 | "Enter Component Name", true); | ||
1661 | 747 | Template template = selectedModel(); | 742 | Template template = selectedModel(); |
1662 | 748 | if (nameToShow.equals("")){ | 743 | if (nameToShow.equals("")){ |
1663 | 749 | initComponentsOfRenameTemplateDialog(template.model().name()); | 744 | initComponentsOfRenameTemplateDialog(template.model().name()); |
1664 | @@ -777,7 +772,7 @@ | |||
1665 | 777 | 772 | ||
1666 | 778 | public void openSelectedTemplate() { | 773 | public void openSelectedTemplate() { |
1667 | 779 | Template tapn = selectedModel(); | 774 | Template tapn = selectedModel(); |
1669 | 780 | if (tapn != null && parent.isTabInFocus()) { | 775 | if (tapn != null) { |
1670 | 781 | parent.changeToTemplate(tapn); | 776 | parent.changeToTemplate(tapn); |
1671 | 782 | } | 777 | } |
1672 | 783 | //parent.drawingSurface().repaintAll(); | 778 | //parent.drawingSurface().repaintAll(); |
1673 | @@ -789,7 +784,7 @@ | |||
1674 | 789 | 784 | ||
1675 | 790 | public void updateTemplateList() { | 785 | public void updateTemplateList() { |
1676 | 791 | int selectedIndex = templateList.getSelectedIndex(); | 786 | int selectedIndex = templateList.getSelectedIndex(); |
1678 | 792 | DefaultListModel newList = new DefaultListModel(); | 787 | DefaultListModel<Template> newList = new DefaultListModel<>(); |
1679 | 793 | 788 | ||
1680 | 794 | if(isInAnimationMode) { | 789 | if(isInAnimationMode) { |
1681 | 795 | for (Template net : parent.activeTemplates()) { | 790 | for (Template net : parent.activeTemplates()) { |
1682 | @@ -852,7 +847,7 @@ | |||
1683 | 852 | listModel.setElementAt(o, index+1); | 847 | listModel.setElementAt(o, index+1); |
1684 | 853 | } | 848 | } |
1685 | 854 | @Override | 849 | @Override |
1687 | 855 | public JList getJList(){ | 850 | public JList<Template> getJList(){ |
1688 | 856 | return templateList; | 851 | return templateList; |
1689 | 857 | } | 852 | } |
1690 | 858 | 853 | ||
1691 | @@ -995,21 +990,24 @@ | |||
1692 | 995 | } | 990 | } |
1693 | 996 | renameButton.setEnabled(true); | 991 | renameButton.setEnabled(true); |
1694 | 997 | copyButton.setEnabled(true); | 992 | copyButton.setEnabled(true); |
1704 | 998 | if(templateList.getModel().getSize() >= 2) | 993 | if(templateList.getModel().getSize() >= 2) { |
1705 | 999 | sortButton.setEnabled(true); | 994 | sortButton.setEnabled(true); |
1706 | 1000 | else | 995 | } else { |
1707 | 1001 | sortButton.setEnabled(false); | 996 | sortButton.setEnabled(false); |
1708 | 1002 | 997 | } | |
1709 | 1003 | if(index > 0) | 998 | |
1710 | 1004 | moveUpButton.setEnabled(true); | 999 | if(index > 0) { |
1711 | 1005 | else | 1000 | moveUpButton.setEnabled(true); |
1712 | 1006 | moveUpButton.setEnabled(false); | 1001 | } else { |
1713 | 1002 | moveUpButton.setEnabled(false); | ||
1714 | 1003 | } | ||
1715 | 1007 | 1004 | ||
1716 | 1008 | 1005 | ||
1721 | 1009 | if(index < parent.network().allTemplates().size() - 1) | 1006 | if(index < parent.network().allTemplates().size() - 1) { |
1722 | 1010 | moveDownButton.setEnabled(true); | 1007 | moveDownButton.setEnabled(true); |
1723 | 1011 | else | 1008 | } else { |
1724 | 1012 | moveDownButton.setEnabled(false); | 1009 | moveDownButton.setEnabled(false); |
1725 | 1010 | } | ||
1726 | 1013 | } | 1011 | } |
1727 | 1014 | templateList.ensureIndexIsVisible(index); | 1012 | templateList.ensureIndexIsVisible(index); |
1728 | 1015 | openSelectedTemplate(); | 1013 | openSelectedTemplate(); |
1729 | 1016 | 1014 | ||
1730 | === modified file 'src/dk/aau/cs/gui/components/EnabledTransitionsList.java' | |||
1731 | --- src/dk/aau/cs/gui/components/EnabledTransitionsList.java 2020-05-18 08:14:37 +0000 | |||
1732 | +++ src/dk/aau/cs/gui/components/EnabledTransitionsList.java 2020-07-09 12:55:48 +0000 | |||
1733 | @@ -38,17 +38,14 @@ | |||
1734 | 38 | initPanel(); | 38 | initPanel(); |
1735 | 39 | } | 39 | } |
1736 | 40 | 40 | ||
1740 | 41 | DefaultListModel<TransitionListItem> transitions; | 41 | final DefaultListModel<TransitionListItem> transitions = new DefaultListModel<>(); |
1741 | 42 | JList<TransitionListItem> transitionsList; | 42 | final JList<TransitionListItem> transitionsList = new JList<>(transitions); |
1742 | 43 | JScrollPane scrollPane; | 43 | final JScrollPane scrollPane = new JScrollPane(transitionsList); |
1743 | 44 | TransitionListItem lastSelected; | 44 | TransitionListItem lastSelected; |
1744 | 45 | 45 | ||
1745 | 46 | public void initPanel(){ | 46 | public void initPanel(){ |
1746 | 47 | transitions = new DefaultListModel<>(); | ||
1747 | 48 | transitionsList = new JList<>(transitions); | ||
1748 | 49 | transitionsList.setCellRenderer(new EnabledTransitionListCellRenderer()); | ||
1749 | 50 | 47 | ||
1751 | 51 | transitionsList.addMouseListener(new MouseAdapter() { | 48 | transitionsList.addMouseListener(new MouseAdapter() { |
1752 | 52 | @Override | 49 | @Override |
1753 | 53 | public void mouseClicked(MouseEvent e) { | 50 | public void mouseClicked(MouseEvent e) { |
1754 | 54 | if(e.getClickCount() == 2){ | 51 | if(e.getClickCount() == 2){ |
1755 | @@ -64,9 +61,7 @@ | |||
1756 | 64 | } | 61 | } |
1757 | 65 | }); | 62 | }); |
1758 | 66 | 63 | ||
1762 | 67 | scrollPane = new JScrollPane(transitionsList); | 64 | this.add(scrollPane, BorderLayout.CENTER); |
1760 | 68 | |||
1761 | 69 | this.add(scrollPane, BorderLayout.CENTER); | ||
1763 | 70 | } | 65 | } |
1764 | 71 | 66 | ||
1765 | 72 | public void startReInit(){ | 67 | public void startReInit(){ |
1766 | @@ -110,18 +105,12 @@ | |||
1767 | 110 | public void addTransition(Template template, Transition transition){ | 105 | public void addTransition(Template template, Transition transition){ |
1768 | 111 | TransitionListItem item = new TransitionListItem(transition, template); | 106 | TransitionListItem item = new TransitionListItem(transition, template); |
1769 | 112 | 107 | ||
1770 | 113 | transition.isDelayEnabled(); | ||
1771 | 114 | if(!transitions.contains(item)){ | 108 | if(!transitions.contains(item)){ |
1772 | 115 | transitions.addElement(item); | 109 | transitions.addElement(item); |
1773 | 116 | } | 110 | } |
1774 | 117 | } | 111 | } |
1775 | 118 | 112 | ||
1782 | 119 | public void removeTransition(Template template, Transition transition){ | 113 | public void fireSelectedTransition(){ |
1777 | 120 | TransitionListItem item = new TransitionListItem(transition, template); | ||
1778 | 121 | transitions.removeElement(item); | ||
1779 | 122 | } | ||
1780 | 123 | |||
1781 | 124 | public void fireSelectedTransition(){ | ||
1783 | 125 | TransitionListItem item = transitionsList.getSelectedValue(); | 114 | TransitionListItem item = transitionsList.getSelectedValue(); |
1784 | 126 | 115 | ||
1785 | 127 | if(item != null) { | 116 | if(item != null) { |
1786 | @@ -131,27 +120,10 @@ | |||
1787 | 131 | 120 | ||
1788 | 132 | interface ListItem extends Comparable<ListItem>{} | 121 | interface ListItem extends Comparable<ListItem>{} |
1789 | 133 | 122 | ||
1790 | 134 | class SplitterListItem implements ListItem{ | ||
1791 | 135 | |||
1792 | 136 | @Override | ||
1793 | 137 | public int compareTo(ListItem o) { | ||
1794 | 138 | if(o instanceof TransitionListItem){ | ||
1795 | 139 | return o.compareTo(this); | ||
1796 | 140 | } else { | ||
1797 | 141 | return 0; | ||
1798 | 142 | } | ||
1799 | 143 | } | ||
1800 | 144 | |||
1801 | 145 | @Override | ||
1802 | 146 | public String toString() { | ||
1803 | 147 | return "_"; | ||
1804 | 148 | } | ||
1805 | 149 | |||
1806 | 150 | } | ||
1807 | 151 | 123 | ||
1808 | 152 | static class TransitionListItem implements ListItem{ | 124 | static class TransitionListItem implements ListItem{ |
1811 | 153 | private Transition transition; | 125 | private final Transition transition; |
1812 | 154 | private Template template; | 126 | private final Template template; |
1813 | 155 | 127 | ||
1814 | 156 | public TransitionListItem(Transition transition, Template template){ | 128 | public TransitionListItem(Transition transition, Template template){ |
1815 | 157 | this.transition = transition; | 129 | this.transition = transition; |
1816 | @@ -160,8 +132,7 @@ | |||
1817 | 160 | 132 | ||
1818 | 161 | public String toString(boolean showIntervals) { | 133 | public String toString(boolean showIntervals) { |
1819 | 162 | 134 | ||
1822 | 163 | String interval = transition.getDInterval() == null || !showIntervals ? | 135 | String interval = transition.getDInterval() == null || !showIntervals ? "" : transition.getDInterval().toString() + " "; |
1821 | 164 | "" : transition.getDInterval().toString() + " "; | ||
1823 | 165 | 136 | ||
1824 | 166 | String transitionName = getTransition().getName(); | 137 | String transitionName = getTransition().getName(); |
1825 | 167 | if(isShared()){ | 138 | if(isShared()){ |
1826 | @@ -237,51 +208,6 @@ | |||
1827 | 237 | } | 208 | } |
1828 | 238 | } | 209 | } |
1829 | 239 | 210 | ||
1830 | 240 | //This class creates the stippled line shown between the enabled transitions and the delay-enabled transitions | ||
1831 | 241 | class EnabledTransitionListCellRenderer extends DefaultListCellRenderer{ | ||
1832 | 242 | |||
1833 | 243 | @Override | ||
1834 | 244 | public Component getListCellRendererComponent(JList list, Object value, | ||
1835 | 245 | int index, boolean isSelected, boolean cellHasFocus) { | ||
1836 | 246 | if(value instanceof SplitterListItem){ | ||
1837 | 247 | JLabel separator = new JLabel(); | ||
1838 | 248 | separator.setBorder(new DashBorder()); | ||
1839 | 249 | separator.setPreferredSize(new Dimension(1, 1)); | ||
1840 | 250 | return separator; | ||
1841 | 251 | } else { | ||
1842 | 252 | return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); | ||
1843 | 253 | } | ||
1844 | 254 | } | ||
1845 | 255 | |||
1846 | 256 | class DashBorder implements Border { | ||
1847 | 257 | private final Insets insets = new Insets(1, 1, 1, 1); | ||
1848 | 258 | private final int length = 5; | ||
1849 | 259 | private final int space = 3; | ||
1850 | 260 | public boolean isBorderOpaque() { | ||
1851 | 261 | return false; | ||
1852 | 262 | } | ||
1853 | 263 | public void paintBorder(Component c, Graphics g, int x, int y, | ||
1854 | 264 | int width, int height) { | ||
1855 | 265 | g.setColor(Color.BLACK); | ||
1856 | 266 | // --- draw horizontal --- | ||
1857 | 267 | for (int i = 0; i < width; i += length) { | ||
1858 | 268 | g.drawLine(i, y, i + length, y); | ||
1859 | 269 | g.drawLine(i, height - 1, i + length, height - 1); | ||
1860 | 270 | i += space; | ||
1861 | 271 | } | ||
1862 | 272 | // --- draw vertical --- | ||
1863 | 273 | for (int i = 0; i < height; i += length) { | ||
1864 | 274 | g.drawLine(0, i, 0, i + length); | ||
1865 | 275 | g.drawLine(width - 1, i, width - 1, i + length); | ||
1866 | 276 | i += space; | ||
1867 | 277 | } | ||
1868 | 278 | } | ||
1869 | 279 | public Insets getBorderInsets(Component c) { | ||
1870 | 280 | return insets; | ||
1871 | 281 | } | ||
1872 | 282 | } | ||
1873 | 283 | } | ||
1874 | 284 | |||
1875 | 285 | public int getNumberOfTransitions() { | 211 | public int getNumberOfTransitions() { |
1876 | 286 | return transitions.size(); | 212 | return transitions.size(); |
1877 | 287 | } | 213 | } |
1878 | 288 | 214 | ||
1879 | === modified file 'src/dk/aau/cs/gui/components/NonsearchableJList.java' | |||
1880 | --- src/dk/aau/cs/gui/components/NonsearchableJList.java 2020-04-18 12:27:02 +0000 | |||
1881 | +++ src/dk/aau/cs/gui/components/NonsearchableJList.java 2020-07-09 12:55:48 +0000 | |||
1882 | @@ -19,7 +19,7 @@ | |||
1883 | 19 | removeKeyListener(); | 19 | removeKeyListener(); |
1884 | 20 | } | 20 | } |
1885 | 21 | 21 | ||
1887 | 22 | public NonsearchableJList(ListModel dataModel){ | 22 | public NonsearchableJList(ListModel<E> dataModel){ |
1888 | 23 | super (dataModel); | 23 | super (dataModel); |
1889 | 24 | removeKeyListener(); | 24 | removeKeyListener(); |
1890 | 25 | } | 25 | } |
1891 | 26 | 26 | ||
1892 | === modified file 'src/dk/aau/cs/gui/components/TransitionFireingComponent.java' | |||
1893 | --- src/dk/aau/cs/gui/components/TransitionFireingComponent.java 2020-05-18 14:10:47 +0000 | |||
1894 | +++ src/dk/aau/cs/gui/components/TransitionFireingComponent.java 2020-07-09 12:55:48 +0000 | |||
1895 | @@ -28,14 +28,19 @@ | |||
1896 | 28 | 28 | ||
1897 | 29 | enabledTransitionsList = new EnabledTransitionsList(); | 29 | enabledTransitionsList = new EnabledTransitionsList(); |
1898 | 30 | 30 | ||
1900 | 31 | this.setBorder(BorderFactory.createCompoundBorder( | 31 | this.setBorder( |
1901 | 32 | BorderFactory.createCompoundBorder( | ||
1902 | 32 | BorderFactory.createTitledBorder("Enabled Transitions"), | 33 | BorderFactory.createTitledBorder("Enabled Transitions"), |
1907 | 33 | BorderFactory.createEmptyBorder(3, 3, 3, 3))); | 34 | BorderFactory.createEmptyBorder(3, 3, 3, 3) |
1908 | 34 | this | 35 | ) |
1909 | 35 | .setToolTipText("List of currently enabled transitions (double click a transition to fire it)"); | 36 | ); |
1910 | 36 | enabledTransitionsList.setPreferredSize(new Dimension( | 37 | this.setToolTipText("List of currently enabled transitions (double click a transition to fire it)"); |
1911 | 38 | enabledTransitionsList.setPreferredSize( | ||
1912 | 39 | new Dimension( | ||
1913 | 37 | enabledTransitionsList.getPreferredSize().width, | 40 | enabledTransitionsList.getPreferredSize().width, |
1915 | 38 | enabledTransitionsList.getMinimumSize().height)); | 41 | enabledTransitionsList.getMinimumSize().height |
1916 | 42 | ) | ||
1917 | 43 | ); | ||
1918 | 39 | 44 | ||
1919 | 40 | settingsButton = new JButton("Settings"); | 45 | settingsButton = new JButton("Settings"); |
1920 | 41 | settingsButton.setPreferredSize(new Dimension(0, settingsButton.getPreferredSize().height)); //Make the two buttons equal in size | 46 | settingsButton.setPreferredSize(new Dimension(0, settingsButton.getPreferredSize().height)); //Make the two buttons equal in size |
1921 | @@ -50,6 +55,7 @@ | |||
1922 | 50 | fireSelectedTransition(); | 55 | fireSelectedTransition(); |
1923 | 51 | } | 56 | } |
1924 | 52 | }); | 57 | }); |
1925 | 58 | |||
1926 | 53 | fireButton.addKeyListener(new KeyAdapter() { | 59 | fireButton.addKeyListener(new KeyAdapter() { |
1927 | 54 | @Override | 60 | @Override |
1928 | 55 | public void keyPressed(KeyEvent e) { | 61 | public void keyPressed(KeyEvent e) { |
1929 | 56 | 62 | ||
1930 | === modified file 'src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java' | |||
1931 | --- src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java 2020-05-23 12:57:37 +0000 | |||
1932 | +++ src/dk/aau/cs/gui/smartDraw/SmartDrawWorker.java 2020-07-09 12:55:48 +0000 | |||
1933 | @@ -2,7 +2,6 @@ | |||
1934 | 2 | 2 | ||
1935 | 3 | import java.awt.Point; | 3 | import java.awt.Point; |
1936 | 4 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
1937 | 5 | import java.util.Iterator; | ||
1938 | 6 | import java.util.List; | 5 | import java.util.List; |
1939 | 7 | import java.util.Random; | 6 | import java.util.Random; |
1940 | 8 | 7 | ||
1941 | @@ -199,19 +198,16 @@ | |||
1942 | 199 | } | 198 | } |
1943 | 200 | } | 199 | } |
1944 | 201 | 200 | ||
1946 | 202 | private ArrayList<Arc> getAllArcsFromObject(PlaceTransitionObject object) { | 201 | private ArrayList<Arc> getAllArcsFromObject(PlaceTransitionObject pno) { |
1947 | 203 | ArrayList<Arc> arcsForObject = new ArrayList<Arc>(); | 202 | ArrayList<Arc> arcsForObject = new ArrayList<Arc>(); |
1959 | 204 | Iterator<Arc> fromIterator = object.getConnectFromIterator(); | 203 | |
1960 | 205 | Iterator<Arc> toIterator = object.getConnectToIterator(); | 204 | for (Arc a : pno.getPreset()) { |
1961 | 206 | Arc arc; | 205 | arcsForObject.add(a); |
1962 | 207 | while(fromIterator.hasNext()) { | 206 | } |
1963 | 208 | arc = fromIterator.next(); | 207 | for (Arc a : pno.getPostset()) { |
1964 | 209 | arcsForObject.add(arc); | 208 | arcsForObject.add(a); |
1965 | 210 | } | 209 | } |
1966 | 211 | while(toIterator.hasNext()) { | 210 | |
1956 | 212 | arc = toIterator.next(); | ||
1957 | 213 | arcsForObject.add(arc); | ||
1958 | 214 | } | ||
1967 | 215 | return arcsForObject; | 211 | return arcsForObject; |
1968 | 216 | } | 212 | } |
1969 | 217 | private void moveObject(PlaceTransitionObject object, Point point) { | 213 | private void moveObject(PlaceTransitionObject object, Point point) { |
1970 | 218 | 214 | ||
1971 | === modified file 'src/dk/aau/cs/gui/undo/TimedPlaceMarkingEdit.java' | |||
1972 | --- src/dk/aau/cs/gui/undo/TimedPlaceMarkingEdit.java 2011-09-23 21:23:31 +0000 | |||
1973 | +++ src/dk/aau/cs/gui/undo/TimedPlaceMarkingEdit.java 2020-07-09 12:55:48 +0000 | |||
1974 | @@ -4,7 +4,7 @@ | |||
1975 | 4 | 4 | ||
1976 | 5 | // TODO: Fix this to work on the model class instead of the GUI class | 5 | // TODO: Fix this to work on the model class instead of the GUI class |
1977 | 6 | public class TimedPlaceMarkingEdit extends Command { | 6 | public class TimedPlaceMarkingEdit extends Command { |
1979 | 7 | private int numberOfTokens; | 7 | private final int numberOfTokens; |
1980 | 8 | private final TimedPlaceComponent timedPlaceComponent; | 8 | private final TimedPlaceComponent timedPlaceComponent; |
1981 | 9 | 9 | ||
1982 | 10 | public TimedPlaceMarkingEdit(TimedPlaceComponent tpc, int numberOfTokens) { | 10 | public TimedPlaceMarkingEdit(TimedPlaceComponent tpc, int numberOfTokens) { |
1983 | @@ -15,9 +15,9 @@ | |||
1984 | 15 | @Override | 15 | @Override |
1985 | 16 | public void redo() { | 16 | public void redo() { |
1986 | 17 | if (numberOfTokens > 0) { | 17 | if (numberOfTokens > 0) { |
1988 | 18 | timedPlaceComponent.addTokens(Math.abs(numberOfTokens)); | 18 | timedPlaceComponent.underlyingPlace().addTokens(Math.abs(numberOfTokens)); |
1989 | 19 | } else { | 19 | } else { |
1991 | 20 | timedPlaceComponent.removeTokens(Math.abs(numberOfTokens)); | 20 | timedPlaceComponent.underlyingPlace().removeTokens(Math.abs(numberOfTokens)); |
1992 | 21 | } | 21 | } |
1993 | 22 | timedPlaceComponent.repaint(); | 22 | timedPlaceComponent.repaint(); |
1994 | 23 | } | 23 | } |
1995 | @@ -25,9 +25,9 @@ | |||
1996 | 25 | @Override | 25 | @Override |
1997 | 26 | public void undo() { | 26 | public void undo() { |
1998 | 27 | if (numberOfTokens > 0) { | 27 | if (numberOfTokens > 0) { |
2000 | 28 | timedPlaceComponent.removeTokens(Math.abs(numberOfTokens)); | 28 | timedPlaceComponent.underlyingPlace().removeTokens(Math.abs(numberOfTokens)); |
2001 | 29 | } else { | 29 | } else { |
2003 | 30 | timedPlaceComponent.addTokens(Math.abs(numberOfTokens)); | 30 | timedPlaceComponent.underlyingPlace().addTokens(Math.abs(numberOfTokens)); |
2004 | 31 | } | 31 | } |
2005 | 32 | timedPlaceComponent.repaint(); | 32 | timedPlaceComponent.repaint(); |
2006 | 33 | } | 33 | } |
2007 | 34 | 34 | ||
2008 | === modified file 'src/dk/aau/cs/io/TapnXmlLoader.java' | |||
2009 | --- src/dk/aau/cs/io/TapnXmlLoader.java 2020-05-06 15:19:14 +0000 | |||
2010 | +++ src/dk/aau/cs/io/TapnXmlLoader.java 2020-07-09 12:55:48 +0000 | |||
2011 | @@ -162,10 +162,9 @@ | |||
2012 | 162 | } | 162 | } |
2013 | 163 | 163 | ||
2014 | 164 | SharedPlace place = new SharedPlace(name, invariant); | 164 | SharedPlace place = new SharedPlace(name, invariant); |
2015 | 165 | place.addTokens(numberOfTokens); | ||
2016 | 165 | place.setCurrentMarking(marking); | 166 | place.setCurrentMarking(marking); |
2020 | 166 | for(int j = 0; j < numberOfTokens; j++){ | 167 | |
2018 | 167 | marking.add(new TimedToken(place)); | ||
2019 | 168 | } | ||
2021 | 169 | return place; | 168 | return place; |
2022 | 170 | } | 169 | } |
2023 | 171 | 170 | ||
2024 | 172 | 171 | ||
2025 | === modified file 'src/dk/aau/cs/model/tapn/LocalTimedPlace.java' | |||
2026 | --- src/dk/aau/cs/model/tapn/LocalTimedPlace.java 2019-11-26 13:59:12 +0000 | |||
2027 | +++ src/dk/aau/cs/model/tapn/LocalTimedPlace.java 2020-07-09 12:55:48 +0000 | |||
2028 | @@ -1,28 +1,12 @@ | |||
2029 | 1 | package dk.aau.cs.model.tapn; | 1 | package dk.aau.cs.model.tapn; |
2030 | 2 | 2 | ||
2031 | 3 | import java.util.ArrayList; | ||
2032 | 4 | import java.util.List; | ||
2033 | 5 | import java.util.regex.Pattern; | ||
2034 | 6 | |||
2035 | 7 | import dk.aau.cs.model.tapn.TimedPlace.PlaceType; | ||
2036 | 8 | import dk.aau.cs.model.tapn.event.TimedPlaceEvent; | ||
2037 | 9 | import dk.aau.cs.model.tapn.event.TimedPlaceListener; | ||
2038 | 10 | import dk.aau.cs.util.Require; | ||
2039 | 11 | import dk.aau.cs.util.Tuple; | 3 | import dk.aau.cs.util.Tuple; |
2040 | 12 | 4 | ||
2041 | 13 | public class LocalTimedPlace extends TimedPlace { | 5 | public class LocalTimedPlace extends TimedPlace { |
2042 | 14 | private static final Pattern namePattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); | ||
2043 | 15 | |||
2044 | 16 | private String name; | ||
2045 | 17 | private TimeInvariant invariant; | ||
2046 | 18 | 6 | ||
2047 | 19 | private TimedArcPetriNet model; | 7 | private TimedArcPetriNet model; |
2048 | 20 | private TimedMarking currentMarking; | ||
2049 | 21 | private List<TimedPlaceListener> listeners = new ArrayList<TimedPlaceListener>(); | ||
2050 | 22 | |||
2051 | 23 | private Tuple<PlaceType, Integer> extrapolation = new Tuple<TimedPlace.PlaceType, Integer>(PlaceType.Dead, -2); | ||
2052 | 24 | 8 | ||
2054 | 25 | public LocalTimedPlace(String name) { | 9 | public LocalTimedPlace(String name) { |
2055 | 26 | this(name, TimeInvariant.LESS_THAN_INFINITY); | 10 | this(name, TimeInvariant.LESS_THAN_INFINITY); |
2056 | 27 | } | 11 | } |
2057 | 28 | 12 | ||
2058 | @@ -39,111 +23,10 @@ | |||
2059 | 39 | this.model = model; | 23 | this.model = model; |
2060 | 40 | } | 24 | } |
2061 | 41 | 25 | ||
2062 | 42 | public void addTimedPlaceListener(TimedPlaceListener listener){ | ||
2063 | 43 | Require.that(listener != null, "Listener cannot be null"); | ||
2064 | 44 | listeners.add(listener); | ||
2065 | 45 | } | ||
2066 | 46 | |||
2067 | 47 | public void removeTimedPlaceListener(TimedPlaceListener listener){ | ||
2068 | 48 | Require.that(listener != null, "Listener cannot be null"); | ||
2069 | 49 | listeners.remove(listener); | ||
2070 | 50 | } | ||
2071 | 51 | |||
2072 | 52 | public boolean isShared() { | 26 | public boolean isShared() { |
2073 | 53 | return false; | 27 | return false; |
2074 | 54 | } | 28 | } |
2075 | 55 | 29 | ||
2076 | 56 | public void setCurrentMarking(TimedMarking marking) { | ||
2077 | 57 | Require.that(marking != null, "marking cannot be null"); | ||
2078 | 58 | currentMarking = marking; | ||
2079 | 59 | fireMarkingChanged(); | ||
2080 | 60 | } | ||
2081 | 61 | |||
2082 | 62 | public String name() { | ||
2083 | 63 | return name; | ||
2084 | 64 | } | ||
2085 | 65 | |||
2086 | 66 | public void setName(String newName) { | ||
2087 | 67 | Require.that(newName != null && !newName.isEmpty(), "A timed place must have a name"); | ||
2088 | 68 | Require.that(isValid(newName) && !newName.toLowerCase().equals("true") && !newName.toLowerCase().equals("false"), "The specified name must conform to the pattern [a-zA-Z_][a-zA-Z0-9_]*"); | ||
2089 | 69 | this.name = newName; | ||
2090 | 70 | fireNameChanged(); | ||
2091 | 71 | } | ||
2092 | 72 | |||
2093 | 73 | private void fireNameChanged() { | ||
2094 | 74 | for(TimedPlaceListener listener : listeners){ | ||
2095 | 75 | listener.nameChanged(new TimedPlaceEvent(this)); | ||
2096 | 76 | } | ||
2097 | 77 | } | ||
2098 | 78 | |||
2099 | 79 | private void fireInvariantChanged(){ | ||
2100 | 80 | for(TimedPlaceListener listener : listeners){ | ||
2101 | 81 | listener.invariantChanged(new TimedPlaceEvent(this)); | ||
2102 | 82 | } | ||
2103 | 83 | } | ||
2104 | 84 | |||
2105 | 85 | private void fireMarkingChanged(){ | ||
2106 | 86 | for(TimedPlaceListener listener : listeners){ | ||
2107 | 87 | listener.markingChanged(new TimedPlaceEvent(this)); | ||
2108 | 88 | } | ||
2109 | 89 | } | ||
2110 | 90 | |||
2111 | 91 | private boolean isValid(String newName) { | ||
2112 | 92 | return namePattern.matcher(newName).matches(); | ||
2113 | 93 | } | ||
2114 | 94 | |||
2115 | 95 | public TimeInvariant invariant() { | ||
2116 | 96 | return invariant; | ||
2117 | 97 | } | ||
2118 | 98 | |||
2119 | 99 | public void setInvariant(TimeInvariant invariant) { | ||
2120 | 100 | Require.that(invariant != null, "A timed place must have a non-null invariant"); | ||
2121 | 101 | this.invariant = invariant; | ||
2122 | 102 | fireInvariantChanged(); | ||
2123 | 103 | } | ||
2124 | 104 | |||
2125 | 105 | public List<TimedToken> tokens() { | ||
2126 | 106 | return currentMarking.getTokensFor(this); | ||
2127 | 107 | } | ||
2128 | 108 | |||
2129 | 109 | public int numberOfTokens() { | ||
2130 | 110 | return tokens().size(); | ||
2131 | 111 | } | ||
2132 | 112 | |||
2133 | 113 | @Override | ||
2134 | 114 | public void addToken(TimedToken timedToken) { | ||
2135 | 115 | Require.that(timedToken != null, "timedToken cannot be null"); | ||
2136 | 116 | Require.that(timedToken.place().equals(this), "token is located in a different place"); | ||
2137 | 117 | |||
2138 | 118 | currentMarking.add(timedToken); | ||
2139 | 119 | fireMarkingChanged(); | ||
2140 | 120 | } | ||
2141 | 121 | |||
2142 | 122 | @Override | ||
2143 | 123 | public void addTokens(Iterable<TimedToken> tokens) { | ||
2144 | 124 | Require.that(tokens != null, "tokens cannot be null"); | ||
2145 | 125 | |||
2146 | 126 | for(TimedToken token : tokens){ | ||
2147 | 127 | currentMarking.add(token); // avoid firing marking changed on every add | ||
2148 | 128 | } | ||
2149 | 129 | fireMarkingChanged(); | ||
2150 | 130 | } | ||
2151 | 131 | |||
2152 | 132 | @Override | ||
2153 | 133 | public void removeToken(TimedToken timedToken) { | ||
2154 | 134 | Require.that(timedToken != null, "timedToken cannot be null"); | ||
2155 | 135 | currentMarking.remove(timedToken); | ||
2156 | 136 | fireMarkingChanged(); | ||
2157 | 137 | } | ||
2158 | 138 | |||
2159 | 139 | @Override | ||
2160 | 140 | public void removeToken() { | ||
2161 | 141 | if (numberOfTokens() > 0) { | ||
2162 | 142 | currentMarking.remove(tokens().get(0)); | ||
2163 | 143 | fireMarkingChanged(); | ||
2164 | 144 | } | ||
2165 | 145 | } | ||
2166 | 146 | |||
2167 | 147 | public LocalTimedPlace copy() { | 30 | public LocalTimedPlace copy() { |
2168 | 148 | LocalTimedPlace p = new LocalTimedPlace(name); | 31 | LocalTimedPlace p = new LocalTimedPlace(name); |
2169 | 149 | 32 | ||
2170 | 150 | 33 | ||
2171 | === modified file 'src/dk/aau/cs/model/tapn/NetworkMarking.java' | |||
2172 | --- src/dk/aau/cs/model/tapn/NetworkMarking.java 2020-05-23 13:29:16 +0000 | |||
2173 | +++ src/dk/aau/cs/model/tapn/NetworkMarking.java 2020-07-09 12:55:48 +0000 | |||
2174 | @@ -14,8 +14,8 @@ | |||
2175 | 14 | import dk.aau.cs.util.Tuple; | 14 | import dk.aau.cs.util.Tuple; |
2176 | 15 | 15 | ||
2177 | 16 | public class NetworkMarking implements TimedMarking { | 16 | public class NetworkMarking implements TimedMarking { |
2180 | 17 | private HashMap<TimedArcPetriNet, LocalTimedMarking> markings = new HashMap<TimedArcPetriNet, LocalTimedMarking>(); | 17 | private final HashMap<TimedArcPetriNet, LocalTimedMarking> markings = new HashMap<TimedArcPetriNet, LocalTimedMarking>(); |
2181 | 18 | private HashMap<TimedPlace, List<TimedToken>> sharedPlacesTokens = new HashMap<TimedPlace, List<TimedToken>>(); | 18 | private final HashMap<TimedPlace, List<TimedToken>> sharedPlacesTokens = new HashMap<TimedPlace, List<TimedToken>>(); |
2182 | 19 | 19 | ||
2183 | 20 | public NetworkMarking() { | 20 | public NetworkMarking() { |
2184 | 21 | } | 21 | } |
2185 | @@ -130,8 +130,9 @@ | |||
2186 | 130 | private Tuple<NetworkMarking, List<TimedToken>> fireSharedTransition(SharedTransition sharedTransition, FiringMode firingMode) { | 130 | private Tuple<NetworkMarking, List<TimedToken>> fireSharedTransition(SharedTransition sharedTransition, FiringMode firingMode) { |
2187 | 131 | // validity of arguments already checked above | 131 | // validity of arguments already checked above |
2188 | 132 | NetworkMarking clone = clone(); | 132 | NetworkMarking clone = clone(); |
2191 | 133 | Tuple<LocalTimedMarking, List<TimedToken>> ltm; | 133 | Tuple<LocalTimedMarking, List<TimedToken>> ltm; |
2192 | 134 | List<TimedToken> consumedTokens = new ArrayList<TimedToken>(); | 134 | List<TimedToken> consumedTokens = new ArrayList<TimedToken>(); |
2193 | 135 | |||
2194 | 135 | for(TimedTransition transition : sharedTransition.transitions()){ | 136 | for(TimedTransition transition : sharedTransition.transitions()){ |
2195 | 136 | if(transition.model().isActive()) { | 137 | if(transition.model().isActive()) { |
2196 | 137 | ltm = clone.getMarkingFor(transition.model()).fireTransition(transition, firingMode); | 138 | ltm = clone.getMarkingFor(transition.model()).fireTransition(transition, firingMode); |
2197 | 138 | 139 | ||
2198 | === modified file 'src/dk/aau/cs/model/tapn/SharedPlace.java' | |||
2199 | --- src/dk/aau/cs/model/tapn/SharedPlace.java 2020-06-03 18:20:30 +0000 | |||
2200 | +++ src/dk/aau/cs/model/tapn/SharedPlace.java 2020-07-09 12:55:48 +0000 | |||
2201 | @@ -1,30 +1,16 @@ | |||
2202 | 1 | package dk.aau.cs.model.tapn; | 1 | package dk.aau.cs.model.tapn; |
2203 | 2 | 2 | ||
2204 | 3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
2205 | 4 | import java.util.List; | ||
2206 | 5 | import java.util.regex.Pattern; | ||
2207 | 6 | 4 | ||
2208 | 7 | import pipe.dataLayer.Template; | 5 | import pipe.dataLayer.Template; |
2209 | 8 | import pipe.gui.CreateGui; | 6 | import pipe.gui.CreateGui; |
2210 | 9 | import dk.aau.cs.model.tapn.event.TimedPlaceEvent; | ||
2211 | 10 | import dk.aau.cs.model.tapn.event.TimedPlaceListener; | ||
2212 | 11 | import dk.aau.cs.util.Require; | ||
2213 | 12 | import dk.aau.cs.util.Tuple; | 7 | import dk.aau.cs.util.Tuple; |
2214 | 13 | 8 | ||
2215 | 14 | public class SharedPlace extends TimedPlace{ | 9 | public class SharedPlace extends TimedPlace{ |
2229 | 15 | private static final Pattern namePattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); | 10 | |
2230 | 16 | 11 | private TimedArcPetriNetNetwork network; | |
2231 | 17 | private String name; | 12 | |
2232 | 18 | private List<TimedPlace> places = new ArrayList<TimedPlace>(); | 13 | public SharedPlace(String name){ |
2220 | 19 | private TimeInvariant invariant; | ||
2221 | 20 | |||
2222 | 21 | private TimedArcPetriNetNetwork network; | ||
2223 | 22 | private TimedMarking currentMarking; | ||
2224 | 23 | private Tuple<PlaceType, Integer> extrapolation = new Tuple<TimedPlace.PlaceType, Integer>(PlaceType.Dead, -2); | ||
2225 | 24 | |||
2226 | 25 | private List<TimedPlaceListener> listeners = new ArrayList<TimedPlaceListener>(); | ||
2227 | 26 | |||
2228 | 27 | public SharedPlace(String name){ | ||
2233 | 28 | this(name, TimeInvariant.LESS_THAN_INFINITY); | 14 | this(name, TimeInvariant.LESS_THAN_INFINITY); |
2234 | 29 | } | 15 | } |
2235 | 30 | 16 | ||
2236 | @@ -32,33 +18,8 @@ | |||
2237 | 32 | setName(name); | 18 | setName(name); |
2238 | 33 | setInvariant(invariant); | 19 | setInvariant(invariant); |
2239 | 34 | } | 20 | } |
2267 | 35 | 21 | ||
2268 | 36 | public String name() { | 22 | public void setNetwork(TimedArcPetriNetNetwork network) { |
2242 | 37 | return name; | ||
2243 | 38 | } | ||
2244 | 39 | |||
2245 | 40 | public void setName(String newName) { | ||
2246 | 41 | Require.that(newName != null && !newName.isEmpty(), "A timed transition must have a name"); | ||
2247 | 42 | Require.that(isValid(newName) && !newName.toLowerCase().equals("true") && !newName.toLowerCase().equals("false"), "The specified name must conform to the pattern [a-zA-Z_][a-zA-Z0-9_]*"); | ||
2248 | 43 | name = newName; | ||
2249 | 44 | fireNameChanged(); | ||
2250 | 45 | } | ||
2251 | 46 | |||
2252 | 47 | private boolean isValid(String newName) { | ||
2253 | 48 | return namePattern.matcher(newName).matches(); | ||
2254 | 49 | } | ||
2255 | 50 | |||
2256 | 51 | public TimeInvariant invariant(){ | ||
2257 | 52 | return invariant; | ||
2258 | 53 | } | ||
2259 | 54 | |||
2260 | 55 | public void setInvariant(TimeInvariant invariant) { | ||
2261 | 56 | Require.that(invariant != null, "invariant must not be null"); | ||
2262 | 57 | this.invariant = invariant; | ||
2263 | 58 | fireInvariantChanged(); | ||
2264 | 59 | } | ||
2265 | 60 | |||
2266 | 61 | public void setNetwork(TimedArcPetriNetNetwork network) { | ||
2269 | 62 | this.network = network; | 23 | this.network = network; |
2270 | 63 | } | 24 | } |
2271 | 64 | 25 | ||
2272 | @@ -66,15 +27,7 @@ | |||
2273 | 66 | return network; | 27 | return network; |
2274 | 67 | } | 28 | } |
2275 | 68 | 29 | ||
2276 | 69 | public void addTimedPlaceListener(TimedPlaceListener listener) { | ||
2277 | 70 | Require.that(listener != null, "Listener cannot be null"); | ||
2278 | 71 | listeners.add(listener); | ||
2279 | 72 | } | ||
2280 | 73 | 30 | ||
2281 | 74 | public void removeTimedPlaceListener(TimedPlaceListener listener) { | ||
2282 | 75 | Require.that(listener != null, "Listener cannot be null"); | ||
2283 | 76 | listeners.remove(listener); | ||
2284 | 77 | } | ||
2285 | 78 | 31 | ||
2286 | 79 | public TimedPlace copy() { | 32 | public TimedPlace copy() { |
2287 | 80 | return new SharedPlace(this.name(), this.invariant().copy()); | 33 | return new SharedPlace(this.name(), this.invariant().copy()); |
2288 | @@ -84,71 +37,6 @@ | |||
2289 | 84 | return true; | 37 | return true; |
2290 | 85 | } | 38 | } |
2291 | 86 | 39 | ||
2292 | 87 | public void setCurrentMarking(TimedMarking marking) { | ||
2293 | 88 | Require.that(marking != null, "marking cannot be null"); | ||
2294 | 89 | currentMarking = marking; | ||
2295 | 90 | fireMarkingChanged(); | ||
2296 | 91 | } | ||
2297 | 92 | |||
2298 | 93 | @Override | ||
2299 | 94 | public void addToken(TimedToken timedToken) { | ||
2300 | 95 | Require.that(timedToken != null, "timedToken cannot be null"); | ||
2301 | 96 | Require.that(timedToken.place().equals(this), "token is located in a different place"); | ||
2302 | 97 | |||
2303 | 98 | currentMarking.add(timedToken); | ||
2304 | 99 | fireMarkingChanged(); | ||
2305 | 100 | } | ||
2306 | 101 | |||
2307 | 102 | @Override | ||
2308 | 103 | public void addTokens(Iterable<TimedToken> tokens) { | ||
2309 | 104 | Require.that(tokens != null, "tokens cannot be null"); // TODO: maybe check that tokens are in this place? | ||
2310 | 105 | |||
2311 | 106 | for(TimedToken token : tokens){ | ||
2312 | 107 | currentMarking.add(token); // avoid firing marking changed on every add | ||
2313 | 108 | } | ||
2314 | 109 | fireMarkingChanged(); | ||
2315 | 110 | } | ||
2316 | 111 | |||
2317 | 112 | @Override | ||
2318 | 113 | public void removeToken(TimedToken timedToken) { | ||
2319 | 114 | Require.that(timedToken != null, "timedToken cannot be null"); | ||
2320 | 115 | currentMarking.remove(timedToken); | ||
2321 | 116 | fireMarkingChanged(); | ||
2322 | 117 | } | ||
2323 | 118 | |||
2324 | 119 | @Override | ||
2325 | 120 | public void removeToken() { | ||
2326 | 121 | if (numberOfTokens() > 0) { | ||
2327 | 122 | currentMarking.remove(tokens().get(0)); | ||
2328 | 123 | fireMarkingChanged(); | ||
2329 | 124 | } | ||
2330 | 125 | } | ||
2331 | 126 | |||
2332 | 127 | public List<TimedToken> tokens() { | ||
2333 | 128 | return currentMarking.getTokensFor(this); | ||
2334 | 129 | } | ||
2335 | 130 | |||
2336 | 131 | public int numberOfTokens() { | ||
2337 | 132 | return tokens().size(); | ||
2338 | 133 | } | ||
2339 | 134 | |||
2340 | 135 | private void fireMarkingChanged() { | ||
2341 | 136 | for(TimedPlaceListener listener : listeners){ | ||
2342 | 137 | listener.markingChanged(new TimedPlaceEvent(this)); | ||
2343 | 138 | } | ||
2344 | 139 | } | ||
2345 | 140 | |||
2346 | 141 | private void fireNameChanged() { | ||
2347 | 142 | for(TimedPlaceListener listener : listeners){ | ||
2348 | 143 | listener.nameChanged(new TimedPlaceEvent(this)); | ||
2349 | 144 | } | ||
2350 | 145 | } | ||
2351 | 146 | |||
2352 | 147 | private void fireInvariantChanged() { | ||
2353 | 148 | for(TimedPlaceListener listener : listeners){ | ||
2354 | 149 | listener.invariantChanged(new TimedPlaceEvent(this)); | ||
2355 | 150 | } | ||
2356 | 151 | } | ||
2357 | 152 | 40 | ||
2358 | 153 | public ArrayList<String> getComponentsUsingThisPlace(){ | 41 | public ArrayList<String> getComponentsUsingThisPlace(){ |
2359 | 154 | ArrayList<String> components = new ArrayList<String>(); | 42 | ArrayList<String> components = new ArrayList<String>(); |
2360 | @@ -214,8 +102,4 @@ | |||
2361 | 214 | 102 | ||
2362 | 215 | return new Tuple<TimedPlace.PlaceType, Integer>(type, cmax); | 103 | return new Tuple<TimedPlace.PlaceType, Integer>(type, cmax); |
2363 | 216 | } | 104 | } |
2364 | 217 | |||
2365 | 218 | public List<TimedPlace> getPlaces() { | ||
2366 | 219 | return places; | ||
2367 | 220 | } | ||
2368 | 221 | } | 105 | } |
2369 | 222 | 106 | ||
2370 | === modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNet.java' | |||
2371 | --- src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2020-06-03 12:16:19 +0000 | |||
2372 | +++ src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2020-07-09 12:55:48 +0000 | |||
2373 | @@ -18,18 +18,17 @@ | |||
2374 | 18 | //This is used when loading big nets as the checking of names is slow. | 18 | //This is used when loading big nets as the checking of names is slow. |
2375 | 19 | private boolean checkNames = true; | 19 | private boolean checkNames = true; |
2376 | 20 | 20 | ||
2383 | 21 | private List<TimedPlace> places = new ArrayList<TimedPlace>(); | 21 | private final List<TimedPlace> places = new ArrayList<TimedPlace>(); |
2384 | 22 | private List<TimedTransition> transitions = new ArrayList<TimedTransition>(); | 22 | private final List<TimedTransition> transitions = new ArrayList<TimedTransition>(); |
2385 | 23 | private List<TimedInputArc> inputArcs = new ArrayList<TimedInputArc>(); | 23 | private final List<TimedInputArc> inputArcs = new ArrayList<TimedInputArc>(); |
2386 | 24 | private List<TimedOutputArc> outputArcs = new ArrayList<TimedOutputArc>(); | 24 | private final List<TimedOutputArc> outputArcs = new ArrayList<TimedOutputArc>(); |
2387 | 25 | private List<TimedInhibitorArc> inhibitorArcs = new ArrayList<TimedInhibitorArc>(); | 25 | private final List<TimedInhibitorArc> inhibitorArcs = new ArrayList<TimedInhibitorArc>(); |
2388 | 26 | private List<TransportArc> transportArcs = new ArrayList<TransportArc>(); | 26 | private final List<TransportArc> transportArcs = new ArrayList<TransportArc>(); |
2389 | 27 | 27 | ||
2391 | 28 | private TimedMarking currentMarking; | 28 | private TimedMarking currentMarking = new LocalTimedMarking(); |
2392 | 29 | 29 | ||
2393 | 30 | public TimedArcPetriNet(String name) { | 30 | public TimedArcPetriNet(String name) { |
2394 | 31 | setName(name); | 31 | setName(name); |
2395 | 32 | setMarking(new LocalTimedMarking()); | ||
2396 | 33 | isActive = true; | 32 | isActive = true; |
2397 | 34 | } | 33 | } |
2398 | 35 | 34 | ||
2399 | @@ -127,11 +126,7 @@ | |||
2400 | 127 | currentMarking.add(token); | 126 | currentMarking.add(token); |
2401 | 128 | } | 127 | } |
2402 | 129 | 128 | ||
2408 | 130 | public void removeToken(TimedToken token) { | 129 | public void remove(TimedPlace place) { |
2404 | 131 | currentMarking.remove(token); | ||
2405 | 132 | } | ||
2406 | 133 | |||
2407 | 134 | public void remove(TimedPlace place) { | ||
2409 | 135 | boolean removed = places.remove(place); | 130 | boolean removed = places.remove(place); |
2410 | 136 | if (removed && !place.isShared()){ | 131 | if (removed && !place.isShared()){ |
2411 | 137 | currentMarking.removePlaceFromMarking(place); | 132 | currentMarking.removePlaceFromMarking(place); |
2412 | 138 | 133 | ||
2413 | === modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java' | |||
2414 | --- src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2019-03-22 13:57:03 +0000 | |||
2415 | +++ src/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java 2020-07-09 12:55:48 +0000 | |||
2416 | @@ -15,16 +15,16 @@ | |||
2417 | 15 | import dk.aau.cs.verification.TAPNComposer; | 15 | import dk.aau.cs.verification.TAPNComposer; |
2418 | 16 | 16 | ||
2419 | 17 | public class TimedArcPetriNetNetwork { | 17 | public class TimedArcPetriNetNetwork { |
2423 | 18 | private List<TimedArcPetriNet> tapns = new ArrayList<TimedArcPetriNet>(); | 18 | private final List<TimedArcPetriNet> tapns = new ArrayList<TimedArcPetriNet>(); |
2424 | 19 | private List<SharedPlace> sharedPlaces = new ArrayList<SharedPlace>(); | 19 | private final List<SharedPlace> sharedPlaces = new ArrayList<SharedPlace>(); |
2425 | 20 | private List<SharedTransition> sharedTransitions = new ArrayList<SharedTransition>(); | 20 | private final List<SharedTransition> sharedTransitions = new ArrayList<SharedTransition>(); |
2426 | 21 | 21 | ||
2429 | 22 | private NetworkMarking currentMarking; | 22 | private NetworkMarking currentMarking = new NetworkMarking(); |
2430 | 23 | private ConstantStore constants; | 23 | private final ConstantStore constants; |
2431 | 24 | 24 | ||
2432 | 25 | private int defaultBound = 3; | 25 | private int defaultBound = 3; |
2433 | 26 | 26 | ||
2435 | 27 | private List<ConstantsListener> constantsListeners = new ArrayList<ConstantsListener>(); | 27 | private final List<ConstantsListener> constantsListeners = new ArrayList<ConstantsListener>(); |
2436 | 28 | 28 | ||
2437 | 29 | private boolean paintNet = true; | 29 | private boolean paintNet = true; |
2438 | 30 | 30 | ||
2439 | @@ -34,8 +34,7 @@ | |||
2440 | 34 | 34 | ||
2441 | 35 | public TimedArcPetriNetNetwork(ConstantStore constants){ | 35 | public TimedArcPetriNetNetwork(ConstantStore constants){ |
2442 | 36 | this.constants = constants; | 36 | this.constants = constants; |
2445 | 37 | currentMarking = new NetworkMarking(); | 37 | buildConstraints(); |
2444 | 38 | buildConstraints(); | ||
2446 | 39 | } | 38 | } |
2447 | 40 | 39 | ||
2448 | 41 | public void addConstantsListener(ConstantsListener listener){ | 40 | public void addConstantsListener(ConstantsListener listener){ |
2449 | 42 | 41 | ||
2450 | === modified file 'src/dk/aau/cs/model/tapn/TimedInhibitorArc.java' | |||
2451 | --- src/dk/aau/cs/model/tapn/TimedInhibitorArc.java 2012-09-19 18:15:59 +0000 | |||
2452 | +++ src/dk/aau/cs/model/tapn/TimedInhibitorArc.java 2020-07-09 12:55:48 +0000 | |||
2453 | @@ -14,8 +14,12 @@ | |||
2454 | 14 | public TimedInhibitorArc(TimedPlace source, TimedTransition destination, TimeInterval interval, Weight weight) { | 14 | public TimedInhibitorArc(TimedPlace source, TimedTransition destination, TimeInterval interval, Weight weight) { |
2455 | 15 | super(source, destination, TimeInterval.ZERO_INF, weight); | 15 | super(source, destination, TimeInterval.ZERO_INF, weight); |
2456 | 16 | } | 16 | } |
2459 | 17 | 17 | ||
2460 | 18 | public List<TimeInterval> getDEnabledInterval(){ | 18 | public TimedInhibitorArc(TimedPlace source, TimedTransition destination) { |
2461 | 19 | this(source, destination, TimeInterval.ZERO_INF, new IntWeight(1)); | ||
2462 | 20 | } | ||
2463 | 21 | |||
2464 | 22 | public List<TimeInterval> getDEnabledInterval(){ | ||
2465 | 19 | if(source().tokens().size() < getWeight().value()){ | 23 | if(source().tokens().size() < getWeight().value()){ |
2466 | 20 | return Arrays.asList(new TimeInterval(true, new RatBound(BigDecimal.ZERO), Bound.Infinity, false)); | 24 | return Arrays.asList(new TimeInterval(true, new RatBound(BigDecimal.ZERO), Bound.Infinity, false)); |
2467 | 21 | } else { | 25 | } else { |
2468 | 22 | 26 | ||
2469 | === modified file 'src/dk/aau/cs/model/tapn/TimedPlace.java' | |||
2470 | --- src/dk/aau/cs/model/tapn/TimedPlace.java 2020-06-03 12:16:19 +0000 | |||
2471 | +++ src/dk/aau/cs/model/tapn/TimedPlace.java 2020-07-09 12:55:48 +0000 | |||
2472 | @@ -1,13 +1,24 @@ | |||
2473 | 1 | package dk.aau.cs.model.tapn; | 1 | package dk.aau.cs.model.tapn; |
2474 | 2 | 2 | ||
2475 | 3 | import java.math.BigDecimal; | ||
2476 | 3 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
2477 | 4 | import java.util.List; | 5 | import java.util.List; |
2478 | 6 | import java.util.regex.Pattern; | ||
2479 | 5 | 7 | ||
2480 | 8 | import dk.aau.cs.model.tapn.event.TimedPlaceEvent; | ||
2481 | 6 | import dk.aau.cs.model.tapn.event.TimedPlaceListener; | 9 | import dk.aau.cs.model.tapn.event.TimedPlaceListener; |
2482 | 7 | import dk.aau.cs.util.Require; | 10 | import dk.aau.cs.util.Require; |
2483 | 8 | import dk.aau.cs.util.Tuple; | 11 | import dk.aau.cs.util.Tuple; |
2484 | 9 | 12 | ||
2485 | 10 | public abstract class TimedPlace { | 13 | public abstract class TimedPlace { |
2486 | 14 | |||
2487 | 15 | protected static final Pattern namePattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); | ||
2488 | 16 | protected final List<TimedPlaceListener> listeners = new ArrayList<TimedPlaceListener>(); | ||
2489 | 17 | protected Tuple<PlaceType, Integer> extrapolation = new Tuple<PlaceType, Integer>(PlaceType.Dead, -2); | ||
2490 | 18 | protected String name; | ||
2491 | 19 | protected TimeInvariant invariant; | ||
2492 | 20 | protected TimedMarking currentMarking; | ||
2493 | 21 | |||
2494 | 11 | private SharedPlace sharedPlace; | 22 | private SharedPlace sharedPlace; |
2495 | 12 | private List<TimedOutputArc> postset = new ArrayList<TimedOutputArc>(); | 23 | private List<TimedOutputArc> postset = new ArrayList<TimedOutputArc>(); |
2496 | 13 | private List<TimedInputArc> preset = new ArrayList<TimedInputArc>(); | 24 | private List<TimedInputArc> preset = new ArrayList<TimedInputArc>(); |
2497 | @@ -17,28 +28,67 @@ | |||
2498 | 17 | public enum PlaceType{ | 28 | public enum PlaceType{ |
2499 | 18 | Standard, Invariant, Dead | 29 | Standard, Invariant, Dead |
2500 | 19 | } | 30 | } |
2501 | 20 | |||
2502 | 21 | public abstract void addTimedPlaceListener(TimedPlaceListener listener); | ||
2503 | 22 | public abstract void removeTimedPlaceListener(TimedPlaceListener listener); | ||
2504 | 23 | 31 | ||
2505 | 24 | public abstract boolean isShared(); | 32 | public abstract boolean isShared(); |
2506 | 25 | 33 | ||
2523 | 26 | public abstract String name(); | 34 | public String name() { |
2524 | 27 | public abstract void setName(String newName); | 35 | return name; |
2525 | 28 | 36 | } | |
2526 | 29 | public abstract TimeInvariant invariant(); | 37 | |
2527 | 30 | public abstract void setInvariant(TimeInvariant invariant); | 38 | public void setName(String newName) { |
2528 | 31 | 39 | Require.that(newName != null && !newName.isEmpty(), "A timed place must have a name"); | |
2529 | 32 | public abstract List<TimedToken> tokens(); | 40 | Require.that(isValid(newName) && !newName.toLowerCase().equals("true") && !newName.toLowerCase().equals("false"), "The specified name must conform to the pattern [a-zA-Z_][a-zA-Z0-9_]*"); |
2530 | 33 | public abstract int numberOfTokens(); | 41 | this.name = newName; |
2531 | 34 | 42 | fireNameChanged(); | |
2532 | 35 | public abstract void setCurrentMarking(TimedMarking marking); | 43 | } |
2533 | 36 | 44 | ||
2534 | 37 | public abstract void addToken(TimedToken timedToken); | 45 | public TimeInvariant invariant(){ |
2535 | 38 | public abstract void addTokens(Iterable<TimedToken> tokens); | 46 | return invariant; |
2536 | 39 | 47 | } | |
2537 | 40 | public abstract void removeToken(TimedToken timedToken); | 48 | |
2538 | 41 | public abstract void removeToken(); | 49 | public List<TimedToken> tokens() { |
2539 | 50 | return currentMarking.getTokensFor(this); | ||
2540 | 51 | } | ||
2541 | 52 | |||
2542 | 53 | public int numberOfTokens() { | ||
2543 | 54 | return tokens().size(); | ||
2544 | 55 | } | ||
2545 | 56 | |||
2546 | 57 | public void addToken(TimedToken timedToken) { | ||
2547 | 58 | Require.that(timedToken != null, "timedToken cannot be null"); | ||
2548 | 59 | Require.that(timedToken.place().equals(this), "token is located in a different place"); | ||
2549 | 60 | |||
2550 | 61 | currentMarking.add(timedToken); | ||
2551 | 62 | fireMarkingChanged(); | ||
2552 | 63 | } | ||
2553 | 64 | |||
2554 | 65 | public void addTokens(Iterable<TimedToken> tokens) { | ||
2555 | 66 | Require.that(tokens != null, "tokens cannot be null"); | ||
2556 | 67 | |||
2557 | 68 | for(TimedToken token : tokens){ | ||
2558 | 69 | currentMarking.add(token); // avoid firing marking changed on every add | ||
2559 | 70 | } | ||
2560 | 71 | fireMarkingChanged(); | ||
2561 | 72 | } | ||
2562 | 73 | |||
2563 | 74 | public void addTokens(int numberOfTokensToAdd) { | ||
2564 | 75 | for (int i = 0; i < numberOfTokensToAdd; i++) { | ||
2565 | 76 | addToken(new TimedToken(this, BigDecimal.ZERO)); | ||
2566 | 77 | } | ||
2567 | 78 | } | ||
2568 | 79 | |||
2569 | 80 | public void removeTokens(int numberOfTokensToRemove) { | ||
2570 | 81 | for (int i = 0; i < numberOfTokensToRemove; i++) { | ||
2571 | 82 | removeToken(); | ||
2572 | 83 | } | ||
2573 | 84 | } | ||
2574 | 85 | |||
2575 | 86 | public void removeToken() { | ||
2576 | 87 | if (numberOfTokens() > 0) { | ||
2577 | 88 | currentMarking.remove(tokens().get(0)); | ||
2578 | 89 | fireMarkingChanged(); | ||
2579 | 90 | } | ||
2580 | 91 | } | ||
2581 | 42 | 92 | ||
2582 | 43 | public abstract Tuple<PlaceType, Integer> extrapolate(); | 93 | public abstract Tuple<PlaceType, Integer> extrapolate(); |
2583 | 44 | 94 | ||
2584 | @@ -65,6 +115,51 @@ | |||
2585 | 65 | return name() == other.name(); | 115 | return name() == other.name(); |
2586 | 66 | } | 116 | } |
2587 | 67 | 117 | ||
2588 | 118 | |||
2589 | 119 | protected void fireMarkingChanged() { | ||
2590 | 120 | for(TimedPlaceListener listener : listeners){ | ||
2591 | 121 | listener.markingChanged(new TimedPlaceEvent(this)); | ||
2592 | 122 | } | ||
2593 | 123 | } | ||
2594 | 124 | |||
2595 | 125 | protected void fireNameChanged() { | ||
2596 | 126 | for(TimedPlaceListener listener : listeners){ | ||
2597 | 127 | listener.nameChanged(new TimedPlaceEvent(this)); | ||
2598 | 128 | } | ||
2599 | 129 | } | ||
2600 | 130 | |||
2601 | 131 | protected void fireInvariantChanged() { | ||
2602 | 132 | for(TimedPlaceListener listener : listeners){ | ||
2603 | 133 | listener.invariantChanged(new TimedPlaceEvent(this)); | ||
2604 | 134 | } | ||
2605 | 135 | } | ||
2606 | 136 | |||
2607 | 137 | protected boolean isValid(String newName) { | ||
2608 | 138 | return namePattern.matcher(newName).matches(); | ||
2609 | 139 | } | ||
2610 | 140 | |||
2611 | 141 | public void setInvariant(TimeInvariant invariant) { | ||
2612 | 142 | Require.that(invariant != null, "invariant must not be null"); | ||
2613 | 143 | this.invariant = invariant; | ||
2614 | 144 | fireInvariantChanged(); | ||
2615 | 145 | } | ||
2616 | 146 | |||
2617 | 147 | public void addTimedPlaceListener(TimedPlaceListener listener) { | ||
2618 | 148 | Require.that(listener != null, "Listener cannot be null"); | ||
2619 | 149 | listeners.add(listener); | ||
2620 | 150 | } | ||
2621 | 151 | |||
2622 | 152 | public void removeTimedPlaceListener(TimedPlaceListener listener) { | ||
2623 | 153 | Require.that(listener != null, "Listener cannot be null"); | ||
2624 | 154 | listeners.remove(listener); | ||
2625 | 155 | } | ||
2626 | 156 | |||
2627 | 157 | public void setCurrentMarking(TimedMarking marking) { | ||
2628 | 158 | Require.that(marking != null, "marking cannot be null"); | ||
2629 | 159 | currentMarking = marking; | ||
2630 | 160 | fireMarkingChanged(); | ||
2631 | 161 | } | ||
2632 | 162 | |||
2633 | 68 | public boolean isOrphan() { | 163 | public boolean isOrphan() { |
2634 | 69 | return presetSize() == 0 && postsetSize() == 0; | 164 | return presetSize() == 0 && postsetSize() == 0; |
2635 | 70 | } | 165 | } |
2636 | @@ -112,16 +207,4 @@ | |||
2637 | 112 | return postset.size() + transportArcs.size() + inhibitorArcs.size(); | 207 | return postset.size() + transportArcs.size() + inhibitorArcs.size(); |
2638 | 113 | } | 208 | } |
2639 | 114 | 209 | ||
2640 | 115 | // public abstract void addInhibitorArc(TimedInhibitorArc arc); | ||
2641 | 116 | // public abstract void addToPreset(TransportArc arc); | ||
2642 | 117 | // public abstract void addToPreset(TimedOutputArc arc); | ||
2643 | 118 | // public abstract void addToPostset(TransportArc arc); | ||
2644 | 119 | // public abstract void addToPostset(TimedInputArc arc); | ||
2645 | 120 | // | ||
2646 | 121 | // public abstract void removeFromPostset(TimedInputArc arc); | ||
2647 | 122 | // public abstract void removeFromPostset(TransportArc arc); | ||
2648 | 123 | // public abstract void removeFromPreset(TransportArc arc); | ||
2649 | 124 | // public abstract void removeFromPreset(TimedOutputArc arc); | ||
2650 | 125 | // public abstract void removeInhibitorArc(TimedInhibitorArc arc); | ||
2651 | 126 | |||
2652 | 127 | } | 210 | } |
2653 | 128 | \ No newline at end of file | 211 | \ No newline at end of file |
2654 | 129 | 212 | ||
2655 | === modified file 'src/dk/aau/cs/model/tapn/TimedToken.java' | |||
2656 | --- src/dk/aau/cs/model/tapn/TimedToken.java 2019-03-23 07:51:29 +0000 | |||
2657 | +++ src/dk/aau/cs/model/tapn/TimedToken.java 2020-07-09 12:55:48 +0000 | |||
2658 | @@ -31,8 +31,7 @@ | |||
2659 | 31 | } | 31 | } |
2660 | 32 | 32 | ||
2661 | 33 | public TimedToken clone() { | 33 | public TimedToken clone() { |
2664 | 34 | return new TimedToken(place, age); // age is immutable so ok to pass it | 34 | return new TimedToken(place, age); // age is immutable so ok to pass it to constructor |
2663 | 35 | // to constructor | ||
2665 | 36 | } | 35 | } |
2666 | 37 | 36 | ||
2667 | 38 | public TimedToken delay(BigDecimal delay) { | 37 | public TimedToken delay(BigDecimal delay) { |
2668 | @@ -44,12 +43,7 @@ | |||
2669 | 44 | DecimalFormat df = new DecimalFormat(); | 43 | DecimalFormat df = new DecimalFormat(); |
2670 | 45 | df.setMaximumFractionDigits(Pipe.AGE_DECIMAL_PRECISION); | 44 | df.setMaximumFractionDigits(Pipe.AGE_DECIMAL_PRECISION); |
2671 | 46 | 45 | ||
2678 | 47 | StringBuilder buffer = new StringBuilder("("); | 46 | return String.format("(%s, %s)", place.toString(), df.format(age)); |
2673 | 48 | buffer.append(place.toString()); | ||
2674 | 49 | buffer.append(", "); | ||
2675 | 50 | buffer.append(df.format(age)); | ||
2676 | 51 | buffer.append(')'); | ||
2677 | 52 | return buffer.toString(); | ||
2679 | 53 | } | 47 | } |
2680 | 54 | 48 | ||
2681 | 55 | @Override | 49 | @Override |
2682 | 56 | 50 | ||
2683 | === modified file 'src/dk/aau/cs/model/tapn/TimedTransition.java' | |||
2684 | --- src/dk/aau/cs/model/tapn/TimedTransition.java 2020-06-18 20:57:07 +0000 | |||
2685 | +++ src/dk/aau/cs/model/tapn/TimedTransition.java 2020-07-09 12:55:48 +0000 | |||
2686 | @@ -17,16 +17,16 @@ | |||
2687 | 17 | private static final Pattern namePattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); | 17 | private static final Pattern namePattern = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); |
2688 | 18 | 18 | ||
2689 | 19 | private String name; | 19 | private String name; |
2694 | 20 | private List<TimedOutputArc> postset = new ArrayList<TimedOutputArc>(); | 20 | private final List<TimedOutputArc> postset = new ArrayList<TimedOutputArc>(); |
2695 | 21 | private List<TimedInputArc> preset = new ArrayList<TimedInputArc>(); | 21 | private final List<TimedInputArc> preset = new ArrayList<TimedInputArc>(); |
2696 | 22 | private List<TransportArc> transportArcsGoingThrough = new ArrayList<TransportArc>(); | 22 | private final List<TransportArc> transportArcsGoingThrough = new ArrayList<TransportArc>(); |
2697 | 23 | private List<TimedInhibitorArc> inhibitorArcs = new ArrayList<TimedInhibitorArc>(); | 23 | private final List<TimedInhibitorArc> inhibitorArcs = new ArrayList<TimedInhibitorArc>(); |
2698 | 24 | private TimeInterval dInterval = null; | 24 | private TimeInterval dInterval = null; |
2699 | 25 | private boolean isUrgent = false; | 25 | private boolean isUrgent = false; |
2700 | 26 | 26 | ||
2701 | 27 | private SharedTransition sharedTransition; | 27 | private SharedTransition sharedTransition; |
2702 | 28 | 28 | ||
2704 | 29 | private List<TimedTransitionListener> listeners = new ArrayList<TimedTransitionListener>(); | 29 | private final List<TimedTransitionListener> listeners = new ArrayList<TimedTransitionListener>(); |
2705 | 30 | 30 | ||
2706 | 31 | public TimedTransition(String name) { | 31 | public TimedTransition(String name) { |
2707 | 32 | this(name, false); | 32 | this(name, false); |
2708 | 33 | 33 | ||
2709 | === modified file 'src/dk/aau/cs/model/tapn/TransportArc.java' | |||
2710 | --- src/dk/aau/cs/model/tapn/TransportArc.java 2018-05-13 19:54:55 +0000 | |||
2711 | +++ src/dk/aau/cs/model/tapn/TransportArc.java 2020-07-09 12:55:48 +0000 | |||
2712 | @@ -36,8 +36,12 @@ | |||
2713 | 36 | setTimeInterval(interval); | 36 | setTimeInterval(interval); |
2714 | 37 | this.weight = weight; | 37 | this.weight = weight; |
2715 | 38 | } | 38 | } |
2718 | 39 | 39 | ||
2719 | 40 | public Weight getWeight(){ | 40 | public TransportArc(TimedPlace source, TimedTransition transitions, TimedPlace destination) { |
2720 | 41 | this(source, transitions, destination, TimeInterval.ZERO_INF); | ||
2721 | 42 | } | ||
2722 | 43 | |||
2723 | 44 | public Weight getWeight(){ | ||
2724 | 41 | return weight; | 45 | return weight; |
2725 | 42 | } | 46 | } |
2726 | 43 | 47 | ||
2727 | 44 | 48 | ||
2728 | === modified file 'src/net/tapaal/gui/DrawingSurfaceManager/AbstractDrawingSurfaceManager.java' | |||
2729 | --- src/net/tapaal/gui/DrawingSurfaceManager/AbstractDrawingSurfaceManager.java 2020-04-18 14:41:05 +0000 | |||
2730 | +++ src/net/tapaal/gui/DrawingSurfaceManager/AbstractDrawingSurfaceManager.java 2020-07-09 12:55:48 +0000 | |||
2731 | @@ -1,5 +1,7 @@ | |||
2732 | 1 | package net.tapaal.gui.DrawingSurfaceManager; | 1 | package net.tapaal.gui.DrawingSurfaceManager; |
2733 | 2 | 2 | ||
2734 | 3 | import pipe.gui.canvas.DrawingSurfaceImpl; | ||
2735 | 4 | import pipe.gui.graphicElements.GraphicalElement; | ||
2736 | 3 | import pipe.gui.graphicElements.PetriNetObject; | 5 | import pipe.gui.graphicElements.PetriNetObject; |
2737 | 4 | 6 | ||
2738 | 5 | import java.awt.event.MouseEvent; | 7 | import java.awt.event.MouseEvent; |
2739 | @@ -11,6 +13,8 @@ | |||
2740 | 11 | 13 | ||
2741 | 12 | public abstract class AbstractDrawingSurfaceManager { | 14 | public abstract class AbstractDrawingSurfaceManager { |
2742 | 13 | 15 | ||
2743 | 16 | protected DrawingSurfaceImpl canvas; | ||
2744 | 17 | |||
2745 | 14 | public void drawingSurfaceMouseClicked(MouseEvent e) {} | 18 | public void drawingSurfaceMouseClicked(MouseEvent e) {} |
2746 | 15 | public void drawingSurfaceMousePressed(MouseEvent e) {} | 19 | public void drawingSurfaceMousePressed(MouseEvent e) {} |
2747 | 16 | public void drawingSurfaceMouseReleased(MouseEvent e){} | 20 | public void drawingSurfaceMouseReleased(MouseEvent e){} |
2748 | @@ -20,6 +24,8 @@ | |||
2749 | 20 | 24 | ||
2750 | 21 | public enum MouseAction { | 25 | public enum MouseAction { |
2751 | 22 | clicked, | 26 | clicked, |
2752 | 27 | doubleClicked, | ||
2753 | 28 | rightClicked, | ||
2754 | 23 | pressed, | 29 | pressed, |
2755 | 24 | released, | 30 | released, |
2756 | 25 | dragged, | 31 | dragged, |
2757 | @@ -31,12 +37,12 @@ | |||
2758 | 31 | public static class DrawingSurfaceEvent { | 37 | public static class DrawingSurfaceEvent { |
2759 | 32 | 38 | ||
2760 | 33 | 39 | ||
2762 | 34 | public final PetriNetObject pno; | 40 | public final GraphicalElement pno; |
2763 | 35 | public final MouseEvent e; | 41 | public final MouseEvent e; |
2764 | 36 | public final MouseAction a; | 42 | public final MouseAction a; |
2765 | 37 | //Mouse Event type eg click mouse over etc | 43 | //Mouse Event type eg click mouse over etc |
2766 | 38 | 44 | ||
2768 | 39 | public DrawingSurfaceEvent(PetriNetObject pno, MouseEvent e, MouseAction a) { | 45 | public DrawingSurfaceEvent(GraphicalElement pno, MouseEvent e, MouseAction a) { |
2769 | 40 | this.pno = pno; | 46 | this.pno = pno; |
2770 | 41 | this.e = e; | 47 | this.e = e; |
2771 | 42 | this.a = a; | 48 | this.a = a; |
2772 | @@ -47,8 +53,12 @@ | |||
2773 | 47 | private final Map<Predicate<DrawingSurfaceEvent>, Consumer<DrawingSurfaceEvent>> filter = new LinkedHashMap<>(); | 53 | private final Map<Predicate<DrawingSurfaceEvent>, Consumer<DrawingSurfaceEvent>> filter = new LinkedHashMap<>(); |
2774 | 48 | private final AbstractDrawingSurfaceManager next = null; | 54 | private final AbstractDrawingSurfaceManager next = null; |
2775 | 49 | 55 | ||
2778 | 50 | public void registerManager(){} | 56 | public void registerManager(DrawingSurfaceImpl canvas){ |
2779 | 51 | public void deregisterManager(){} | 57 | this.canvas = canvas; |
2780 | 58 | } | ||
2781 | 59 | public void deregisterManager(){ | ||
2782 | 60 | this.canvas = null; | ||
2783 | 61 | } | ||
2784 | 52 | 62 | ||
2785 | 53 | public AbstractDrawingSurfaceManager() { | 63 | public AbstractDrawingSurfaceManager() { |
2786 | 54 | registerEvents(); | 64 | registerEvents(); |
2787 | 55 | 65 | ||
2788 | === added file 'src/net/tapaal/swinghelpers/DispatchEventsToParentHandler.java' | |||
2789 | --- src/net/tapaal/swinghelpers/DispatchEventsToParentHandler.java 1970-01-01 00:00:00 +0000 | |||
2790 | +++ src/net/tapaal/swinghelpers/DispatchEventsToParentHandler.java 2020-07-09 12:55:48 +0000 | |||
2791 | @@ -0,0 +1,58 @@ | |||
2792 | 1 | package net.tapaal.swinghelpers; | ||
2793 | 2 | |||
2794 | 3 | import javax.swing.*; | ||
2795 | 4 | import java.awt.*; | ||
2796 | 5 | import java.awt.event.*; | ||
2797 | 6 | |||
2798 | 7 | public final class DispatchEventsToParentHandler implements MouseListener, MouseWheelListener, MouseMotionListener { | ||
2799 | 8 | |||
2800 | 9 | private static void dispatchEventToParent(MouseEvent e) { | ||
2801 | 10 | if(e.getSource() instanceof Component) { | ||
2802 | 11 | Component c = ((Component) e.getSource()); | ||
2803 | 12 | if (c.getParent() != null) { | ||
2804 | 13 | SwingUtilities.convertPoint(c, e.getPoint(), c.getParent()); | ||
2805 | 14 | c.getParent().dispatchEvent(e); | ||
2806 | 15 | } | ||
2807 | 16 | } | ||
2808 | 17 | } | ||
2809 | 18 | |||
2810 | 19 | @Override | ||
2811 | 20 | public final void mouseClicked(MouseEvent e) { | ||
2812 | 21 | dispatchEventToParent(e); | ||
2813 | 22 | } | ||
2814 | 23 | |||
2815 | 24 | @Override | ||
2816 | 25 | public final void mousePressed(MouseEvent e) { | ||
2817 | 26 | dispatchEventToParent(e); | ||
2818 | 27 | } | ||
2819 | 28 | |||
2820 | 29 | @Override | ||
2821 | 30 | public final void mouseReleased(MouseEvent e) { | ||
2822 | 31 | dispatchEventToParent(e); | ||
2823 | 32 | } | ||
2824 | 33 | |||
2825 | 34 | @Override | ||
2826 | 35 | public final void mouseEntered(MouseEvent e) { | ||
2827 | 36 | dispatchEventToParent(e); | ||
2828 | 37 | } | ||
2829 | 38 | |||
2830 | 39 | @Override | ||
2831 | 40 | public final void mouseExited(MouseEvent e) { | ||
2832 | 41 | dispatchEventToParent(e); | ||
2833 | 42 | } | ||
2834 | 43 | |||
2835 | 44 | @Override | ||
2836 | 45 | public final void mouseDragged(MouseEvent e) { | ||
2837 | 46 | dispatchEventToParent(e); | ||
2838 | 47 | } | ||
2839 | 48 | |||
2840 | 49 | @Override | ||
2841 | 50 | public final void mouseMoved(MouseEvent e) { | ||
2842 | 51 | dispatchEventToParent(e); | ||
2843 | 52 | } | ||
2844 | 53 | |||
2845 | 54 | @Override | ||
2846 | 55 | public final void mouseWheelMoved(MouseWheelEvent e) { | ||
2847 | 56 | dispatchEventToParent(e); | ||
2848 | 57 | } | ||
2849 | 58 | } | ||
2850 | 0 | 59 | ||
2851 | === modified file 'src/pipe/dataLayer/DataLayer.java' | |||
2852 | --- src/pipe/dataLayer/DataLayer.java 2020-05-18 10:06:28 +0000 | |||
2853 | +++ src/pipe/dataLayer/DataLayer.java 2020-07-09 12:55:48 +0000 | |||
2854 | @@ -29,36 +29,36 @@ | |||
2855 | 29 | //migth not be best solution long term. | 29 | //migth not be best solution long term. |
2856 | 30 | private void removeFromViewIfConnected(PetriNetObject pno) { | 30 | private void removeFromViewIfConnected(PetriNetObject pno) { |
2857 | 31 | if (view != null) { | 31 | if (view != null) { |
2859 | 32 | view.removePetriNetObject(pno); | 32 | view.removePetriNetObject(pno.getGraphicalElement()); |
2860 | 33 | } | 33 | } |
2861 | 34 | } | 34 | } |
2862 | 35 | 35 | ||
2863 | 36 | private void addToViewIfConnected(PetriNetObject pno) { | 36 | private void addToViewIfConnected(PetriNetObject pno) { |
2864 | 37 | if (view != null) { | 37 | if (view != null) { |
2866 | 38 | view.addNewPetriNetObject(pno); | 38 | view.addNewPetriNetObject(pno.getGraphicalElement()); |
2867 | 39 | } | 39 | } |
2868 | 40 | } | 40 | } |
2869 | 41 | 41 | ||
2870 | 42 | /** PNML File Name */ | 42 | /** PNML File Name */ |
2871 | 43 | public String pnmlName = null; | 43 | public String pnmlName = null; |
2872 | 44 | /** List containing all the Place objects in the Petri-Net */ | 44 | /** List containing all the Place objects in the Petri-Net */ |
2874 | 45 | private ArrayList<Place> placesArray = null; | 45 | private final ArrayList<Place> placesArray = new ArrayList<Place>(); |
2875 | 46 | /** ArrayList containing all the Transition objects in the Petri-Net */ | 46 | /** ArrayList containing all the Transition objects in the Petri-Net */ |
2877 | 47 | private ArrayList<Transition> transitionsArray = null; | 47 | private final ArrayList<Transition> transitionsArray = new ArrayList<Transition>(); |
2878 | 48 | /** ArrayList containing all the Arc objects in the Petri-Net */ | 48 | /** ArrayList containing all the Arc objects in the Petri-Net */ |
2880 | 49 | private ArrayList<Arc> arcsArray = null; | 49 | private final ArrayList<Arc> arcsArray = new ArrayList<Arc>(); |
2881 | 50 | 50 | ||
2882 | 51 | /** Set holding all ArcPathPoints | 51 | /** Set holding all ArcPathPoints |
2883 | 52 | * Uses the reference as lookup key (not hash code) | 52 | * Uses the reference as lookup key (not hash code) |
2884 | 53 | * Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); | 53 | * Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); |
2885 | 54 | * */ | 54 | * */ |
2887 | 55 | private Set<ArcPathPoint> arcPathSet = Collections.newSetFromMap(new IdentityHashMap<>()); | 55 | private final Set<ArcPathPoint> arcPathSet = Collections.newSetFromMap(new IdentityHashMap<>()); |
2888 | 56 | 56 | ||
2889 | 57 | /** | 57 | /** |
2890 | 58 | * ArrayList for net-level label objects (as opposed to element-level | 58 | * ArrayList for net-level label objects (as opposed to element-level |
2891 | 59 | * labels). | 59 | * labels). |
2892 | 60 | */ | 60 | */ |
2894 | 61 | private ArrayList<AnnotationNote> labelsArray = null; | 61 | private final ArrayList<AnnotationNote> labelsArray = new ArrayList<AnnotationNote>(); |
2895 | 62 | 62 | ||
2896 | 63 | /** | 63 | /** |
2897 | 64 | * An ArrayList used to point to either the Arc, Place or Transition | 64 | * An ArrayList used to point to either the Arc, Place or Transition |
2898 | @@ -66,22 +66,23 @@ | |||
2899 | 66 | */ | 66 | */ |
2900 | 67 | private ArrayList<? extends PetriNetObject> changeArrayList = null; | 67 | private ArrayList<? extends PetriNetObject> changeArrayList = null; |
2901 | 68 | 68 | ||
2903 | 69 | /** | 69 | // may as well do the hashtable here as well |
2904 | 70 | /** | ||
2905 | 70 | * Hashtable which maps PlaceTransitionObjects to their list of connected | 71 | * Hashtable which maps PlaceTransitionObjects to their list of connected |
2906 | 71 | * arcs | 72 | * arcs |
2907 | 72 | */ | 73 | */ |
2909 | 73 | private Hashtable<PlaceTransitionObject, ArrayList<TimedOutputArcComponent>> arcsMap = null; | 74 | private final Hashtable<PlaceTransitionObject, ArrayList<TimedOutputArcComponent>> arcsMap = new Hashtable<PlaceTransitionObject, ArrayList<TimedOutputArcComponent>>(); |
2910 | 74 | 75 | ||
2911 | 75 | /** | 76 | /** |
2912 | 76 | * Hashtable which maps PlaceTransitionObjects to their list of connected | 77 | * Hashtable which maps PlaceTransitionObjects to their list of connected |
2913 | 77 | * arcs | 78 | * arcs |
2914 | 78 | */ | 79 | */ |
2916 | 79 | private Hashtable<PlaceTransitionObject, ArrayList<TimedInhibitorArcComponent>> tapnInhibitorsMap = null; | 80 | private final Hashtable<PlaceTransitionObject, ArrayList<TimedInhibitorArcComponent>> tapnInhibitorsMap = new Hashtable<PlaceTransitionObject, ArrayList<TimedInhibitorArcComponent>>(); |
2917 | 80 | 81 | ||
2918 | 81 | 82 | ||
2919 | 82 | //XXX: Added from drawingsurface to have a way to acces all elements added, | 83 | //XXX: Added from drawingsurface to have a way to acces all elements added, |
2920 | 83 | //Should be refactored later to combine the existing list, however this is the quick fix during refactoring | 84 | //Should be refactored later to combine the existing list, however this is the quick fix during refactoring |
2922 | 84 | private ArrayList<PetriNetObject> petriNetObjects = new ArrayList<PetriNetObject>(); | 85 | private final ArrayList<PetriNetObject> petriNetObjects = new ArrayList<PetriNetObject>(); |
2923 | 85 | 86 | ||
2924 | 86 | public ArrayList<PetriNetObject> getPNObjects() { | 87 | public ArrayList<PetriNetObject> getPNObjects() { |
2925 | 87 | return petriNetObjects; | 88 | return petriNetObjects; |
2926 | @@ -101,16 +102,8 @@ | |||
2927 | 101 | * Create empty Petri-Net object | 102 | * Create empty Petri-Net object |
2928 | 102 | */ | 103 | */ |
2929 | 103 | public DataLayer() { | 104 | public DataLayer() { |
2940 | 104 | placesArray = new ArrayList<Place>(); | 105 | super(); |
2941 | 105 | transitionsArray = new ArrayList<Transition>(); | 106 | } |
2932 | 106 | arcsArray = new ArrayList<Arc>(); | ||
2933 | 107 | |||
2934 | 108 | labelsArray = new ArrayList<AnnotationNote>(); | ||
2935 | 109 | |||
2936 | 110 | // may as well do the hashtable here as well | ||
2937 | 111 | arcsMap = new Hashtable<PlaceTransitionObject, ArrayList<TimedOutputArcComponent>>(); | ||
2938 | 112 | tapnInhibitorsMap = new Hashtable<PlaceTransitionObject, ArrayList<TimedInhibitorArcComponent>>(); | ||
2939 | 113 | } | ||
2942 | 114 | 107 | ||
2943 | 115 | 108 | ||
2944 | 116 | /** | 109 | /** |
2945 | @@ -162,105 +155,94 @@ | |||
2946 | 162 | 155 | ||
2947 | 163 | // Check if the arcs have a valid source and target | 156 | // Check if the arcs have a valid source and target |
2948 | 164 | if (arcInput.getSource() == null || arcInput.getTarget() == null) { | 157 | if (arcInput.getSource() == null || arcInput.getTarget() == null) { |
2950 | 165 | System.err.println(("Cant add arc" + arcInput + " where source: " | 158 | System.err.println( |
2951 | 159 | "Cant add arc" + arcInput + " where source: " | ||
2952 | 166 | + arcInput.getSource() + " or target: " | 160 | + arcInput.getSource() + " or target: " |
2954 | 167 | + arcInput.getTarget() + " is null")); | 161 | + arcInput.getTarget() + " is null" |
2955 | 162 | ); | ||
2956 | 168 | return; | 163 | return; |
2957 | 169 | } | 164 | } |
2958 | 170 | 165 | ||
3052 | 171 | if (arcInput != null) { | 166 | if (arcInput.getId() != null && arcInput.getId().length() > 0) { |
3053 | 172 | if (arcInput.getId() != null && arcInput.getId().length() > 0) { | 167 | for (Arc arc : arcsArray) { |
3054 | 173 | for (int i = 0; i < arcsArray.size(); i++) { | 168 | if (arcInput.getId().equals(arc.getId())) { |
3055 | 174 | if (arcInput.getId().equals((arcsArray.get(i)).getId())) { | 169 | unique = false; |
3056 | 175 | unique = false; | 170 | } |
3057 | 176 | } | 171 | } |
3058 | 177 | } | 172 | } else { |
3059 | 178 | } else { | 173 | String id = null; |
3060 | 179 | String id = null; | 174 | if (arcsArray.size() > 0) { |
3061 | 180 | if (arcsArray != null && arcsArray.size() > 0) { | 175 | int no = arcsArray.size(); |
3062 | 181 | int no = arcsArray.size(); | 176 | do { |
3063 | 182 | do { | 177 | for (Arc arc : arcsArray) { |
3064 | 183 | for (int i = 0; i < arcsArray.size(); i++) { | 178 | id = "A" + no; |
3065 | 184 | id = "A" + no; | 179 | if (arc != null) { |
3066 | 185 | if (arcsArray.get(i) != null) { | 180 | if (id.equals(arc.getId())) { |
3067 | 186 | if (id.equals((arcsArray.get(i)).getId())) { | 181 | unique = false; |
3068 | 187 | unique = false; | 182 | no++; |
3069 | 188 | no++; | 183 | } else { |
3070 | 189 | } else { | 184 | unique = true; |
3071 | 190 | unique = true; | 185 | } |
3072 | 191 | } | 186 | } |
3073 | 192 | } | 187 | } |
3074 | 193 | } | 188 | } while (!unique); |
3075 | 194 | } while (!unique); | 189 | } else { |
3076 | 195 | } else { | 190 | id = "A0"; |
3077 | 196 | id = "A0"; | 191 | } |
3078 | 197 | } | 192 | arcInput.setId(id); |
3079 | 198 | if (id != null) { | 193 | } |
3080 | 199 | arcInput.setId(id); | 194 | |
3081 | 200 | } else { | 195 | //XXX: this is still nedede as nets loaded from file (XML/tapn) does not set connectedTo correctly //2019-09-18 |
3082 | 201 | arcInput.setId("error"); | 196 | // Transportarc fix boddy |
3083 | 202 | } | 197 | if (arcInput instanceof TimedTransportArcComponent) { |
3084 | 203 | } | 198 | TimedTransportArcComponent tmp = (TimedTransportArcComponent) arcInput; |
3085 | 204 | 199 | PlaceTransitionObject first = tmp.getSource(); | |
3086 | 205 | //XXX: this is still nedede as nets loaded from file (XML/tapn) does not set connectedTo correctly //2019-09-18 | 200 | |
3087 | 206 | // Transportarc fix boddy | 201 | if (tmp.getConnectedTo() == null) { |
3088 | 207 | if (arcInput instanceof TimedTransportArcComponent) { | 202 | if (first instanceof TimedPlaceComponent) { |
3089 | 208 | TimedTransportArcComponent tmp = (TimedTransportArcComponent) arcInput; | 203 | |
3090 | 209 | PlaceTransitionObject first = tmp.getSource(); | 204 | for (Object o : tmp.getTarget().getPostset()) { |
3091 | 210 | 205 | ||
3092 | 211 | if (tmp.getConnectedTo() == null) { | 206 | if (o instanceof TimedTransportArcComponent) { |
3093 | 212 | if (first instanceof TimedPlaceComponent) { | 207 | if (tmp.getGroupNr() == ((TimedTransportArcComponent) o).getGroupNr()) { |
3094 | 213 | 208 | // Found partner | |
3095 | 214 | for (Object o : tmp.getTarget().getPostset()) { | 209 | |
3096 | 215 | 210 | tmp.setConnectedTo(((TimedTransportArcComponent) o)); | |
3097 | 216 | if (o instanceof TimedTransportArcComponent) { | 211 | ((TimedTransportArcComponent) o).setConnectedTo(tmp); |
3098 | 217 | if (tmp.getGroupNr() == ((TimedTransportArcComponent) o) | 212 | |
3099 | 218 | .getGroupNr()) { | 213 | break; |
3100 | 219 | // Found partner | 214 | } |
3101 | 220 | 215 | } | |
3102 | 221 | tmp | 216 | |
3103 | 222 | .setConnectedTo(((TimedTransportArcComponent) o)); | 217 | } |
3104 | 223 | ((TimedTransportArcComponent) o) | 218 | |
3105 | 224 | .setConnectedTo(tmp); | 219 | } else { |
3106 | 225 | 220 | // First is TimedTransition | |
3107 | 226 | break; | 221 | |
3108 | 227 | } | 222 | for (Object o : tmp.getSource().getPreset()) { |
3109 | 228 | } | 223 | |
3110 | 229 | 224 | if (o instanceof TimedTransportArcComponent) { | |
3111 | 230 | } | 225 | if (tmp.getGroupNr() == ((TimedTransportArcComponent) o).getGroupNr()) { |
3112 | 231 | 226 | // Found partner | |
3113 | 232 | } else { | 227 | |
3114 | 233 | // First is TimedTransition | 228 | tmp.setConnectedTo(((TimedTransportArcComponent) o)); |
3115 | 234 | tmp = (TimedTransportArcComponent) arcInput; | 229 | ((TimedTransportArcComponent) o).setConnectedTo(tmp); |
3116 | 235 | 230 | ||
3117 | 236 | for (Object o : tmp.getSource().getPreset()) { | 231 | break; |
3118 | 237 | 232 | } | |
3119 | 238 | if (o instanceof TimedTransportArcComponent) { | 233 | } |
3120 | 239 | if (tmp.getGroupNr() == ((TimedTransportArcComponent) o) | 234 | |
3121 | 240 | .getGroupNr()) { | 235 | } |
3122 | 241 | // Found partner | 236 | |
3123 | 242 | 237 | } | |
3124 | 243 | tmp | 238 | } |
3125 | 244 | .setConnectedTo(((TimedTransportArcComponent) o)); | 239 | |
3126 | 245 | ((TimedTransportArcComponent) o) | 240 | } |
3127 | 246 | .setConnectedTo(tmp); | 241 | |
3128 | 247 | 242 | arcsArray.add(arcInput); | |
3129 | 248 | break; | 243 | addArcToArcsMap(arcInput); |
3130 | 249 | } | 244 | |
3131 | 250 | } | 245 | } |
3039 | 251 | |||
3040 | 252 | } | ||
3041 | 253 | |||
3042 | 254 | } | ||
3043 | 255 | } | ||
3044 | 256 | |||
3045 | 257 | } | ||
3046 | 258 | |||
3047 | 259 | arcsArray.add(arcInput); | ||
3048 | 260 | addArcToArcsMap(arcInput); | ||
3049 | 261 | |||
3050 | 262 | } | ||
3051 | 263 | } | ||
3132 | 264 | 246 | ||
3133 | 265 | private void addTransportArc(TimedTransportArcComponent transportArc) { | 247 | private void addTransportArc(TimedTransportArcComponent transportArc) { |
3134 | 266 | arcsArray.add(transportArc); | 248 | arcsArray.add(transportArc); |
3135 | @@ -271,40 +253,34 @@ | |||
3136 | 271 | boolean unique = true; | 253 | boolean unique = true; |
3137 | 272 | 254 | ||
3138 | 273 | if (inhibitorArcInput != null) { | 255 | if (inhibitorArcInput != null) { |
3147 | 274 | if (inhibitorArcInput.getId() != null | 256 | if (inhibitorArcInput.getId() != null && inhibitorArcInput.getId().length() > 0) { |
3148 | 275 | && inhibitorArcInput.getId().length() > 0) { | 257 | for (Arc arc : arcsArray) { |
3149 | 276 | for (int i = 0; i < arcsArray.size(); i++) { | 258 | if (inhibitorArcInput.getId().equals(arc.getId())) { |
3150 | 277 | if (inhibitorArcInput.getId().equals( | 259 | unique = false; |
3151 | 278 | (arcsArray.get(i)).getId())) { | 260 | } |
3152 | 279 | unique = false; | 261 | } |
3145 | 280 | } | ||
3146 | 281 | } | ||
3153 | 282 | } else { | 262 | } else { |
3154 | 283 | String id = null; | 263 | String id = null; |
3156 | 284 | if (arcsArray != null && arcsArray.size() > 0) { | 264 | if (arcsArray.size() > 0) { |
3157 | 285 | int no = arcsArray.size(); | 265 | int no = arcsArray.size(); |
3158 | 286 | do { | 266 | do { |
3170 | 287 | for (int i = 0; i < arcsArray.size(); i++) { | 267 | for (Arc arc : arcsArray) { |
3171 | 288 | id = "I" + no; | 268 | id = "I" + no; |
3172 | 289 | if (arcsArray.get(i) != null) { | 269 | if (arc != null) { |
3173 | 290 | if (id.equals((arcsArray.get(i)).getId())) { | 270 | if (id.equals(arc.getId())) { |
3174 | 291 | unique = false; | 271 | unique = false; |
3175 | 292 | no++; | 272 | no++; |
3176 | 293 | } else { | 273 | } else { |
3177 | 294 | unique = true; | 274 | unique = true; |
3178 | 295 | } | 275 | } |
3179 | 296 | } | 276 | } |
3180 | 297 | } | 277 | } |
3181 | 298 | } while (!unique); | 278 | } while (!unique); |
3182 | 299 | } else { | 279 | } else { |
3183 | 300 | id = "I0"; | 280 | id = "I0"; |
3184 | 301 | } | 281 | } |
3191 | 302 | if (id != null) { | 282 | inhibitorArcInput.setId(id); |
3192 | 303 | inhibitorArcInput.setId(id); | 283 | } |
3187 | 304 | } else { | ||
3188 | 305 | inhibitorArcInput.setId("error"); | ||
3189 | 306 | } | ||
3190 | 307 | } | ||
3193 | 308 | 284 | ||
3194 | 309 | arcsArray.add(inhibitorArcInput); | 285 | arcsArray.add(inhibitorArcInput); |
3195 | 310 | addInhibitorArcToInhibitorsMap(inhibitorArcInput); | 286 | addInhibitorArcToInhibitorsMap(inhibitorArcInput); |
3196 | @@ -529,18 +505,13 @@ | |||
3197 | 529 | attached = ((Arc) pnObject).getTarget(); | 505 | attached = ((Arc) pnObject).getTarget(); |
3198 | 530 | 506 | ||
3199 | 531 | if (attached != null) { | 507 | if (attached != null) { |
3205 | 532 | if (tapnInhibitorsMap.get(attached) != null) { // causing | 508 | if (tapnInhibitorsMap.get(attached) != null) { // causing null pointer exceptions (!) |
3201 | 533 | // null | ||
3202 | 534 | // pointer | ||
3203 | 535 | // exceptions | ||
3204 | 536 | // (!) | ||
3206 | 537 | tapnInhibitorsMap.get(attached).remove(pnObject); | 509 | tapnInhibitorsMap.get(attached).remove(pnObject); |
3207 | 538 | } | 510 | } |
3208 | 539 | 511 | ||
3209 | 540 | attached.removeToArc((Arc) pnObject); | 512 | attached.removeToArc((Arc) pnObject); |
3210 | 541 | if (attached instanceof Transition) { | 513 | if (attached instanceof Transition) { |
3213 | 542 | ((Transition) attached) | 514 | ((Transition) attached).removeArcCompareObject((Arc) pnObject); |
3212 | 543 | .removeArcCompareObject((Arc) pnObject); | ||
3214 | 544 | } | 515 | } |
3215 | 545 | // attached.updateConnected(); //causing null pointer | 516 | // attached.updateConnected(); //causing null pointer |
3216 | 546 | // exceptions (?) | 517 | // exceptions (?) |
3217 | @@ -567,10 +538,7 @@ | |||
3218 | 567 | 538 | ||
3219 | 568 | attached = ((Arc) pnObject).getTarget(); | 539 | attached = ((Arc) pnObject).getTarget(); |
3220 | 569 | if (attached != null) { | 540 | if (attached != null) { |
3225 | 570 | if (arcsMap.get(attached) != null) { // causing null | 541 | if (arcsMap.get(attached) != null) { // causing null pointer exceptions (!) |
3222 | 571 | // pointer | ||
3223 | 572 | // exceptions | ||
3224 | 573 | // (!) | ||
3226 | 574 | arcsMap.get(attached).remove(pnObject); | 542 | arcsMap.get(attached).remove(pnObject); |
3227 | 575 | } | 543 | } |
3228 | 576 | 544 | ||
3229 | @@ -586,8 +554,7 @@ | |||
3230 | 586 | 554 | ||
3231 | 587 | } | 555 | } |
3232 | 588 | } catch (NullPointerException npe) { | 556 | } catch (NullPointerException npe) { |
3235 | 589 | System.out.println("NullPointerException [debug]\n" | 557 | System.out.println("NullPointerException [debug]\n" + npe.getMessage()); |
3234 | 590 | + npe.getMessage()); | ||
3236 | 591 | throw npe; | 558 | throw npe; |
3237 | 592 | } | 559 | } |
3238 | 593 | // we reset to null so that the wrong ArrayList can't get added to | 560 | // we reset to null so that the wrong ArrayList can't get added to |
3239 | @@ -599,8 +566,10 @@ | |||
3240 | 599 | * set all enabled transitions to highlighted | 566 | * set all enabled transitions to highlighted |
3241 | 600 | */ | 567 | */ |
3242 | 601 | public Iterable<Transition> transitions() { | 568 | public Iterable<Transition> transitions() { |
3245 | 602 | return transitionsArray; | 569 | |
3246 | 603 | } | 570 | return transitionsArray; |
3247 | 571 | } | ||
3248 | 572 | |||
3249 | 604 | 573 | ||
3250 | 605 | /** | 574 | /** |
3251 | 606 | * Sets an internal ArrayList according to the class of the object passed | 575 | * Sets an internal ArrayList according to the class of the object passed |
3252 | @@ -735,16 +704,14 @@ | |||
3253 | 735 | public Transition getTransitionById(String transitionID) { | 704 | public Transition getTransitionById(String transitionID) { |
3254 | 736 | Transition returnTransition = null; | 705 | Transition returnTransition = null; |
3255 | 737 | 706 | ||
3266 | 738 | if (transitionsArray != null) { | 707 | if (transitionID != null) { |
3267 | 739 | if (transitionID != null) { | 708 | for (Transition transition : transitionsArray) { |
3268 | 740 | for (Transition transition : transitionsArray) { | 709 | if (transitionID.equalsIgnoreCase(transition.getId())) { |
3269 | 741 | if (transitionID.equalsIgnoreCase(transition.getId())) { | 710 | returnTransition = transition; |
3270 | 742 | returnTransition = transition; | 711 | } |
3271 | 743 | } | 712 | } |
3272 | 744 | } | 713 | } |
3273 | 745 | } | 714 | return returnTransition; |
3264 | 746 | } | ||
3265 | 747 | return returnTransition; | ||
3274 | 748 | } | 715 | } |
3275 | 749 | 716 | ||
3276 | 750 | /** | 717 | /** |
3277 | @@ -758,16 +725,14 @@ | |||
3278 | 758 | public Transition getTransitionByName(String transitionName) { | 725 | public Transition getTransitionByName(String transitionName) { |
3279 | 759 | Transition returnTransition = null; | 726 | Transition returnTransition = null; |
3280 | 760 | 727 | ||
3291 | 761 | if (transitionsArray != null) { | 728 | if (transitionName != null) { |
3292 | 762 | if (transitionName != null) { | 729 | for (Transition transition : transitionsArray) { |
3293 | 763 | for (Transition transition : transitionsArray) { | 730 | if (transitionName.equalsIgnoreCase(transition.getName())) { |
3294 | 764 | if (transitionName.equalsIgnoreCase(transition.getName())) { | 731 | returnTransition = transition; |
3295 | 765 | returnTransition = transition; | 732 | } |
3296 | 766 | } | 733 | } |
3297 | 767 | } | 734 | } |
3298 | 768 | } | 735 | return returnTransition; |
3289 | 769 | } | ||
3290 | 770 | return returnTransition; | ||
3299 | 771 | } | 736 | } |
3300 | 772 | 737 | ||
3301 | 773 | /** | 738 | /** |
3302 | @@ -780,16 +745,14 @@ | |||
3303 | 780 | public Place getPlaceById(String placeID) { | 745 | public Place getPlaceById(String placeID) { |
3304 | 781 | Place returnPlace = null; | 746 | Place returnPlace = null; |
3305 | 782 | 747 | ||
3316 | 783 | if (placesArray != null) { | 748 | if (placeID != null) { |
3317 | 784 | if (placeID != null) { | 749 | for (Place place : placesArray) { |
3318 | 785 | for (Place place : placesArray) { | 750 | if (placeID.equalsIgnoreCase(place.getId())) { |
3319 | 786 | if (placeID.equalsIgnoreCase(place.getId())) { | 751 | returnPlace = place; |
3320 | 787 | returnPlace = place; | 752 | } |
3321 | 788 | } | 753 | } |
3322 | 789 | } | 754 | } |
3323 | 790 | } | 755 | return returnPlace; |
3314 | 791 | } | ||
3315 | 792 | return returnPlace; | ||
3324 | 793 | } | 756 | } |
3325 | 794 | 757 | ||
3326 | 795 | /** | 758 | /** |
3327 | @@ -802,16 +765,14 @@ | |||
3328 | 802 | public Place getPlaceByName(String placeName) { | 765 | public Place getPlaceByName(String placeName) { |
3329 | 803 | Place returnPlace = null; | 766 | Place returnPlace = null; |
3330 | 804 | 767 | ||
3341 | 805 | if (placesArray != null) { | 768 | if (placeName != null) { |
3342 | 806 | if (placeName != null) { | 769 | for (Place place : placesArray) { |
3343 | 807 | for (Place place : placesArray) { | 770 | if (placeName.equalsIgnoreCase(place.getName())) { |
3344 | 808 | if (placeName.equalsIgnoreCase(place.getName())) { | 771 | returnPlace = place; |
3345 | 809 | returnPlace = place; | 772 | } |
3346 | 810 | } | 773 | } |
3347 | 811 | } | 774 | } |
3348 | 812 | } | 775 | return returnPlace; |
3339 | 813 | } | ||
3340 | 814 | return returnPlace; | ||
3349 | 815 | } | 776 | } |
3350 | 816 | 777 | ||
3351 | 817 | /** | 778 | /** |
3352 | 818 | 779 | ||
3353 | === modified file 'src/pipe/dataLayer/Template.java' | |||
3354 | --- src/pipe/dataLayer/Template.java 2020-01-12 10:11:08 +0000 | |||
3355 | +++ src/pipe/dataLayer/Template.java 2020-07-09 12:55:48 +0000 | |||
3356 | @@ -5,9 +5,9 @@ | |||
3357 | 5 | import dk.aau.cs.util.Require; | 5 | import dk.aau.cs.util.Require; |
3358 | 6 | 6 | ||
3359 | 7 | public class Template { | 7 | public class Template { |
3363 | 8 | private TimedArcPetriNet net; | 8 | private final TimedArcPetriNet net; |
3364 | 9 | private DataLayer guiModel; | 9 | private final DataLayer guiModel; |
3365 | 10 | private Zoomer zoomer; | 10 | private final Zoomer zoomer; |
3366 | 11 | private boolean hasPositionalInfo = false; | 11 | private boolean hasPositionalInfo = false; |
3367 | 12 | 12 | ||
3368 | 13 | public Template(TimedArcPetriNet net, DataLayer guiModel, Zoomer zoomer) { | 13 | public Template(TimedArcPetriNet net, DataLayer guiModel, Zoomer zoomer) { |
3369 | @@ -37,11 +37,6 @@ | |||
3370 | 37 | net.setActive(isActive); | 37 | net.setActive(isActive); |
3371 | 38 | } | 38 | } |
3372 | 39 | 39 | ||
3373 | 40 | public void setGuiModel(DataLayer guiModel) { | ||
3374 | 41 | Require.notNull(guiModel, "GuiModel cannot be null"); | ||
3375 | 42 | this.guiModel = guiModel; | ||
3376 | 43 | } | ||
3377 | 44 | |||
3378 | 45 | public Template copy() { | 40 | public Template copy() { |
3379 | 46 | TimedArcPetriNet tapn = net.copy(); | 41 | TimedArcPetriNet tapn = net.copy(); |
3380 | 47 | tapn.setName(tapn.name() + "Copy"); | 42 | tapn.setName(tapn.name() + "Copy"); |
3381 | 48 | 43 | ||
3382 | === modified file 'src/pipe/gui/AnimationHistoryList.java' | |||
3383 | --- src/pipe/gui/AnimationHistoryList.java 2020-05-18 11:23:28 +0000 | |||
3384 | +++ src/pipe/gui/AnimationHistoryList.java 2020-07-09 12:55:48 +0000 | |||
3385 | @@ -152,7 +152,7 @@ | |||
3386 | 152 | } | 152 | } |
3387 | 153 | for (Template t : CreateGui.getCurrentTab().activeTemplates()){ | 153 | for (Template t : CreateGui.getCurrentTab().activeTemplates()){ |
3388 | 154 | for(Transition trans : t.guiModel().getTransitions()){ | 154 | for(Transition trans : t.guiModel().getTransitions()){ |
3390 | 155 | if(trans.isEnabled(true) || trans.isDelayEnabledTransition(true)){ | 155 | if(trans.isTransitionEnabled() || trans.isDelayEnabled()){ |
3391 | 156 | return; | 156 | return; |
3392 | 157 | } | 157 | } |
3393 | 158 | } | 158 | } |
3394 | 159 | 159 | ||
3395 | === modified file 'src/pipe/gui/Animator.java' | |||
3396 | --- src/pipe/gui/Animator.java 2020-05-25 07:16:04 +0000 | |||
3397 | +++ src/pipe/gui/Animator.java 2020-07-09 12:55:48 +0000 | |||
3398 | @@ -39,659 +39,648 @@ | |||
3399 | 39 | import dk.aau.cs.verification.VerifyTAPN.TraceType; | 39 | import dk.aau.cs.verification.VerifyTAPN.TraceType; |
3400 | 40 | 40 | ||
3401 | 41 | public class Animator { | 41 | public class Animator { |
3433 | 42 | private final ArrayList<TAPNNetworkTraceStep> actionHistory = new ArrayList<TAPNNetworkTraceStep>(); | 42 | private final ArrayList<TAPNNetworkTraceStep> actionHistory = new ArrayList<TAPNNetworkTraceStep>(); |
3434 | 43 | private int currentAction; | 43 | private int currentAction = -1; |
3435 | 44 | private final ArrayList<NetworkMarking> markings = new ArrayList<NetworkMarking>(); | 44 | private final ArrayList<NetworkMarking> markings = new ArrayList<NetworkMarking>(); |
3436 | 45 | private int currentMarkingIndex = 0; | 45 | private int currentMarkingIndex = 0; |
3437 | 46 | private TAPNNetworkTrace trace = null; | 46 | private TAPNNetworkTrace trace = null; |
3438 | 47 | 47 | ||
3439 | 48 | public FiringMode firingmode = new RandomFiringMode(); | 48 | public FiringMode firingmode = new RandomFiringMode(); |
3440 | 49 | private TabContent tab; | 49 | private final TabContent tab; |
3441 | 50 | private NetworkMarking initialMarking; | 50 | private NetworkMarking initialMarking; |
3442 | 51 | 51 | ||
3443 | 52 | private boolean isDisplayingUntimedTrace = false; | 52 | private boolean isDisplayingUntimedTrace = false; |
3444 | 53 | private static boolean isUrgentTransitionEnabled = false; | 53 | private static boolean isUrgentTransitionEnabled = false; |
3445 | 54 | 54 | ||
3446 | 55 | public static boolean isUrgentTransitionEnabled(){ | 55 | public static boolean isUrgentTransitionEnabled(){ |
3447 | 56 | return isUrgentTransitionEnabled; | 56 | return isUrgentTransitionEnabled; |
3448 | 57 | } | 57 | } |
3449 | 58 | 58 | ||
3450 | 59 | public Animator(TabContent tab) { | 59 | public Animator(TabContent tab) { |
3451 | 60 | currentAction = -1; | 60 | super(); |
3452 | 61 | setTabContent(tab); | 61 | |
3453 | 62 | } | 62 | this.tab = tab; |
3454 | 63 | 63 | } | |
3455 | 64 | private void setTabContent(TabContent tab) { | 64 | |
3456 | 65 | this.tab = tab; | 65 | private NetworkMarking currentMarking() { |
3457 | 66 | } | 66 | return markings.get(currentMarkingIndex); |
3458 | 67 | 67 | } | |
3459 | 68 | private NetworkMarking currentMarking() { | 68 | |
3460 | 69 | return markings.get(currentMarkingIndex); | 69 | public void setTrace(TAPNNetworkTrace trace) { |
3430 | 70 | } | ||
3431 | 71 | |||
3432 | 72 | public void setTrace(TAPNNetworkTrace trace) { | ||
3461 | 73 | CreateGui.getCurrentTab().setAnimationMode(true); | 70 | CreateGui.getCurrentTab().setAnimationMode(true); |
3462 | 74 | 71 | ||
3555 | 75 | if (trace.isConcreteTrace()) { | 72 | if (trace.isConcreteTrace()) { |
3556 | 76 | this.trace = trace; | 73 | this.trace = trace; |
3557 | 77 | setTimedTrace(trace); | 74 | setTimedTrace(trace); |
3558 | 78 | } else { | 75 | } else { |
3559 | 79 | setUntimedTrace(trace); | 76 | setUntimedTrace(trace); |
3560 | 80 | isDisplayingUntimedTrace = true; | 77 | isDisplayingUntimedTrace = true; |
3561 | 81 | } | 78 | } |
3562 | 82 | currentAction = -1; | 79 | currentAction = -1; |
3563 | 83 | currentMarkingIndex = 0; | 80 | currentMarkingIndex = 0; |
3564 | 84 | tab.network().setMarking(markings.get(currentMarkingIndex)); | 81 | tab.network().setMarking(markings.get(currentMarkingIndex)); |
3565 | 85 | tab.getAnimationHistorySidePanel().setSelectedIndex(0); | 82 | tab.getAnimationHistorySidePanel().setSelectedIndex(0); |
3566 | 86 | updateAnimationButtonsEnabled(); | 83 | updateAnimationButtonsEnabled(); |
3567 | 87 | updateFireableTransitions(); | 84 | updateFireableTransitions(); |
3568 | 88 | } | 85 | } |
3569 | 89 | 86 | ||
3570 | 90 | private void setUntimedTrace(TAPNNetworkTrace trace) { | 87 | private void setUntimedTrace(TAPNNetworkTrace trace) { |
3571 | 91 | tab.addAbstractAnimationPane(); | 88 | tab.addAbstractAnimationPane(); |
3572 | 92 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); | 89 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); |
3573 | 93 | 90 | ||
3574 | 94 | for(TAPNNetworkTraceStep step : trace){ | 91 | for(TAPNNetworkTraceStep step : trace){ |
3575 | 95 | untimedAnimationHistory.addHistoryItem(step.toString()); | 92 | untimedAnimationHistory.addHistoryItem(step.toString()); |
3576 | 96 | } | 93 | } |
3577 | 97 | 94 | ||
3578 | 98 | tab.getUntimedAnimationHistory().setSelectedIndex(0); | 95 | tab.getUntimedAnimationHistory().setSelectedIndex(0); |
3579 | 99 | setFiringmode("Random"); | 96 | setFiringmode("Random"); |
3580 | 100 | 97 | ||
3581 | 101 | JOptionPane.showMessageDialog(CreateGui.getApp(), | 98 | JOptionPane.showMessageDialog(CreateGui.getApp(), |
3582 | 102 | "The verification process returned an untimed trace.\n\n" | 99 | "The verification process returned an untimed trace.\n\n" |
3583 | 103 | + "This means that with appropriate time delays the displayed\n" | 100 | + "This means that with appropriate time delays the displayed\n" |
3584 | 104 | + "sequence of discrete transitions can become a concrete trace.\n" | 101 | + "sequence of discrete transitions can become a concrete trace.\n" |
3585 | 105 | + "In case of liveness properties (EG, AF) the untimed trace\n" | 102 | + "In case of liveness properties (EG, AF) the untimed trace\n" |
3586 | 106 | + "either ends in a deadlock, a time divergent computation without\n" | 103 | + "either ends in a deadlock, a time divergent computation without\n" |
3587 | 107 | + "any discrete transitions, or it loops back to some earlier configuration.\n" | 104 | + "any discrete transitions, or it loops back to some earlier configuration.\n" |
3588 | 108 | + "The user may experiment in the simulator with different time delays\n" | 105 | + "The user may experiment in the simulator with different time delays\n" |
3589 | 109 | + "in order to realize the suggested untimed trace in the model.", | 106 | + "in order to realize the suggested untimed trace in the model.", |
3590 | 110 | "Verification Information", JOptionPane.INFORMATION_MESSAGE); | 107 | "Verification Information", JOptionPane.INFORMATION_MESSAGE); |
3591 | 111 | } | 108 | } |
3592 | 112 | 109 | ||
3593 | 113 | private void setTimedTrace(TAPNNetworkTrace trace) { | 110 | private void setTimedTrace(TAPNNetworkTrace trace) { |
3594 | 114 | for (TAPNNetworkTraceStep step : trace) { | 111 | for (TAPNNetworkTraceStep step : trace) { |
3595 | 115 | addMarking(step, step.performStepFrom(currentMarking())); | 112 | addMarking(step, step.performStepFrom(currentMarking())); |
3596 | 116 | } | 113 | } |
3597 | 117 | if(getTrace().getTraceType() != TraceType.NOT_EG){ //If the trace was not explicitly set, maybe we have calculated it is deadlock. | 114 | if(getTrace().getTraceType() != TraceType.NOT_EG){ //If the trace was not explicitly set, maybe we have calculated it is deadlock. |
3598 | 118 | tab.getAnimationHistorySidePanel().setLastShown(getTrace().getTraceType()); | 115 | tab.getAnimationHistorySidePanel().setLastShown(getTrace().getTraceType()); |
3599 | 119 | } | 116 | } |
3600 | 120 | } | 117 | } |
3601 | 121 | 118 | ||
3602 | 122 | private void addToTimedTrace(List<TAPNNetworkTraceStep> stepList){ | 119 | private void addToTimedTrace(List<TAPNNetworkTraceStep> stepList){ |
3603 | 123 | for (TAPNNetworkTraceStep step : stepList) { | 120 | for (TAPNNetworkTraceStep step : stepList) { |
3604 | 124 | addMarking(step, step.performStepFrom(currentMarking())); | 121 | addMarking(step, step.performStepFrom(currentMarking())); |
3605 | 125 | } | 122 | } |
3606 | 126 | } | 123 | } |
3607 | 127 | 124 | ||
3608 | 128 | public NetworkMarking getInitialMarking(){ | 125 | public NetworkMarking getInitialMarking(){ |
3609 | 129 | return initialMarking; | 126 | return initialMarking; |
3610 | 130 | } | 127 | } |
3611 | 131 | 128 | ||
3612 | 132 | /** | 129 | /** |
3613 | 133 | * Highlights enabled transitions | 130 | * Highlights enabled transitions |
3614 | 134 | */ | 131 | */ |
3615 | 135 | public void highlightEnabledTransitions() { | 132 | public void highlightEnabledTransitions() { |
3616 | 136 | updateFireableTransitions(); | 133 | updateFireableTransitions(); |
3617 | 137 | DataLayer current = activeGuiModel(); | 134 | } |
3618 | 138 | 135 | ||
3619 | 139 | for (Transition tempTransition : current.transitions()) { | 136 | /** |
3620 | 140 | if (tempTransition.isEnabled(true) || (tempTransition.isDelayEnabledTransition(true) && !isUrgentTransitionEnabled)) { | 137 | * Called during animation to unhighlight previously highlighted transitions |
3621 | 141 | tempTransition.repaint(); | 138 | */ |
3622 | 142 | } | 139 | private void unhighlightDisabledTransitions() { |
3623 | 143 | } | 140 | disableTransitions(); |
3624 | 144 | } | 141 | } |
3625 | 145 | 142 | ||
3626 | 146 | /** | 143 | public void updateFireableTransitions(){ |
3627 | 147 | * Called during animation to unhighlight previously highlighted transitions | 144 | TransitionFireingComponent transFireComponent = tab.getTransitionFireingComponent(); |
3628 | 148 | */ | 145 | transFireComponent.startReInit(); |
3629 | 149 | private void unhighlightDisabledTransitions() { | 146 | isUrgentTransitionEnabled = false; |
3630 | 150 | DataLayer current = activeGuiModel(); | 147 | |
3631 | 151 | 148 | outer: for( Template template : tab.activeTemplates()){ | |
3632 | 152 | for (Transition t : current.transitions()) { | 149 | for (TimedTransition t : template.model().transitions()) { |
3633 | 153 | if (!(t.isEnabled(true)) || !t.isDelayEnabledTransition(true) || (t.isDelayEnabledTransition(true) && isUrgentTransitionEnabled)) { | 150 | if (t.isUrgent() && t.isEnabled()) { |
3542 | 154 | t.repaint(); | ||
3543 | 155 | } | ||
3544 | 156 | } | ||
3545 | 157 | } | ||
3546 | 158 | |||
3547 | 159 | public void updateFireableTransitions(){ | ||
3548 | 160 | TransitionFireingComponent transFireComponent = tab.getTransitionFireingComponent(); | ||
3549 | 161 | transFireComponent.startReInit(); | ||
3550 | 162 | isUrgentTransitionEnabled = false; | ||
3551 | 163 | |||
3552 | 164 | outer: for( Template temp : tab.activeTemplates()){ | ||
3553 | 165 | for (Transition tempTransition : temp.guiModel().transitions()) { | ||
3554 | 166 | if (tempTransition.isEnabled(true) && temp.model().getTransitionByName(tempTransition.getName()).isUrgent()) { | ||
3634 | 167 | isUrgentTransitionEnabled = true; | 151 | isUrgentTransitionEnabled = true; |
3635 | 168 | break outer; | 152 | break outer; |
3636 | 169 | } | 153 | } |
3637 | 170 | } | 154 | } |
3644 | 171 | } | 155 | } |
3645 | 172 | 156 | ||
3646 | 173 | for( Template temp : tab.activeTemplates()){ | 157 | for( Template template : tab.activeTemplates()){ |
3647 | 174 | for (Transition tempTransition : temp.guiModel().transitions()) { | 158 | for (Transition t : template.guiModel().transitions()) { |
3648 | 175 | if (tempTransition.isEnabled(true) || (tempTransition.isDelayEnabledTransition(true) && CreateGui.getApp().isShowingDelayEnabledTransitions() && !isUrgentTransitionEnabled)) { | 159 | if (t.isTransitionEnabled()) { |
3649 | 176 | transFireComponent.addTransition(temp, tempTransition); | 160 | t.markTransitionEnabled(true); |
3650 | 161 | transFireComponent.addTransition(template, t); | ||
3651 | 162 | } else if (CreateGui.getApp().isShowingDelayEnabledTransitions() && | ||
3652 | 163 | t.isDelayEnabled() && !isUrgentTransitionEnabled | ||
3653 | 164 | ) { | ||
3654 | 165 | t.markTransitionDelayEnabled(true); | ||
3655 | 166 | transFireComponent.addTransition(template, t); | ||
3656 | 177 | } | 167 | } |
3657 | 168 | |||
3658 | 178 | } | 169 | } |
3671 | 179 | } | 170 | } |
3672 | 180 | 171 | ||
3673 | 181 | transFireComponent.reInitDone(); | 172 | transFireComponent.reInitDone(); |
3674 | 182 | } | 173 | } |
3675 | 183 | 174 | ||
3676 | 184 | /** | 175 | /** |
3677 | 185 | * Called at end of animation and resets all Transitions to false and | 176 | * Called at end of animation and resets all Transitions to false and |
3678 | 186 | * unhighlighted | 177 | * unhighlighted |
3679 | 187 | */ | 178 | */ |
3680 | 188 | private void disableTransitions() { | 179 | private void disableTransitions() { |
3681 | 189 | for(Template template : tab.allTemplates()) | 180 | for(Template template : tab.allTemplates()) |
3682 | 190 | { | 181 | { |
3683 | 191 | for (Transition tempTransition : template.guiModel().transitions()) { | 182 | for (Transition tempTransition : template.guiModel().transitions()) { |
3686 | 192 | tempTransition.setEnabledFalse(); | 183 | tempTransition.disableHightligh(); |
3687 | 193 | tempTransition.setDelayEnabledTransitionFalse(); | 184 | |
3688 | 194 | tempTransition.repaint(); | 185 | tempTransition.repaint(); |
3689 | 195 | } | 186 | } |
3723 | 196 | } | 187 | } |
3724 | 197 | } | 188 | } |
3725 | 198 | 189 | ||
3726 | 199 | /** | 190 | /** |
3727 | 200 | * Stores model at start of animation | 191 | * Stores model at start of animation |
3728 | 201 | */ | 192 | */ |
3729 | 202 | public void storeModel() { | 193 | public void storeModel() { |
3730 | 203 | initialMarking = tab.network().marking(); | 194 | initialMarking = tab.network().marking(); |
3731 | 204 | resethistory(); | 195 | resethistory(); |
3732 | 205 | markings.add(initialMarking); | 196 | markings.add(initialMarking); |
3733 | 206 | } | 197 | } |
3734 | 207 | 198 | ||
3735 | 208 | /** | 199 | /** |
3736 | 209 | * Restores model at end of animation and sets all transitions to false and | 200 | * Restores model at end of animation and sets all transitions to false and |
3737 | 210 | * unhighlighted | 201 | * unhighlighted |
3738 | 211 | */ | 202 | */ |
3739 | 212 | public void restoreModel() { | 203 | public void restoreModel() { |
3740 | 213 | if (tab != null) { | 204 | if (tab != null) { |
3741 | 214 | disableTransitions(); | 205 | disableTransitions(); |
3742 | 215 | if (initialMarking != null) { | 206 | tab.network().setMarking(initialMarking); |
3743 | 216 | tab.network().setMarking(initialMarking); | 207 | currentAction = -1; |
3744 | 217 | } | 208 | } |
3745 | 218 | currentAction = -1; | 209 | } |
3746 | 219 | } | 210 | |
3747 | 220 | } | 211 | /** |
3748 | 221 | 212 | * Steps back through previously fired transitions | |
3749 | 222 | /** | 213 | * |
3750 | 223 | * Steps back through previously fired transitions | 214 | * @author jokke refactored and added backwards firing for TAPNTransitions |
3751 | 224 | * | 215 | */ |
3752 | 225 | * @author jokke refactored and added backwards firing for TAPNTransitions | 216 | |
3753 | 226 | */ | 217 | public void stepBack() { |
3721 | 227 | |||
3722 | 228 | public void stepBack() { | ||
3754 | 229 | tab.getAnimationHistorySidePanel().stepBackwards(); | 218 | tab.getAnimationHistorySidePanel().stepBackwards(); |
3765 | 230 | if (!actionHistory.isEmpty()){ | 219 | if (!actionHistory.isEmpty()){ |
3766 | 231 | TAPNNetworkTraceStep lastStep = actionHistory.get(currentAction); | 220 | TAPNNetworkTraceStep lastStep = actionHistory.get(currentAction); |
3767 | 232 | if(isDisplayingUntimedTrace && lastStep instanceof TAPNNetworkTimedTransitionStep){ | 221 | if(isDisplayingUntimedTrace && lastStep instanceof TAPNNetworkTimedTransitionStep){ |
3768 | 233 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); | 222 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); |
3769 | 234 | String previousInUntimedTrace = untimedAnimationHistory.getElement(untimedAnimationHistory.getSelectedIndex()); | 223 | String previousInUntimedTrace = untimedAnimationHistory.getElement(untimedAnimationHistory.getSelectedIndex()); |
3770 | 235 | if(previousInUntimedTrace.equals(lastStep.toString())){ | 224 | if(previousInUntimedTrace.equals(lastStep.toString())){ |
3771 | 236 | untimedAnimationHistory.stepBackwards(); | 225 | untimedAnimationHistory.stepBackwards(); |
3772 | 237 | } | 226 | } |
3773 | 238 | } | 227 | } |
3774 | 239 | tab.network().setMarking(markings.get(currentMarkingIndex - 1)); | 228 | tab.network().setMarking(markings.get(currentMarkingIndex - 1)); |
3775 | 240 | 229 | ||
3781 | 241 | activeGuiModel().repaintPlaces(); | 230 | activeGuiModel().repaintPlaces(); |
3782 | 242 | unhighlightDisabledTransitions(); | 231 | unhighlightDisabledTransitions(); |
3783 | 243 | highlightEnabledTransitions(); | 232 | highlightEnabledTransitions(); |
3784 | 244 | currentAction--; | 233 | currentAction--; |
3785 | 245 | currentMarkingIndex--; | 234 | currentMarkingIndex--; |
3786 | 246 | 235 | ||
3787 | 247 | updateAnimationButtonsEnabled(); | 236 | updateAnimationButtonsEnabled(); |
3788 | 248 | updateMouseOverInformation(); | 237 | updateMouseOverInformation(); |
3798 | 249 | reportBlockingPlaces(); | 238 | reportBlockingPlaces(); |
3799 | 250 | } | 239 | } |
3800 | 251 | } | 240 | } |
3801 | 252 | 241 | ||
3802 | 253 | /** | 242 | /** |
3803 | 254 | * Steps forward through previously fired transitions | 243 | * Steps forward through previously fired transitions |
3804 | 255 | */ | 244 | */ |
3805 | 256 | 245 | ||
3806 | 257 | public void stepForward() { | 246 | public void stepForward() { |
3807 | 258 | tab.getAnimationHistorySidePanel().stepForward(); | 247 | tab.getAnimationHistorySidePanel().stepForward(); |
3842 | 259 | if(currentAction == actionHistory.size()-1 && trace != null){ | 248 | if(currentAction == actionHistory.size()-1 && trace != null){ |
3843 | 260 | int selectedIndex = tab.getAnimationHistorySidePanel().getSelectedIndex(); | 249 | int selectedIndex = tab.getAnimationHistorySidePanel().getSelectedIndex(); |
3844 | 261 | int action = currentAction; | 250 | int action = currentAction; |
3845 | 262 | int markingIndex = currentMarkingIndex; | 251 | int markingIndex = currentMarkingIndex; |
3846 | 263 | 252 | ||
3847 | 264 | if(getTrace().getTraceType() == TraceType.EG_DELAY_FOREVER){ | 253 | if(getTrace().getTraceType() == TraceType.EG_DELAY_FOREVER){ |
3848 | 265 | addMarking(new TAPNNetworkTimeDelayStep(BigDecimal.ONE), currentMarking().delay(BigDecimal.ONE)); | 254 | addMarking(new TAPNNetworkTimeDelayStep(BigDecimal.ONE), currentMarking().delay(BigDecimal.ONE)); |
3849 | 266 | } | 255 | } |
3850 | 267 | if(getTrace().getLoopToIndex() != -1){ | 256 | if(getTrace().getLoopToIndex() != -1){ |
3851 | 268 | addToTimedTrace(getTrace().getLoopSteps()); | 257 | addToTimedTrace(getTrace().getLoopSteps()); |
3852 | 269 | } | 258 | } |
3853 | 270 | 259 | ||
3854 | 271 | tab.getAnimationHistorySidePanel().setSelectedIndex(selectedIndex); | 260 | tab.getAnimationHistorySidePanel().setSelectedIndex(selectedIndex); |
3855 | 272 | currentAction = action; | 261 | currentAction = action; |
3856 | 273 | currentMarkingIndex = markingIndex; | 262 | currentMarkingIndex = markingIndex; |
3857 | 274 | } | 263 | } |
3858 | 275 | 264 | ||
3859 | 276 | if (currentAction < actionHistory.size() - 1) { | 265 | if (currentAction < actionHistory.size() - 1) { |
3860 | 277 | TAPNNetworkTraceStep nextStep = actionHistory.get(currentAction+1); | 266 | TAPNNetworkTraceStep nextStep = actionHistory.get(currentAction+1); |
3861 | 278 | if(isDisplayingUntimedTrace && nextStep instanceof TAPNNetworkTimedTransitionStep){ | 267 | if(isDisplayingUntimedTrace && nextStep instanceof TAPNNetworkTimedTransitionStep){ |
3862 | 279 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); | 268 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); |
3863 | 280 | String nextInUntimedTrace = untimedAnimationHistory.getElement(untimedAnimationHistory.getSelectedIndex()+1); | 269 | String nextInUntimedTrace = untimedAnimationHistory.getElement(untimedAnimationHistory.getSelectedIndex()+1); |
3864 | 281 | if(nextInUntimedTrace.equals(nextStep.toString())){ | 270 | if(nextInUntimedTrace.equals(nextStep.toString())){ |
3865 | 282 | untimedAnimationHistory.stepForward(); | 271 | untimedAnimationHistory.stepForward(); |
3866 | 283 | } | 272 | } |
3867 | 284 | } | 273 | } |
3868 | 285 | tab.network().setMarking(markings.get(currentMarkingIndex + 1)); | 274 | tab.network().setMarking(markings.get(currentMarkingIndex + 1)); |
3869 | 286 | 275 | ||
3870 | 287 | activeGuiModel().repaintPlaces(); | 276 | activeGuiModel().repaintPlaces(); |
3871 | 288 | unhighlightDisabledTransitions(); | 277 | unhighlightDisabledTransitions(); |
3872 | 289 | highlightEnabledTransitions(); | 278 | highlightEnabledTransitions(); |
3873 | 290 | currentAction++; | 279 | currentAction++; |
3874 | 291 | currentMarkingIndex++; | 280 | currentMarkingIndex++; |
3875 | 292 | activeGuiModel().redrawVisibleTokenLists(); | 281 | activeGuiModel().redrawVisibleTokenLists(); |
3876 | 293 | 282 | ||
3877 | 294 | updateAnimationButtonsEnabled(); | 283 | updateAnimationButtonsEnabled(); |
3878 | 295 | updateMouseOverInformation(); | 284 | updateMouseOverInformation(); |
4096 | 296 | reportBlockingPlaces(); | 285 | reportBlockingPlaces(); |
4097 | 297 | 286 | ||
4098 | 298 | } | 287 | } |
4099 | 299 | } | 288 | } |
4100 | 300 | 289 | ||
4101 | 301 | /** | 290 | /** |
4102 | 302 | * Make the selected transition in the animation box blink, based on the | 291 | * Make the selected transition in the animation box blink, based on the |
4103 | 303 | * list element label | 292 | * list element label |
4104 | 304 | */ | 293 | */ |
4105 | 305 | 294 | ||
4106 | 306 | public void blinkSelected(String label){ | 295 | public void blinkSelected(String label){ |
4107 | 307 | if(label.contains(".")){ | 296 | if(label.contains(".")){ |
4108 | 308 | label = label.split("\\.")[1]; | 297 | label = label.split("\\.")[1]; |
4109 | 309 | } | 298 | } |
4110 | 310 | 299 | ||
4111 | 311 | Transition t = activeGuiModel().getTransitionByName(label); | 300 | Transition t = activeGuiModel().getTransitionByName(label); |
4112 | 312 | if(t != null){ | 301 | if(t != null){ |
4113 | 313 | t.blink(); | 302 | t.blink(); |
4114 | 314 | } | 303 | } |
4115 | 315 | } | 304 | } |
4116 | 316 | 305 | ||
4117 | 317 | public void dFireTransition(TimedTransition transition){ | 306 | public void dFireTransition(TimedTransition transition){ |
4118 | 318 | if(!CreateGui.getApp().isShowingDelayEnabledTransitions() || isUrgentTransitionEnabled()){ | 307 | if(!CreateGui.getApp().isShowingDelayEnabledTransitions() || isUrgentTransitionEnabled()){ |
4119 | 319 | fireTransition(transition); | 308 | fireTransition(transition); |
4120 | 320 | return; | 309 | return; |
4121 | 321 | } | 310 | } |
4122 | 322 | 311 | ||
4123 | 323 | TimeInterval dInterval = transition.getdInterval(); | 312 | TimeInterval dInterval = transition.getdInterval(); |
4124 | 324 | 313 | ||
4125 | 325 | BigDecimal delayGranularity = tab.getDelayEnabledTransitionControl().getValue(); | 314 | BigDecimal delayGranularity = tab.getDelayEnabledTransitionControl().getValue(); |
4126 | 326 | //Make sure the granularity is small enough | 315 | //Make sure the granularity is small enough |
4127 | 327 | BigDecimal lowerBound = IntervalOperations.getRatBound(dInterval.lowerBound()).getBound(); | 316 | BigDecimal lowerBound = IntervalOperations.getRatBound(dInterval.lowerBound()).getBound(); |
4128 | 328 | if(!dInterval.IsLowerBoundNonStrict() && !dInterval.isIncluded(lowerBound.add(delayGranularity))){ | 317 | if(!dInterval.IsLowerBoundNonStrict() && !dInterval.isIncluded(lowerBound.add(delayGranularity))){ |
4129 | 329 | do{ | 318 | do{ |
4130 | 330 | delayGranularity = delayGranularity.divide(BigDecimal.TEN); | 319 | delayGranularity = delayGranularity.divide(BigDecimal.TEN); |
4131 | 331 | } while (delayGranularity.compareTo(new BigDecimal("0.00001")) >= 0 && !dInterval.isIncluded(lowerBound.add(delayGranularity))); | 320 | } while (delayGranularity.compareTo(new BigDecimal("0.00001")) >= 0 && !dInterval.isIncluded(lowerBound.add(delayGranularity))); |
4132 | 332 | } | 321 | } |
4133 | 333 | 322 | ||
4134 | 334 | if(delayGranularity.compareTo(new BigDecimal("0.00001")) < 0){ | 323 | if(delayGranularity.compareTo(new BigDecimal("0.00001")) < 0){ |
4135 | 335 | JOptionPane.showMessageDialog(CreateGui.getApp(), "<html>Due to the limit of only five decimal points in the simulator</br> its not possible to fire the transition</html>"); | 324 | JOptionPane.showMessageDialog(CreateGui.getApp(), "<html>Due to the limit of only five decimal points in the simulator</br> its not possible to fire the transition</html>"); |
4136 | 336 | } else { | 325 | } else { |
4137 | 337 | BigDecimal delay = tab.getDelayEnabledTransitionControl().getDelayMode().GetDelay(transition, dInterval, delayGranularity); | 326 | BigDecimal delay = tab.getDelayEnabledTransitionControl().getDelayMode().GetDelay(transition, dInterval, delayGranularity); |
4138 | 338 | if(delay != null){ | 327 | if(delay != null){ |
4139 | 339 | if(delay.compareTo(BigDecimal.ZERO) != 0){ //Don't delay if the chosen delay is 0 | 328 | if(delay.compareTo(BigDecimal.ZERO) != 0){ //Don't delay if the chosen delay is 0 |
4140 | 340 | if(!letTimePass(delay)){ | 329 | if(!letTimePass(delay)){ |
4141 | 341 | return; | 330 | return; |
4142 | 342 | } | 331 | } |
4143 | 343 | } | 332 | } |
4144 | 344 | 333 | ||
4145 | 345 | fireTransition(transition); | 334 | fireTransition(transition); |
4146 | 346 | 335 | } | |
4147 | 347 | } | 336 | } |
4148 | 348 | } | 337 | } |
4149 | 349 | } | 338 | |
4150 | 350 | 339 | // TODO: Clean up this method | |
4151 | 351 | // TODO: Clean up this method | 340 | private void fireTransition(TimedTransition transition) { |
4152 | 352 | private void fireTransition(TimedTransition transition) { | 341 | |
4153 | 353 | 342 | if(!clearStepsForward()){ | |
4154 | 354 | if(!clearStepsForward()){ | 343 | return; |
4155 | 355 | return; | 344 | } |
4156 | 356 | } | 345 | |
4157 | 357 | 346 | Tuple<NetworkMarking, List<TimedToken>> next = null; | |
4158 | 358 | Tuple<NetworkMarking, List<TimedToken>> next = null; | 347 | List<TimedToken> tokensToConsume = null; |
4159 | 359 | List<TimedToken> tokensToConsume = null; | 348 | try{ |
4160 | 360 | 349 | if (getFiringmode() != null) { | |
4161 | 361 | try{ | 350 | next = currentMarking().fireTransition(transition, getFiringmode()); |
4162 | 362 | if (getFiringmode() != null) { | 351 | } else { |
4163 | 363 | next = currentMarking().fireTransition(transition, getFiringmode()); | 352 | tokensToConsume = getTokensToConsume(transition); |
4164 | 364 | } else { | 353 | if(tokensToConsume == null) return; // Cancelled |
4165 | 365 | tokensToConsume = getTokensToConsume(transition); | 354 | next = new Tuple<NetworkMarking, List<TimedToken>> (currentMarking().fireTransition(transition, tokensToConsume), tokensToConsume); |
4166 | 366 | if(tokensToConsume == null) return; // Cancelled | 355 | } |
4167 | 367 | next = new Tuple<NetworkMarking, List<TimedToken>> (currentMarking().fireTransition(transition, tokensToConsume), tokensToConsume); | 356 | }catch(RequireException e){ |
4168 | 368 | } | 357 | JOptionPane.showMessageDialog(CreateGui.getApp(), "There was an error firing the transition. Reason: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
4169 | 369 | }catch(RequireException e){ | 358 | return; |
4170 | 370 | JOptionPane.showMessageDialog(CreateGui.getApp(), "There was an error firing the transition. Reason: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); | 359 | } |
4171 | 371 | return; | 360 | |
4172 | 372 | } | 361 | // It is important that this comes after the above, since |
4173 | 373 | 362 | // cancelling the token selection dialogue above should not result in changes | |
4174 | 374 | // It is important that this comes after the above, since | 363 | // to the untimed animation history |
4175 | 375 | // cancelling the token selection dialogue above should not result in changes | 364 | if (isDisplayingUntimedTrace){ |
4176 | 376 | // to the untimed animation history | 365 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); |
4177 | 377 | if (isDisplayingUntimedTrace){ | 366 | if(untimedAnimationHistory.isStepForwardAllowed()){ |
4178 | 378 | AnimationHistoryList untimedAnimationHistory = tab.getUntimedAnimationHistory(); | 367 | String nextFromUntimedTrace = untimedAnimationHistory.getElement(untimedAnimationHistory.getSelectedIndex()+1); |
4179 | 379 | if(untimedAnimationHistory.isStepForwardAllowed()){ | 368 | |
4180 | 380 | String nextFromUntimedTrace = untimedAnimationHistory.getElement(untimedAnimationHistory.getSelectedIndex()+1); | 369 | if(nextFromUntimedTrace.equals(transition.model().name() + "." + transition.name()) || transition.isShared() && nextFromUntimedTrace.equals(transition.name())){ |
4181 | 381 | 370 | untimedAnimationHistory.stepForward(); | |
4182 | 382 | if(nextFromUntimedTrace.equals(transition.model().name() + "." + transition.name()) || transition.isShared() && nextFromUntimedTrace.equals(transition.name())){ | 371 | }else{ |
4183 | 383 | untimedAnimationHistory.stepForward(); | 372 | int fireTransition = JOptionPane.showConfirmDialog(CreateGui.getApp(), |
4184 | 384 | }else{ | 373 | "Are you sure you want to fire a transition which does not follow the untimed trace?\n" |
4185 | 385 | int fireTransition = JOptionPane.showConfirmDialog(CreateGui.getApp(), | 374 | + "Firing this transition will discard the untimed trace and revert to standard simulation.", |
4186 | 386 | "Are you sure you want to fire a transition which does not follow the untimed trace?\n" | 375 | "Discrading Untimed Trace", JOptionPane.YES_NO_OPTION ); |
4187 | 387 | + "Firing this transition will discard the untimed trace and revert to standard simulation.", | 376 | |
4188 | 388 | "Discrading Untimed Trace", JOptionPane.YES_NO_OPTION ); | 377 | if (fireTransition == JOptionPane.NO_OPTION){ |
4189 | 389 | 378 | return; | |
4190 | 390 | if (fireTransition == JOptionPane.NO_OPTION){ | 379 | }else{ |
4191 | 391 | return; | 380 | removeSetTrace(false); |
4192 | 392 | }else{ | 381 | } |
4193 | 393 | removeSetTrace(false); | 382 | } |
4194 | 394 | } | 383 | } |
4195 | 395 | } | 384 | } |
4196 | 396 | } | 385 | |
4197 | 397 | } | 386 | tab.network().setMarking(next.value1()); |
4198 | 398 | 387 | ||
4199 | 399 | tab.network().setMarking(next.value1()); | 388 | activeGuiModel().repaintPlaces(); |
4200 | 400 | 389 | unhighlightDisabledTransitions(); | |
4201 | 401 | activeGuiModel().repaintPlaces(); | 390 | highlightEnabledTransitions(); |
4202 | 402 | highlightEnabledTransitions(); | 391 | |
4203 | 403 | unhighlightDisabledTransitions(); | 392 | addMarking(new TAPNNetworkTimedTransitionStep(transition, next.value2()), next.value1()); |
4204 | 404 | addMarking(new TAPNNetworkTimedTransitionStep(transition, next.value2()), next.value1()); | 393 | |
4205 | 405 | 394 | updateAnimationButtonsEnabled(); | |
4206 | 406 | updateAnimationButtonsEnabled(); | 395 | updateMouseOverInformation(); |
4207 | 407 | updateMouseOverInformation(); | 396 | reportBlockingPlaces(); |
4208 | 408 | reportBlockingPlaces(); | 397 | |
4209 | 409 | 398 | } | |
4210 | 410 | } | 399 | |
4211 | 411 | 400 | public boolean letTimePass(BigDecimal delay) { | |
4212 | 412 | public boolean letTimePass(BigDecimal delay) { | 401 | |
4213 | 413 | 402 | if(!clearStepsForward()){ | |
4214 | 414 | if(!clearStepsForward()){ | 403 | return false; |
4215 | 415 | return false; | 404 | } |
4216 | 416 | } | 405 | |
4217 | 417 | 406 | boolean result = false; | |
4218 | 418 | boolean result = false; | 407 | if (delay.compareTo(new BigDecimal(0))==0 || (currentMarking().isDelayPossible(delay) && !isUrgentTransitionEnabled)) { |
4219 | 419 | if (delay.compareTo(new BigDecimal(0))==0 || (currentMarking().isDelayPossible(delay) && !isUrgentTransitionEnabled)) { | 408 | NetworkMarking delayedMarking = currentMarking().delay(delay); |
4220 | 420 | NetworkMarking delayedMarking = currentMarking().delay(delay); | 409 | tab.network().setMarking(delayedMarking); |
4221 | 421 | tab.network().setMarking(delayedMarking); | 410 | addMarking(new TAPNNetworkTimeDelayStep(delay), delayedMarking); |
4222 | 422 | addMarking(new TAPNNetworkTimeDelayStep(delay), delayedMarking); | 411 | result = true; |
4223 | 423 | result = true; | 412 | } |
4224 | 424 | } | 413 | |
4225 | 425 | 414 | activeGuiModel().repaintPlaces(); | |
4226 | 426 | activeGuiModel().repaintPlaces(); | 415 | unhighlightDisabledTransitions(); |
4227 | 427 | highlightEnabledTransitions(); | 416 | highlightEnabledTransitions(); |
4228 | 428 | unhighlightDisabledTransitions(); | 417 | |
4229 | 429 | 418 | updateAnimationButtonsEnabled(); | |
4230 | 430 | updateAnimationButtonsEnabled(); | 419 | updateMouseOverInformation(); |
4231 | 431 | updateMouseOverInformation(); | 420 | reportBlockingPlaces(); |
4232 | 432 | reportBlockingPlaces(); | 421 | return result; |
4233 | 433 | 422 | } | |
4234 | 434 | return result; | 423 | |
4235 | 435 | } | 424 | public void reportBlockingPlaces() { |
4236 | 436 | 425 | ||
4237 | 437 | public void reportBlockingPlaces(){ | 426 | try { |
4238 | 438 | 427 | BigDecimal delay = tab.getAnimationController().getCurrentDelay(); | |
4239 | 439 | try{ | 428 | |
4240 | 440 | BigDecimal delay = tab.getAnimationController().getCurrentDelay(); | 429 | if (isUrgentTransitionEnabled && !delay.equals(BigDecimal.ZERO) ) { |
4241 | 441 | if(isUrgentTransitionEnabled && delay.compareTo(new BigDecimal(0))>0){ | 430 | tab.getAnimationController().getOkButton().setEnabled(false); |
4242 | 442 | tab.getAnimationController().getOkButton().setEnabled(false); | 431 | |
4243 | 443 | StringBuilder sb = new StringBuilder(); | 432 | StringBuilder sb = new StringBuilder(); |
4244 | 444 | sb.append("<html>Time delay is disabled due to the<br /> following enabled urgent transitions:<br /><br />"); | 433 | sb.append("<html>Time delay is disabled due to the<br /> following enabled urgent transitions:<br /><br />"); |
4245 | 445 | for( Template temp : tab.activeTemplates()){ | 434 | for (Template template : tab.activeTemplates()) { |
4246 | 446 | for (Transition tempTransition : temp.guiModel().transitions()) { | 435 | for (Transition t : template.guiModel().transitions()) { |
4247 | 447 | if (tempTransition.isEnabled(true) && temp.model().getTransitionByName(tempTransition.getName()).isUrgent()) { | 436 | if (t.isTransitionEnabled() && template.model().getTransitionByName(t.getName()).isUrgent()) { |
4248 | 448 | sb.append(temp.toString() + "." + tempTransition.getName() + "<br />"); | 437 | sb.append(template.toString() + "." + t.getName() + "<br />"); |
4249 | 449 | } | 438 | } |
4250 | 450 | } | 439 | } |
4251 | 451 | } | 440 | } |
4252 | 452 | sb.append("</html>"); | 441 | sb.append("</html>"); |
4253 | 453 | tab.getAnimationController().getOkButton().setToolTipText(sb.toString()); | 442 | |
4254 | 454 | return; | 443 | tab.getAnimationController().getOkButton().setToolTipText(sb.toString()); |
4255 | 455 | } | 444 | |
4256 | 456 | if(delay.compareTo(new BigDecimal(0))<0){ | 445 | return; |
4257 | 457 | tab.getAnimationController().getOkButton().setEnabled(false); | 446 | } |
4258 | 458 | tab.getAnimationController().getOkButton().setToolTipText("Time delay is possible only for nonnegative rational numbers"); | 447 | |
4259 | 459 | } else { | 448 | if (delay.compareTo(new BigDecimal(0)) < 0) { |
4260 | 460 | List<TimedPlace> blockingPlaces = currentMarking().getBlockingPlaces(delay); | 449 | tab.getAnimationController().getOkButton().setEnabled(false); |
4261 | 461 | if(blockingPlaces.size() == 0){ | 450 | tab.getAnimationController().getOkButton().setToolTipText("Time delay is possible only for nonnegative rational numbers"); |
4262 | 462 | tab.getAnimationController().getOkButton().setEnabled(true); | 451 | } else { |
4263 | 463 | tab.getAnimationController().getOkButton().setToolTipText("Press to add the delay"); | 452 | List<TimedPlace> blockingPlaces = currentMarking().getBlockingPlaces(delay); |
4264 | 464 | } else { | 453 | if (blockingPlaces.size() == 0) { |
4265 | 465 | StringBuilder sb = new StringBuilder(); | 454 | tab.getAnimationController().getOkButton().setEnabled(true); |
4266 | 466 | sb.append("<html>Time delay of " + delay + " time unit(s) is disabled due to <br /> age invariants in the following places:<br /><br />"); | 455 | tab.getAnimationController().getOkButton().setToolTipText("Press to add the delay"); |
4267 | 467 | for (TimedPlace t :blockingPlaces){ | 456 | } else { |
4268 | 468 | sb.append(t.toString() + "<br />"); | 457 | StringBuilder sb = new StringBuilder(); |
4269 | 469 | } | 458 | sb.append("<html>Time delay of " + delay + " time unit(s) is disabled due to <br /> age invariants in the following places:<br /><br />"); |
4270 | 470 | //JOptionPane.showMessageDialog(null, sb.toString()); | 459 | for (TimedPlace t : blockingPlaces) { |
4271 | 471 | sb.append("</html>"); | 460 | sb.append(t.toString() + "<br />"); |
4272 | 472 | tab.getAnimationController().getOkButton().setEnabled(false); | 461 | } |
4273 | 473 | tab.getAnimationController().getOkButton().setToolTipText(sb.toString()); | 462 | //JOptionPane.showMessageDialog(null, sb.toString()); |
4274 | 474 | } | 463 | sb.append("</html>"); |
4275 | 475 | } | 464 | tab.getAnimationController().getOkButton().setEnabled(false); |
4276 | 476 | } catch (NumberFormatException e) { | 465 | tab.getAnimationController().getOkButton().setToolTipText(sb.toString()); |
4277 | 477 | // Do nothing, invalud number | 466 | } |
4278 | 478 | } catch (ParseException e) { | 467 | } |
4279 | 479 | tab.getAnimationController().getOkButton().setEnabled(false); | 468 | } catch (ParseException | NumberFormatException e) { |
4280 | 480 | tab.getAnimationController().getOkButton().setToolTipText("The text in the input field is not a number"); | 469 | tab.getAnimationController().getOkButton().setEnabled(false); |
4281 | 481 | } | 470 | tab.getAnimationController().getOkButton().setToolTipText("The text in the input field is not a number"); |
4282 | 482 | } | 471 | } |
4283 | 483 | 472 | } | |
4284 | 484 | private DataLayer activeGuiModel() { | 473 | |
4285 | 485 | return tab.currentTemplate().guiModel(); | 474 | private DataLayer activeGuiModel() { |
4286 | 486 | } | 475 | return tab.currentTemplate().guiModel(); |
4287 | 487 | 476 | } | |
4288 | 488 | private void resethistory() { | 477 | |
4289 | 489 | actionHistory.clear(); | 478 | private void resethistory() { |
4290 | 490 | markings.clear(); | 479 | actionHistory.clear(); |
4291 | 491 | currentAction = -1; | 480 | markings.clear(); |
4292 | 492 | currentMarkingIndex = 0; | 481 | currentAction = -1; |
4293 | 493 | tab.getAnimationHistorySidePanel().reset(); | 482 | currentMarkingIndex = 0; |
4294 | 494 | if(tab.getUntimedAnimationHistory() != null){ | 483 | tab.getAnimationHistorySidePanel().reset(); |
4295 | 495 | tab.getUntimedAnimationHistory().reset(); | 484 | if(tab.getUntimedAnimationHistory() != null){ |
4296 | 496 | } | 485 | tab.getUntimedAnimationHistory().reset(); |
4297 | 497 | } | 486 | } |
4298 | 498 | 487 | } | |
4299 | 499 | public FiringMode getFiringmode() { | 488 | |
4300 | 500 | return firingmode; | 489 | public FiringMode getFiringmode() { |
4301 | 501 | } | 490 | return firingmode; |
4302 | 502 | 491 | } | |
4303 | 503 | // removes stored markings and actions from index "startWith" (included) | 492 | |
4304 | 504 | private void removeStoredActions(int startWith) { | 493 | // removes stored markings and actions from index "startWith" (included) |
4305 | 505 | int lastIndex = actionHistory.size() - 1; | 494 | private void removeStoredActions(int startWith) { |
4306 | 506 | for (int i = startWith; i <= lastIndex; i++) { | 495 | int lastIndex = actionHistory.size() - 1; |
4307 | 507 | removeLastHistoryStep(); | 496 | for (int i = startWith; i <= lastIndex; i++) { |
4308 | 508 | } | 497 | removeLastHistoryStep(); |
4309 | 509 | } | 498 | } |
4310 | 510 | 499 | } | |
4311 | 511 | private void addMarking(TAPNNetworkTraceStep action, NetworkMarking marking) { | 500 | |
4312 | 512 | if (currentAction < actionHistory.size() - 1) { | 501 | private void addMarking(TAPNNetworkTraceStep action, NetworkMarking marking) { |
4313 | 502 | if (currentAction < actionHistory.size() - 1) { | ||
4314 | 513 | removeStoredActions(currentAction + 1); | 503 | removeStoredActions(currentAction + 1); |
4315 | 514 | } | 504 | } |
4316 | 515 | 505 | ||
4331 | 516 | tab.network().setMarking(marking); | 506 | tab.network().setMarking(marking); |
4332 | 517 | tab.getAnimationHistorySidePanel().addHistoryItem(action.toString()); | 507 | tab.getAnimationHistorySidePanel().addHistoryItem(action.toString()); |
4333 | 518 | actionHistory.add(action); | 508 | actionHistory.add(action); |
4334 | 519 | markings.add(marking); | 509 | markings.add(marking); |
4335 | 520 | currentAction++; | 510 | currentAction++; |
4336 | 521 | currentMarkingIndex++; | 511 | currentMarkingIndex++; |
4337 | 522 | } | 512 | } |
4338 | 523 | 513 | ||
4339 | 524 | private void removeLastHistoryStep() { | 514 | private void removeLastHistoryStep() { |
4340 | 525 | actionHistory.remove(actionHistory.size() - 1); | 515 | actionHistory.remove(actionHistory.size() - 1); |
4341 | 526 | markings.remove(markings.size() - 1); | 516 | markings.remove(markings.size() - 1); |
4342 | 527 | } | 517 | } |
4343 | 528 | 518 | ||
4344 | 529 | //XXX: should be enum? | 519 | //XXX: should be enum? |
4345 | 530 | public static final String[] FIRINGMODES = { "Random", "Oldest", "Youngest", "Manual" }; | 520 | public static final String[] FIRINGMODES = { "Random", "Oldest", "Youngest", "Manual" }; |
4499 | 531 | public void setFiringmode(String t) { | 521 | public void setFiringmode(String t) { |
4500 | 532 | switch (t) { | 522 | switch (t) { |
4501 | 533 | case "Random": | 523 | case "Random": |
4502 | 534 | firingmode = new RandomFiringMode(); | 524 | firingmode = new RandomFiringMode(); |
4503 | 535 | break; | 525 | break; |
4504 | 536 | case "Youngest": | 526 | case "Youngest": |
4505 | 537 | firingmode = new YoungestFiringMode(); | 527 | firingmode = new YoungestFiringMode(); |
4506 | 538 | break; | 528 | break; |
4507 | 539 | case "Oldest": | 529 | case "Oldest": |
4508 | 540 | firingmode = new OldestFiringMode(); | 530 | firingmode = new OldestFiringMode(); |
4509 | 541 | break; | 531 | break; |
4510 | 542 | case "Manual": | 532 | case "Manual": |
4511 | 543 | firingmode = null; | 533 | firingmode = null; |
4512 | 544 | break; | 534 | break; |
4513 | 545 | default: | 535 | default: |
4514 | 546 | System.err | 536 | System.err |
4515 | 547 | .println("Illegal firing mode mode: " + t + " not found."); | 537 | .println("Illegal firing mode mode: " + t + " not found."); |
4516 | 548 | break; | 538 | break; |
4517 | 549 | } | 539 | } |
4518 | 550 | 540 | ||
4519 | 551 | tab.getAnimationController().updateFiringModeComboBox(); | 541 | tab.getAnimationController().updateFiringModeComboBox(); |
4520 | 552 | tab.getAnimationController().setToolTipText("Select a method for choosing tokens during transition firing"); | 542 | tab.getAnimationController().setToolTipText("Select a method for choosing tokens during transition firing"); |
4521 | 553 | } | 543 | } |
4522 | 554 | 544 | ||
4523 | 555 | enum FillListStatus{ | 545 | enum FillListStatus{ |
4524 | 556 | lessThanWeight, | 546 | lessThanWeight, |
4525 | 557 | weight, | 547 | weight, |
4526 | 558 | moreThanWeight | 548 | moreThanWeight |
4527 | 559 | } | 549 | } |
4528 | 560 | 550 | ||
4529 | 561 | //Creates a list of tokens if there is only weight tokens in each of the places | 551 | //Creates a list of tokens if there is only weight tokens in each of the places |
4530 | 562 | //Used by getTokensToConsume | 552 | //Used by getTokensToConsume |
4531 | 563 | private FillListStatus fillList(TimedTransition transition, List<TimedToken> listToFill){ | 553 | private FillListStatus fillList(TimedTransition transition, List<TimedToken> listToFill){ |
4532 | 564 | for(TimedInputArc in: transition.getInputArcs()){ | 554 | for(TimedInputArc in: transition.getInputArcs()){ |
4533 | 565 | List<TimedToken> elligibleTokens = in.getElligibleTokens(); | 555 | List<TimedToken> elligibleTokens = in.getElligibleTokens(); |
4534 | 566 | if(elligibleTokens.size() < in.getWeight().value()){ | 556 | if(elligibleTokens.size() < in.getWeight().value()){ |
4535 | 567 | return FillListStatus.lessThanWeight; | 557 | return FillListStatus.lessThanWeight; |
4536 | 568 | } else if(elligibleTokens.size() == in.getWeight().value()){ | 558 | } else if(elligibleTokens.size() == in.getWeight().value()){ |
4537 | 569 | listToFill.addAll(elligibleTokens); | 559 | listToFill.addAll(elligibleTokens); |
4538 | 570 | } else { | 560 | } else { |
4539 | 571 | return FillListStatus.moreThanWeight; | 561 | return FillListStatus.moreThanWeight; |
4540 | 572 | } | 562 | } |
4541 | 573 | } | 563 | } |
4542 | 574 | for(TransportArc in: transition.getTransportArcsGoingThrough()){ | 564 | for(TransportArc in: transition.getTransportArcsGoingThrough()){ |
4543 | 575 | List<TimedToken> elligibleTokens = in.getElligibleTokens(); | 565 | List<TimedToken> elligibleTokens = in.getElligibleTokens(); |
4544 | 576 | if(elligibleTokens.size() < in.getWeight().value()){ | 566 | if(elligibleTokens.size() < in.getWeight().value()){ |
4545 | 577 | return FillListStatus.lessThanWeight; | 567 | return FillListStatus.lessThanWeight; |
4546 | 578 | } else if(elligibleTokens.size() == in.getWeight().value()){ | 568 | } else if(elligibleTokens.size() == in.getWeight().value()){ |
4547 | 579 | listToFill.addAll(elligibleTokens); | 569 | listToFill.addAll(elligibleTokens); |
4548 | 580 | } else { | 570 | } else { |
4549 | 581 | return FillListStatus.moreThanWeight; | 571 | return FillListStatus.moreThanWeight; |
4550 | 582 | } | 572 | } |
4551 | 583 | } | 573 | } |
4552 | 584 | return FillListStatus.weight; | 574 | return FillListStatus.weight; |
4553 | 585 | } | 575 | } |
4554 | 586 | 576 | ||
4555 | 587 | private List<TimedToken> getTokensToConsume(TimedTransition transition){ | 577 | private List<TimedToken> getTokensToConsume(TimedTransition transition){ |
4556 | 588 | //If there are only "weight tokens in each place | 578 | //If there are only "weight tokens in each place |
4557 | 589 | List<TimedToken> result = new ArrayList<TimedToken>(); | 579 | List<TimedToken> result = new ArrayList<TimedToken>(); |
4558 | 590 | boolean userShouldChoose = false; | 580 | boolean userShouldChoose = false; |
4559 | 591 | if(transition.isShared()){ | 581 | if(transition.isShared()){ |
4560 | 592 | for(TimedTransition t : transition.sharedTransition().transitions()){ | 582 | for(TimedTransition t : transition.sharedTransition().transitions()){ |
4561 | 593 | FillListStatus status = fillList(t, result); | 583 | FillListStatus status = fillList(t, result); |
4562 | 594 | if(status == FillListStatus.lessThanWeight){ | 584 | if(status == FillListStatus.lessThanWeight){ |
4563 | 595 | return null; | 585 | return null; |
4564 | 596 | } else if(status == FillListStatus.moreThanWeight){ | 586 | } else if(status == FillListStatus.moreThanWeight){ |
4565 | 597 | userShouldChoose = true; | 587 | userShouldChoose = true; |
4566 | 598 | break; | 588 | break; |
4567 | 599 | } | 589 | } |
4568 | 600 | } | 590 | } |
4569 | 601 | } else { | 591 | } else { |
4570 | 602 | FillListStatus status = fillList(transition, result); | 592 | FillListStatus status = fillList(transition, result); |
4571 | 603 | if(status == FillListStatus.lessThanWeight){ | 593 | if(status == FillListStatus.lessThanWeight){ |
4572 | 604 | return null; | 594 | return null; |
4573 | 605 | } else if(status == FillListStatus.moreThanWeight){ | 595 | } else if(status == FillListStatus.moreThanWeight){ |
4574 | 606 | userShouldChoose = true; | 596 | userShouldChoose = true; |
4575 | 607 | } | 597 | } |
4576 | 608 | } | 598 | } |
4577 | 609 | 599 | ||
4578 | 610 | if (userShouldChoose){ | 600 | if (userShouldChoose){ |
4579 | 611 | return showSelectSimulatorDialogue(transition); | 601 | return showSelectSimulatorDialogue(transition); |
4580 | 612 | } else { | 602 | } else { |
4581 | 613 | return result; | 603 | return result; |
4582 | 614 | } | 604 | } |
4583 | 615 | } | 605 | } |
4584 | 616 | 606 | ||
4585 | 617 | private List<TimedToken> showSelectSimulatorDialogue(TimedTransition transition) { | 607 | private List<TimedToken> showSelectSimulatorDialogue(TimedTransition transition) { |
4586 | 618 | EscapableDialog guiDialog = new EscapableDialog(CreateGui.getApp(), "Select Tokens", true); | 608 | EscapableDialog guiDialog = new EscapableDialog(CreateGui.getApp(), "Select Tokens", true); |
4587 | 619 | 609 | ||
4588 | 620 | Container contentPane = guiDialog.getContentPane(); | 610 | Container contentPane = guiDialog.getContentPane(); |
4589 | 621 | contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); | 611 | contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); |
4590 | 622 | AnimationTokenSelectDialog animationTokenSelectDialog = new AnimationTokenSelectDialog(transition); | 612 | AnimationTokenSelectDialog animationSelectmodeDialog = new AnimationTokenSelectDialog(transition); |
4591 | 623 | contentPane.add(animationTokenSelectDialog); | 613 | contentPane.add(animationSelectmodeDialog); |
4592 | 624 | guiDialog.setResizable(true); | 614 | guiDialog.setResizable(true); |
4593 | 625 | 615 | ||
4594 | 626 | // Make window fit contents' preferred size | 616 | // Make window fit contents' preferred size |
4595 | 627 | guiDialog.pack(); | 617 | guiDialog.pack(); |
4596 | 628 | 618 | ||
4597 | 629 | // Move window to the middle of the screen | 619 | // Move window to the middle of the screen |
4598 | 630 | guiDialog.setLocationRelativeTo(null); | 620 | guiDialog.setLocationRelativeTo(null); |
4599 | 631 | guiDialog.setVisible(true); | 621 | guiDialog.setVisible(true); |
4600 | 632 | 622 | ||
4601 | 633 | return animationTokenSelectDialog.getTokens(); | 623 | return animationSelectmodeDialog.getTokens(); |
4602 | 634 | } | 624 | } |
4603 | 635 | 625 | ||
4604 | 636 | public void reset(boolean keepInitial){ | 626 | public void reset(boolean keepInitial){ |
4605 | 637 | resethistory(); | 627 | resethistory(); |
4606 | 638 | removeSetTrace(false); | 628 | removeSetTrace(false); |
4607 | 639 | if(keepInitial && initialMarking != null){ | 629 | if(keepInitial && initialMarking != null){ |
4608 | 640 | markings.add(initialMarking); | 630 | markings.add(initialMarking); |
4609 | 641 | tab.network().setMarking(initialMarking); | 631 | tab.network().setMarking(initialMarking); |
4610 | 642 | currentAction = -1; | 632 | currentAction = -1; |
4611 | 643 | updateFireableTransitions(); | 633 | updateFireableTransitions(); |
4612 | 644 | } | 634 | } |
4613 | 645 | } | 635 | } |
4614 | 646 | 636 | ||
4615 | 647 | private boolean removeSetTrace(boolean askUser){ | 637 | private boolean removeSetTrace(boolean askUser){ |
4616 | 648 | if(askUser && isShowingTrace()){ //Warn about deleting trace | 638 | if(askUser && isShowingTrace()){ //Warn about deleting trace |
4617 | 649 | int answer = JOptionPane.showConfirmDialog(CreateGui.getApp(), | 639 | int answer = JOptionPane.showConfirmDialog(CreateGui.getApp(), |
4618 | 650 | "You are about to remove the current trace.", | 640 | "You are about to remove the current trace.", |
4619 | 651 | "Removing Trace", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); | 641 | "Removing Trace", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); |
4620 | 652 | if(answer != JOptionPane.OK_OPTION) return false; | 642 | if(answer != JOptionPane.OK_OPTION) return false; |
4621 | 653 | } | 643 | } |
4622 | 654 | if(isDisplayingUntimedTrace){ | 644 | if(isDisplayingUntimedTrace){ |
4623 | 655 | tab.removeAbstractAnimationPane(); | 645 | tab.removeAbstractAnimationPane(); |
4624 | 656 | } | 646 | } |
4625 | 657 | isDisplayingUntimedTrace = false; | 647 | isDisplayingUntimedTrace = false; |
4626 | 658 | trace = null; | 648 | trace = null; |
4627 | 659 | return true; | 649 | return true; |
4628 | 660 | } | 650 | } |
4629 | 661 | 651 | ||
4630 | 662 | public TimedTAPNNetworkTrace getTrace(){ | 652 | public TimedTAPNNetworkTrace getTrace(){ |
4631 | 663 | return (TimedTAPNNetworkTrace)trace; | 653 | return (TimedTAPNNetworkTrace)trace; |
4632 | 664 | } | 654 | } |
4633 | 665 | 655 | ||
4634 | 666 | private boolean clearStepsForward(){ | 656 | private boolean clearStepsForward(){ |
4635 | 667 | boolean answer = true; | 657 | boolean answer = true; |
4636 | 668 | if(!isDisplayingUntimedTrace){ | 658 | if(!isDisplayingUntimedTrace){ |
4637 | 669 | answer = removeSetTrace(true); | 659 | answer = removeSetTrace(true); |
4638 | 670 | } | 660 | } |
4639 | 671 | if(answer){ | 661 | if(answer){ |
4640 | 672 | tab.getAnimationHistorySidePanel().clearStepsForward(); | 662 | tab.getAnimationHistorySidePanel().clearStepsForward(); |
4641 | 673 | } | 663 | } |
4642 | 674 | return answer; | 664 | return answer; |
4643 | 675 | } | 665 | } |
4644 | 676 | 666 | ||
4645 | 677 | private boolean isShowingTrace(){ | 667 | private boolean isShowingTrace(){ |
4646 | 678 | return isDisplayingUntimedTrace || trace != null; | 668 | return isDisplayingUntimedTrace || trace != null; |
4647 | 679 | } | 669 | } |
4648 | 680 | 670 | ||
4649 | 681 | public ArrayList<TAPNNetworkTraceStep> getActionHistory() { | 671 | public ArrayList<TAPNNetworkTraceStep> getActionHistory() { |
4650 | 682 | return actionHistory; | 672 | return actionHistory; |
4651 | 683 | } | 673 | } |
4652 | 684 | 674 | ||
4653 | 685 | 675 | ||
4654 | 686 | private void setEnabledStepbackwardAction(boolean b) { | 676 | private void setEnabledStepbackwardAction(boolean b) { |
4655 | 687 | stepbackwardAction.setEnabled(b); | 677 | stepbackwardAction.setEnabled(b); |
4656 | 688 | |||
4657 | 689 | } | 678 | } |
4658 | 690 | 679 | ||
4659 | 691 | private void setEnabledStepforwardAction(boolean b) { | 680 | private void setEnabledStepforwardAction(boolean b) { |
4660 | 692 | stepforwardAction.setEnabled(b); | 681 | stepforwardAction.setEnabled(b); |
4661 | 682 | } | ||
4662 | 693 | 683 | ||
4663 | 694 | } | ||
4664 | 695 | public final GuiAction stepforwardAction = CreateGui.getAppGui().stepforwardAction; | 684 | public final GuiAction stepforwardAction = CreateGui.getAppGui().stepforwardAction; |
4665 | 696 | public final GuiAction stepbackwardAction = CreateGui.getAppGui().stepbackwardAction; | 685 | public final GuiAction stepbackwardAction = CreateGui.getAppGui().stepbackwardAction; |
4666 | 697 | 686 | ||
4667 | @@ -703,8 +692,6 @@ | |||
4668 | 703 | 692 | ||
4669 | 704 | } | 693 | } |
4670 | 705 | 694 | ||
4671 | 706 | /* GUI Model / Actions helpers */ | ||
4672 | 707 | //XXX: Should be moved to animationController or similar | ||
4673 | 708 | /** | 695 | /** |
4674 | 709 | * Updates the mouseOver label showing token ages in animationmode | 696 | * Updates the mouseOver label showing token ages in animationmode |
4675 | 710 | * when a "animation" action is happening. "live updates" any mouseOver label | 697 | * when a "animation" action is happening. "live updates" any mouseOver label |
4676 | @@ -717,4 +704,5 @@ | |||
4677 | 717 | } | 704 | } |
4678 | 718 | } | 705 | } |
4679 | 719 | } | 706 | } |
4680 | 707 | |||
4681 | 720 | } | 708 | } |
4682 | 721 | 709 | ||
4683 | === modified file 'src/pipe/gui/CreateGui.java' | |||
4684 | --- src/pipe/gui/CreateGui.java 2020-05-27 13:07:27 +0000 | |||
4685 | +++ src/pipe/gui/CreateGui.java 2020-07-09 12:55:48 +0000 | |||
4686 | @@ -14,16 +14,14 @@ | |||
4687 | 14 | 14 | ||
4688 | 15 | public class CreateGui { | 15 | public class CreateGui { |
4689 | 16 | 16 | ||
4692 | 17 | private static GuiFrame appGui; | 17 | private final static GuiFrame appGui = new GuiFrame(TAPAAL.getProgramName()); |
4693 | 18 | private static GuiFrameController appGuiController; | 18 | private final static GuiFrameController appGuiController = new GuiFrameController(appGui); |
4694 | 19 | 19 | ||
4696 | 20 | private static ArrayList<TabContent> tabs = new ArrayList<TabContent>(); | 20 | private static final ArrayList<TabContent> tabs = new ArrayList<TabContent>(); |
4697 | 21 | 21 | ||
4698 | 22 | public static void init() { | 22 | public static void init() { |
4699 | 23 | appGui = new GuiFrame(TAPAAL.getProgramName()); | ||
4700 | 24 | appGuiController = new GuiFrameController(appGui); | ||
4701 | 25 | 23 | ||
4703 | 26 | if (Platform.isMac()){ | 24 | if (Platform.isMac()){ |
4704 | 27 | try { | 25 | try { |
4705 | 28 | SpecialMacHandler.postprocess(); | 26 | SpecialMacHandler.postprocess(); |
4706 | 29 | } catch (NoClassDefFoundError e) { | 27 | } catch (NoClassDefFoundError e) { |
4707 | @@ -37,8 +35,7 @@ | |||
4708 | 37 | 35 | ||
4709 | 38 | @Deprecated | 36 | @Deprecated |
4710 | 39 | public static DataLayer getModel() { | 37 | public static DataLayer getModel() { |
4713 | 40 | if (appGui==null) return null; | 38 | return getModel(appGui.getSelectedTabIndex()); |
4712 | 41 | return getModel(appGui.getSelectedTabIndex()); | ||
4714 | 42 | } | 39 | } |
4715 | 43 | 40 | ||
4716 | 44 | @Deprecated | 41 | @Deprecated |
4717 | @@ -140,4 +137,6 @@ | |||
4718 | 140 | } | 137 | } |
4719 | 141 | 138 | ||
4720 | 142 | 139 | ||
4721 | 140 | public static boolean useExtendedBounds = false; | ||
4722 | 141 | |||
4723 | 143 | } | 142 | } |
4724 | 144 | 143 | ||
4725 | === modified file 'src/pipe/gui/DelayEnabledTransitionControl.java' | |||
4726 | --- src/pipe/gui/DelayEnabledTransitionControl.java 2020-05-18 14:33:45 +0000 | |||
4727 | +++ src/pipe/gui/DelayEnabledTransitionControl.java 2020-07-09 12:55:48 +0000 | |||
4728 | @@ -30,11 +30,11 @@ | |||
4729 | 30 | private static BigDecimal defaultGranularity = new BigDecimal("0.1"); | 30 | private static BigDecimal defaultGranularity = new BigDecimal("0.1"); |
4730 | 31 | private static boolean defaultIsRandomTrasition; | 31 | private static boolean defaultIsRandomTrasition; |
4731 | 32 | 32 | ||
4737 | 33 | private JLabel precitionLabel; | 33 | private final JLabel precitionLabel; |
4738 | 34 | private JSlider delayEnabledPrecision; | 34 | private final JSlider delayEnabledPrecision; |
4739 | 35 | private JLabel delayModeLabel; | 35 | private final JLabel delayModeLabel; |
4740 | 36 | private JComboBox<DelayMode> delayMode; | 36 | private final JComboBox<DelayMode> delayMode; |
4741 | 37 | JCheckBox randomMode; | 37 | final JCheckBox randomMode = new JCheckBox("Choose next transition randomly"); |
4742 | 38 | 38 | ||
4743 | 39 | private DelayEnabledTransitionControl() { | 39 | private DelayEnabledTransitionControl() { |
4744 | 40 | super(new GridBagLayout()); | 40 | super(new GridBagLayout()); |
4745 | @@ -61,9 +61,8 @@ | |||
4746 | 61 | DelayMode[] items = {ShortestDelayMode.getInstance(), RandomDelayMode.getInstance(), ManualDelayMode.getInstance()}; | 61 | DelayMode[] items = {ShortestDelayMode.getInstance(), RandomDelayMode.getInstance(), ManualDelayMode.getInstance()}; |
4747 | 62 | delayMode = new JComboBox(items); | 62 | delayMode = new JComboBox(items); |
4748 | 63 | setDelayMode(defaultDelayMode); | 63 | setDelayMode(defaultDelayMode); |
4752 | 64 | 64 | ||
4753 | 65 | randomMode = new JCheckBox("Choose next transition randomly"); | 65 | setRandomTransitionMode(defaultIsRandomTrasition); |
4751 | 66 | setRandomTransitionMode(defaultIsRandomTrasition); | ||
4754 | 67 | 66 | ||
4755 | 68 | GridBagConstraints gbc = new GridBagConstraints(); | 67 | GridBagConstraints gbc = new GridBagConstraints(); |
4756 | 69 | gbc.gridwidth = 2; | 68 | gbc.gridwidth = 2; |
4757 | 70 | 69 | ||
4758 | === modified file 'src/pipe/gui/GuiFrame.java' | |||
4759 | --- src/pipe/gui/GuiFrame.java 2020-06-22 08:06:22 +0000 | |||
4760 | +++ src/pipe/gui/GuiFrame.java 2020-07-09 12:55:48 +0000 | |||
4761 | @@ -40,1103 +40,1175 @@ | |||
4762 | 40 | import dk.aau.cs.verification.VerifyTAPN.VerifyTAPNDiscreteVerification; | 40 | import dk.aau.cs.verification.VerifyTAPN.VerifyTAPNDiscreteVerification; |
4763 | 41 | 41 | ||
4764 | 42 | 42 | ||
4897 | 43 | public class GuiFrame extends JFrame implements GuiFrameActions, SafeGuiFrameActions { | 43 | public class GuiFrame extends JFrame implements GuiFrameActions, SafeGuiFrameActions { |
4898 | 44 | 44 | ||
4899 | 45 | // for zoom combobox and dropdown | 45 | // for zoom combobox and dropdown |
4900 | 46 | private final int[] zoomLevels = { 40, 60, 80, 100, 120, 140, 160, 180, 200, 300 }; | 46 | private final int[] zoomLevels = {40, 60, 80, 100, 120, 140, 160, 180, 200, 300}; |
4901 | 47 | 47 | ||
4902 | 48 | private String frameTitle; | 48 | private String frameTitle; |
4903 | 49 | 49 | ||
4904 | 50 | private Pipe.ElementType mode; | 50 | private Pipe.ElementType mode; |
4905 | 51 | 51 | ||
4906 | 52 | private int newNameCounter = 1; | 52 | private int newNameCounter = 1; |
4907 | 53 | 53 | ||
4908 | 54 | final MutableReference<GuiFrameControllerActions> guiFrameController = new MutableReference<>(); | 54 | final MutableReference<GuiFrameControllerActions> guiFrameController = new MutableReference<>(); |
4909 | 55 | 55 | ||
4910 | 56 | private ExtendedJTabbedPane<TabContent> appTab; | 56 | private ExtendedJTabbedPane<TabContent> appTab; |
4911 | 57 | 57 | ||
4912 | 58 | private StatusBar statusBar; | 58 | private StatusBar statusBar; |
4913 | 59 | private JMenuBar menuBar; | 59 | private JMenuBar menuBar; |
4914 | 60 | private JToolBar drawingToolBar; | 60 | private JToolBar drawingToolBar; |
4915 | 61 | private JComboBox<String> zoomComboBox; | 61 | private JComboBox<String> zoomComboBox; |
4916 | 62 | 62 | ||
4917 | 63 | private GuiAction createAction; | 63 | private static final int shortcutkey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); |
4918 | 64 | private GuiAction openAction; | 64 | |
4919 | 65 | private GuiAction closeAction; | 65 | private final GuiAction createAction = new GuiAction("New", "Create a new Petri net", KeyStroke.getKeyStroke('N', shortcutkey)) { |
4920 | 66 | private GuiAction saveAction; | 66 | public void actionPerformed(ActionEvent arg0) { |
4921 | 67 | private GuiAction saveAsAction; | 67 | guiFrameController.ifPresent(GuiFrameControllerActions::showNewPNDialog); |
4922 | 68 | private GuiAction exitAction; | 68 | } |
4923 | 69 | private GuiAction printAction; | 69 | }; |
4924 | 70 | private GuiAction importPNMLAction; | 70 | private final GuiAction openAction = new GuiAction("Open", "Open", KeyStroke.getKeyStroke('O', shortcutkey)) { |
4925 | 71 | private GuiAction importSUMOAction; | 71 | public void actionPerformed(ActionEvent arg0) { |
4926 | 72 | private GuiAction importXMLAction; | 72 | guiFrameController.ifPresent(GuiFrameControllerActions::openTAPNFile); |
4927 | 73 | private GuiAction exportPNGAction; | 73 | } |
4928 | 74 | private GuiAction exportPSAction; | 74 | }; |
4929 | 75 | private GuiAction exportToTikZAction; | 75 | private final GuiAction closeAction = new GuiAction("Close", "Close the current tab", KeyStroke.getKeyStroke('W', shortcutkey)) { |
4930 | 76 | private GuiAction exportToPNMLAction; | 76 | public void actionPerformed(ActionEvent arg0) { |
4931 | 77 | private GuiAction exportToXMLAction; | 77 | TabContent index = (TabContent) appTab.getSelectedComponent(); |
4932 | 78 | private GuiAction exportTraceAction; | 78 | guiFrameController.ifPresent(o -> o.closeTab(index)); |
4933 | 79 | private GuiAction importTraceAction; | 79 | } |
4934 | 80 | private GuiAction exportBatchAction; | 80 | }; |
4935 | 81 | 81 | private final GuiAction saveAction = new GuiAction("Save", "Save", KeyStroke.getKeyStroke('S', shortcutkey)) { | |
4936 | 82 | private GuiAction /* copyAction, cutAction, pasteAction, */undoAction, redoAction; | 82 | public void actionPerformed(ActionEvent arg0) { |
4937 | 83 | private GuiAction toggleGrid; | 83 | if (canNetBeSavedAndShowMessage()) { |
4938 | 84 | private GuiAction alignToGrid; | 84 | guiFrameController.ifPresent(GuiFrameControllerActions::save); |
4939 | 85 | private GuiAction netStatisticsAction; | 85 | } |
4940 | 86 | private GuiAction batchProcessingAction; | 86 | } |
4941 | 87 | private GuiAction engineSelectionAction; | 87 | }; |
4942 | 88 | private GuiAction clearPreferencesAction; | 88 | private final GuiAction saveAsAction = new GuiAction("Save as", "Save as...", KeyStroke.getKeyStroke('S', (shortcutkey + InputEvent.SHIFT_MASK))) { |
4943 | 89 | 89 | public void actionPerformed(ActionEvent arg0) { | |
4944 | 90 | private GuiAction verifyAction; | 90 | if (canNetBeSavedAndShowMessage()) { |
4945 | 91 | private GuiAction workflowDialogAction; | 91 | guiFrameController.ifPresent(GuiFrameControllerActions::saveAs); |
4946 | 92 | private GuiAction smartDrawAction; | 92 | } |
4947 | 93 | private GuiAction mergeComponentsDialogAction; | 93 | } |
4948 | 94 | private GuiAction stripTimeDialogAction; | 94 | }; |
4949 | 95 | 95 | private final GuiAction exitAction = new GuiAction("Exit", "Close the program", KeyStroke.getKeyStroke('Q', shortcutkey)) { | |
4950 | 96 | private GuiAction zoomOutAction; | 96 | public void actionPerformed(ActionEvent arg0) { |
4951 | 97 | private GuiAction zoomInAction; | 97 | guiFrameController.ifPresent(GuiFrameControllerActions::exit); |
4952 | 98 | private GuiAction zoomToAction; | 98 | } |
4953 | 99 | 99 | }; | |
4954 | 100 | private GuiAction incSpacingAction; | 100 | private final GuiAction printAction = new GuiAction("Print", "Print", KeyStroke.getKeyStroke('P', shortcutkey)) { |
4955 | 101 | private GuiAction decSpacingAction; | 101 | public void actionPerformed(ActionEvent arg0) { |
4956 | 102 | public GuiAction deleteAction; | 102 | Export.exportGuiView(getCurrentTab().drawingSurface(), Export.PRINTER, null); |
4957 | 103 | 103 | } | |
4958 | 104 | private GuiAction annotationAction; | 104 | }; |
4959 | 105 | private GuiAction inhibarcAction; | 105 | private final GuiAction importPNMLAction = new GuiAction("PNML untimed net", "Import an untimed net in the PNML format", KeyStroke.getKeyStroke('X', shortcutkey)) { |
4960 | 106 | private GuiAction transAction; | 106 | public void actionPerformed(ActionEvent arg0) { |
4961 | 107 | private GuiAction tokenAction; | 107 | guiFrameController.ifPresent(GuiFrameControllerActions::importPNMLFile); |
4962 | 108 | private GuiAction selectAction; | 108 | } |
4963 | 109 | private GuiAction deleteTokenAction; | 109 | }; |
4964 | 110 | private GuiAction timedPlaceAction; | 110 | private final GuiAction importSUMOAction = new GuiAction("SUMO queries (.txt)", "Import SUMO queries in a plain text format") { |
4965 | 111 | 111 | public void actionPerformed(ActionEvent arg0) { | |
4966 | 112 | private GuiAction timedArcAction; | 112 | currentTab.ifPresent(TabContentActions::importSUMOQueries); |
4967 | 113 | private GuiAction transportArcAction; | 113 | } |
4968 | 114 | 114 | }; | |
4969 | 115 | private GuiAction showTokenAgeAction; | 115 | private final GuiAction importXMLAction = new GuiAction("XML queries (.xml)", "Import MCC queries in XML format", KeyStroke.getKeyStroke('R', shortcutkey)) { |
4970 | 116 | private GuiAction showComponentsAction; | 116 | public void actionPerformed(ActionEvent arg0) { |
4971 | 117 | private GuiAction showSharedPTAction; | 117 | currentTab.ifPresent(TabContentActions::importXMLQueries); |
4972 | 118 | private GuiAction showQueriesAction; | 118 | } |
4973 | 119 | private GuiAction showConstantsAction; | 119 | }; |
4974 | 120 | private GuiAction showZeroToInfinityIntervalsAction; | 120 | private final GuiAction exportPNGAction = new GuiAction("PNG", "Export the net to PNG format", KeyStroke.getKeyStroke('G', shortcutkey)) { |
4975 | 121 | private GuiAction showEnabledTransitionsAction; | 121 | public void actionPerformed(ActionEvent arg0) { |
4976 | 122 | private GuiAction showDelayEnabledTransitionsAction; | 122 | if (canNetBeSavedAndShowMessage()) { |
4977 | 123 | private GuiAction showToolTipsAction; | 123 | Export.exportGuiView(getCurrentTab().drawingSurface(), Export.PNG, null); |
4978 | 124 | private GuiAction showAdvancedWorkspaceAction; | 124 | } |
4979 | 125 | private GuiAction showSimpleWorkspaceAction; | 125 | } |
4980 | 126 | private GuiAction saveWorkSpaceAction; | 126 | }; |
4981 | 127 | private GuiAction showAboutAction; | 127 | private final GuiAction exportPSAction = new GuiAction("PostScript", "Export the net to PostScript format", KeyStroke.getKeyStroke('T', shortcutkey)) { |
4982 | 128 | private GuiAction showHomepage; | 128 | public void actionPerformed(ActionEvent arg0) { |
4983 | 129 | private GuiAction showAskQuestionAction; | 129 | if (canNetBeSavedAndShowMessage()) { |
4984 | 130 | private GuiAction showReportBugAction; | 130 | Export.exportGuiView(getCurrentTab().drawingSurface(), Export.POSTSCRIPT, null); |
4985 | 131 | private GuiAction showFAQAction; | 131 | } |
4986 | 132 | private GuiAction checkUpdate; | 132 | } |
4987 | 133 | 133 | }; | |
4988 | 134 | 134 | private final GuiAction exportToTikZAction = new GuiAction("TikZ", "Export the net to LaTex (TikZ) format", KeyStroke.getKeyStroke('L', shortcutkey)) { | |
4989 | 135 | private GuiAction selectAllAction; | 135 | public void actionPerformed(ActionEvent arg0) { |
4990 | 136 | 136 | if (canNetBeSavedAndShowMessage()) { | |
4991 | 137 | private GuiAction startAction; | 137 | Export.exportGuiView(getCurrentTab().drawingSurface(), Export.TIKZ, getCurrentTab().drawingSurface().getGuiModel()); |
4992 | 138 | public GuiAction stepforwardAction; | 138 | } |
4993 | 139 | public GuiAction stepbackwardAction; | 139 | } |
4994 | 140 | private GuiAction timeAction; | 140 | }; |
4995 | 141 | private GuiAction delayFireAction; | 141 | private final GuiAction exportToPNMLAction = new GuiAction("PNML", "Export the net to PNML format", KeyStroke.getKeyStroke('D', shortcutkey)) { |
4996 | 142 | private GuiAction prevcomponentAction; | 142 | public void actionPerformed(ActionEvent arg0) { |
4997 | 143 | private GuiAction nextcomponentAction; | 143 | if (canNetBeSavedAndShowMessage()) { |
4998 | 144 | 144 | if (Preferences.getInstance().getShowPNMLWarning()) { | |
4999 | 145 | public enum GUIMode { | 145 | JCheckBox showAgain = new JCheckBox("Do not show this warning."); |
5000 | 146 | draw, animation, noNet | 146 | String message = "In the saved PNML all timing information will be lost\n" + |
4869 | 147 | } | ||
4870 | 148 | |||
4871 | 149 | private JCheckBoxMenuItem showZeroToInfinityIntervalsCheckBox; | ||
4872 | 150 | private JCheckBoxMenuItem showTokenAgeCheckBox; | ||
4873 | 151 | |||
4874 | 152 | private JMenu zoomMenu; | ||
4875 | 153 | |||
4876 | 154 | public GuiFrame(String title) { | ||
4877 | 155 | // HAK-arrange for frameTitle to be initialized and the default file | ||
4878 | 156 | // name to be appended to basic window title | ||
4879 | 157 | |||
4880 | 158 | frameTitle = title; | ||
4881 | 159 | setTitle(null); | ||
4882 | 160 | trySetLookAndFeel(); | ||
4883 | 161 | |||
4884 | 162 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | ||
4885 | 163 | this.setSize(screenSize.width * 80 / 100, screenSize.height * 80 / 100); | ||
4886 | 164 | this.setLocationRelativeTo(null); | ||
4887 | 165 | this.setMinimumSize(new Dimension(825, 480)); | ||
4888 | 166 | |||
4889 | 167 | setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); | ||
4890 | 168 | |||
4891 | 169 | //XXX: Moved appTab from creategui needs further refacotring | ||
4892 | 170 | //kyrke 2018-05-20 | ||
4893 | 171 | appTab = new ExtendedJTabbedPane<TabContent>() { | ||
4894 | 172 | @Override | ||
4895 | 173 | public Component generator() { | ||
4896 | 174 | return new TabComponent(this) { |
This branch fixes stuff related to drawing and animation; we should test nothing unexpected is broken.
Bugfixes:
- Clearify text in manual select token menu #1883974
- Fixed undo/redo of objects moved at differnt zoom than current
- Fixed adding arcpah point (menu or double click) at zoom differnt than 100
- Fixed an issue archpath endpoint could be moved.
Changes:
Animation:
- Updated now enabled transitions are calculated, now have one function that calculates and update components.
- Enabledness i no longer saved in TranstionComponents (dispatches to model)
- Moved code needed to setup animation from TabContent to the animation controller
- Renamed animation components to clarify behavior
-
Drawing:
- Moved drawing of place/transitions arcs and notes to new controller (CanvasController)
- Updated calulation of arc angles (between objecs) from using tan to use atan2, this also fixes an exception thrown when two objecs are very close.
- Made a number of members final
- Pushed members in Local/Shared Time Places up (to share code)
- Added a new function a add X tokens to a place (insted of having to create a new token and add them in a loop)
- Added tests for loading tokens
- Added new type GraphicalElement that is added to Canvas, for now PetriNetObject exstendes GraphicalElmenet, but then can later be split
- setNetwork in a tab is now removed an a network set via constructor
- labels Offset is not saved in unzoom coords
- arcpath poins are not created uning unzoomed coords