~yrke/tapaal/slimImageIcons-2

« back to all changes in this revision

Viewing changes to src/pipe/gui/graphicElements/Transition.java

  • Committer: Jiri Srba
  • Date: 2020-04-28 19:15:28 UTC
  • mfrom: (998.2.376 testbranch)
  • Revision ID: srba@cs.aau.dk-20200428191528-3xxjqa1r4jcob5ur
merged in lp:~yrke/tapaal/testbranch doing majour refactoring of the GUI

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import java.awt.Graphics2D;
6
6
import java.awt.RenderingHints;
7
7
import java.awt.Shape;
8
 
import java.awt.event.ActionEvent;
9
 
import java.awt.event.ActionListener;
10
8
import java.awt.geom.AffineTransform;
11
9
import java.awt.geom.GeneralPath;
12
10
import java.awt.geom.Point2D;
59
57
                        String idInput, double nameOffsetXInput,
60
58
                        double nameOffsetYInput,
61
59
                        boolean infServer, int angleInput, int priority) {
 
60
                this((int)positionXInput, (int)positionYInput, idInput, (int)nameOffsetXInput, (int)nameOffsetYInput, angleInput);
 
61
        }
 
62
 
 
63
        /**
 
64
         * Create Petri-Net Transition object
 
65
         */
 
66
        public Transition(
 
67
                        int positionXInput,
 
68
                        int positionYInput,
 
69
                        String idInput,
 
70
                        int nameOffsetXInput,
 
71
                        int nameOffsetYInput,
 
72
                        int angleInput
 
73
        ){
62
74
                super(positionXInput, positionYInput, idInput, nameOffsetXInput, nameOffsetYInput);
63
75
                componentWidth = TRANSITION_HEIGHT; // sets width
64
76
                componentHeight = TRANSITION_HEIGHT;// sets height
65
77
                constructTransition();
66
78
                angle = 0;
67
 
                setCentre((int) positionX, (int) positionY);
68
79
                rotate(angleInput);
69
80
                updateBounds();
70
81
        }
78
89
         *            Y-axis Position
79
90
         */
80
91
        public Transition(double positionXInput, double positionYInput) {
81
 
                super(positionXInput, positionYInput);
82
 
                componentWidth = TRANSITION_HEIGHT; // sets width
83
 
                componentHeight = TRANSITION_HEIGHT;// sets height
84
 
                constructTransition();
85
 
                setCentre((int) positionX, (int) positionY);
86
 
                updateBounds();
87
 
                this.updateEndPoints();
 
92
                this((int)positionXInput, (int)positionYInput,null, 0,0, 0);
88
93
        }
89
94
 
90
95
        @Override
127
132
                                .toRadians(angleInc), componentWidth / 2, componentHeight / 2));
128
133
                outlineTransition();
129
134
 
130
 
                Iterator<ArcAngleCompare> arcIterator = arcAngleList.iterator();
