Merge lp:~yrke/tapaal/cleanup-drawingsurface-mouseEvents into lp:tapaal/dev
- cleanup-drawingsurface-mouseEvents
- Merge into tapaal-dev
Proposed by
Kenneth Yrke Jørgensen
Status: | Merged |
---|---|
Merged at revision: | 1023 |
Proposed branch: | lp:~yrke/tapaal/cleanup-drawingsurface-mouseEvents |
Merge into: | lp:tapaal/dev |
Diff against target: |
382 lines (+138/-151) 1 file modified
src/pipe/gui/DrawingSurfaceImpl.java (+138/-151) |
To merge this branch: | bzr merge lp:~yrke/tapaal/cleanup-drawingsurface-mouseEvents |
Related bugs: | |
Related blueprints: |
tapaal 4 dev
(Low)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Kenneth Yrke Jørgensen | Approve | ||
Review via email: mp+368857@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Kenneth Yrke Jørgensen (yrke) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/pipe/gui/DrawingSurfaceImpl.java' | |||
2 | --- src/pipe/gui/DrawingSurfaceImpl.java 2019-04-24 07:11:25 +0000 | |||
3 | +++ src/pipe/gui/DrawingSurfaceImpl.java 2019-06-15 08:31:30 +0000 | |||
4 | @@ -37,7 +37,7 @@ | |||
5 | 37 | private boolean animationmode = false; | 37 | private boolean animationmode = false; |
6 | 38 | 38 | ||
7 | 39 | public Arc createArc; // no longer static | 39 | public Arc createArc; // no longer static |
9 | 40 | 40 | ||
10 | 41 | private static final int DRAWING_SURFACE_GROW = 100; | 41 | private static final int DRAWING_SURFACE_GROW = 100; |
11 | 42 | 42 | ||
12 | 43 | private SelectionManager selection; | 43 | private SelectionManager selection; |
13 | @@ -225,10 +225,10 @@ | |||
14 | 225 | private void calculateNewBoundsForScrollPane(Rectangle rect) { | 225 | private void calculateNewBoundsForScrollPane(Rectangle rect) { |
15 | 226 | boolean changed = false; | 226 | boolean changed = false; |
16 | 227 | Dimension current = getPreferredSize(); | 227 | Dimension current = getPreferredSize(); |
18 | 228 | 228 | ||
19 | 229 | int this_width = (rect.x + rect.width + 2); | 229 | int this_width = (rect.x + rect.width + 2); |
20 | 230 | int this_height = (rect.y + rect.height+ 2); | 230 | int this_height = (rect.y + rect.height+ 2); |
22 | 231 | 231 | ||
23 | 232 | if (this_width > current.width) { | 232 | if (this_width > current.width) { |
24 | 233 | current.width = this_width; changed=true; | 233 | current.width = this_width; changed=true; |
25 | 234 | } | 234 | } |
26 | @@ -270,7 +270,7 @@ | |||
27 | 270 | public ArrayList<PetriNetObject> getPNObjects() { | 270 | public ArrayList<PetriNetObject> getPNObjects() { |
28 | 271 | return petriNetObjects; | 271 | return petriNetObjects; |
29 | 272 | } | 272 | } |
31 | 273 | 273 | ||
32 | 274 | public ArrayList<PetriNetObject> getPlaceTransitionObjects(){ | 274 | public ArrayList<PetriNetObject> getPlaceTransitionObjects(){ |
33 | 275 | ArrayList<PetriNetObject> result = new ArrayList<PetriNetObject>(); | 275 | ArrayList<PetriNetObject> result = new ArrayList<PetriNetObject>(); |
34 | 276 | for (PetriNetObject pnObject : petriNetObjects) { | 276 | for (PetriNetObject pnObject : petriNetObjects) { |
35 | @@ -340,7 +340,7 @@ | |||
36 | 340 | 340 | ||
37 | 341 | int zoomPercent = getZoom(); | 341 | int zoomPercent = getZoom(); |
38 | 342 | 342 | ||
40 | 343 | JViewport viewport = (JViewport) getParent(); | 343 | JViewport viewport = (JViewport) getParent(); |
41 | 344 | 344 | ||
42 | 345 | Component[] children = getComponents(); | 345 | Component[] children = getComponents(); |
43 | 346 | 346 | ||
44 | @@ -350,7 +350,7 @@ | |||
45 | 350 | ((Zoomable) child).zoomUpdate(zoomPercent); | 350 | ((Zoomable) child).zoomUpdate(zoomPercent); |
46 | 351 | } | 351 | } |
47 | 352 | } | 352 | } |
49 | 353 | 353 | ||
50 | 354 | // Calculate new position of the Drawing Surface. | 354 | // Calculate new position of the Drawing Surface. |
51 | 355 | double newZoomedX = Zoomer.getZoomedValue(point.x, zoomPercent); | 355 | double newZoomedX = Zoomer.getZoomedValue(point.x, zoomPercent); |
52 | 356 | double newZoomedY = Zoomer.getZoomedValue(point.y, zoomPercent); | 356 | double newZoomedY = Zoomer.getZoomedValue(point.y, zoomPercent); |
53 | @@ -377,8 +377,6 @@ | |||
54 | 377 | 377 | ||
55 | 378 | class MouseHandler extends MouseInputAdapter { | 378 | class MouseHandler extends MouseInputAdapter { |
56 | 379 | 379 | ||
57 | 380 | private PetriNetObject pnObject; | ||
58 | 381 | |||
59 | 382 | private DrawingSurfaceImpl view; | 380 | private DrawingSurfaceImpl view; |
60 | 383 | 381 | ||
61 | 384 | private DataLayer guiModel; | 382 | private DataLayer guiModel; |
62 | @@ -398,7 +396,7 @@ | |||
63 | 398 | guiModel = _model; | 396 | guiModel = _model; |
64 | 399 | } | 397 | } |
65 | 400 | 398 | ||
67 | 401 | private Point adjustPoint(Point p, int zoom) { | 399 | private Point adjustPointToZoom(Point p, int zoom) { |
68 | 402 | int offset = (int) (Zoomer.getScaleFactor(zoom) | 400 | int offset = (int) (Zoomer.getScaleFactor(zoom) |
69 | 403 | * Pipe.PLACE_TRANSITION_HEIGHT / 2); | 401 | * Pipe.PLACE_TRANSITION_HEIGHT / 2); |
70 | 404 | 402 | ||
71 | @@ -408,34 +406,71 @@ | |||
72 | 408 | p.setLocation(x, y); | 406 | p.setLocation(x, y); |
73 | 409 | return p; | 407 | return p; |
74 | 410 | } | 408 | } |
78 | 411 | 409 | private Point adjustPointToGrid(Point p) { | |
79 | 412 | private PlaceTransitionObject newTimedPlace(Point p) { | 410 | int x = Grid.getModifiedX(p.x); |
80 | 413 | p = adjustPoint(p, view.getZoom()); | 411 | int y = Grid.getModifiedY(p.y); |
81 | 412 | |||
82 | 413 | return new Point(x, y); | ||
83 | 414 | } | ||
84 | 415 | |||
85 | 416 | private Point adjustPointToGridAndZoom(Point p, int zoom) { | ||
86 | 417 | Point newP = adjustPointToZoom(p, zoom); | ||
87 | 418 | newP = adjustPointToGrid(newP); | ||
88 | 419 | |||
89 | 420 | return newP; | ||
90 | 421 | } | ||
91 | 422 | |||
92 | 423 | private void addPetriNetObjectToModelandView(PetriNetObject pnObject) { | ||
93 | 424 | guiModel.addPetriNetObject(pnObject); | ||
94 | 425 | view.addNewPetriNetObject(pnObject); | ||
95 | 426 | } | ||
96 | 427 | |||
97 | 428 | private PlaceTransitionObject newTimedPlaceAddToModelView(Point p) { | ||
98 | 429 | p = adjustPointToGridAndZoom(p, view.getZoom()); | ||
99 | 430 | |||
100 | 414 | dk.aau.cs.model.tapn.LocalTimedPlace tp = new dk.aau.cs.model.tapn.LocalTimedPlace(nameGenerator.getNewPlaceName(model)); | 431 | dk.aau.cs.model.tapn.LocalTimedPlace tp = new dk.aau.cs.model.tapn.LocalTimedPlace(nameGenerator.getNewPlaceName(model)); |
103 | 415 | pnObject = new TimedPlaceComponent(Grid.getModifiedX(p.x), Grid | 432 | TimedPlaceComponent pnObject = new TimedPlaceComponent(p.x, p.y, tp); |
102 | 416 | .getModifiedY(p.y), tp); | ||
104 | 417 | model.add(tp); | 433 | model.add(tp); |
108 | 418 | guiModel.addPetriNetObject(pnObject); | 434 | addPetriNetObjectToModelandView(pnObject); |
109 | 419 | view.addNewPetriNetObject(pnObject); | 435 | |
110 | 420 | return (PlaceTransitionObject) pnObject; | 436 | getUndoManager().addNewEdit(new AddTimedPlaceCommand(pnObject, model, guiModel, view)); |
111 | 437 | |||
112 | 438 | return pnObject; | ||
113 | 421 | } | 439 | } |
114 | 422 | 440 | ||
123 | 423 | private PlaceTransitionObject newTAPNTransition(Point p, boolean timed) { | 441 | private PlaceTransitionObject newTAPNTransitionAddToModelView(Point p) { |
124 | 424 | p = adjustPoint(p, view.getZoom()); | 442 | p = adjustPointToGridAndZoom(p, view.getZoom()); |
125 | 425 | dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition( | 443 | |
126 | 426 | nameGenerator.getNewTransitionName(model)); | 444 | dk.aau.cs.model.tapn.TimedTransition transition = new dk.aau.cs.model.tapn.TimedTransition(nameGenerator.getNewTransitionName(model)); |
127 | 427 | 445 | ||
128 | 428 | pnObject = new TimedTransitionComponent(Grid.getModifiedX(p.x), | 446 | TimedTransitionComponent pnObject = new TimedTransitionComponent(p.x, p.y, transition); |
129 | 429 | Grid.getModifiedY(p.y), transition); | 447 | |
122 | 430 | |||
130 | 431 | model.add(transition); | 448 | model.add(transition); |
134 | 432 | guiModel.addPetriNetObject(pnObject); | 449 | addPetriNetObjectToModelandView(pnObject); |
135 | 433 | view.addNewPetriNetObject(pnObject); | 450 | |
136 | 434 | return (PlaceTransitionObject) pnObject; | 451 | getUndoManager().addNewEdit(new AddTimedTransitionCommand(pnObject, model, guiModel, view)); |
137 | 452 | return pnObject; | ||
138 | 435 | } | 453 | } |
139 | 436 | 454 | ||
142 | 437 | private PlaceTransitionObject newTAPNTransition(Point p) { | 455 | private AnnotationNote newAnnotationNoteAddToModelView(Point clickPoint) { |
143 | 438 | return newTAPNTransition(p, false); | 456 | Point p = adjustPointToGridAndZoom(clickPoint, view.getZoom()); |
144 | 457 | |||
145 | 458 | AnnotationNote pnObject = new AnnotationNote(p.x, p.y, true); | ||
146 | 459 | addPetriNetObjectToModelandView(pnObject); | ||
147 | 460 | |||
148 | 461 | getUndoManager().addNewEdit(new AddPetriNetObjectEdit(pnObject, view, guiModel)); | ||
149 | 462 | pnObject.enableEditMode(); | ||
150 | 463 | return pnObject; | ||
151 | 464 | } | ||
152 | 465 | |||
153 | 466 | private void continueFastMode(MouseEvent e, PlaceTransitionObject pto, ElementType nextMode) { | ||
154 | 467 | // connect arc | ||
155 | 468 | app.setMode(ElementType.TAPNARC); | ||
156 | 469 | pto.getMouseHandler().mousePressed(e); | ||
157 | 470 | pto.getMouseHandler().mouseReleased(e); | ||
158 | 471 | app.setMode(nextMode); | ||
159 | 472 | // enter fast mode | ||
160 | 473 | pto.dispatchEvent(e); | ||
161 | 439 | } | 474 | } |
162 | 440 | 475 | ||
163 | 441 | @Override | 476 | @Override |
164 | @@ -444,135 +479,89 @@ | |||
165 | 444 | 479 | ||
166 | 445 | // check for control down here enables it to attach the arc being drawn to an existing place/transition | 480 | // check for control down here enables it to attach the arc being drawn to an existing place/transition |
167 | 446 | 481 | ||
170 | 447 | Point start = e.getPoint(); | 482 | |
171 | 448 | Point p; | 483 | Point clickPoint = e.getPoint(); |
172 | 484 | |||
173 | 449 | if (SwingUtilities.isLeftMouseButton(e)) { | 485 | if (SwingUtilities.isLeftMouseButton(e)) { |
174 | 450 | 486 | ||
175 | 451 | Pipe.ElementType mode = app.getMode(); | 487 | Pipe.ElementType mode = app.getMode(); |
177 | 452 | PlaceTransitionObject pto; | 488 | PlaceTransitionObject newpto; //declared here as switch is one big scope |
178 | 489 | |||
179 | 453 | switch (mode) { | 490 | switch (mode) { |
293 | 454 | 491 | case TAPNPLACE: | |
294 | 455 | case TAPNPLACE: | 492 | // create place |
295 | 456 | // create place | 493 | newpto = newTimedPlaceAddToModelView(clickPoint); |
296 | 457 | PlaceTransitionObject pto2 = newTimedPlace(e.getPoint()); | 494 | |
297 | 458 | getUndoManager().addNewEdit( | 495 | if (e.isControlDown()) { |
298 | 459 | new AddTimedPlaceCommand( | 496 | continueFastMode(e, newpto, ElementType.FAST_TRANSITION); |
299 | 460 | (TimedPlaceComponent) pto2, model, | 497 | } |
300 | 461 | guiModel, view)); | 498 | break; |
301 | 462 | if (e.isControlDown()) { | 499 | |
302 | 463 | // connect arc | 500 | case TAPNTRANS: |
303 | 464 | app.setMode(ElementType.TAPNARC); | 501 | // create transition |
304 | 465 | pto2.getMouseHandler().mousePressed(e); | 502 | newpto = newTAPNTransitionAddToModelView(clickPoint); |
305 | 466 | pto2.getMouseHandler().mouseReleased(e); | 503 | |
306 | 467 | app.setMode(ElementType.FAST_TRANSITION); | 504 | if (e.isControlDown()) { |
307 | 468 | // enter fast mode | 505 | continueFastMode(e, newpto, ElementType.FAST_PLACE); |
308 | 469 | pnObject.dispatchEvent(e); | 506 | } |
309 | 470 | } | 507 | break; |
310 | 471 | break; | 508 | |
311 | 472 | 509 | case ANNOTATION: | |
312 | 473 | case TAPNTRANS: | 510 | newAnnotationNoteAddToModelView(clickPoint); |
313 | 474 | // create transition | 511 | break; |
314 | 475 | pto = newTAPNTransition(e.getPoint()); | 512 | |
315 | 476 | getUndoManager().addNewEdit( | 513 | case ARC: |
316 | 477 | new AddTimedTransitionCommand( | 514 | case TAPNARC: |
317 | 478 | (TimedTransitionComponent) pto, model, | 515 | case INHIBARC: |
318 | 479 | guiModel, view)); | 516 | case TRANSPORTARC: |
319 | 480 | if (e.isControlDown()) { | 517 | case TAPNINHIBITOR_ARC: |
320 | 481 | // connect arc | 518 | // Add point to arc in creation |
321 | 482 | app.setMode(ElementType.TAPNARC); | 519 | if (createArc != null) { |
322 | 483 | pto.getMouseHandler().mousePressed(e); | 520 | addArcPathPoint(createArc, e); |
323 | 484 | pto.getMouseHandler().mouseReleased(e); | 521 | } |
324 | 485 | // enter fast mode | 522 | break; |
325 | 486 | app.setMode(ElementType.FAST_PLACE); | 523 | |
326 | 487 | pnObject.dispatchEvent(e); | 524 | |
327 | 488 | } | 525 | case DRAG: |
328 | 489 | break; | 526 | dragStart = new Point(clickPoint); |
329 | 490 | 527 | break; | |
330 | 491 | case ARC: | 528 | |
331 | 492 | case TAPNARC: | 529 | case FAST_TRANSITION: |
332 | 493 | case INHIBARC: | 530 | // create transition |
333 | 494 | // Add point to arc in creation | 531 | newpto = newTAPNTransitionAddToModelView(e.getPoint()); |
334 | 495 | if (createArc != null) { | 532 | |
335 | 496 | addPoint(createArc, e); | 533 | fastDrawAction(e, newpto, ElementType.FAST_PLACE); |
336 | 497 | } | 534 | break; |
337 | 498 | break; | 535 | |
338 | 499 | 536 | case FAST_PLACE: | |
339 | 500 | case ANNOTATION: | 537 | // create place |
340 | 501 | p = adjustPoint(e.getPoint(), view.getZoom()); | 538 | newpto = newTimedPlaceAddToModelView(e.getPoint()); |
341 | 502 | 539 | ||
342 | 503 | pnObject = new AnnotationNote(p.x, p.y, true); | 540 | fastDrawAction(e, newpto, ElementType.FAST_TRANSITION); |
343 | 504 | guiModel.addPetriNetObject(pnObject); | 541 | break; |
344 | 505 | view.addNewPetriNetObject(pnObject); | 542 | |
345 | 506 | getUndoManager() | 543 | default: |
346 | 507 | .addNewEdit( | 544 | break; |
234 | 508 | new AddPetriNetObjectEdit(pnObject, view, | ||
235 | 509 | guiModel)); | ||
236 | 510 | ((AnnotationNote) pnObject).enableEditMode(); | ||
237 | 511 | break; | ||
238 | 512 | case TRANSPORTARC: | ||
239 | 513 | if (createArc != null) { | ||
240 | 514 | addPoint(createArc, e); | ||
241 | 515 | } | ||
242 | 516 | break; | ||
243 | 517 | case TAPNINHIBITOR_ARC: | ||
244 | 518 | // Add point to arc in creation | ||
245 | 519 | if (createArc != null) { | ||
246 | 520 | addPoint(createArc, e); | ||
247 | 521 | } | ||
248 | 522 | break; | ||
249 | 523 | case DRAG: | ||
250 | 524 | dragStart = new Point(start); | ||
251 | 525 | break; | ||
252 | 526 | |||
253 | 527 | case FAST_TRANSITION: | ||
254 | 528 | // create transition | ||
255 | 529 | pto = newTAPNTransition(e.getPoint()); | ||
256 | 530 | getUndoManager().addNewEdit(new AddTimedTransitionCommand((TimedTransitionComponent) pto, model, guiModel, view)); | ||
257 | 531 | app.setMode(ElementType.TAPNARC); | ||
258 | 532 | pto.getMouseHandler().mouseReleased(e); | ||
259 | 533 | |||
260 | 534 | if (e.isControlDown()) { | ||
261 | 535 | // connect arc | ||
262 | 536 | pnObject.dispatchEvent(e); | ||
263 | 537 | app.setMode(ElementType.TAPNARC); | ||
264 | 538 | pto.getMouseHandler().mousePressed(e); | ||
265 | 539 | pto.getMouseHandler().mouseReleased(e); | ||
266 | 540 | // enter fast mode | ||
267 | 541 | app.setMode(ElementType.FAST_PLACE); | ||
268 | 542 | } else{ | ||
269 | 543 | app.endFastMode(); | ||
270 | 544 | } | ||
271 | 545 | break; | ||
272 | 546 | case FAST_PLACE: | ||
273 | 547 | // create place | ||
274 | 548 | PlaceTransitionObject pto3 = newTimedPlace(e.getPoint()); | ||
275 | 549 | getUndoManager().addNewEdit(new AddTimedPlaceCommand((TimedPlaceComponent) pto3, model, guiModel, view)); | ||
276 | 550 | app.setMode(ElementType.TAPNARC); | ||
277 | 551 | pto3.getMouseHandler().mouseReleased(e); | ||
278 | 552 | |||
279 | 553 | if (e.isControlDown()) { | ||
280 | 554 | // connect arc | ||
281 | 555 | pnObject.dispatchEvent(e); | ||
282 | 556 | app.setMode(ElementType.TAPNARC); | ||
283 | 557 | pto3.getMouseHandler().mousePressed(e); | ||
284 | 558 | pto3.getMouseHandler().mouseReleased(e); | ||
285 | 559 | // enter fast mode | ||
286 | 560 | app.setMode(ElementType.FAST_TRANSITION); | ||
287 | 561 | } else{ | ||
288 | 562 | app.endFastMode(); | ||
289 | 563 | } | ||
290 | 564 | break; | ||
291 | 565 | default: | ||
292 | 566 | break; | ||
347 | 567 | } | 545 | } |
348 | 568 | } else { | 546 | } else { |
349 | 569 | setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); | 547 | setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); |
351 | 570 | dragStart = new Point(start); | 548 | dragStart = new Point(clickPoint); |
352 | 571 | } | 549 | } |
353 | 572 | updatePreferredSize(); | 550 | updatePreferredSize(); |
354 | 573 | } | 551 | } |
355 | 574 | 552 | ||
357 | 575 | private void addPoint(final Arc createArc, final MouseEvent e) { | 553 | private void fastDrawAction(MouseEvent e, PlaceTransitionObject newpto, ElementType fastTransition) { |
358 | 554 | app.setMode(ElementType.TAPNARC); | ||
359 | 555 | newpto.getMouseHandler().mouseReleased(e); | ||
360 | 556 | |||
361 | 557 | if (e.isControlDown()) { | ||
362 | 558 | continueFastMode(e, newpto, fastTransition); | ||
363 | 559 | } else { | ||
364 | 560 | app.endFastMode(); | ||
365 | 561 | } | ||
366 | 562 | } | ||
367 | 563 | |||
368 | 564 | private void addArcPathPoint(final Arc createArc, final MouseEvent e) { | ||
369 | 576 | int x = Grid.getModifiedX(e.getX()); | 565 | int x = Grid.getModifiedX(e.getX()); |
370 | 577 | int y = Grid.getModifiedY(e.getY()); | 566 | int y = Grid.getModifiedY(e.getY()); |
371 | 578 | 567 | ||
372 | @@ -594,9 +583,7 @@ | |||
373 | 594 | } | 583 | } |
374 | 595 | } | 584 | } |
375 | 596 | 585 | ||
379 | 597 | /** | 586 | |
377 | 598 | * @see javax.swing.event.MouseInputAdapter#mouseDragged(java.awt.event.MouseEvent) | ||
378 | 599 | */ | ||
380 | 600 | @Override | 587 | @Override |
381 | 601 | public void mouseDragged(MouseEvent e) { | 588 | public void mouseDragged(MouseEvent e) { |
382 | 602 | // if (CreateGui.getApp().getMode() == Pipe.DRAG){ | 589 | // if (CreateGui.getApp().getMode() == Pipe.DRAG){ |