Merge lp:~yrke/tapaal/placetransitionobjecthandler-refactor into lp:tapaal

Proposed by Kenneth Yrke Jørgensen
Status: Merged
Approved by: Kenneth Yrke Jørgensen
Approved revision: 1031
Merged at revision: 985
Proposed branch: lp:~yrke/tapaal/placetransitionobjecthandler-refactor
Merge into: lp:tapaal
Diff against target: 3093 lines (+669/-1219)
34 files modified
src/dk/aau/cs/io/PNMLoader.java (+4/-103)
src/dk/aau/cs/io/TapnLegacyXmlLoader.java (+13/-110)
src/dk/aau/cs/io/TapnXmlLoader.java (+3/-98)
src/dk/aau/cs/verification/TAPNComposer.java (+2/-9)
src/pipe/dataLayer/DataLayer.java (+1/-1)
src/pipe/gui/DrawingSurfaceImpl.java (+132/-141)
src/pipe/gui/graphicElements/AnnotationNote.java (+25/-16)
src/pipe/gui/graphicElements/Arc.java (+33/-19)
src/pipe/gui/graphicElements/ArcPath.java (+10/-61)
src/pipe/gui/graphicElements/ArcPathPoint.java (+20/-1)
src/pipe/gui/graphicElements/NameLabel.java (+1/-15)
src/pipe/gui/graphicElements/Note.java (+0/-1)
src/pipe/gui/graphicElements/PetriNetObject.java (+80/-37)
src/pipe/gui/graphicElements/Place.java (+16/-65)
src/pipe/gui/graphicElements/PlaceTransitionObject.java (+9/-63)
src/pipe/gui/graphicElements/Transition.java (+8/-32)
src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java (+15/-5)
src/pipe/gui/graphicElements/tapn/TimedInputArcComponent.java (+23/-24)
src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java (+18/-60)
src/pipe/gui/graphicElements/tapn/TimedPlaceComponent.java (+22/-48)
src/pipe/gui/graphicElements/tapn/TimedTransitionComponent.java (+20/-16)
src/pipe/gui/graphicElements/tapn/TimedTransportArcComponent.java (+15/-36)
src/pipe/gui/handler/AnnotationNoteHandler.java (+2/-2)
src/pipe/gui/handler/ArcHandler.java (+3/-3)
src/pipe/gui/handler/ArcPathPointHandler.java (+2/-3)
src/pipe/gui/handler/NoteHandler.java (+2/-2)
src/pipe/gui/handler/PetriNetObjectHandler.java (+5/-11)
src/pipe/gui/handler/PlaceHandler.java (+10/-12)
src/pipe/gui/handler/PlaceTransitionObjectHandler.java (+165/-203)
src/pipe/gui/handler/TAPNTransitionHandler.java (+4/-9)
src/pipe/gui/handler/TimedArcHandler.java (+2/-2)
src/pipe/gui/handler/TransitionHandler.java (+2/-7)
src/pipe/gui/handler/TransportArcHandler.java (+2/-2)
src/pipe/gui/undo/DeletePetriNetObjectEdit.java (+0/-2)
To merge this branch: bzr merge lp:~yrke/tapaal/placetransitionobjecthandler-refactor
Reviewer Review Type Date Requested Status
TAPAAL Reviewers Pending
Review via email: mp+355902@code.launchpad.net

Commit message

Cleanup of the placetranistions object and handling of Mouse Events

Description of the change

Test needed: general drawing of elements and arc
Special attention to creating of transport arcs, and error handeling of this.

To post a comment you must log in.
Revision history for this message
Kenneth Yrke Jørgensen (yrke) wrote :