131
 
                while (arcIterator.hasNext()) {
132
 
                        (arcIterator.next()).calcAngle();
 
135
                for (ArcAngleCompare arcAngleCompare : arcAngleList) {
 
136
                        arcAngleCompare.calcAngle();
133
137
                }
134
138
                Collections.sort(arcAngleList);
135
139
 
199
203
        
200
204
        /**
201
205
         * Sets whether Transition is enabled
202
 
         * 
203
 
         * @return enabled if True
204
206
         */
205
207
        @Override
206
208
        public void setEnabled(boolean status) {
227
229
 
228
230
        @Override
229
231
        public boolean contains(int x, int y) {
230
 
                int zoomPercentage = zoom;
231
 
 
232
 
                double unZoomedX = (x - COMPONENT_DRAW_OFFSET)
233
 
                                / (zoomPercentage / 100.0);
234
 
                double unZoomedY = (y - COMPONENT_DRAW_OFFSET)
235
 
                                / (zoomPercentage / 100.0);
236
 
 
237
 
                Arc someArc = CreateGui.getDrawingSurface().createArc;
238
 
                if (someArc != null) { // Must be drawing a new Arc if non-NULL.
239
 
                        if ((proximityTransition.contains((int) unZoomedX, (int) unZoomedY) || transition
240
 
                                        .contains((int) unZoomedX, (int) unZoomedY))
241
 
                                        && areNotSameType(someArc.getSource())) {
242
 
                                // assume we are only snapping the target...
243
 
                                if (someArc.getTarget() != this) {
244
 
                                        someArc.setTarget(this);
245
 
                                }
246
 
                                someArc.updateArcPosition();
247
 
                                return true;
248
 
                        } else {
249
 
                                if (someArc.getTarget() == this) {
250
 
 
251
 
                                        someArc.setTarget(null);
252
 
                                        removeArcCompareObject(someArc);
253
 
                                        updateConnected();
254
 
                                }
255
 
                                return false;
256
 
                        }
 
232
                int zoomPercentage = getZoom();
 
233
 
 
234
                double unZoomedX = (x - COMPONENT_DRAW_OFFSET) / (zoomPercentage / 100.0);
 
235
                double unZoomedY = (y - COMPONENT_DRAW_OFFSET) / (zoomPercentage / 100.0);
 
236
 
 
237
                Arc createArc = CreateGui.getDrawingSurface().createArc;
 
238
                if (createArc != null) { // Must be drawing a new Arc if non-NULL.
 
239
                        return (proximityTransition.contains((int) unZoomedX, (int) unZoomedY) ||
 
240
                                        transition.contains((int) unZoomedX, (int) unZoomedY));
257
241
                } else {
258
242
                        return transition.contains((int) unZoomedX, (int) unZoomedY);
259
243
                }
279
263
                                arcIterator.remove();
280
264
                                continue;
281
265
                        }
 
266
 
282
267
                        if (thisArc.arc == arc) {
283
268
                                thisArc.calcAngle();
284
269
                                match = true;
323
308
                                .toRadians(angle + Math.PI));
324
309
                Point2D.Double transformed = new Point2D.Double();
325
310
 
326
 
                transform.concatenate(Zoomer.getTransform(zoom));
 
311
                transform.concatenate(Zoomer.getTransform(getZoom()));
327
312
 
328
313
                arcIterator = top.iterator();
329
314
                transform.transform(new Point2D.Double(1, 0.5 * TRANSITION_HEIGHT),
396
381
                }
397
382
        }
398
383
 
399
 
        @Override
400
 
        public void addedToGui() {
401
 
                super.addedToGui();
402
 
                update(true);
403
 
        }
404
 
 
405
384
        private String getText() {
406
385
                return "";
407
386
        }
408
387
 
409
388
        @Override
410
 
        public void setCentre(double x, double y) {
411
 
                super.setCentre(x, y);
412
 
                update(true);
413
 
        }
414
 
 
415
 
        @Override
416
 
        public void toggleAttributesVisible() {
417
 
                attributesVisible = !attributesVisible;
418
 
                update(true);
419
 
        }
420
 
 
421
 
        @Override
422
389
        public void update(boolean displayConstantNames) {
423
 
                pnName.setText(getText());
424
 
                pnName.zoomUpdate(zoom);
 
390
                getNameLabel().setText(getText());
 
391
 
425
392
                super.update(displayConstantNames);
426
393
                this.repaint();
427
394
        }
441
408
                }
442
409
 
443
410
                public int compareTo(ArcAngleCompare arg0) {
444
 
                        double angle2 = arg0.angle;
445
 
 
446
 
                        return (angle < angle2 ? -1 : (angle == angle2 ? 0 : 1));
 
411
                        return (Double.compare(this.angle, arg0.angle));
447
412
                }
448
413
 
449
414
                private void calcAngle() {
487
452
         }
488
453
         
489
454
         private void initBlinkTimer(){
490
 
                 blinkTimer = new Timer(150, new ActionListener() {                      
491
 
                      public void actionPerformed(ActionEvent evt) {                                              
492
 
                          if(blinkCount <= 2 ){
493
 
                                  setVisible(!isVisible());
494
 
                                  blinkCount++;                   
495
 
                          } else {
496
 
                                  setVisible(true); // Ensures that transition is always visible after last blink
497
 
                                  blinkTimer.stop();
498
 
                          }
499
 
                      }
 
455
                 blinkTimer = new Timer(150, evt -> {
 
456
                         if(blinkCount <= 2 ){
 
457
                                 setVisible(!isVisible());
 
458
                                 blinkCount++;
 
459
                         } else {
 
460
                                 setVisible(true); // Ensures that transition is always visible after last blink
 
461
                                 blinkTimer.stop();
 
462
                         }
500
463
                 });
501
464
         }
502
465
}