Branch is now ready to be merged.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dk/aau/cs/io/PNMLoader.java'
2--- src/dk/aau/cs/io/PNMLoader.java 2018-10-09 12:50:41 +0000
3+++ src/dk/aau/cs/io/PNMLoader.java 2018-10-18 13:14:57 +0000
4@@ -44,29 +44,14 @@
5 import pipe.gui.DrawingSurfaceImpl;
6 import pipe.gui.Pipe;
7 import pipe.gui.Zoomer;
8-import pipe.gui.graphicElements.ArcPathPoint;
9-import pipe.gui.graphicElements.AnnotationNote;
10 import pipe.gui.graphicElements.Arc;
11-import pipe.gui.graphicElements.Note;
12 import pipe.gui.graphicElements.PetriNetObject;
13-import pipe.gui.graphicElements.Place;
14 import pipe.gui.graphicElements.PlaceTransitionObject;
15-import pipe.gui.graphicElements.Transition;
16 import pipe.gui.graphicElements.tapn.TimedInhibitorArcComponent;
17 import pipe.gui.graphicElements.tapn.TimedInputArcComponent;
18 import pipe.gui.graphicElements.tapn.TimedOutputArcComponent;
19 import pipe.gui.graphicElements.tapn.TimedPlaceComponent;
20 import pipe.gui.graphicElements.tapn.TimedTransitionComponent;
21-import pipe.gui.graphicElements.tapn.TimedTransportArcComponent;
22-import pipe.gui.handler.AnimationHandler;
23-import pipe.gui.handler.AnnotationNoteHandler;
24-import pipe.gui.handler.ArcHandler;
25-import pipe.gui.handler.LabelHandler;
26-import pipe.gui.handler.PlaceHandler;
27-import pipe.gui.handler.TAPNTransitionHandler;
28-import pipe.gui.handler.TimedArcHandler;
29-import pipe.gui.handler.TransitionHandler;
30-import pipe.gui.handler.TransportArcHandler;
31
32 public class PNMLoader {
33
34@@ -214,8 +199,8 @@
35
36 if(isNetDrawable()){
37 //We parse the id as both the name and id as in tapaal name = id, and name/id has to be unique
38- TimedPlaceComponent placeComponent = new TimedPlaceComponent(position.getX(), position.getY(), id, id, name.point.getX(), name.point.getY(),
39- marking.marking, marking.point.x, marking.point.y, 0);
40+ TimedPlaceComponent placeComponent = new TimedPlaceComponent(position.getX(), position.getY(), id, name.point.getX(), name.point.getY(),
41+ marking.point.x, marking.point.y);
42 placeComponent.setUnderlyingPlace(place);
43 template.guiModel().addPetriNetObject(placeComponent);
44 addListeners(placeComponent, template);
45@@ -260,7 +245,7 @@
46 if(isNetDrawable()){
47 TimedTransitionComponent transitionComponent =
48 //We parse the id as both the name and id as in tapaal name = id, and name/id has to be unique
49- new TimedTransitionComponent(position.getX(), position.getY(), id, id, name.point.getX(), name.point.getY(),
50+ new TimedTransitionComponent(position.getX(), position.getY(), id, name.point.getX(), name.point.getY(),
51 true, false, 0, 0);
52 transitionComponent.setUnderlyingTransition(transition);
53 template.guiModel().addPetriNetObject(transitionComponent);
54@@ -533,90 +518,6 @@
55 }
56
57 private void addListeners(PetriNetObject newObject, Template template) {
58- if (newObject != null) {
59- if (newObject.getMouseListeners().length == 0) {
60- if (newObject instanceof Place) {
61- // XXX - kyrke
62- if (newObject instanceof TimedPlaceComponent) {
63-
64- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
65- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
66- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
67- ((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
68-
69- PlaceHandler placeHandler = new PlaceHandler(drawingSurface, (Place) newObject, template.guiModel(), template.model());
70- newObject.addMouseListener(placeHandler);
71- newObject.addMouseWheelListener(placeHandler);
72- newObject.addMouseMotionListener(placeHandler);
73- } else {
74-
75- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
76- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
77- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
78- //((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
79-
80- PlaceHandler placeHandler = new PlaceHandler(drawingSurface, (Place) newObject);
81- newObject.addMouseListener(placeHandler);
82- //newObject.addMouseWheelListener(placeHandler);
83- newObject.addMouseMotionListener(placeHandler);
84-
85- }
86- } else if (newObject instanceof Transition) {
87- TransitionHandler transitionHandler;
88- if (newObject instanceof TimedTransitionComponent) {
89- transitionHandler = new TAPNTransitionHandler(drawingSurface, (Transition) newObject, template.guiModel(), template.model());
90- } else {
91- transitionHandler = new TransitionHandler(drawingSurface, (Transition) newObject);
92- }
93-
94- LabelHandler labelHandler = new LabelHandler(((Transition) newObject).getNameLabel(), (Transition) newObject);
95- ((Transition) newObject).getNameLabel().addMouseListener(labelHandler);
96- ((Transition) newObject).getNameLabel().addMouseMotionListener(labelHandler);
97- ((Transition) newObject).getNameLabel().addMouseWheelListener(labelHandler);
98-
99- newObject.addMouseListener(transitionHandler);
100- newObject.addMouseMotionListener(transitionHandler);
101- newObject.addMouseWheelListener(transitionHandler);
102-
103- newObject.addMouseListener(new AnimationHandler());
104-
105- } else if (newObject instanceof Arc) {
106- LabelHandler labelHandler = new LabelHandler(((Arc) newObject).getNameLabel(), (Arc) newObject);
107- ((Arc) newObject).getNameLabel().addMouseListener(labelHandler);
108- ((Arc) newObject).getNameLabel().addMouseMotionListener(labelHandler);
109- ((Arc) newObject).getNameLabel().addMouseWheelListener(labelHandler);
110- /* CB - Joakim Byg add timed arcs */
111- if (newObject instanceof TimedInputArcComponent) {
112- if (newObject instanceof TimedTransportArcComponent) {
113- TransportArcHandler transportArcHandler = new TransportArcHandler(drawingSurface, (Arc) newObject);
114- newObject.addMouseListener(transportArcHandler);
115- //newObject.addMouseWheelListener(transportArcHandler);
116- newObject.addMouseMotionListener(transportArcHandler);
117- } else {
118- TimedArcHandler timedArcHandler = new TimedArcHandler(drawingSurface, (Arc) newObject);
119- newObject.addMouseListener(timedArcHandler);
120- //newObject.addMouseWheelListener(timedArcHandler);
121- newObject.addMouseMotionListener(timedArcHandler);
122- }
123- } else {
124- /* EOC */
125- ArcHandler arcHandler = new ArcHandler(drawingSurface,(Arc) newObject);
126- newObject.addMouseListener(arcHandler);
127- //newObject.addMouseWheelListener(arcHandler);
128- newObject.addMouseMotionListener(arcHandler);
129- }
130- } else if (newObject instanceof AnnotationNote) {
131- AnnotationNoteHandler noteHandler = new AnnotationNoteHandler(drawingSurface, (AnnotationNote) newObject);
132- newObject.addMouseListener(noteHandler);
133- newObject.addMouseMotionListener(noteHandler);
134- ((Note) newObject).getNote().addMouseListener(noteHandler);
135- ((Note) newObject).getNote().addMouseMotionListener(noteHandler);
136- }
137-
138- newObject.zoomUpdate(drawingSurface.getZoom());
139-
140- }
141- newObject.setGuiModel(template.guiModel());
142- }
143+ drawingSurface.addPNListeners(newObject, drawingSurface, template.guiModel());
144 }
145 }
146
147=== modified file 'src/dk/aau/cs/io/TapnLegacyXmlLoader.java'
148--- src/dk/aau/cs/io/TapnLegacyXmlLoader.java 2018-08-05 22:13:16 +0000
149+++ src/dk/aau/cs/io/TapnLegacyXmlLoader.java 2018-10-18 13:14:57 +0000
150@@ -6,9 +6,7 @@
151 import java.math.BigDecimal;
152 import java.util.ArrayList;
153 import java.util.Collection;
154-import java.util.Collections;
155 import java.util.HashMap;
156-import java.util.List;
157
158 import javax.swing.JOptionPane;
159 import javax.xml.parsers.DocumentBuilder;
160@@ -35,26 +33,15 @@
161 import pipe.gui.Zoomer;
162 import pipe.gui.graphicElements.AnnotationNote;
163 import pipe.gui.graphicElements.Arc;
164-import pipe.gui.graphicElements.Note;
165 import pipe.gui.graphicElements.PetriNetObject;
166 import pipe.gui.graphicElements.Place;
167 import pipe.gui.graphicElements.PlaceTransitionObject;
168-import pipe.gui.graphicElements.Transition;
169 import pipe.gui.graphicElements.tapn.TimedInhibitorArcComponent;
170 import pipe.gui.graphicElements.tapn.TimedInputArcComponent;
171 import pipe.gui.graphicElements.tapn.TimedOutputArcComponent;
172 import pipe.gui.graphicElements.tapn.TimedPlaceComponent;
173 import pipe.gui.graphicElements.tapn.TimedTransitionComponent;
174 import pipe.gui.graphicElements.tapn.TimedTransportArcComponent;
175-import pipe.gui.handler.AnimationHandler;
176-import pipe.gui.handler.AnnotationNoteHandler;
177-import pipe.gui.handler.ArcHandler;
178-import pipe.gui.handler.LabelHandler;
179-import pipe.gui.handler.PlaceHandler;
180-import pipe.gui.handler.TAPNTransitionHandler;
181-import pipe.gui.handler.TimedArcHandler;
182-import pipe.gui.handler.TransitionHandler;
183-import pipe.gui.handler.TransportArcHandler;
184 import pipe.gui.widgets.InclusionPlaces;
185 import dk.aau.cs.TCTL.TCTLAbstractProperty;
186 import dk.aau.cs.TCTL.Parsing.TAPAALQueryParser;
187@@ -575,7 +562,7 @@
188 TimedTransition t = new TimedTransition(nameInput);
189
190 TimedTransitionComponent transition = new TimedTransitionComponent(
191- positionXInput, positionYInput, idInput, nameInput,
192+ positionXInput, positionYInput, idInput,
193 nameOffsetXInput, nameOffsetYInput, timedTransition,
194 infiniteServer, angle, priority);
195 transition.setUnderlyingTransition(t);
196@@ -618,17 +605,17 @@
197
198 Place place = null;
199
200- if (invariant == null || invariant.equals("")) {
201- place = new Place(positionXInput, positionYInput, idInput,
202- nameInput, nameOffsetXInput, nameOffsetYInput,
203- initialMarkingInput, markingOffsetXInput,
204- markingOffsetYInput, capacityInput);
205-
206- } else {
207+// if (invariant == null || invariant.equals("")) {
208+// place = new Place(positionXInput, positionYInput, idInput,
209+// nameInput, nameOffsetXInput, nameOffsetYInput,
210+// initialMarkingInput, markingOffsetXInput,
211+// markingOffsetYInput, capacityInput);
212+//
213+// } else {
214 place = new TimedPlaceComponent(positionXInput, positionYInput,
215- idInput, nameInput, nameOffsetXInput, nameOffsetYInput,
216- initialMarkingInput, markingOffsetXInput,
217- markingOffsetYInput, capacityInput);
218+ idInput, nameOffsetXInput, nameOffsetYInput,
219+ markingOffsetXInput,
220+ markingOffsetYInput);
221
222 LocalTimedPlace p = new LocalTimedPlace(nameInput, TimeInvariant.parse(invariant, constants));
223 tapn.add(p);
224@@ -641,7 +628,7 @@
225 marking.add(new TimedToken(p, new BigDecimal(0.0)));
226 }
227 }
228- }
229+// }
230
231 private void parseAndAddArcAsOldFormat(Element inputArcElement) throws FormatException {
232 String idInput = inputArcElement.getAttribute("id");
233@@ -895,90 +882,6 @@
234 }
235
236 private void addListeners(PetriNetObject newObject) {
237- if (newObject != null) {
238- if (newObject.getMouseListeners().length == 0) {
239- if (newObject instanceof Place) {
240- // XXX - kyrke
241- if (newObject instanceof TimedPlaceComponent) {
242-
243- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
244- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
245- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
246- ((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
247-
248- PlaceHandler placeHandler = new PlaceHandler(drawingSurface, (Place) newObject, guiModel, tapn);
249- newObject.addMouseListener(placeHandler);
250- newObject.addMouseWheelListener(placeHandler);
251- newObject.addMouseMotionListener(placeHandler);
252- } else {
253-
254- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
255- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
256- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
257- //((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
258-
259- PlaceHandler placeHandler = new PlaceHandler(drawingSurface, (Place) newObject);
260- newObject.addMouseListener(placeHandler);
261- //newObject.addMouseWheelListener(placeHandler);
262- newObject.addMouseMotionListener(placeHandler);
263-
264- }
265- } else if (newObject instanceof Transition) {
266- TransitionHandler transitionHandler;
267- if (newObject instanceof TimedTransitionComponent) {
268- transitionHandler = new TAPNTransitionHandler(drawingSurface, (Transition) newObject, guiModel, tapn);
269- } else {
270- transitionHandler = new TransitionHandler(drawingSurface, (Transition) newObject);
271- }
272-
273- LabelHandler labelHandler = new LabelHandler(((Transition) newObject).getNameLabel(), (Transition) newObject);
274- ((Transition) newObject).getNameLabel().addMouseListener(labelHandler);
275- ((Transition) newObject).getNameLabel().addMouseMotionListener(labelHandler);
276- ((Transition) newObject).getNameLabel().addMouseWheelListener(labelHandler);
277-
278- newObject.addMouseListener(transitionHandler);
279- newObject.addMouseMotionListener(transitionHandler);
280- newObject.addMouseWheelListener(transitionHandler);
281-
282- newObject.addMouseListener(new AnimationHandler());
283-
284- } else if (newObject instanceof Arc) {
285- LabelHandler labelHandler = new LabelHandler(((Arc) newObject).getNameLabel(), (Arc) newObject);
286- ((Arc) newObject).getNameLabel().addMouseListener(labelHandler);
287- ((Arc) newObject).getNameLabel().addMouseMotionListener(labelHandler);
288- ((Arc) newObject).getNameLabel().addMouseWheelListener(labelHandler);
289- /* CB - Joakim Byg add timed arcs */
290- if (newObject instanceof TimedInputArcComponent) {
291- if (newObject instanceof TimedTransportArcComponent) {
292- TransportArcHandler transportArcHandler = new TransportArcHandler(drawingSurface, (Arc) newObject);
293- newObject.addMouseListener(transportArcHandler);
294- //newObject.addMouseWheelListener(transportArcHandler);
295- newObject.addMouseMotionListener(transportArcHandler);
296- } else {
297- TimedArcHandler timedArcHandler = new TimedArcHandler(drawingSurface, (Arc) newObject);
298- newObject.addMouseListener(timedArcHandler);
299- //newObject.addMouseWheelListener(timedArcHandler);
300- newObject.addMouseMotionListener(timedArcHandler);
301- }
302- } else {
303- /* EOC */
304- ArcHandler arcHandler = new ArcHandler(drawingSurface,(Arc) newObject);
305- newObject.addMouseListener(arcHandler);
306- //newObject.addMouseWheelListener(arcHandler);
307- newObject.addMouseMotionListener(arcHandler);
308- }
309- } else if (newObject instanceof AnnotationNote) {
310- AnnotationNoteHandler noteHandler = new AnnotationNoteHandler(drawingSurface, (AnnotationNote) newObject);
311- newObject.addMouseListener(noteHandler);
312- newObject.addMouseMotionListener(noteHandler);
313- ((Note) newObject).getNote().addMouseListener(noteHandler);
314- ((Note) newObject).getNote().addMouseMotionListener(noteHandler);
315- }
316-
317- newObject.zoomUpdate(drawingSurface.getZoom());
318-
319- }
320- newObject.setGuiModel(guiModel);
321- }
322+ drawingSurface.addPNListeners(newObject, drawingSurface, guiModel);
323 }
324 }
325
326=== modified file 'src/dk/aau/cs/io/TapnXmlLoader.java'
327--- src/dk/aau/cs/io/TapnXmlLoader.java 2018-08-05 22:13:16 +0000
328+++ src/dk/aau/cs/io/TapnXmlLoader.java 2018-10-18 13:14:57 +0000
329@@ -29,26 +29,15 @@
330 import pipe.gui.Zoomer;
331 import pipe.gui.graphicElements.AnnotationNote;
332 import pipe.gui.graphicElements.Arc;
333-import pipe.gui.graphicElements.Note;
334 import pipe.gui.graphicElements.PetriNetObject;
335 import pipe.gui.graphicElements.Place;
336 import pipe.gui.graphicElements.PlaceTransitionObject;
337-import pipe.gui.graphicElements.Transition;
338 import pipe.gui.graphicElements.tapn.TimedInhibitorArcComponent;
339 import pipe.gui.graphicElements.tapn.TimedInputArcComponent;
340 import pipe.gui.graphicElements.tapn.TimedOutputArcComponent;
341 import pipe.gui.graphicElements.tapn.TimedPlaceComponent;
342 import pipe.gui.graphicElements.tapn.TimedTransitionComponent;
343 import pipe.gui.graphicElements.tapn.TimedTransportArcComponent;
344-import pipe.gui.handler.AnimationHandler;
345-import pipe.gui.handler.AnnotationNoteHandler;
346-import pipe.gui.handler.ArcHandler;
347-import pipe.gui.handler.LabelHandler;
348-import pipe.gui.handler.PlaceHandler;
349-import pipe.gui.handler.TAPNTransitionHandler;
350-import pipe.gui.handler.TimedArcHandler;
351-import pipe.gui.handler.TransitionHandler;
352-import pipe.gui.handler.TransportArcHandler;
353 import dk.aau.cs.gui.NameGenerator;
354 import dk.aau.cs.io.queries.TAPNQueryLoader;
355 import dk.aau.cs.model.tapn.Constant;
356@@ -405,7 +394,7 @@
357 }
358 nameGenerator.updateIndicesForAllModels(nameInput);
359 TimedTransitionComponent transitionComponent = new TimedTransitionComponent(
360- positionXInput, positionYInput, idInput, nameInput,
361+ positionXInput, positionYInput, idInput,
362 nameOffsetXInput, nameOffsetYInput, true,
363 infiniteServer, angle, priority);
364 transitionComponent.setUnderlyingTransition(t);
365@@ -462,7 +451,7 @@
366 }
367 }
368 nameGenerator.updateIndicesForAllModels(nameInput);
369- TimedPlaceComponent placeComponent = new TimedPlaceComponent(positionXInput, positionYInput, idInput, nameInput, nameOffsetXInput, nameOffsetYInput, initialMarkingInput, markingOffsetXInput, markingOffsetYInput, 0);
370+ TimedPlaceComponent placeComponent = new TimedPlaceComponent(positionXInput, positionYInput, idInput, nameOffsetXInput, nameOffsetYInput, markingOffsetXInput, markingOffsetYInput);
371 placeComponent.setUnderlyingPlace(p);
372
373 if (!displayName){
374@@ -743,90 +732,6 @@
375 }
376
377 private void addListeners(PetriNetObject newObject, Template template) {
378- if (newObject != null) {
379- if (newObject.getMouseListeners().length == 0) {
380- if (newObject instanceof Place) {
381- // XXX - kyrke
382- if (newObject instanceof TimedPlaceComponent) {
383-
384- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
385- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
386- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
387- ((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
388-
389- PlaceHandler placeHandler = new PlaceHandler(drawingSurface, (Place) newObject, template.guiModel(), template.model());
390- newObject.addMouseListener(placeHandler);
391- newObject.addMouseWheelListener(placeHandler);
392- newObject.addMouseMotionListener(placeHandler);
393- } else {
394-
395- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
396- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
397- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
398- //((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
399-
400- PlaceHandler placeHandler = new PlaceHandler(drawingSurface, (Place) newObject);
401- newObject.addMouseListener(placeHandler);
402- //newObject.addMouseWheelListener(placeHandler);
403- newObject.addMouseMotionListener(placeHandler);
404-
405- }
406- } else if (newObject instanceof Transition) {
407- TransitionHandler transitionHandler;
408- if (newObject instanceof TimedTransitionComponent) {
409- transitionHandler = new TAPNTransitionHandler(drawingSurface, (Transition) newObject, template.guiModel(), template.model());
410- } else {
411- transitionHandler = new TransitionHandler(drawingSurface, (Transition) newObject);
412- }
413-
414- LabelHandler labelHandler = new LabelHandler(((Transition) newObject).getNameLabel(), (Transition) newObject);
415- ((Transition) newObject).getNameLabel().addMouseListener(labelHandler);
416- ((Transition) newObject).getNameLabel().addMouseMotionListener(labelHandler);
417- ((Transition) newObject).getNameLabel().addMouseWheelListener(labelHandler);
418-
419- newObject.addMouseListener(transitionHandler);
420- newObject.addMouseMotionListener(transitionHandler);
421- newObject.addMouseWheelListener(transitionHandler);
422-
423- newObject.addMouseListener(new AnimationHandler());
424-
425- } else if (newObject instanceof Arc) {
426- LabelHandler labelHandler = new LabelHandler(((Arc) newObject).getNameLabel(), (Arc) newObject);
427- ((Arc) newObject).getNameLabel().addMouseListener(labelHandler);
428- ((Arc) newObject).getNameLabel().addMouseMotionListener(labelHandler);
429- ((Arc) newObject).getNameLabel().addMouseWheelListener(labelHandler);
430- /* CB - Joakim Byg add timed arcs */
431- if (newObject instanceof TimedInputArcComponent) {
432- if (newObject instanceof TimedTransportArcComponent) {
433- TransportArcHandler transportArcHandler = new TransportArcHandler(drawingSurface, (Arc) newObject);
434- newObject.addMouseListener(transportArcHandler);
435- //newObject.addMouseWheelListener(transportArcHandler);
436- newObject.addMouseMotionListener(transportArcHandler);
437- } else {
438- TimedArcHandler timedArcHandler = new TimedArcHandler(drawingSurface, (Arc) newObject);
439- newObject.addMouseListener(timedArcHandler);
440- //newObject.addMouseWheelListener(timedArcHandler);
441- newObject.addMouseMotionListener(timedArcHandler);
442- }
443- } else {
444- /* EOC */
445- ArcHandler arcHandler = new ArcHandler(drawingSurface,(Arc) newObject);
446- newObject.addMouseListener(arcHandler);
447- //newObject.addMouseWheelListener(arcHandler);
448- newObject.addMouseMotionListener(arcHandler);
449- }
450- } else if (newObject instanceof AnnotationNote) {
451- AnnotationNoteHandler noteHandler = new AnnotationNoteHandler(drawingSurface, (AnnotationNote) newObject);
452- newObject.addMouseListener(noteHandler);
453- newObject.addMouseMotionListener(noteHandler);
454- ((Note) newObject).getNote().addMouseListener(noteHandler);
455- ((Note) newObject).getNote().addMouseMotionListener(noteHandler);
456- }
457-
458- newObject.zoomUpdate(drawingSurface.getZoom());
459-
460- }
461- newObject.setGuiModel(template.guiModel());
462- }
463+ drawingSurface.addPNListeners(newObject, drawingSurface, template.guiModel());
464 }
465 }
466
467=== modified file 'src/dk/aau/cs/verification/TAPNComposer.java'
468--- src/dk/aau/cs/verification/TAPNComposer.java 2018-05-13 19:54:55 +0000
469+++ src/dk/aau/cs/verification/TAPNComposer.java 2018-10-18 13:14:57 +0000
470@@ -185,13 +185,10 @@
471 oldPlace.getPositionX(),
472 oldPlace.getPositionY(),
473 oldPlace.getId(),
474- uniquePlaceName,
475 oldPlace.getNameOffsetX(),
476 oldPlace.getNameOffsetY(),
477- 0,
478 oldPlace.getMarkingOffsetXObject().doubleValue(),
479- oldPlace.getMarkingOffsetYObject().doubleValue(),
480- 0
481+ oldPlace.getMarkingOffsetYObject().doubleValue()
482 );
483 newPlace.setGuiModel(guiModel);
484 newPlace.setUnderlyingPlace(constructedPlace);
485@@ -238,13 +235,10 @@
486 oldPlace.getPositionX() + offset.value1() * greatestWidth,
487 oldPlace.getPositionY() + offset.value2() * greatestHeight,
488 oldPlace.getId(),
489- uniquePlaceName,
490 oldPlace.getNameOffsetX(),
491 oldPlace.getNameOffsetY(),
492- 0,
493 oldPlace.getMarkingOffsetXObject().doubleValue(),
494- oldPlace.getMarkingOffsetYObject().doubleValue(),
495- 0
496+ oldPlace.getMarkingOffsetYObject().doubleValue()
497 );
498 newPlace.setGuiModel(guiModel);
499 newPlace.setUnderlyingPlace(place);
500@@ -295,7 +289,6 @@
501 oldTransition.getPositionX() + offset.value1() * greatestWidth,
502 oldTransition.getPositionY() + offset.value2() * greatestHeight,
503 oldTransition.getId(),
504- uniqueTransitionName,
505 oldTransition.getNameOffsetX(),
506 oldTransition.getNameOffsetY(),
507 true,
508
509=== modified file 'src/pipe/dataLayer/DataLayer.java'
510--- src/pipe/dataLayer/DataLayer.java 2018-08-05 16:25:47 +0000
511+++ src/pipe/dataLayer/DataLayer.java 2018-10-18 13:14:57 +0000
512@@ -23,7 +23,7 @@
513 import dk.aau.cs.util.Require;
514
515
516-public class DataLayer implements Cloneable {
517+public class DataLayer {
518
519 /** PNML File Name */
520 public String pnmlName = null;
521
522=== modified file 'src/pipe/gui/DrawingSurfaceImpl.java'
523--- src/pipe/gui/DrawingSurfaceImpl.java 2018-08-13 09:38:20 +0000
524+++ src/pipe/gui/DrawingSurfaceImpl.java 2018-10-18 13:14:57 +0000
525@@ -48,8 +48,6 @@
526
527 private static final int DRAWING_SURFACE_GROW = 100;
528
529- private AnimationHandler animationHandler = new AnimationHandler();
530-
531 private SelectionManager selection;
532 private UndoManager undoManager;
533 private ArrayList<PetriNetObject> petriNetObjects = new ArrayList<PetriNetObject>();
534@@ -129,98 +127,99 @@
535
536 }
537
538+
539+ //XXX: KYRKE 2018-09-06: Code moved here, as duplicated several places in net loaders, tmp solution, untill
540+ //XXX handlers are handled better.
541+ public static void addPNListeners(PetriNetObject newObject, DrawingSurfaceImpl drawingSurface, DataLayer guiModel) {
542+
543+ if (newObject != null) {
544+
545+ //XXX 2018-09-06 temp solution while we are moving creation of handlers to the objects
546+ if(newObject.getMouseHandler() != null) {
547+ drawingSurface.add(newObject);
548+ }else {
549+ throw new RuntimeException("This code should never be called");
550+
551+// //if (newObject.getMouseListeners().length == 0) {
552+// if (newObject instanceof Place) {
553+// // XXX - kyrke
554+// if (newObject instanceof TimedPlaceComponent) {
555+//
556+// PlaceHandler placeHandler = new PlaceHandler((Place) newObject);
557+// newObject.addMouseListener(placeHandler);
558+// newObject.addMouseWheelListener(placeHandler);
559+// newObject.addMouseMotionListener(placeHandler);
560+// drawingSurface.add(newObject);
561+//
562+// } else {
563+//
564+// PlaceHandler placeHandler = new PlaceHandler((Place) newObject);
565+// newObject.addMouseListener(placeHandler);
566+// newObject.addMouseWheelListener(placeHandler);
567+// newObject.addMouseMotionListener(placeHandler);
568+// drawingSurface.add(newObject);
569+//
570+// }
571+// } else if (newObject instanceof Transition) {
572+// TransitionHandler transitionHandler;
573+// if (newObject instanceof TimedTransitionComponent) {
574+// transitionHandler = new TAPNTransitionHandler((Transition) newObject);
575+// } else {
576+// transitionHandler = new TransitionHandler((Transition) newObject);
577+// }
578+//
579+// newObject.addMouseListener(transitionHandler);
580+// newObject.addMouseMotionListener(transitionHandler);
581+// newObject.addMouseWheelListener(transitionHandler);
582+//
583+// newObject.addMouseListener(new AnimationHandler());
584+//
585+// drawingSurface.add(newObject);
586+// } else if (newObject instanceof Arc) {
587+// drawingSurface.add(newObject);
588+//
589+// /* CB - Joakim Byg add timed arcs */
590+// if (newObject instanceof TimedInputArcComponent) {
591+// if (newObject instanceof TimedTransportArcComponent) {
592+// TransportArcHandler transportArcHandler = new TransportArcHandler((Arc) newObject);
593+// newObject.addMouseListener(transportArcHandler);
594+// newObject.addMouseWheelListener(transportArcHandler);
595+// newObject.addMouseMotionListener(transportArcHandler);
596+// } else {
597+// TimedArcHandler timedArcHandler = new TimedArcHandler((Arc) newObject);
598+// newObject.addMouseListener(timedArcHandler);
599+// newObject.addMouseWheelListener(timedArcHandler);
600+// newObject.addMouseMotionListener(timedArcHandler);
601+// }
602+// } else {
603+// /* EOC */
604+// ArcHandler arcHandler = new ArcHandler((Arc) newObject);
605+// newObject.addMouseListener(arcHandler);
606+// newObject.addMouseWheelListener(arcHandler);
607+// newObject.addMouseMotionListener(arcHandler);
608+// }
609+// } else if (newObject instanceof AnnotationNote) {
610+// drawingSurface.add(newObject);
611+// AnnotationNoteHandler noteHandler = new AnnotationNoteHandler((AnnotationNote) newObject);
612+// newObject.addMouseListener(noteHandler);
613+// newObject.addMouseMotionListener(noteHandler);
614+// ((Note) newObject).getNote().addMouseListener(noteHandler);
615+// ((Note) newObject).getNote().addMouseMotionListener(noteHandler);
616+// }
617+//
618+// newObject.zoomUpdate(drawingSurface.getZoom());
619+
620+ }
621+
622+ newObject.setGuiModel(guiModel);
623+ //}
624+ }
625+
626+
627+ }
628+
629 public void addNewPetriNetObject(PetriNetObject newObject) {
630- if (newObject != null) {
631- if (newObject.getMouseListeners().length == 0) {
632- if (newObject instanceof Place) {
633- // XXX - kyrke
634- if (newObject instanceof TimedPlaceComponent) {
635-
636- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
637- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
638- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
639- ((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
640-
641- PlaceHandler placeHandler = new PlaceHandler(this,(Place) newObject, this.guiModel, this.model);
642- newObject.addMouseListener(placeHandler);
643- newObject.addMouseWheelListener(placeHandler);
644- newObject.addMouseMotionListener(placeHandler);
645- add(newObject);
646-
647- } else {
648-
649- LabelHandler labelHandler = new LabelHandler(((Place) newObject).getNameLabel(), (Place) newObject);
650- ((Place) newObject).getNameLabel().addMouseListener(labelHandler);
651- ((Place) newObject).getNameLabel().addMouseMotionListener(labelHandler);
652- //((Place) newObject).getNameLabel().addMouseWheelListener(labelHandler);
653-
654- PlaceHandler placeHandler = new PlaceHandler(this, (Place) newObject);
655- newObject.addMouseListener(placeHandler);
656- //newObject.addMouseWheelListener(placeHandler);
657- newObject.addMouseMotionListener(placeHandler);
658- add(newObject);
659-
660- }
661- } else if (newObject instanceof Transition) {
662- TransitionHandler transitionHandler;
663- if (newObject instanceof TimedTransitionComponent) {
664- transitionHandler = new TAPNTransitionHandler(this, (Transition) newObject, guiModel, model);
665- } else {
666- transitionHandler = new TransitionHandler(this, (Transition) newObject);
667- }
668-
669- LabelHandler labelHandler = new LabelHandler(((Transition) newObject).getNameLabel(),(Transition) newObject);
670- ((Transition) newObject).getNameLabel().addMouseListener(labelHandler);
671- ((Transition) newObject).getNameLabel().addMouseMotionListener(labelHandler);
672- ((Transition) newObject).getNameLabel().addMouseWheelListener(labelHandler);
673-
674- newObject.addMouseListener(transitionHandler);
675- newObject.addMouseMotionListener(transitionHandler);
676- newObject.addMouseWheelListener(transitionHandler);
677-
678- newObject.addMouseListener(animationHandler);
679-
680- add(newObject);
681- } else if (newObject instanceof Arc) {
682- add(newObject);
683- LabelHandler labelHandler = new LabelHandler(((Arc) newObject).getNameLabel(), (Arc) newObject);
684- ((Arc) newObject).getNameLabel().addMouseListener(labelHandler);
685- ((Arc) newObject).getNameLabel().addMouseMotionListener(labelHandler);
686- ((Arc) newObject).getNameLabel().addMouseWheelListener(labelHandler);
687- /* CB - Joakim Byg add timed arcs */
688- if (newObject instanceof TimedInputArcComponent) {
689- if (newObject instanceof TimedTransportArcComponent) {
690- TransportArcHandler transportArcHandler = new TransportArcHandler(this, (Arc) newObject);
691- newObject.addMouseListener(transportArcHandler);
692- //newObject.addMouseWheelListener(transportArcHandler);
693- newObject.addMouseMotionListener(transportArcHandler);
694- } else {
695- TimedArcHandler timedArcHandler = new TimedArcHandler(this, (Arc) newObject);
696- newObject.addMouseListener(timedArcHandler);
697- //newObject.addMouseWheelListener(timedArcHandler);
698- newObject.addMouseMotionListener(timedArcHandler);
699- }
700- } else {
701- /* EOC */
702- ArcHandler arcHandler = new ArcHandler(this,(Arc) newObject);
703- newObject.addMouseListener(arcHandler);
704- //newObject.addMouseWheelListener(arcHandler);
705- newObject.addMouseMotionListener(arcHandler);
706- }
707- } else if (newObject instanceof AnnotationNote) {
708- add(newObject);
709- AnnotationNoteHandler noteHandler = new AnnotationNoteHandler(this, (AnnotationNote) newObject);
710- newObject.addMouseListener(noteHandler);
711- newObject.addMouseMotionListener(noteHandler);
712- ((Note) newObject).getNote().addMouseListener(noteHandler);
713- ((Note) newObject).getNote().addMouseMotionListener(noteHandler);
714- }
715-
716- newObject.zoomUpdate(getZoom());
717-
718- }
719- newObject.setGuiModel(guiModel);
720- }
721+ addPNListeners(newObject, this, guiModel);
722 validate();
723 repaint();
724 }
725@@ -531,14 +530,14 @@
726 return p;
727 }
728
729- private PlaceTransitionObject newPlace(Point p) {
730- p = adjustPoint(p, view.getZoom());
731-
732- pnObject = new Place(Grid.getModifiedX(p.x), Grid.getModifiedY(p.y));
733- guiModel.addPetriNetObject(pnObject);
734- view.addNewPetriNetObject(pnObject);
735- return (PlaceTransitionObject) pnObject;
736- }
737+// private PlaceTransitionObject newPlace(Point p) {
738+// p = adjustPoint(p, view.getZoom());
739+//
740+// pnObject = new Place(Grid.getModifiedX(p.x), Grid.getModifiedY(p.y));
741+// guiModel.addPetriNetObject(pnObject);
742+// view.addNewPetriNetObject(pnObject);
743+// return (PlaceTransitionObject) pnObject;
744+// }
745
746 private PlaceTransitionObject newTimedPlace(Point p) {
747 p = adjustPoint(p, view.getZoom());
748@@ -551,7 +550,7 @@
749 return (PlaceTransitionObject) pnObject;
750 }
751
752- private PlaceTransitionObject newTransition(Point p, boolean timed) {
753+/* private PlaceTransitionObject newTransition(Point p, boolean timed) {
754 p = adjustPoint(p, view.getZoom());
755
756 pnObject = new Transition(Grid.getModifiedX(p.x), Grid
757@@ -560,7 +559,7 @@
758 guiModel.addPetriNetObject(pnObject);
759 view.addNewPetriNetObject(pnObject);
760 return (PlaceTransitionObject) pnObject;
761- }
762+ }*/
763
764 private PlaceTransitionObject newTAPNTransition(Point p, boolean timed) {
765 p = adjustPoint(p, view.getZoom());
766@@ -591,16 +590,17 @@
767 if (SwingUtilities.isLeftMouseButton(e)) {
768
769 Pipe.ElementType mode = app.getMode();
770+ PlaceTransitionObject pto;
771 switch (mode) {
772- case PLACE:
773- PlaceTransitionObject pto = newPlace(e.getPoint());
774- getUndoManager().addNewEdit(
775- new AddPetriNetObjectEdit(pto, view, guiModel));
776- if (e.isControlDown()) {
777- app.setMode(ElementType.FAST_TRANSITION);
778- pnObject.dispatchEvent(e);
779- }
780- break;
781+// case PLACE:
782+// PlaceTransitionObject pto = newPlace(e.getPoint());
783+// getUndoManager().addNewEdit(
784+// new AddPetriNetObjectEdit(pto, view, guiModel));
785+// if (e.isControlDown()) {
786+// app.setMode(ElementType.FAST_TRANSITION);
787+// pnObject.dispatchEvent(e);
788+// }
789+// break;
790
791 case TAPNPLACE:
792 // create place
793@@ -612,25 +612,24 @@
794 if (e.isControlDown()) {
795 // connect arc
796 app.setMode(ElementType.TAPNARC);
797- getPlaceTransitionObjectHandlerOf(pto2).mousePressed(e);
798- getPlaceTransitionObjectHandlerOf(pto2).mouseReleased(e);
799+ pto2.getMouseHandler().mousePressed(e);
800+ pto2.getMouseHandler().mouseReleased(e);
801 app.setMode(ElementType.FAST_TRANSITION);
802 // enter fast mode
803 pnObject.dispatchEvent(e);
804 }
805 break;
806
807- case IMMTRANS:
808- case TIMEDTRANS:
809- boolean timed = (mode == ElementType.TIMEDTRANS);
810- pto = newTransition(e.getPoint(), timed);
811- getUndoManager().addNewEdit(
812- new AddPetriNetObjectEdit(pto, view, guiModel));
813- if (e.isControlDown()) {
814- app.setMode(ElementType.FAST_PLACE);
815- pnObject.dispatchEvent(e);
816- }
817- break;
818+// case IMMTRANS:
819+// case TIMEDTRANS:
820+// boolean timed = (mode == ElementType.TIMEDTRANS);
821+// pto = newTransition(e.getPoint(), timed);
822+// getUndoManager().addNewEdit(new AddPetriNetObjectEdit(pto, view, guiModel));
823+// if (e.isControlDown()) {
824+// app.setMode(ElementType.FAST_PLACE);
825+// pnObject.dispatchEvent(e);
826+// }
827+// break;
828 case TAPNTRANS:
829 // create transition
830 pto = newTAPNTransition(e.getPoint());
831@@ -641,8 +640,8 @@
832 if (e.isControlDown()) {
833 // connect arc
834 app.setMode(ElementType.TAPNARC);
835- getPlaceTransitionObjectHandlerOf(pto).mousePressed(e);
836- getPlaceTransitionObjectHandlerOf(pto).mouseReleased(e);
837+ pto.getMouseHandler().mousePressed(e);
838+ pto.getMouseHandler().mouseReleased(e);
839 // enter fast mode
840 app.setMode(ElementType.FAST_PLACE);
841 pnObject.dispatchEvent(e);
842@@ -690,14 +689,14 @@
843 pto = newTAPNTransition(e.getPoint());
844 getUndoManager().addNewEdit(new AddTimedTransitionCommand((TimedTransitionComponent) pto, model, guiModel, view));
845 app.setMode(ElementType.TAPNARC);
846- getPlaceTransitionObjectHandlerOf(pto).mouseReleased(e);
847+ pto.getMouseHandler().mouseReleased(e);
848
849 if (e.isControlDown()) {
850 // connect arc
851 pnObject.dispatchEvent(e);
852 app.setMode(ElementType.TAPNARC);
853- getPlaceTransitionObjectHandlerOf(pto).mousePressed(e);
854- getPlaceTransitionObjectHandlerOf(pto).mouseReleased(e);
855+ pto.getMouseHandler().mousePressed(e);
856+ pto.getMouseHandler().mouseReleased(e);
857 // enter fast mode
858 app.setMode(ElementType.FAST_PLACE);
859 } else{
860@@ -709,14 +708,14 @@
861 PlaceTransitionObject pto3 = newTimedPlace(e.getPoint());
862 getUndoManager().addNewEdit(new AddTimedPlaceCommand((TimedPlaceComponent) pto3, model, guiModel, view));
863 app.setMode(ElementType.TAPNARC);
864- getPlaceTransitionObjectHandlerOf(pto3).mouseReleased(e);
865+ pto3.getMouseHandler().mouseReleased(e);
866
867 if (e.isControlDown()) {
868 // connect arc
869 pnObject.dispatchEvent(e);
870 app.setMode(ElementType.TAPNARC);
871- getPlaceTransitionObjectHandlerOf(pto3).mousePressed(e);
872- getPlaceTransitionObjectHandlerOf(pto3).mouseReleased(e);
873+ pto3.getMouseHandler().mousePressed(e);
874+ pto3.getMouseHandler().mouseReleased(e);
875 // enter fast mode
876 app.setMode(ElementType.FAST_TRANSITION);
877 } else{
878@@ -733,14 +732,6 @@
879 updatePreferredSize();
880 }
881
882- private MouseListener getPlaceTransitionObjectHandlerOf(PlaceTransitionObject obj){
883- for (MouseListener listener : obj.getMouseListeners()) {
884- if (listener instanceof PlaceTransitionObjectHandler)
885- return listener;
886- }
887- return null;
888- }
889-
890 private void addPoint(final Arc createArc, final MouseEvent e) {
891 int x = Grid.getModifiedX(e.getX());
892 int y = Grid.getModifiedY(e.getY());
893
894=== modified file 'src/pipe/gui/graphicElements/AnnotationNote.java'
895--- src/pipe/gui/graphicElements/AnnotationNote.java 2018-05-13 14:57:15 +0000
896+++ src/pipe/gui/graphicElements/AnnotationNote.java 2018-10-18 13:14:57 +0000
897@@ -39,20 +39,34 @@
898 super(x, y);
899 setDragPoints();
900 this.isNew = isNew;
901- }
902-
903- public AnnotationNote(String id, String text, int x, int y, boolean isNew) {
904- super(id, text, x, y);
905- this.isNew = isNew;
906- setDragPoints();
907- }
908-
909- public AnnotationNote(String text, int x, int y, int w, int h,
910- boolean border, boolean isNew) {
911+
912+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
913+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
914+ addMouseHandler();
915+ }
916+
917+ public AnnotationNote(String text, int x, int y, int w, int h, boolean border, boolean isNew) {
918 super(text, x, y, w, h, border);
919 this.isNew = isNew;
920 setDragPoints();
921- }
922+
923+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
924+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
925+ addMouseHandler();
926+ }
927+
928+ private void addMouseHandler() {
929+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
930+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
931+
932+ AnnotationNoteHandler h = new AnnotationNoteHandler(this);
933+ mouseHandler = h;
934+
935+ getNote().addMouseListener(h);
936+ getNote().addMouseMotionListener(h);
937+
938+ }
939+
940
941 private void setDragPoints() {
942 dragPoints[0] = new ResizePoint(this, ResizePoint.TOP
943@@ -332,11 +346,6 @@
944
945 public AnnotationNote copy() {
946 AnnotationNote annotation = new AnnotationNote(note.getText(), getOriginalX(), getOriginalY(), note.getWidth(), note.getHeight(), this.isShowingBorder(), isNew);
947- AnnotationNoteHandler noteHandler = new AnnotationNoteHandler((DrawingSurfaceImpl)getParent(), annotation);
948- annotation.addMouseListener(noteHandler);
949- annotation.addMouseMotionListener(noteHandler);
950- annotation.getNote().addMouseListener(noteHandler);
951- annotation.getNote().addMouseMotionListener(noteHandler);
952
953 return annotation;
954 }
955
956=== modified file 'src/pipe/gui/graphicElements/Arc.java'
957--- src/pipe/gui/graphicElements/Arc.java 2018-08-05 22:20:35 +0000
958+++ src/pipe/gui/graphicElements/Arc.java 2018-10-18 13:14:57 +0000
959@@ -11,6 +11,7 @@
960 import pipe.gui.Grid;
961 import pipe.gui.Pipe;
962 import pipe.gui.Zoomer;
963+import pipe.gui.handler.LabelHandler;
964 import pipe.gui.undo.AddArcPathPointEdit;
965 import dk.aau.cs.gui.undo.Command;
966 import dk.aau.cs.model.tapn.Weight;
967@@ -18,7 +19,7 @@
968 /**
969 Implementation of Element for drawing an arc
970 */
971-public abstract class Arc extends PetriNetObject implements Cloneable {
972+public abstract class Arc extends PetriNetObject {
973
974 private static final long serialVersionUID = 6527845538091358791L;
975
976@@ -53,10 +54,11 @@
977 id = idInput;
978 setSource(sourceInput);
979 setTarget(targetInput);
980+
981+ //XXX see comment in function
982+ setLableHandler();
983 }
984-
985- abstract public void setWeight(Weight weight);
986- abstract public Weight getWeight();
987+
988
989 /**
990 * Create Petri-Net Arc object
991@@ -67,11 +69,34 @@
992 myPath.addPoint();
993 myPath.addPoint();
994 myPath.createPath();
995+
996+ //XXX see comment in function
997+ setLableHandler();
998 }
999
1000 public Arc() {
1001 super();
1002- }
1003+
1004+ label = new NameLabel(zoom);
1005+ //XXX see comment in function
1006+ setLableHandler();
1007+ }
1008+
1009+
1010+ private void setLableHandler() {
1011+
1012+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
1013+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
1014+ LabelHandler labelHandler = new LabelHandler(this.getNameLabel(), this);
1015+
1016+ getNameLabel().addMouseListener(labelHandler);
1017+ getNameLabel().addMouseMotionListener(labelHandler);
1018+ getNameLabel().addMouseWheelListener(labelHandler);
1019+
1020+ }
1021+
1022+ abstract public void setWeight(Weight weight);
1023+ abstract public Weight getWeight();
1024
1025 /**
1026 * Set source
1027@@ -238,13 +263,9 @@
1028 public void addedToGui() {
1029 // called by GuiView / State viewer when adding component.
1030 deleted = false;
1031- markedAsDeleted = false;
1032-
1033- if (getParent() instanceof DrawingSurfaceImpl) {
1034- myPath.addPointsToGui((DrawingSurfaceImpl) getParent());
1035- } else {
1036- myPath.addPointsToGui((JLayeredPane) getParent());
1037- }
1038+
1039+ myPath.addPointsToGui((DrawingSurfaceImpl) getParent());
1040+
1041 updateArcPosition();
1042 if (getParent() != null && label.getParent() == null) {
1043 getParent().add(label);
1044@@ -343,13 +364,6 @@
1045 }
1046 }
1047
1048- /**
1049- * Method to clone an Arc object
1050- */
1051- @Override
1052- public PetriNetObject clone() {
1053- return super.clone();
1054- }
1055
1056 /**
1057 * Handles keyboard input when drawing arcs in the GUI. Keys are bound to action names,
1058
1059=== modified file 'src/pipe/gui/graphicElements/ArcPath.java'
1060--- src/pipe/gui/graphicElements/ArcPath.java 2015-11-23 17:12:41 +0000
1061+++ src/pipe/gui/graphicElements/ArcPath.java 2018-10-18 13:14:57 +0000
1062@@ -29,7 +29,7 @@
1063 *
1064 * @author Pere Bonet: modified the weight label placement
1065 */
1066-public class ArcPath implements Shape, Cloneable {
1067+public class ArcPath implements Shape {
1068
1069 private GeneralPath path = new GeneralPath();
1070 private List<ArcPathPoint> pathPoints = new ArrayList<ArcPathPoint>();
1071@@ -616,61 +616,12 @@
1072 // Nadeem 21/06/2005
1073 if (editWindow.getIndexOf(pathPoint) < 0) {
1074 editWindow.add(pathPoint);
1075-
1076- pointHandler = new ArcPathPointHandler(editWindow, pathPoint);
1077-
1078- if (pathPoint.getMouseListeners().length == 0) {
1079- pathPoint.addMouseListener(pointHandler);
1080- }
1081-
1082- if (pathPoint.getMouseMotionListeners().length == 0) {
1083- pathPoint.addMouseMotionListener(pointHandler);
1084- }
1085-
1086-// if (pathPoint.getMouseWheelListeners().length == 0) {
1087-// pathPoint.addMouseWheelListener(pointHandler);
1088-// }
1089- pathPoint.updatePointLocation();
1090- }
1091- }
1092- }
1093-
1094- public void addPointsToGui(JLayeredPane editWindow) {
1095- ArcPathPoint pathPoint;
1096- ArcPathPointHandler pointHandler;
1097-
1098- (pathPoints.get(0)).setDraggable(false);
1099- (pathPoints.get(pathPoints.size() - 1)).setDraggable(false);
1100-
1101- for (int i = 0; i < pathPoints.size(); i++) {
1102- pathPoint = pathPoints.get(i);
1103- pathPoint.setVisible(false);
1104-
1105- // Check whether the point has already been added to the gui
1106- // as addPointsToGui() may have been called after the user
1107- // split an existing point. If this is the case, we don't want
1108- // to add all the points again along with new action listeners,
1109- // we just want to add the new point.
1110- // Nadeem 21/06/2005
1111- if (editWindow.getIndexOf(pathPoint) < 0) {
1112- editWindow.add(pathPoint);
1113- pointHandler = new ArcPathPointHandler(editWindow, pathPoint);
1114-
1115- if (pathPoint.getMouseListeners().length == 0) {
1116- pathPoint.addMouseListener(pointHandler);
1117- }
1118-
1119- if (pathPoint.getMouseMotionListeners().length == 0) {
1120- pathPoint.addMouseMotionListener(pointHandler);
1121- }
1122-
1123-// if (pathPoint.getMouseWheelListeners().length == 0) {
1124-// pathPoint.addMouseWheelListener(pointHandler);
1125-// }
1126- pathPoint.updatePointLocation();
1127- }
1128- }
1129- }
1130+ pathPoint.updatePointLocation();
1131+ }
1132+ }
1133+ }
1134+
1135+
1136
1137 public void delete() { // Michael: Tells the arc points to remove themselves
1138 while (!pathPoints.isEmpty()) {
1139@@ -714,11 +665,9 @@
1140 */
1141 public void insertPoint(int index, ArcPathPoint newpoint) {
1142 pathPoints.add(index, newpoint);
1143- if (myArc.getParent() instanceof DrawingSurfaceImpl) {
1144- addPointsToGui((DrawingSurfaceImpl) myArc.getParent());
1145- } else {
1146- addPointsToGui((JLayeredPane) myArc.getParent());
1147- }
1148+
1149+ addPointsToGui((DrawingSurfaceImpl) myArc.getParent());
1150+
1151 }
1152
1153 /**
1154
1155=== modified file 'src/pipe/gui/graphicElements/ArcPathPoint.java'
1156--- src/pipe/gui/graphicElements/ArcPathPoint.java 2017-07-02 18:03:21 +0000
1157+++ src/pipe/gui/graphicElements/ArcPathPoint.java 2018-10-18 13:14:57 +0000
1158@@ -17,6 +17,8 @@
1159 import pipe.gui.DrawingSurfaceImpl;
1160 import pipe.gui.Pipe;
1161 import pipe.gui.Zoomer;
1162+import pipe.gui.handler.ArcPathPointHandler;
1163+import pipe.gui.handler.TimedArcHandler;
1164 import pipe.gui.undo.AddArcPathPointEdit;
1165 import pipe.gui.undo.ArcPathPointTypeEdit;
1166 import dk.aau.cs.gui.undo.Command;
1167@@ -43,14 +45,19 @@
1168 private boolean pointType; // STRAIGHT or CURVED
1169
1170 private ArcPathPoint() {
1171- copyPasteable = false; // we can't copy & paste indivial arc points!
1172 zoom = Pipe.ZOOM_DEFAULT;
1173+
1174+ //XXX: see note in function
1175+ addMouseHandler();
1176 }
1177
1178 public ArcPathPoint(ArcPath a) {
1179 this();
1180 myArcPath = a;
1181 setPointLocation(0, 0);
1182+
1183+ //XXX: see note in function
1184+ addMouseHandler();
1185 }
1186
1187 public ArcPathPoint(float x, float y, boolean _pointType, ArcPath a) {
1188@@ -58,11 +65,23 @@
1189 myArcPath = a;
1190 setPointLocation(x, y);
1191 pointType = _pointType;
1192+
1193+ //XXX: see note in function
1194+ addMouseHandler();
1195 }
1196
1197 public ArcPathPoint(float x, float y, boolean _pointType, ArcPath a, int zoomLevel) {
1198 this(x,y,_pointType,a);
1199 zoom = zoomLevel;
1200+
1201+ //XXX: see note in function
1202+ addMouseHandler();
1203+ }
1204+
1205+ private void addMouseHandler() {
1206+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
1207+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
1208+ mouseHandler = new ArcPathPointHandler(this);
1209 }
1210
1211 /**
1212
1213=== modified file 'src/pipe/gui/graphicElements/NameLabel.java'
1214--- src/pipe/gui/graphicElements/NameLabel.java 2015-11-15 20:31:13 +0000
1215+++ src/pipe/gui/graphicElements/NameLabel.java 2018-10-18 13:14:57 +0000
1216@@ -16,7 +16,7 @@
1217 * @version 1.0
1218 * @author Camilla Clifford
1219 */
1220-public class NameLabel extends JTextArea implements Cloneable, Translatable,
1221+public class NameLabel extends JTextArea implements Translatable,
1222 Zoomable {
1223
1224 private static final long serialVersionUID = 5167510420195429773L;
1225@@ -28,10 +28,6 @@
1226 private Font font = new Font(Pipe.LABEL_FONT, Font.BOLD,
1227 Pipe.LABEL_DEFAULT_FONT_SIZE);
1228
1229- public NameLabel() {
1230- this("");
1231- }
1232-
1233 public NameLabel(int zoom) {
1234 this("");
1235 setFont(getFont().deriveFont(Zoomer.getZoomedValue((float) Pipe.LABEL_DEFAULT_FONT_SIZE, zoom)));
1236@@ -111,16 +107,6 @@
1237 setFont(getFont().deriveFont(Zoomer.getZoomedValue((float) Pipe.LABEL_DEFAULT_FONT_SIZE, value)));
1238 updateSize();
1239 }
1240-
1241- @Override
1242- public Object clone() {
1243- try {
1244- return super.clone();
1245- } catch (CloneNotSupportedException e) {
1246- e.printStackTrace();
1247- }
1248- return null;
1249- }
1250
1251 public void displayName(boolean display){
1252 if(display && name != null && text != null){
1253
1254=== modified file 'src/pipe/gui/graphicElements/Note.java'
1255--- src/pipe/gui/graphicElements/Note.java 2018-05-13 14:57:15 +0000
1256+++ src/pipe/gui/graphicElements/Note.java 2018-10-18 13:14:57 +0000
1257@@ -182,7 +182,6 @@
1258 @Override
1259 public void addedToGui() {
1260 if (CreateGui.getDrawingSurface() != null) {
1261- markedAsDeleted = false;
1262 deleted = false;
1263 updateBounds();
1264 // CreateGui.getDrawingSurface().setNetChanged(true);
1265
1266=== modified file 'src/pipe/gui/graphicElements/PetriNetObject.java'
1267--- src/pipe/gui/graphicElements/PetriNetObject.java 2018-08-05 22:13:16 +0000
1268+++ src/pipe/gui/graphicElements/PetriNetObject.java 2018-10-18 13:14:57 +0000
1269@@ -4,12 +4,12 @@
1270 import java.awt.Container;
1271 import java.awt.Graphics;
1272 import java.awt.Rectangle;
1273-import java.awt.event.MouseListener;
1274-import java.awt.event.MouseMotionListener;
1275+import java.awt.event.*;
1276 import java.util.EventListener;
1277
1278 import javax.swing.JComponent;
1279
1280+import dk.aau.cs.debug.Logger;
1281 import pipe.dataLayer.DataLayer;
1282 import pipe.gui.DrawingSurfaceImpl;
1283 import pipe.gui.Grid;
1284@@ -17,13 +17,13 @@
1285 import pipe.gui.Translatable;
1286 import pipe.gui.Zoomable;
1287 import pipe.gui.Zoomer;
1288+import pipe.gui.handler.PetriNetObjectHandler;
1289
1290 /**
1291 * Petri-Net Object Class
1292 * Implements things in common between all types of objects
1293 */
1294-public abstract class PetriNetObject extends JComponent implements Zoomable,
1295- Cloneable, Translatable {
1296+public abstract class PetriNetObject extends JComponent implements Zoomable, Translatable {
1297
1298 private static final long serialVersionUID = 2693171860021066729L;
1299
1300@@ -48,25 +48,91 @@
1301 protected boolean selected = false; // True if part of the current selection.
1302 protected boolean selectable = true; // True if object can be selected.
1303 protected boolean draggable = true; // True if object can be dragged.
1304- protected boolean copyPasteable = true; // True if object can be cloned.
1305 protected static boolean ignoreSelection = false;
1306 protected Rectangle bounds = new Rectangle();
1307
1308 protected boolean deleted = false;
1309- protected boolean markedAsDeleted = false;
1310
1311 // Integer value which represents a zoom percentage
1312 protected int zoom = Pipe.ZOOM_DEFAULT;
1313 private DataLayer guiModel;
1314
1315+ public PetriNetObjectHandler getMouseHandler() {
1316+ return mouseHandler;
1317+ }
1318+
1319+ protected PetriNetObjectHandler mouseHandler;
1320+
1321+ PetriNetObject() {
1322+
1323+ addMouseListener(new MouseListener() {
1324+ @Override
1325+ public void mouseClicked(MouseEvent e) {
1326+ if (mouseHandler != null) {
1327+ mouseHandler.mouseClicked(e);
1328+ }
1329+ }
1330+
1331+ @Override
1332+ public void mousePressed(MouseEvent e) {
1333+ if (mouseHandler != null) {
1334+ mouseHandler.mousePressed(e);
1335+ }
1336+ }
1337+
1338+ @Override
1339+ public void mouseReleased(MouseEvent e) {
1340+ if (mouseHandler != null) {
1341+ mouseHandler.mouseReleased(e);
1342+ }
1343+ }
1344+
1345+ @Override
1346+ public void mouseEntered(MouseEvent e) {
1347+ if (mouseHandler != null) {
1348+ mouseHandler.mouseEntered(e);
1349+ }
1350+ }
1351+
1352+ @Override
1353+ public void mouseExited(MouseEvent e) {
1354+ if (mouseHandler != null) {
1355+ mouseHandler.mouseExited(e);
1356+ }
1357+ }
1358+ });
1359+
1360+ addMouseWheelListener(new MouseWheelListener() {
1361+ @Override
1362+ public void mouseWheelMoved(MouseWheelEvent e) {
1363+ if (mouseHandler != null) {
1364+ mouseHandler.mouseWheelMoved(e);
1365+ }
1366+ }
1367+ });
1368+
1369+ addMouseMotionListener(new MouseMotionListener() {
1370+ @Override
1371+ public void mouseDragged(MouseEvent e) {
1372+ if (mouseHandler != null) {
1373+ mouseHandler.mouseDragged(e);
1374+ }
1375+ }
1376+
1377+ @Override
1378+ public void mouseMoved(MouseEvent e) {
1379+ if (mouseHandler != null) {
1380+ mouseHandler.mouseMoved(e);
1381+ }
1382+ }
1383+ });
1384+
1385+ }
1386+
1387 public void setGuiModel(DataLayer guiModel) {
1388 this.guiModel = guiModel;
1389 }
1390
1391- public DataLayer getGuiModel() {
1392- return guiModel;
1393- }
1394-
1395 public void setId(String idInput) {
1396 id = idInput;
1397 setName(idInput);
1398@@ -224,11 +290,7 @@
1399
1400
1401 public boolean isDeleted() {
1402- return deleted || markedAsDeleted;
1403- }
1404-
1405- public void markAsDeleted() {
1406- markedAsDeleted = true;
1407+ return deleted;
1408 }
1409
1410 public void select(Rectangle selectionRectangle) {
1411@@ -248,28 +310,9 @@
1412 return zoom;
1413 }
1414
1415- @Override
1416- public PetriNetObject clone() {
1417- try {
1418- PetriNetObject pnObjectCopy = (PetriNetObject) super.clone();
1419-
1420- // Remove all mouse listeners on the new object
1421- EventListener[] mouseListeners = pnObjectCopy
1422- .getListeners(MouseListener.class);
1423- for (int i = 0; i < mouseListeners.length; i++) {
1424- pnObjectCopy.removeMouseListener((MouseListener) mouseListeners[i]);
1425- }
1426-
1427- mouseListeners = pnObjectCopy.getListeners(MouseMotionListener.class);
1428-
1429- for (int i = 0; i < mouseListeners.length; i++) {
1430- pnObjectCopy.removeMouseMotionListener((MouseMotionListener) mouseListeners[i]);
1431- }
1432-
1433- return pnObjectCopy;
1434- } catch (CloneNotSupportedException e) {
1435- throw new Error(e);
1436- }
1437+ public DrawingSurfaceImpl getParent() {
1438+ return (DrawingSurfaceImpl) super.getParent();
1439 }
1440
1441+
1442 }
1443
1444=== modified file 'src/pipe/gui/graphicElements/Place.java'
1445--- src/pipe/gui/graphicElements/Place.java 2018-08-14 07:52:41 +0000
1446+++ src/pipe/gui/graphicElements/Place.java 2018-10-18 13:14:57 +0000
1447@@ -15,7 +15,7 @@
1448 /**
1449 * Class for drawing a Place
1450 */
1451-public class Place extends PlaceTransitionObject {
1452+public abstract class Place extends PlaceTransitionObject {
1453
1454 private static final long serialVersionUID = -5155964364065651381L;
1455
1456@@ -28,30 +28,29 @@
1457 // Value of the capacity restriction; 0 means no capacity restriction
1458 protected Integer capacity = 0;
1459
1460- public static final int DIAMETER = Pipe.PLACE_TRANSITION_HEIGHT;
1461+ protected static final int DIAMETER = Pipe.PLACE_TRANSITION_HEIGHT;
1462
1463 // Token Width and Height
1464- public static int tWidth = 5;
1465- public static int tHeight = 5;
1466+ protected static int tWidth = 5;
1467+ protected static int tHeight = 5;
1468
1469 // Token dot position offsets
1470- public static int tLeftX = 7;
1471- public static int tRightX = 19;
1472- public static int tTopY = 7;
1473- public static int tBotY = 19;
1474- public static int tMiddleX = 13;
1475- public static int tMiddleY = 13;
1476+ protected static int tLeftX = 7;
1477+ protected static int tRightX = 19;
1478+ protected static int tTopY = 7;
1479+ protected static int tBotY = 19;
1480+ protected static int tMiddleX = 13;
1481+ protected static int tMiddleY = 13;
1482
1483 // Ellipse2D.Double place
1484 protected static Ellipse2D.Double placeEllipse = new Ellipse2D.Double(0, 0, DIAMETER, DIAMETER);
1485 protected static Shape proximityPlace = (new BasicStroke(Pipe.PLACE_TRANSITION_PROXIMITY_RADIUS)).createStrokedShape(placeEllipse);
1486
1487 public Place(double positionXInput, double positionYInput, String idInput,
1488- String nameInput, Double nameOffsetXInput, Double nameOffsetYInput,
1489- int initialMarkingInput, double markingOffsetXInput,
1490- double markingOffsetYInput, int capacityInput) {
1491- super(positionXInput, positionYInput, idInput, nameInput,
1492- nameOffsetXInput, nameOffsetYInput);
1493+ Double nameOffsetXInput, Double nameOffsetYInput,
1494+ double markingOffsetXInput,
1495+ double markingOffsetYInput) {
1496+ super(positionXInput, positionYInput, idInput, nameOffsetXInput, nameOffsetYInput);
1497 markingOffsetX = new Double(markingOffsetXInput);
1498 markingOffsetY = new Double(markingOffsetYInput);
1499 componentWidth = DIAMETER;
1500@@ -67,36 +66,6 @@
1501 setCentre((int) positionX, (int) positionY);
1502 }
1503
1504-
1505- public Place paste(double x, double y, boolean fromAnotherView) {
1506- this.incrementCopyNumber();
1507- Place copy = new Place(Grid.getModifiedX(x + this.getX()+ Pipe.PLACE_TRANSITION_HEIGHT / 2),
1508- Grid.getModifiedY(y + this.getY() + Pipe.PLACE_TRANSITION_HEIGHT / 2));
1509- copy.pnName.setName(pnName.getName() + "(" + this.getCopyNumber() + ")");
1510- this.newCopy(copy);
1511- copy.nameOffsetX = nameOffsetX;
1512- copy.nameOffsetY = nameOffsetY;
1513- copy.capacity = capacity;
1514- copy.attributesVisible = attributesVisible;
1515- copy.markingOffsetX = markingOffsetX;
1516- copy.markingOffsetY = markingOffsetY;
1517- copy.update(true);
1518- return copy;
1519- }
1520-
1521- public Place copy() {
1522- Place copy = new Place(Zoomer.getUnzoomedValue(this.getX(), zoom), Zoomer.getUnzoomedValue(this.getY(), zoom));
1523- copy.pnName.setName(this.getName());
1524- copy.nameOffsetX = nameOffsetX;
1525- copy.nameOffsetY = nameOffsetY;
1526- copy.capacity = capacity;
1527- copy.attributesVisible = attributesVisible;
1528- copy.markingOffsetX = markingOffsetX;
1529- copy.markingOffsetY = markingOffsetY;
1530- copy.setOriginal(this);
1531- return copy;
1532- }
1533-
1534 @Override
1535 public void paintComponent(Graphics g) {
1536 super.paintComponent(g);
1537@@ -155,7 +124,7 @@
1538 double unZoomedX = Zoomer.getUnzoomedValue(x - COMPONENT_DRAW_OFFSET, zoom);
1539 double unZoomedY = Zoomer.getUnzoomedValue(y - COMPONENT_DRAW_OFFSET, zoom);
1540
1541- someArc = CreateGui.getDrawingSurface().createArc;
1542+ Arc someArc = CreateGui.getDrawingSurface().createArc;
1543 if (someArc != null) { // Must be drawing a new Arc if non-NULL.
1544 if ((proximityPlace.contains((int) unZoomedX, (int) unZoomedY) || placeEllipse
1545 .contains((int) unZoomedX, (int) unZoomedY))
1546@@ -216,11 +185,6 @@
1547 }
1548
1549 @Override
1550- public void showEditor() {
1551- throw new UnsupportedOperationException();
1552- }
1553-
1554- @Override
1555 public void update(boolean displayConstantNames) {
1556 if (attributesVisible) {
1557 pnName.setText("\nk=" + (capacity > 0 ? capacity : "\u221E"));
1558@@ -232,18 +196,5 @@
1559 repaint();
1560 }
1561
1562- @Override
1563- public Place clone() {
1564-
1565- Place toReturn = (Place) super.clone();
1566-
1567- toReturn.markingOffsetX = markingOffsetX;
1568- toReturn.markingOffsetY = markingOffsetY;
1569- toReturn.componentWidth = componentWidth;
1570- toReturn.componentHeight = componentHeight;
1571- toReturn.setCentre((int) positionX, (int) positionY);
1572-
1573- return toReturn;
1574-
1575- }
1576+
1577 }
1578
1579=== modified file 'src/pipe/gui/graphicElements/PlaceTransitionObject.java'
1580--- src/pipe/gui/graphicElements/PlaceTransitionObject.java 2018-08-14 07:52:41 +0000
1581+++ src/pipe/gui/graphicElements/PlaceTransitionObject.java 2018-10-18 13:14:57 +0000
1582@@ -9,13 +9,13 @@
1583 import pipe.gui.Grid;
1584 import pipe.gui.Pipe;
1585 import pipe.gui.Zoomer;
1586+import pipe.gui.handler.LabelHandler;
1587
1588 /**
1589 * Petri-Net Place or Transition SuperClass
1590 *
1591 */
1592-public abstract class PlaceTransitionObject extends PetriNetObject implements
1593-Cloneable {
1594+public abstract class PlaceTransitionObject extends PetriNetObject {
1595
1596 private static final long serialVersionUID = -6629006415467929184L;
1597
1598@@ -24,20 +24,12 @@
1599
1600 private LinkedList<Arc> connectTo = new LinkedList<Arc>();
1601 private LinkedList<Arc> connectFrom = new LinkedList<Arc>();
1602- protected static Arc someArc;
1603-
1604- private PlaceTransitionObject lastCopy = null;
1605- private PlaceTransitionObject original = null;
1606- private int copyNumber = 0;
1607
1608 protected boolean attributesVisible = false;
1609
1610- // The "real" x coordinate of this place or transition in the net.
1611+ // The "real" x/y coordinate of this place or transition in the net.
1612 // i.e. the x position at 100% zoom.
1613 private double locationX;
1614-
1615- // The "real" y coordinate of this place or transition in the net.
1616- // i.e. the y position at 100% zoom.
1617 private double locationY;
1618
1619 /**
1620@@ -49,15 +41,13 @@
1621 * Y-axis Position
1622 * @param idInput
1623 * Place id
1624- * @param nameInput
1625- * Name
1626 * @param nameOffsetXInput
1627 * Name X-axis Position
1628 * @param nameOffsetYInput
1629 * Name Y-axis Position
1630 */
1631 public PlaceTransitionObject(double positionXInput, double positionYInput,
1632- String idInput, String nameInput, double nameOffsetXInput,
1633+ String idInput, double nameOffsetXInput,
1634 double nameOffsetYInput) {
1635 this(positionXInput, positionYInput);
1636 id = idInput;
1637@@ -86,6 +76,10 @@
1638
1639 // sets up Namelabel for each PN object
1640 pnName = new NameLabel(zoom);
1641+ LabelHandler labelHandler = new LabelHandler(pnName, this);
1642+ getNameLabel().addMouseListener(labelHandler);
1643+ getNameLabel().addMouseMotionListener(labelHandler);
1644+ getNameLabel().addMouseWheelListener(labelHandler);
1645 }
1646
1647 /**
1648@@ -277,6 +271,7 @@
1649 public void updateConnected() {
1650 Iterator<Arc> arcsFrom = connectFrom.iterator();
1651
1652+ Arc someArc;
1653 while (arcsFrom.hasNext()) {
1654 someArc = (arcsFrom.next());
1655 updateEndPoint(someArc);
1656@@ -350,7 +345,6 @@
1657 @Override
1658 public void addedToGui() {
1659 deleted = false;
1660- markedAsDeleted = false;
1661 addLabelToContainer();
1662 update(true);
1663 updateOnMoveOrZoom();
1664@@ -389,42 +383,6 @@
1665
1666 public abstract void updateEndPoint(Arc arc);
1667
1668- public int getCopyNumber() {
1669- if (original != null) {
1670- return original.copyNumber;
1671- } else {
1672- return 0;
1673- }
1674- }
1675-
1676- public void incrementCopyNumber() {
1677- if (original != null) {
1678- original.copyNumber++;
1679- }
1680- }
1681-
1682- public void newCopy(PlaceTransitionObject ptObject) {
1683- if (original != null) {
1684- original.lastCopy = ptObject;
1685- }
1686- }
1687-
1688- public PlaceTransitionObject getLastCopy() {
1689- return lastCopy;
1690- }
1691-
1692- public void resetLastCopy() {
1693- lastCopy = null;
1694- }
1695-
1696- public void setOriginal(PlaceTransitionObject ptObject) {
1697- original = ptObject;
1698- }
1699-
1700- public PlaceTransitionObject getOriginal() {
1701- return original;
1702- }
1703-
1704 public abstract void showEditor();
1705
1706 public void setAttributesVisible(boolean flag) {
1707@@ -447,16 +405,4 @@
1708 update(true);
1709 }
1710
1711- // XXX - kyrke now also clones arcs
1712- // Clone object and deep copy the pnNames
1713- @Override
1714- public PlaceTransitionObject clone() {
1715- PlaceTransitionObject toReturn = (PlaceTransitionObject) super.clone();
1716- toReturn.pnName = (NameLabel) pnName.clone();
1717-
1718- toReturn.connectFrom = connectFrom;
1719- toReturn.connectTo = connectTo;
1720-
1721- return toReturn;
1722- }
1723 }
1724
1725=== modified file 'src/pipe/gui/graphicElements/Transition.java'
1726--- src/pipe/gui/graphicElements/Transition.java 2018-08-14 07:52:41 +0000
1727+++ src/pipe/gui/graphicElements/Transition.java 2018-10-18 13:14:57 +0000
1728@@ -27,7 +27,7 @@
1729 /**
1730 * Petri-Net Transition Class for Drawing Transitions
1731 */
1732-public class Transition extends PlaceTransitionObject {
1733+public abstract class Transition extends PlaceTransitionObject {
1734
1735 private static final long serialVersionUID = 942116302162925121L;
1736
1737@@ -36,15 +36,15 @@
1738 private Shape proximityTransition;
1739
1740 // Transition Size
1741- public static final int TRANSITION_HEIGHT = Pipe.PLACE_TRANSITION_HEIGHT;
1742- public static final int TRANSITION_WIDTH = TRANSITION_HEIGHT / 3;
1743+ protected static final int TRANSITION_HEIGHT = Pipe.PLACE_TRANSITION_HEIGHT;
1744+ protected static final int TRANSITION_WIDTH = TRANSITION_HEIGHT / 3;
1745
1746 protected int angle;
1747
1748 // Animation Suff
1749 protected boolean enabled = false;
1750- public boolean delayEnabled = false;
1751- public boolean highlighted = false;
1752+ protected boolean delayEnabled = false;
1753+ protected boolean highlighted = false;
1754 private Timer blinkTimer;
1755 private int blinkCount;
1756
1757@@ -56,11 +56,10 @@
1758 * Create Petri-Net Transition object
1759 */
1760 public Transition(double positionXInput, double positionYInput,
1761- String idInput, String nameInput, double nameOffsetXInput,
1762+ String idInput, double nameOffsetXInput,
1763 double nameOffsetYInput,
1764 boolean infServer, int angleInput, int priority) {
1765- super(positionXInput, positionYInput, idInput, nameInput,
1766- nameOffsetXInput, nameOffsetYInput);
1767+ super(positionXInput, positionYInput, idInput, nameOffsetXInput, nameOffsetYInput);
1768 componentWidth = TRANSITION_HEIGHT; // sets width
1769 componentHeight = TRANSITION_HEIGHT;// sets height
1770 constructTransition();
1771@@ -235,7 +234,7 @@
1772 double unZoomedY = (y - COMPONENT_DRAW_OFFSET)
1773 / (zoomPercentage / 100.0);
1774
1775- someArc = CreateGui.getDrawingSurface().createArc;
1776+ Arc someArc = CreateGui.getDrawingSurface().createArc;
1777 if (someArc != null) { // Must be drawing a new Arc if non-NULL.
1778 if ((proximityTransition.contains((int) unZoomedX, (int) unZoomedY) || transition
1779 .contains((int) unZoomedX, (int) unZoomedY))
1780@@ -416,11 +415,6 @@
1781 }
1782
1783 @Override
1784- public void showEditor() {
1785- throw new UnsupportedOperationException();
1786- }
1787-
1788- @Override
1789 public void update(boolean displayConstantNames) {
1790 pnName.setText(getText());
1791 pnName.zoomUpdate(zoom);
1792@@ -481,24 +475,6 @@
1793 }
1794
1795 }
1796-
1797- @Override
1798- public Transition clone() {
1799- Transition toReturn=null;
1800- toReturn = (Transition)super.clone();
1801-
1802- toReturn.positionX = positionX;
1803-
1804- toReturn.componentWidth = TRANSITION_HEIGHT; //sets width
1805- toReturn.componentHeight = TRANSITION_HEIGHT;//sets height
1806- toReturn.constructTransition();
1807- toReturn.angle = 0;
1808- toReturn.setCentre((int)positionX, (int)positionY);
1809- toReturn.rotate(getAngle());
1810- toReturn.updateBounds();
1811-
1812- return toReturn;
1813- }
1814
1815 public void blink(){
1816 if(blinkTimer == null) { initBlinkTimer(); }
1817
1818=== modified file 'src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java'
1819--- src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java 2014-06-10 16:32:25 +0000
1820+++ src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java 2018-10-18 13:14:57 +0000
1821@@ -29,14 +29,29 @@
1822
1823 public TimedInhibitorArcComponent(TimedOutputArcComponent arc) {
1824 super(arc);
1825+
1826+ //XXX: se note in funcation
1827+ addMouseHandler();
1828 }
1829
1830 public TimedInhibitorArcComponent(TimedOutputArcComponent arc, String guard) {
1831 super(arc, guard);
1832+
1833+ //XXX: se note in funcation
1834+ addMouseHandler();
1835 }
1836
1837 public TimedInhibitorArcComponent(PlaceTransitionObject source) {
1838 super(source);
1839+
1840+ //XXX: se note in funcation
1841+ addMouseHandler();
1842+ }
1843+
1844+ private void addMouseHandler() {
1845+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
1846+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
1847+ mouseHandler = new TimedArcHandler(this);
1848 }
1849
1850 public void setUnderlyingArc(TimedInhibitorArc arc) {
1851@@ -163,11 +178,6 @@
1852
1853 arc.setUnderlyingArc(tapn.getInhibitorArcFromPlaceAndTransition(tapn.getPlaceByName(inhibitorArc.source().name()), tapn.getTransitionByName(inhibitorArc.destination().name())));
1854
1855- TimedArcHandler timedArcHandler = new TimedArcHandler((DrawingSurfaceImpl)getParent(), arc);
1856- arc.addMouseListener(timedArcHandler);
1857- // arc.addMouseWheelListener(timedArcHandler);
1858- arc.addMouseMotionListener(timedArcHandler);
1859-
1860 arc.setGuiModel(guiModel);
1861
1862 return arc;
1863
1864=== modified file 'src/pipe/gui/graphicElements/tapn/TimedInputArcComponent.java'
1865--- src/pipe/gui/graphicElements/tapn/TimedInputArcComponent.java 2018-08-05 10:00:26 +0000
1866+++ src/pipe/gui/graphicElements/tapn/TimedInputArcComponent.java 2018-10-18 13:14:57 +0000
1867@@ -34,22 +34,40 @@
1868 public TimedInputArcComponent(PlaceTransitionObject source) {
1869 super(source);
1870 init();
1871- }
1872-
1873- private void init() {
1874- timeInterval = "[0,inf)";
1875- updateLabel(true);
1876+
1877+ //XXX: se note in funcation
1878+ addMouseHandler();
1879+
1880 }
1881
1882 public TimedInputArcComponent(TimedOutputArcComponent arc) {
1883 super(arc);
1884 init();
1885+
1886+ //XXX: se note in funcation
1887+ addMouseHandler();
1888+
1889 }
1890
1891 public TimedInputArcComponent(TimedOutputArcComponent arc, String guard) {
1892 super(arc);
1893 timeInterval = guard;
1894 updateLabel(true);
1895+
1896+ //XXX: se note in funcation
1897+ addMouseHandler();
1898+
1899+ }
1900+
1901+ private void init() {
1902+ timeInterval = "[0,inf)";
1903+ updateLabel(true);
1904+ }
1905+
1906+ private void addMouseHandler() {
1907+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
1908+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
1909+ mouseHandler = new TimedArcHandler(this);
1910 }
1911
1912 @Override
1913@@ -147,20 +165,6 @@
1914 }
1915
1916 @Override
1917- public TimedInputArcComponent copy() {
1918- return new TimedInputArcComponent(new TimedOutputArcComponent(this), timeInterval);
1919- }
1920-
1921- @Override
1922- public TimedInputArcComponent paste(double despX, double despY, boolean toAnotherView) {
1923- TimedOutputArcComponent copy = new TimedOutputArcComponent(this);
1924- copy.setSource(this.getSource());
1925- copy.setTarget(this.getTarget());
1926- TimedInputArcComponent timedCopy = new TimedInputArcComponent(copy.paste(despX, despY, toAnotherView), timeInterval);
1927- return timedCopy;
1928- }
1929-
1930- @Override
1931 public void setLabelPosition() {
1932 /*label.setPosition((int) (myPath.midPoint.x + nameOffsetX)
1933 + label.getWidth() / 2 - 4, (int) (myPath.midPoint.y + nameOffsetY)
1934@@ -188,11 +192,6 @@
1935 arc.getSource().addConnectFrom(arc);
1936 arc.getTarget().addConnectTo(arc);
1937
1938- TimedArcHandler timedArcHandler = new TimedArcHandler((DrawingSurfaceImpl)getParent(), arc);
1939- arc.addMouseListener(timedArcHandler);
1940- //arc.addMouseWheelListener(timedArcHandler);
1941- arc.addMouseMotionListener(timedArcHandler);
1942-
1943 arc.setGuiModel(guiModel);
1944
1945 return arc;
1946
1947=== modified file 'src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java'
1948--- src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java 2018-08-11 10:29:10 +0000
1949+++ src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java 2018-10-18 13:14:57 +0000
1950@@ -78,6 +78,9 @@
1951 super(startPositionXInput, startPositionYInput, endPositionXInput,
1952 endPositionYInput, sourceInput, targetInput, weightInput,
1953 idInput);
1954+
1955+ //XXX: se note in funcation
1956+ addMouseHandler();
1957 }
1958
1959 /**
1960@@ -85,11 +88,14 @@
1961 */
1962 public TimedOutputArcComponent(PlaceTransitionObject newSource) {
1963 super(newSource);
1964+
1965+ //XXX: se note in funcation
1966+ addMouseHandler();
1967 }
1968
1969 public TimedOutputArcComponent(TimedOutputArcComponent arc) {
1970 zoom = arc.zoom;
1971- label = new NameLabel(zoom);
1972+
1973 myPath = new ArcPath(this);
1974 for (int i = 0; i <= arc.myPath.getEndIndex(); i++) {
1975 myPath.addPoint(arc.myPath.getPoint(i).getX(), arc.myPath.getPoint(i).getY(), arc.myPath.getPointType(i),zoom);
1976@@ -99,60 +105,17 @@
1977 id = arc.id;
1978 this.setSource(arc.getSource());
1979 this.setTarget(arc.getTarget());
1980- }
1981-
1982- public TimedOutputArcComponent paste(double despX, double despY,
1983- boolean toAnotherView) {
1984- PlaceTransitionObject source = this.getSource().getLastCopy();
1985- PlaceTransitionObject target = this.getTarget().getLastCopy();
1986-
1987- if (source == null && target == null) {
1988- // don't paste an arc with neither source nor target
1989- return null;
1990- }
1991-
1992- if (source == null) {
1993- if (toAnotherView) {
1994- // if the source belongs to another Petri Net, the arc can't be
1995- // pasted
1996- return null;
1997- } else {
1998- source = this.getSource();
1999- }
2000- }
2001-
2002- if (target == null) {
2003- if (toAnotherView) {
2004- // if the target belongs to another Petri Net, the arc can't be
2005- // pasted
2006- return null;
2007- } else {
2008- target = this.getTarget();
2009- }
2010- }
2011-
2012- TimedOutputArcComponent copy = new TimedOutputArcComponent(0, 0, // startPoint
2013- 0, 0, // endPoint
2014- source, target, 1, source.getId() + " to "
2015- + target.getId(), false);
2016-
2017- copy.myPath.delete();
2018- for (int i = 0; i <= myPath.getEndIndex(); i++) {
2019- copy.myPath.addPoint(myPath.getPoint(i).getX() + despX,
2020- myPath.getPoint(i).getY() + despY, myPath
2021- .getPointType(i));
2022- copy.myPath.selectPoint(i);
2023- }
2024-
2025- source.addConnectFrom(copy);
2026- target.addConnectTo(copy);
2027-
2028- return copy;
2029- }
2030-
2031- public TimedOutputArcComponent copy() {
2032- return new TimedOutputArcComponent(this);
2033- }
2034+
2035+ //XXX: se note in funcation
2036+ addMouseHandler();
2037+ }
2038+
2039+ private void addMouseHandler() {
2040+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2041+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2042+ mouseHandler = new ArcHandler(this);
2043+ }
2044+
2045
2046 public Command setGuardAndWeight(TimeInterval guard, Weight weight) {
2047
2048@@ -265,11 +228,6 @@
2049
2050 newCopyArc.getSource().addConnectFrom(newCopyArc);
2051 newCopyArc.getTarget().addConnectTo(newCopyArc);
2052-
2053- ArcHandler arcHandler = new ArcHandler((DrawingSurfaceImpl)getParent(), newCopyArc);
2054- newCopyArc.addMouseListener(arcHandler);
2055- //arc.addMouseWheelListener(arcHandler);
2056- newCopyArc.addMouseMotionListener(arcHandler);
2057
2058 newCopyArc.setGuiModel(guiModel);
2059
2060
2061=== modified file 'src/pipe/gui/graphicElements/tapn/TimedPlaceComponent.java'
2062--- src/pipe/gui/graphicElements/tapn/TimedPlaceComponent.java 2018-04-29 09:54:50 +0000
2063+++ src/pipe/gui/graphicElements/tapn/TimedPlaceComponent.java 2018-10-18 13:14:57 +0000
2064@@ -25,11 +25,8 @@
2065
2066 import pipe.dataLayer.DataLayer;
2067 import pipe.gui.CreateGui;
2068-import pipe.gui.DrawingSurfaceImpl;
2069 import pipe.gui.Pipe;
2070-import pipe.gui.Zoomer;
2071 import pipe.gui.graphicElements.Place;
2072-import pipe.gui.handler.LabelHandler;
2073 import pipe.gui.handler.PlaceHandler;
2074 import pipe.gui.undo.TimedPlaceInvariantEdit;
2075 import pipe.gui.widgets.EscapableDialog;
2076@@ -61,27 +58,40 @@
2077
2078 attributesVisible = true;
2079 ageOfTokensWindow = new Window(new Frame());
2080+
2081+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2082+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2083+ addMouseHandler();
2084 }
2085
2086 public TimedPlaceComponent(double positionXInput, double positionYInput,
2087- String idInput, String nameInput, Double nameOffsetXInput,
2088- Double nameOffsetYInput, int initialMarkingInput,
2089- double markingOffsetXInput, double markingOffsetYInput,
2090- int capacityInput) {
2091+ String idInput, Double nameOffsetXInput,
2092+ Double nameOffsetYInput,
2093+ double markingOffsetXInput, double markingOffsetYInput) {
2094
2095- super(positionXInput, positionYInput, idInput, nameInput,
2096- nameOffsetXInput, nameOffsetYInput, initialMarkingInput,
2097- markingOffsetXInput, markingOffsetYInput, capacityInput);
2098+ super(positionXInput, positionYInput, idInput,
2099+ nameOffsetXInput, nameOffsetYInput,
2100+ markingOffsetXInput, markingOffsetYInput);
2101 listener = timedPlaceListener();
2102 attributesVisible = true;
2103 ageOfTokensWindow = new Window(new Frame());
2104+
2105+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2106+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2107+ addMouseHandler();
2108+ }
2109+
2110+ private void addMouseHandler() {
2111+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2112+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2113+ mouseHandler = new PlaceHandler(this);
2114 }
2115
2116 private TimedPlaceListener timedPlaceListener() {
2117 return new TimedPlaceListener() {
2118 public void nameChanged(TimedPlaceEvent e) {
2119 TimedPlace place = e.source();
2120- TimedPlaceComponent.super.setName(place.name());
2121+ TimedPlaceComponent.super.setName(place.name());
2122 }
2123
2124 public void invariantChanged(TimedPlaceEvent e) {
2125@@ -93,32 +103,6 @@
2126 }
2127 };
2128 }
2129-
2130- @Override
2131- public TimedPlaceComponent clone() {
2132- TimedPlaceComponent toReturn = (TimedPlaceComponent) super.clone();
2133-
2134- toReturn.setInvariant(this.getInvariant());
2135- return toReturn;
2136-
2137- }
2138-
2139- @Override
2140- public TimedPlaceComponent copy() {
2141- TimedPlaceComponent copy = new TimedPlaceComponent(Zoomer
2142- .getUnzoomedValue(this.getX(), zoom), Zoomer.getUnzoomedValue(
2143- this.getY(), zoom), place);
2144- copy.pnName.setName(this.getName());
2145- copy.nameOffsetX = nameOffsetX;
2146- copy.nameOffsetY = nameOffsetY;
2147- copy.capacity = capacity;
2148- copy.attributesVisible = attributesVisible;
2149- copy.markingOffsetX = markingOffsetX;
2150- copy.markingOffsetY = markingOffsetY;
2151- copy.setOriginal(this);
2152- return copy;
2153- }
2154-
2155
2156 public String getInvariantAsString() {
2157 return getInvariant().toString();
2158@@ -448,19 +432,9 @@
2159 }
2160
2161 public TimedPlaceComponent copy(TimedArcPetriNet tapn, DataLayer guiModel) {
2162- TimedPlaceComponent placeComponent = new TimedPlaceComponent(getPositionXObject(), getPositionYObject(), id, place.name(), nameOffsetX, nameOffsetY, 0, markingOffsetX, markingOffsetY, capacity);
2163+ TimedPlaceComponent placeComponent = new TimedPlaceComponent(getPositionXObject(), getPositionYObject(), id, nameOffsetX, nameOffsetY, markingOffsetX, markingOffsetY);
2164 placeComponent.setUnderlyingPlace(tapn.getPlaceByName(place.name()));
2165
2166- LabelHandler labelHandler = new LabelHandler(placeComponent.getNameLabel(), placeComponent);
2167- placeComponent.getNameLabel().addMouseListener(labelHandler);
2168- placeComponent.getNameLabel().addMouseMotionListener(labelHandler);
2169- placeComponent.getNameLabel().addMouseWheelListener(labelHandler);
2170-
2171- PlaceHandler placeHandler = new PlaceHandler((DrawingSurfaceImpl)getParent(), placeComponent, guiModel, tapn);
2172- placeComponent.addMouseListener(placeHandler);
2173- placeComponent.addMouseWheelListener(placeHandler);
2174- placeComponent.addMouseMotionListener(placeHandler);
2175-
2176 placeComponent.setGuiModel(guiModel);
2177
2178 return placeComponent;
2179
2180=== modified file 'src/pipe/gui/graphicElements/tapn/TimedTransitionComponent.java'
2181--- src/pipe/gui/graphicElements/tapn/TimedTransitionComponent.java 2016-11-14 09:58:40 +0000
2182+++ src/pipe/gui/graphicElements/tapn/TimedTransitionComponent.java 2018-10-18 13:14:57 +0000
2183@@ -51,18 +51,34 @@
2184 listener = timedTransitionListener();
2185 transition.addTimedTransitionListener(listener);
2186 attributesVisible = true;
2187+
2188+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2189+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2190+ addMouseHandler();
2191 }
2192
2193 public TimedTransitionComponent(double positionXInput,
2194- double positionYInput, String idInput, String nameInput,
2195+ double positionYInput, String idInput,
2196 double nameOffsetXInput, double nameOffsetYInput,
2197 boolean timedTransition, boolean infServer, int angleInput,
2198 int priority) {
2199- super(positionXInput, positionYInput, idInput, nameInput,
2200+ super(positionXInput, positionYInput, idInput,
2201 nameOffsetXInput, nameOffsetYInput, infServer,
2202 angleInput, priority);
2203 listener = timedTransitionListener();
2204 attributesVisible = true;
2205+
2206+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2207+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2208+ addMouseHandler();
2209+ }
2210+
2211+
2212+ private void addMouseHandler() {
2213+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2214+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2215+ mouseHandler = new TAPNTransitionHandler(this);
2216+ addMouseListener(new AnimationHandler());
2217 }
2218
2219 private TimedTransitionListener timedTransitionListener(){
2220@@ -210,21 +226,9 @@
2221 }
2222
2223 public TimedTransitionComponent copy(TimedArcPetriNet tapn, DataLayer guiModel) {
2224- TimedTransitionComponent transitionComponent = new TimedTransitionComponent(getPositionXObject(), getPositionYObject(), id, transition.name(), nameOffsetX, nameOffsetY, true, false, getAngle(), 0);
2225+ TimedTransitionComponent transitionComponent = new TimedTransitionComponent(getPositionXObject(), getPositionYObject(), id, nameOffsetX, nameOffsetY, true, false, getAngle(), 0);
2226 transitionComponent.setUnderlyingTransition(tapn.getTransitionByName(transition.name()));
2227-
2228- LabelHandler labelHandler = new LabelHandler(transitionComponent.getNameLabel(), transitionComponent);
2229- transitionComponent.getNameLabel().addMouseListener(labelHandler);
2230- transitionComponent.getNameLabel().addMouseMotionListener(labelHandler);
2231- transitionComponent.getNameLabel().addMouseWheelListener(labelHandler);
2232-
2233- TransitionHandler transitionHandler = new TAPNTransitionHandler((DrawingSurfaceImpl)getParent(), transitionComponent, guiModel, tapn);
2234- transitionComponent.addMouseListener(transitionHandler);
2235- transitionComponent.addMouseMotionListener(transitionHandler);
2236- transitionComponent.addMouseWheelListener(transitionHandler);
2237-
2238- transitionComponent.addMouseListener(new AnimationHandler());
2239-
2240+
2241 transitionComponent.setGuiModel(guiModel);
2242
2243 return transitionComponent;
2244
2245=== modified file 'src/pipe/gui/graphicElements/tapn/TimedTransportArcComponent.java'
2246--- src/pipe/gui/graphicElements/tapn/TimedTransportArcComponent.java 2018-04-29 09:54:50 +0000
2247+++ src/pipe/gui/graphicElements/tapn/TimedTransportArcComponent.java 2018-10-18 13:14:57 +0000
2248@@ -27,24 +27,34 @@
2249 private TimedTransportArcComponent connectedTo = null;
2250 private TransportArc underlyingTransportArc;
2251
2252- public TimedTransportArcComponent(PlaceTransitionObject newSource, int groupNr,
2253- boolean isInPreSet) {
2254+ public TimedTransportArcComponent(PlaceTransitionObject newSource, int groupNr, boolean isInPreSet) {
2255 super(new TimedOutputArcComponent(newSource));
2256 this.isInPreSet = isInPreSet;
2257 setHead();
2258 setGroup(groupNr);
2259 // hack to reprint the label of the arc
2260 updateLabel(true);
2261+
2262+ //XXX: se note in funcation
2263+ addMouseHandler();
2264 }
2265
2266- public TimedTransportArcComponent(TimedInputArcComponent timedArc, int group,
2267- boolean isInPreSet) {
2268+ public TimedTransportArcComponent(TimedInputArcComponent timedArc, int group, boolean isInPreSet) {
2269 super(timedArc, "");
2270 this.isInPreSet = isInPreSet;
2271 setHead();
2272 this.setGroup(group);
2273 // hack to reprint the label of the arc
2274 updateLabel(true);
2275+
2276+ //XXX: se note in funcation
2277+ addMouseHandler();
2278+ }
2279+
2280+ private void addMouseHandler() {
2281+ //XXX: kyrke 2018-09-06, this is bad as we leak "this", think its ok for now, as it alwas constructed when
2282+ //XXX: handler is called. Make static constructor and add handler from there, to make it safe.
2283+ mouseHandler = new TransportArcHandler(this);
2284 }
2285
2286 public void setUnderlyingArc(TransportArc arc) {
2287@@ -139,12 +149,6 @@
2288 }
2289
2290 @Override
2291- public TimedTransportArcComponent copy() {
2292-
2293- return null;
2294- }
2295-
2296- @Override
2297 public void delete() {
2298 if (underlyingTransportArc != null) {
2299 underlyingTransportArc.delete();
2300@@ -180,26 +184,6 @@
2301 connectedTo = a;
2302 }
2303
2304- @Override
2305- public TimedTransportArcComponent paste(double despX, double despY,
2306- boolean toAnotherView) {
2307-
2308- return null;
2309- }
2310-
2311- /*
2312- * public TransportArc getBuddy() { TransportArc toReturn = null; if
2313- * (isInPreSet){ HashMap<TransportArc, TransportArc> transportArcMap =
2314- * (HashMap<TransportArc, TransportArc>) ((HashMap)
2315- * CreateGui.getModel().getTransportArcMap() ). get( this.getTarget() );
2316- *
2317- * toReturn = transportArcMap.get(this); }else { HashMap<TransportArc,
2318- * TransportArc> transportArcMap = (HashMap<TransportArc, TransportArc>)
2319- * ((HashMap) CreateGui.getModel().getTransportArcMap() ). get(
2320- * this.getSource() ); for ( TransportArc ta : transportArcMap.keySet() ){
2321- * if (transportArcMap.get(ta) == this){ toReturn = ta; } } } return
2322- * toReturn; }
2323- */
2324 public boolean isInPreSet() {
2325 return isInPreSet;
2326 }
2327@@ -274,12 +258,7 @@
2328
2329 arc.getSource().addConnectFrom(arc);
2330 arc.getTarget().addConnectTo(arc);
2331-
2332- TransportArcHandler transportArcHandler = new TransportArcHandler((DrawingSurfaceImpl)getParent(), arc);
2333- arc.addMouseListener(transportArcHandler);
2334- //arc.addMouseWheelListener(transportArcHandler);
2335- arc.addMouseMotionListener(transportArcHandler);
2336-
2337+
2338 arc.setGuiModel(guiModel);
2339
2340 return arc;
2341
2342=== modified file 'src/pipe/gui/handler/AnnotationNoteHandler.java'
2343--- src/pipe/gui/handler/AnnotationNoteHandler.java 2011-10-14 13:00:29 +0000
2344+++ src/pipe/gui/handler/AnnotationNoteHandler.java 2018-10-18 13:14:57 +0000
2345@@ -20,8 +20,8 @@
2346
2347 public class AnnotationNoteHandler extends NoteHandler {
2348
2349- public AnnotationNoteHandler(Container contentpane, AnnotationNote note) {
2350- super(contentpane, note);
2351+ public AnnotationNoteHandler(AnnotationNote note) {
2352+ super(note);
2353 enablePopup = true;
2354 }
2355
2356
2357=== modified file 'src/pipe/gui/handler/ArcHandler.java'
2358--- src/pipe/gui/handler/ArcHandler.java 2018-05-13 14:57:15 +0000
2359+++ src/pipe/gui/handler/ArcHandler.java 2018-10-18 13:14:57 +0000
2360@@ -24,8 +24,8 @@
2361 */
2362 public class ArcHandler extends PetriNetObjectHandler {
2363
2364- public ArcHandler(Container contentpane, Arc obj) {
2365- super(contentpane, obj);
2366+ public ArcHandler(Arc obj) {
2367+ super(obj);
2368 enablePopup = true;
2369 }
2370
2371@@ -86,7 +86,7 @@
2372 // Calculate translation in mouse
2373 int transX = (Grid.getModifiedX(e.getX() - dragInit.x));
2374 int transY = (Grid.getModifiedY(e.getY() - dragInit.y));
2375- ((DrawingSurfaceImpl) contentPane).getSelectionObject()
2376+ myObject.getParent().getSelectionObject()
2377 .translateSelection(transX, transY);
2378 dragInit.translate(
2379 -(currentObject.getLocation().x - oldLocation.x - transX),
2380
2381=== modified file 'src/pipe/gui/handler/ArcPathPointHandler.java'
2382--- src/pipe/gui/handler/ArcPathPointHandler.java 2018-05-13 14:57:15 +0000
2383+++ src/pipe/gui/handler/ArcPathPointHandler.java 2018-10-18 13:14:57 +0000
2384@@ -5,7 +5,6 @@
2385 */
2386 package pipe.gui.handler;
2387
2388-import java.awt.Container;
2389 import java.awt.event.MouseEvent;
2390 import java.awt.event.MouseWheelEvent;
2391
2392@@ -19,8 +18,8 @@
2393
2394 public class ArcPathPointHandler extends PetriNetObjectHandler {
2395
2396- public ArcPathPointHandler(Container contentpane, ArcPathPoint obj) {
2397- super(contentpane, obj);
2398+ public ArcPathPointHandler(ArcPathPoint obj) {
2399+ super(obj);
2400 enablePopup = true;
2401 }
2402
2403
2404=== modified file 'src/pipe/gui/handler/NoteHandler.java'
2405--- src/pipe/gui/handler/NoteHandler.java 2011-09-22 13:02:33 +0000
2406+++ src/pipe/gui/handler/NoteHandler.java 2018-10-18 13:14:57 +0000
2407@@ -7,8 +7,8 @@
2408
2409 public class NoteHandler extends PetriNetObjectHandler {
2410
2411- public NoteHandler(Container contentpane, Note note) {
2412- super(contentpane, note);
2413+ public NoteHandler(Note note) {
2414+ super(note);
2415 enablePopup = true;
2416 }
2417
2418
2419=== modified file 'src/pipe/gui/handler/PetriNetObjectHandler.java'
2420--- src/pipe/gui/handler/PetriNetObjectHandler.java 2018-05-26 19:26:50 +0000
2421+++ src/pipe/gui/handler/PetriNetObjectHandler.java 2018-10-18 13:14:57 +0000
2422@@ -26,7 +26,6 @@
2423 public class PetriNetObjectHandler extends javax.swing.event.MouseInputAdapter
2424 implements java.awt.event.MouseWheelListener {
2425
2426- protected Container contentPane;
2427 protected PetriNetObject myObject = null;
2428
2429 // justSelected: set to true on press, and false on release;
2430@@ -40,8 +39,7 @@
2431 private int totalY = 0;
2432
2433 // constructor passing in all required objects
2434- public PetriNetObjectHandler(Container contentpane, PetriNetObject obj) {
2435- contentPane = contentpane;
2436+ public PetriNetObjectHandler(PetriNetObject obj) {
2437 myObject = obj;
2438 }
2439
2440@@ -76,8 +74,7 @@
2441 if (CreateGui.getApp().getMode() == ElementType.SELECT) {
2442 if (!myObject.isSelected()) {
2443 if (!e.isShiftDown()) {
2444- ((DrawingSurfaceImpl) contentPane).getSelectionObject()
2445- .clearSelection();
2446+ myObject.getParent().getSelectionObject().clearSelection();
2447 }
2448 myObject.select();
2449 justSelected = true;
2450@@ -111,8 +108,7 @@
2451 if (isDragging) {
2452 isDragging = false;
2453 CreateGui.getDrawingSurface().getUndoManager().translateSelection(
2454- ((DrawingSurfaceImpl) contentPane).getSelectionObject()
2455- .getSelection(), totalX, totalY);
2456+ myObject.getParent().getSelectionObject().getSelection(), totalX, totalY);
2457 totalX = 0;
2458 totalY = 0;
2459 } else {
2460@@ -120,8 +116,7 @@
2461 if (e.isShiftDown()) {
2462 myObject.deselect();
2463 } else {
2464- ((DrawingSurfaceImpl) contentPane).getSelectionObject()
2465- .clearSelection();
2466+ myObject.getParent().getSelectionObject().clearSelection();
2467 myObject.select();
2468 }
2469 }
2470@@ -152,8 +147,7 @@
2471 // Calculate translation in mouse
2472 int transX = Grid.getModifiedX(e.getX() - dragInit.x);
2473 int transY = Grid.getModifiedY(e.getY() - dragInit.y);
2474- ((DrawingSurfaceImpl) contentPane).getSelectionObject()
2475- .translateSelection(transX, transY);
2476+ myObject.getParent().getSelectionObject().translateSelection(transX, transY);
2477
2478 //Only register the actual distance and direction moved (in case of dragging past edge)
2479 totalX += myObject.getX() - previousX;
2480
2481=== modified file 'src/pipe/gui/handler/PlaceHandler.java'
2482--- src/pipe/gui/handler/PlaceHandler.java 2018-05-13 14:57:15 +0000
2483+++ src/pipe/gui/handler/PlaceHandler.java 2018-10-18 13:14:57 +0000
2484@@ -29,13 +29,8 @@
2485 */
2486 public class PlaceHandler extends PlaceTransitionObjectHandler {
2487
2488- public PlaceHandler(Container contentpane, Place obj) {
2489- super(contentpane, obj);
2490- }
2491-
2492- public PlaceHandler(DrawingSurfaceImpl drawingSurfaceImpl, Place newObject,
2493- DataLayer guiModel, TimedArcPetriNet model) {
2494- super(drawingSurfaceImpl, newObject, guiModel, model);
2495+ public PlaceHandler(Place obj) {
2496+ super(obj);
2497 }
2498
2499 /**
2500@@ -154,10 +149,13 @@
2501 return;
2502 }
2503
2504- if (e.getWheelRotation() < 0) {
2505- ((TimedPlaceComponent)myObject).addTokens(1);
2506- } else {
2507- ((TimedPlaceComponent)myObject).removeTokens(1);
2508- }
2509+ if (myObject instanceof TimedPlaceComponent) {
2510+ TimedPlaceComponent p = (TimedPlaceComponent) myObject;
2511+ if (e.getWheelRotation() < 0) {
2512+ p.addTokens(1);
2513+ } else {
2514+ p.removeTokens(1);
2515+ }
2516+ }
2517 }
2518 }
2519
2520=== modified file 'src/pipe/gui/handler/PlaceTransitionObjectHandler.java'
2521--- src/pipe/gui/handler/PlaceTransitionObjectHandler.java 2018-05-13 14:57:15 +0000
2522+++ src/pipe/gui/handler/PlaceTransitionObjectHandler.java 2018-10-18 13:14:57 +0000
2523@@ -44,27 +44,17 @@
2524
2525 public class PlaceTransitionObjectHandler extends PetriNetObjectHandler {
2526 private static final String ERROR_MSG_TWO_ARCS = "We do not allow two arcs from a place to a transition or a transition to a place.";
2527- private DataLayer guiModel;
2528- private TimedArcPetriNet model;
2529-
2530- public PlaceTransitionObjectHandler(Container contentpane,
2531- PlaceTransitionObject obj, DataLayer guiModel,
2532- TimedArcPetriNet model) {
2533- this(contentpane, obj);
2534- this.guiModel = guiModel;
2535- this.model = model;
2536- }
2537
2538 // constructor passing in all required objects
2539- public PlaceTransitionObjectHandler(Container contentpane,
2540- PlaceTransitionObject obj) {
2541- super(contentpane, obj);
2542+ public PlaceTransitionObjectHandler(PlaceTransitionObject obj) {
2543+ super(obj);
2544 enablePopup = true;
2545 }
2546
2547 private void createArc(Arc newArc, PlaceTransitionObject currentObject) {
2548 newArc.setZoom(CreateGui.getDrawingSurface().getZoom());
2549- contentPane.add(newArc);
2550+ //Need to be casted to cointainer, as we only add it to the canvas but not the model
2551+ ((Container)CreateGui.getDrawingSurface()).add(newArc);
2552 currentObject.addConnectFrom(newArc);
2553 CreateGui.getDrawingSurface().createArc = newArc;
2554 // addPetriNetObject a handler for shift & esc actions drawing arc
2555@@ -115,8 +105,7 @@
2556 boolean isInPreSet = false;
2557 if (currentObject instanceof Place) {
2558 isInPreSet = true;
2559- Arc arc = new TimedTransportArcComponent(currentObject, 1,
2560- isInPreSet);
2561+ Arc arc = new TimedTransportArcComponent(currentObject, 1, isInPreSet);
2562 createArc(arc, currentObject);
2563 }
2564 break;
2565@@ -135,20 +124,20 @@
2566 super.mouseReleased(e);
2567
2568 PlaceTransitionObject currentObject = (PlaceTransitionObject) myObject;
2569-
2570- if (view.createArc == null){
2571+
2572+ Arc createArc = view.createArc;
2573+ if (createArc == null){
2574 //If we have no arc, we have nothing to do
2575 return;
2576 }
2577
2578 //Check if the mouse was moved since key down event, and we are looking at the target
2579 //Break the drawing if this is the case
2580- Arc createArc = view.createArc;
2581- if (createArc != null && currentObject != createArc.getSource()){
2582- if (createArc.getTarget() == null) {
2583- cleanupArc(createArc, view);
2584- return;
2585- }
2586+ if (currentObject != createArc.getSource()){
2587+ if (createArc.getTarget() == null) {
2588+ cleanupArc(createArc, view);
2589+ return;
2590+ }
2591 }
2592
2593 switch (app.getMode()) {
2594@@ -163,7 +152,7 @@
2595 ((TimedTransitionComponent) createTAPNInhibitorArc
2596 .getTarget()).underlyingTransition(),
2597 TimeInterval.ZERO_INF);
2598- model.add(tia);
2599+ view.getModel().add(tia);
2600 createTAPNInhibitorArc.setUnderlyingArc(tia);
2601 createTAPNInhibitorArc.updateLabel(true);
2602 } catch (RequireException ex) {
2603@@ -183,14 +172,16 @@
2604 createTAPNInhibitorArc.getTransition().updateConnected();
2605
2606 // Evil hack to prevent the arc being added to GuiView twice
2607- contentPane.remove(createTAPNInhibitorArc);
2608+ //Need to be casted to cointainer, as we only add it to the canvas but not the model
2609+ ((Container)CreateGui.getDrawingSurface()).remove(createTAPNInhibitorArc);
2610
2611- guiModel.addArc(createTAPNInhibitorArc);
2612+ view.getGuiModel().addArc(createTAPNInhibitorArc);
2613
2614 view.addNewPetriNetObject(createTAPNInhibitorArc);
2615
2616- undoManager.addNewEdit(new AddTimedInhibitorArcCommand(
2617- createTAPNInhibitorArc, model, guiModel, view));
2618+ undoManager.addNewEdit(
2619+ new AddTimedInhibitorArcCommand(createTAPNInhibitorArc, view.getModel(), view.getGuiModel(), view)
2620+ );
2621
2622 freeArc(createTAPNInhibitorArc);
2623 }
2624@@ -200,168 +191,140 @@
2625
2626 Arc transportArcToCreate = view.createArc;
2627
2628- if (currentObject != transportArcToCreate.getSource()) {
2629-
2630- transportArcToCreate.setSelectable(true);
2631-
2632- // This is the first step
2633- if (transportArcToCreate.getSource() instanceof Place) {
2634-
2635- // mikaelhm - Dont allow a transport arc from place to
2636- // transition if there is another arc.
2637- boolean existsArc = false;
2638-
2639- // Check if arc has leagal target
2640- PlaceTransitionObject target = transportArcToCreate
2641- .getTarget();
2642- if (!(target instanceof Transition && target != null)) {
2643- System.err.println("Error creating transport arc, invalid target");
2644- transportArcToCreate.delete();
2645- break;
2646- }
2647-
2648- Iterator<Arc> arcsFrom = transportArcToCreate
2649- .getSource().getConnectFromIterator();
2650- // search for pre-existent arcs from transportArcToCreate's source to
2651- // transportArcToCreate's target
2652- while (arcsFrom.hasNext()) {
2653- Arc someArc = (arcsFrom.next());
2654- if (someArc == transportArcToCreate) {
2655- break;
2656- } else if (someArc.getSource() == transportArcToCreate.getSource() && someArc.getTarget() == currentObject) {
2657- existsArc = true;
2658-
2659- if (someArc instanceof TimedInhibitorArcComponent) {
2660- // user has drawn a transport arc where there is
2661- // a TAPNInhibitorArc arc already - This does not make sense.
2662- cleanupArc(transportArcToCreate, view);
2663- System.out.println(ERROR_MSG_TWO_ARCS);
2664- JOptionPane.showMessageDialog(
2665- CreateGui.getApp(),
2666- ERROR_MSG_TWO_ARCS,
2667- "Error",
2668- JOptionPane.ERROR_MESSAGE);
2669-
2670- } else if (someArc instanceof TimedTransportArcComponent) {
2671- // user has drawn a transport arc where there is
2672- // a transport arc already - We do not allow that.
2673- cleanupArc(transportArcToCreate, view);
2674- System.out.println(ERROR_MSG_TWO_ARCS);
2675- JOptionPane.showMessageDialog(CreateGui
2676- .getApp(), ERROR_MSG_TWO_ARCS,
2677- "Error", JOptionPane.ERROR_MESSAGE);
2678-
2679- } else if (someArc instanceof TimedOutputArcComponent) {
2680- // user has drawn a transport arc where there is
2681- // a normal arc already - We do not allow that.
2682- cleanupArc(transportArcToCreate, view);
2683- System.out.println(ERROR_MSG_TWO_ARCS);
2684- JOptionPane.showMessageDialog(CreateGui
2685- .getApp(), ERROR_MSG_TWO_ARCS,
2686- "Error", JOptionPane.ERROR_MESSAGE);
2687-
2688- }
2689- break;
2690- }
2691- }
2692- if (existsArc) {
2693- transportArcToCreate.delete();
2694- break;
2695- }
2696-
2697- int groupMaxCounter = 0;
2698-
2699- for (Object pt : transportArcToCreate.getTarget()
2700- .getPostset()) {
2701- if (pt instanceof TimedTransportArcComponent) {
2702- if (((TimedTransportArcComponent) pt).getGroupNr() > groupMaxCounter) {
2703- groupMaxCounter = ((TimedTransportArcComponent) pt).getGroupNr();
2704- }
2705- }
2706- }
2707-
2708- ((TimedTransportArcComponent) transportArcToCreate).setGroupNr(groupMaxCounter + 1);
2709-
2710- currentObject.addConnectTo(transportArcToCreate);
2711-
2712- // Evil hack to prevent the arc being added to GuiView
2713- // twice
2714- contentPane.remove(transportArcToCreate);
2715-
2716- guiModel.addArc((TimedOutputArcComponent) transportArcToCreate);
2717- view.addNewPetriNetObject(transportArcToCreate);
2718-
2719- freeArc(transportArcToCreate);
2720-
2721- // Create the next arc
2722- TimedTransportArcComponent arc2 = new TimedTransportArcComponent(currentObject, groupMaxCounter + 1, false);
2723-
2724- //Update the partners for the arcs
2725- TimedTransportArcComponent arc1 = ((TimedTransportArcComponent) transportArcToCreate);
2726-
2727- arc2.setConnectedTo(arc1);
2728- arc1.setConnectedTo(arc2);
2729-
2730- //Draw part 2 of the transport arc
2731- createArc(arc2, currentObject);
2732-
2733-
2734- } else if (transportArcToCreate.getSource() instanceof Transition) {
2735-
2736- TimedTransportArcComponent arc2 = (TimedTransportArcComponent) transportArcToCreate;
2737- TimedTransportArcComponent arc1 = arc2.getConnectedTo();
2738-
2739- dk.aau.cs.model.tapn.TransportArc ta;
2740- try {
2741- ta = new dk.aau.cs.model.tapn.TransportArc(
2742- ((TimedPlaceComponent) arc1.getSource()).underlyingPlace(),
2743- ((TimedTransitionComponent) arc2.getSource()).underlyingTransition(),
2744- ((TimedPlaceComponent) arc2.getTarget()).underlyingPlace(),
2745- TimeInterval.ZERO_INF);
2746- model.add(ta);
2747- ((TimedTransportArcComponent) transportArcToCreate).setUnderlyingArc(ta);
2748- arc1.setUnderlyingArc(ta);
2749- arc1.updateLabel(true);
2750- ((TimedTransportArcComponent) transportArcToCreate).updateLabel(true);
2751- } catch (RequireException ex) {
2752- cleanupArc(arc1, view);
2753- cleanupArc(arc2, view);
2754+ if (currentObject != transportArcToCreate.getSource()) {
2755+
2756+ transportArcToCreate.setSelectable(true);
2757+
2758+ // This is the first step
2759+ if (transportArcToCreate.getSource() instanceof Place) {
2760+
2761+ // mikaelhm - Dont allow a transport arc from place to
2762+ // transition if there is another arc.
2763+ boolean existsArc = false;
2764+
2765+ // Check if arc has leagal target
2766+ PlaceTransitionObject target = transportArcToCreate.getTarget();
2767+ if (!(target instanceof Transition)) {
2768+ transportArcToCreate.delete();
2769+ break;
2770+ }
2771+
2772+ Iterator<Arc> arcsFrom = transportArcToCreate.getSource().getConnectFromIterator();
2773+ // search for pre-existent arcs from transportArcToCreate's source to
2774+ // transportArcToCreate's target
2775+ while (arcsFrom.hasNext()) {
2776+ Arc someArc = (arcsFrom.next());
2777+ if (someArc == transportArcToCreate) {
2778+ break;
2779+ } else if (someArc.getSource() == transportArcToCreate.getSource() && someArc.getTarget() == currentObject) {
2780+ existsArc = true;
2781+
2782+ // There already is a arc between this place and transition
2783+ cleanupArc(transportArcToCreate, view);
2784 JOptionPane.showMessageDialog(
2785- CreateGui.getApp(),
2786- "There was an error drawing the arc. Possible problems:\n"
2787- + " - There is already an arc between the source place and transition\n"
2788- + " - There is already an arc between the transtion and the target place\n"
2789- + " - You are attempting to draw an arc between a shared transition and a shared place",
2790- "Error", JOptionPane.ERROR_MESSAGE);
2791- break;
2792- }
2793-
2794- // Evil hack to prevent the arc being added to GuiView
2795- // twice
2796- contentPane.remove(arc2);
2797-
2798- guiModel.addArc(arc2);
2799- view.addNewPetriNetObject(arc2);
2800-
2801- currentObject.addConnectTo(arc2);
2802-
2803- undoManager.newEdit();
2804-
2805- undoManager.addEdit(
2806- new AddTransportArcCommand(
2807- arc2,
2808- arc2.underlyingTransportArc(),
2809- model,
2810- guiModel,
2811- view));
2812-
2813- freeArc(transportArcToCreate);
2814-
2815- arc2.setGroupNr(arc1.getGroupNr());
2816- }
2817-
2818+ CreateGui.getApp(),
2819+ ERROR_MSG_TWO_ARCS,
2820+ "Error",
2821+ JOptionPane.ERROR_MESSAGE);
2822+ }
2823+ }
2824+ if (existsArc) {
2825+ transportArcToCreate.delete();
2826+ break;
2827+ }
2828+
2829+ int groupMaxCounter = 0;
2830+
2831+ for (Object pt : transportArcToCreate.getTarget().getPostset()) {
2832+ if (pt instanceof TimedTransportArcComponent) {
2833+ if (((TimedTransportArcComponent) pt).getGroupNr() > groupMaxCounter) {
2834+ groupMaxCounter = ((TimedTransportArcComponent) pt).getGroupNr();
2835+ }
2836+ }
2837+ }
2838+
2839+ ((TimedTransportArcComponent) transportArcToCreate).setGroupNr(groupMaxCounter + 1);
2840+
2841+ currentObject.addConnectTo(transportArcToCreate);
2842+
2843+ // Evil hack to prevent the arc being added to GuiView twice
2844+ //Need to be casted to cointainer, as we only add it to the canvas but not the model
2845+ ((Container) CreateGui.getDrawingSurface()).remove(transportArcToCreate);
2846+
2847+ view.getGuiModel().addArc((TimedOutputArcComponent) transportArcToCreate);
2848+ view.addNewPetriNetObject(transportArcToCreate);
2849+
2850+ freeArc(transportArcToCreate);
2851+
2852+ // Create the next arc
2853+ TimedTransportArcComponent arc2 = new TimedTransportArcComponent(currentObject, groupMaxCounter + 1, false);
2854+
2855+ //Update the partners for the arcs
2856+ TimedTransportArcComponent arc1 = ((TimedTransportArcComponent) transportArcToCreate);
2857+
2858+ arc2.setConnectedTo(arc1);
2859+ arc1.setConnectedTo(arc2);
2860+
2861+ //Draw part 2 of the transport arc
2862+ createArc(arc2, currentObject);
2863+
2864+
2865+ } else if (transportArcToCreate.getSource() instanceof Transition) {
2866+
2867+ TimedTransportArcComponent arc2 = (TimedTransportArcComponent) transportArcToCreate;
2868+ TimedTransportArcComponent arc1 = arc2.getConnectedTo();
2869+
2870+ dk.aau.cs.model.tapn.TransportArc ta;
2871+ try {
2872+ ta = new dk.aau.cs.model.tapn.TransportArc(
2873+ ((TimedPlaceComponent) arc1.getSource()).underlyingPlace(),
2874+ ((TimedTransitionComponent) arc2.getSource()).underlyingTransition(),
2875+ ((TimedPlaceComponent) arc2.getTarget()).underlyingPlace(),
2876+ TimeInterval.ZERO_INF);
2877+ view.getModel().add(ta);
2878+ ((TimedTransportArcComponent) transportArcToCreate).setUnderlyingArc(ta);
2879+ arc1.setUnderlyingArc(ta);
2880+ arc1.updateLabel(true);
2881+ ((TimedTransportArcComponent) transportArcToCreate).updateLabel(true);
2882+ } catch (RequireException ex) {
2883+ cleanupArc(arc1, view);
2884+ cleanupArc(arc2, view);
2885+ JOptionPane.showMessageDialog(
2886+ CreateGui.getApp(),
2887+ "There was an error drawing the arc. Possible problems:\n"
2888+ + " - There is already an arc between the source place and transition\n"
2889+ + " - There is already an arc between the transtion and the target place\n"
2890+ + " - You are attempting to draw an arc between a shared transition and a shared place",
2891+ "Error", JOptionPane.ERROR_MESSAGE);
2892+ break;
2893+ }
2894+
2895+ // Evil hack to prevent the arc being added to GuiView twice
2896+ //Need to be casted to cointainer, as we only add it to the canvas but not the model
2897+ ((Container) CreateGui.getDrawingSurface()).remove(arc2);
2898+
2899+ view.getGuiModel().addArc(arc2);
2900+ view.addNewPetriNetObject(arc2);
2901+
2902+ currentObject.addConnectTo(arc2);
2903+
2904+ undoManager.newEdit();
2905+
2906+ undoManager.addEdit(
2907+ new AddTransportArcCommand(
2908+ arc2,
2909+ arc2.underlyingTransportArc(),
2910+ view.getModel(),
2911+ view.getGuiModel(),
2912+ view));
2913+
2914+ freeArc(transportArcToCreate);
2915+
2916+ arc2.setGroupNr(arc1.getGroupNr());
2917 }
2918
2919+ }
2920+
2921
2922 break;
2923 case TAPNARC:
2924@@ -380,14 +343,14 @@
2925 TimedOutputArcComponent outputArc = (TimedOutputArcComponent) timedArcToCreate;
2926
2927 try {
2928- if(hasArcFromTransitionToPlace(model,((TimedTransitionComponent) outputArc.getSource()), ((TimedPlaceComponent) outputArc.getTarget()))){
2929+ if(hasArcFromTransitionToPlace(view.getModel(),((TimedTransitionComponent) outputArc.getSource()), ((TimedPlaceComponent) outputArc.getTarget()))){
2930 throw new RequireException(ERROR_MSG_TWO_ARCS);
2931 }
2932
2933 dk.aau.cs.model.tapn.TimedOutputArc timedOutputArc = new TimedOutputArc(
2934 ((TimedTransitionComponent) outputArc.getSource()).underlyingTransition(),
2935 ((TimedPlaceComponent) outputArc.getTarget()).underlyingPlace());
2936- model.add(timedOutputArc);
2937+ view.getModel().add(timedOutputArc);
2938 outputArc.setUnderlyingArc(timedOutputArc);
2939 outputArc.updateLabel(true);
2940 } catch (RequireException ex) {
2941@@ -402,18 +365,18 @@
2942 }
2943 currentObject.addConnectTo(timedArcToCreate);
2944
2945- // Evil hack to prevent the arc being added to GuiView
2946- // twice
2947- contentPane.remove(timedArcToCreate);
2948+ // Evil hack to prevent the arc being added to GuiView twice
2949+ //Need to be casted to cointainer, as we only add it to the canvas but not the model
2950+ ((Container)CreateGui.getDrawingSurface()).remove(timedArcToCreate);
2951
2952- guiModel.addArc((TimedOutputArcComponent) timedArcToCreate);
2953+ view.getGuiModel().addArc((TimedOutputArcComponent) timedArcToCreate);
2954 view.addNewPetriNetObject(timedArcToCreate);
2955
2956 undoManager.newEdit(); // new "transaction""
2957
2958 undoManager.addEdit(new AddTimedOutputArcCommand(
2959 (TimedOutputArcComponent) timedArcToCreate,
2960- model, guiModel, view));
2961+ view.getModel(), view.getGuiModel(), view));
2962
2963 // else source is a place (not transition)
2964 } else {
2965@@ -421,7 +384,7 @@
2966 // Set underlying TimedInputArc
2967 TimedInputArcComponent timedArc = (TimedInputArcComponent) timedArcToCreate;
2968 try {
2969- if(hasArcFromPlaceToTransition(model,((TimedPlaceComponent) timedArc.getSource()), ((TimedTransitionComponent) timedArc.getTarget()))){
2970+ if(hasArcFromPlaceToTransition(view.getModel(),((TimedPlaceComponent) timedArc.getSource()), ((TimedTransitionComponent) timedArc.getTarget()))){
2971 throw new RequireException("Cannot have two arcs between the same place and transition");
2972 }
2973
2974@@ -429,7 +392,7 @@
2975 ((TimedPlaceComponent) timedArc.getSource()).underlyingPlace(),
2976 ((TimedTransitionComponent) timedArc.getTarget()).underlyingTransition(),
2977 TimeInterval.ZERO_INF);
2978- model.add(tia);
2979+ view.getModel().add(tia);
2980 timedArc.setUnderlyingArc(tia);
2981 timedArc.updateLabel(true);
2982 } catch (RequireException ex) {
2983@@ -447,18 +410,17 @@
2984 currentObject.addConnectTo(timedArcToCreate);
2985 timedArcToCreate.getTransition().updateConnected();
2986
2987- // Evil hack to prevent the arc being added to GuiView
2988- // twice
2989- contentPane.remove(timedArcToCreate);
2990- guiModel
2991- .addArc((TimedOutputArcComponent) timedArcToCreate);
2992+ // Evil hack to prevent the arc being added to GuiView twice
2993+ //Need to be casted to cointainer, as we only add it to the canvas but not the model
2994+ ((Container)CreateGui.getDrawingSurface()).remove(timedArcToCreate);
2995+ view.getGuiModel().addArc((TimedOutputArcComponent) timedArcToCreate);
2996 view.addNewPetriNetObject(timedArcToCreate);
2997
2998 undoManager.newEdit(); // new "transaction""
2999
3000 undoManager.addEdit(new AddTimedInputArcCommand(
3001 (TimedInputArcComponent) timedArcToCreate,
3002- model, guiModel, view));
3003+ view.getModel(), view.getGuiModel(), view));
3004
3005 }
3006
3007
3008=== modified file 'src/pipe/gui/handler/TAPNTransitionHandler.java'
3009--- src/pipe/gui/handler/TAPNTransitionHandler.java 2018-05-13 14:57:15 +0000
3010+++ src/pipe/gui/handler/TAPNTransitionHandler.java 2018-10-18 13:14:57 +0000
3011@@ -14,15 +14,10 @@
3012
3013 public class TAPNTransitionHandler extends TransitionHandler {
3014
3015- public TAPNTransitionHandler(Container contentpane, Transition obj) {
3016- super(contentpane, obj);
3017-
3018- }
3019-
3020- public TAPNTransitionHandler(DrawingSurfaceImpl drawingSurfaceImpl,
3021- Transition newObject, DataLayer guiModel, TimedArcPetriNet model) {
3022- super(drawingSurfaceImpl, newObject, guiModel, model);
3023- }
3024+ public TAPNTransitionHandler(Transition obj) {
3025+ super(obj);
3026+ }
3027+
3028
3029 // overwrite to remove shift behaviour
3030 @Override
3031
3032=== modified file 'src/pipe/gui/handler/TimedArcHandler.java'
3033--- src/pipe/gui/handler/TimedArcHandler.java 2012-05-02 07:16:22 +0000
3034+++ src/pipe/gui/handler/TimedArcHandler.java 2018-10-18 13:14:57 +0000
3035@@ -19,8 +19,8 @@
3036
3037 public class TimedArcHandler extends ArcHandler {
3038
3039- public TimedArcHandler(Container contentpane, Arc obj) {
3040- super(contentpane, obj);
3041+ public TimedArcHandler(Arc obj) {
3042+ super(obj);
3043 enablePopup = true;
3044 }
3045
3046
3047=== modified file 'src/pipe/gui/handler/TransitionHandler.java'
3048--- src/pipe/gui/handler/TransitionHandler.java 2018-05-13 14:57:15 +0000
3049+++ src/pipe/gui/handler/TransitionHandler.java 2018-10-18 13:14:57 +0000
3050@@ -27,13 +27,8 @@
3051 public class TransitionHandler extends PlaceTransitionObjectHandler implements
3052 java.awt.event.MouseWheelListener {
3053
3054- public TransitionHandler(Container contentpane, Transition obj) {
3055- super(contentpane, obj);
3056- }
3057-
3058- public TransitionHandler(DrawingSurfaceImpl drawingSurfaceImpl,
3059- Transition newObject, DataLayer guiModel, TimedArcPetriNet model) {
3060- super(drawingSurfaceImpl, newObject, guiModel, model);
3061+ public TransitionHandler(Transition obj) {
3062+ super(obj);
3063 }
3064
3065 @Override
3066
3067=== modified file 'src/pipe/gui/handler/TransportArcHandler.java'
3068--- src/pipe/gui/handler/TransportArcHandler.java 2011-09-22 13:02:33 +0000
3069+++ src/pipe/gui/handler/TransportArcHandler.java 2018-10-18 13:14:57 +0000
3070@@ -17,8 +17,8 @@
3071
3072 public class TransportArcHandler extends TimedArcHandler {
3073
3074- public TransportArcHandler(Container contentpane, Arc obj) {
3075- super(contentpane, obj);
3076+ public TransportArcHandler(Arc obj) {
3077+ super(obj);
3078 enablePopup = true;
3079 }
3080
3081
3082=== modified file 'src/pipe/gui/undo/DeletePetriNetObjectEdit.java'
3083--- src/pipe/gui/undo/DeletePetriNetObjectEdit.java 2011-09-22 14:51:36 +0000
3084+++ src/pipe/gui/undo/DeletePetriNetObjectEdit.java 2018-10-18 13:14:57 +0000
3085@@ -25,8 +25,6 @@
3086 pnObject = _pnObject;
3087 view = _view;
3088 model = _model;
3089-
3090- pnObject.markAsDeleted();
3091 }
3092
3093 /** */

Subscribers

People subscribed via source and target branches