Merge lp:~yrke/tapaal/refactor-arcdraw-combinedublicatedraw into lp:tapaal

Proposed by Kenneth Yrke Jørgensen on 2018-12-29
Status: Merged
Approved by: Kenneth Yrke Jørgensen on 2019-03-10
Approved revision: 981
Merged at revision: 988
Proposed branch: lp:~yrke/tapaal/refactor-arcdraw-combinedublicatedraw
Merge into: lp:tapaal
Diff against target: 255 lines (+81/-92)
3 files modified
src/pipe/gui/graphicElements/Arc.java (+70/-1)
src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java (+10/-41)
src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java (+1/-50)
To merge this branch: bzr merge lp:~yrke/tapaal/refactor-arcdraw-combinedublicatedraw
Reviewer Review Type Date Requested Status
TAPAAL Reviewers 2018-12-29 Pending
Review via email: mp+361332@code.launchpad.net

Commit message

Refactored drawing of Arc-heads

Now using one function to draw arc-heads, in supercalss arc. No longer needed to overwrite the paint class to change the arc head. Set arc head via Shape head, and set if transparent with fillHead boolean.

Description of the change

Test drawing of all arc type, and save/load of nets. Check that arc head are rendered correctly.
Especially for inhibitor arcs.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/pipe/gui/graphicElements/Arc.java'
2--- src/pipe/gui/graphicElements/Arc.java 2018-08-05 22:20:35 +0000
3+++ src/pipe/gui/graphicElements/Arc.java 2018-12-29 11:17:56 +0000
4@@ -1,7 +1,8 @@
5 package pipe.gui.graphicElements;
6
7-import java.awt.Rectangle;
8+import java.awt.*;
9 import java.awt.event.ActionEvent;
10+import java.awt.geom.AffineTransform;
11 import java.awt.geom.Point2D;
12
13 import javax.swing.*;
14@@ -22,6 +23,10 @@
15
16 private static final long serialVersionUID = 6527845538091358791L;
17
18+ protected Shape head = new Polygon(new int[] { 0, 5, 0, -5 }, new int[] {
19+ 0, -10, -7, -10 }, 4);
20+ protected boolean fillHead = true; //If true, fill the shape when drawing, if false, fill with bg color.
21+
22 protected NameLabel label;
23
24 private static Point2D.Double point;
25@@ -219,6 +224,70 @@
26 }
27
28 @Override
29+ public void paintComponent(Graphics g) {
30+ super.paintComponent(g);
31+ Graphics2D g2 = (Graphics2D) g;
32+
33+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
34+ RenderingHints.VALUE_ANTIALIAS_ON);
35+
36+ g2.translate(COMPONENT_DRAW_OFFSET + zoomGrow
37+ - myPath.getBounds().getX(), COMPONENT_DRAW_OFFSET + zoomGrow
38+ - myPath.getBounds().getY());
39+
40+ AffineTransform reset = g2.getTransform();
41+
42+ //Draw Path
43+ if (selected && !ignoreSelection) {
44+ g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
45+ this.label.setForeground(Pipe.SELECTION_LINE_COLOUR);
46+ } else {
47+ g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
48+ this.label.setForeground(Pipe.ELEMENT_LINE_COLOUR);
49+ }
50+
51+ g2.setStroke(new BasicStroke(0.01f * zoom));
52+ g2.draw(myPath);
53+
54+ //Draw Arrow-head
55+ //Jump to arc end
56+ g2.translate(myPath.getPoint(myPath.getEndIndex()).getX(), myPath
57+ .getPoint(myPath.getEndIndex()).getY());
58+
59+ //Rotate to match arrowhead to arc angle
60+ g2.rotate(myPath.getEndAngle() + Math.PI);
61+ g2.setColor(java.awt.Color.WHITE);
62+
63+ g2.transform(Zoomer.getTransform(zoom));
64+ g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
65+
66+ if (selected && !ignoreSelection) {
67+ g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
68+ this.label.setForeground(Pipe.SELECTION_LINE_COLOUR);
69+ } else {
70+ g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
71+ this.label.setForeground(Pipe.ELEMENT_LINE_COLOUR);
72+ }
73+
74+ g2.setStroke(new BasicStroke(0.8f));
75+
76+ if (fillHead) {
77+ g2.fill(head);
78+ } else {
79+ Paint p = g2.getPaint();
80+
81+ //Fill first to get thick edge
82+ g2.setColor(java.awt.Color.WHITE); // XXX: should be GB color of canvas / drawingsurface
83+ g2.fill(head);
84+
85+ g2.setPaint(p);
86+ g2.draw(head);
87+ }
88+
89+ g2.transform(reset);
90+ }
91+
92+ @Override
93 public boolean contains(int x, int y) {
94 point = new Point2D.Double(x + myPath.getBounds().getX()
95 - COMPONENT_DRAW_OFFSET - zoomGrow, y
96
97=== modified file 'src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java'
98--- src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java 2014-06-10 16:32:25 +0000
99+++ src/pipe/gui/graphicElements/tapn/TimedInhibitorArcComponent.java 2018-12-29 11:17:56 +0000
100@@ -5,6 +5,7 @@
101 import java.awt.Graphics2D;
102 import java.awt.RenderingHints;
103 import java.awt.geom.AffineTransform;
104+import java.awt.geom.Ellipse2D;
105 import java.util.Hashtable;
106
107 import pipe.dataLayer.DataLayer;
108@@ -29,14 +30,17 @@
109
110 public TimedInhibitorArcComponent(TimedOutputArcComponent arc) {
111 super(arc);
112+ setHead();
113 }
114
115 public TimedInhibitorArcComponent(TimedOutputArcComponent arc, String guard) {
116 super(arc, guard);
117+ setHead();
118 }
119
120 public TimedInhibitorArcComponent(PlaceTransitionObject source) {
121 super(source);
122+ setHead();
123 }
124
125 public void setUnderlyingArc(TimedInhibitorArc arc) {
126@@ -48,6 +52,11 @@
127 return inhibitorArc;
128 }
129
130+ protected void setHead() {
131+ head = new Ellipse2D.Double(-4, -8, 8, 8);
132+ fillHead = false;
133+ }
134+
135 @Override
136 public void delete() {
137 if (inhibitorArc != null)
138@@ -111,47 +120,7 @@
139 }
140
141 @Override
142- public void paintComponent(Graphics g) {
143- // super.paintComponent(g);
144- Graphics2D g2 = (Graphics2D) g;
145-
146- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
147- RenderingHints.VALUE_ANTIALIAS_ON);
148-
149- g2.translate(COMPONENT_DRAW_OFFSET + zoomGrow
150- - myPath.getBounds().getX(), COMPONENT_DRAW_OFFSET + zoomGrow
151- - myPath.getBounds().getY());
152-
153- if (selected && !ignoreSelection) {
154- g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
155- } else {
156- g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
157- }
158-
159- g2.setStroke(new BasicStroke(0.01f * zoom));
160- g2.draw(myPath);
161-
162- g2.translate(myPath.getPoint(myPath.getEndIndex()).getX(), myPath
163- .getPoint(myPath.getEndIndex()).getY());
164-
165- g2.rotate(myPath.getEndAngle() + Math.PI);
166- g2.setColor(java.awt.Color.WHITE);
167-
168- AffineTransform reset = g2.getTransform();
169- g2.transform(Zoomer.getTransform(zoom));
170-
171- g2.setStroke(new BasicStroke(0.8f));
172- g2.fillOval(-4, -8, 8, 8);
173-
174- if (selected && !ignoreSelection) {
175- g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
176- } else {
177- g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
178- }
179- g2.drawOval(-4, -8, 8, 8);
180-
181- g2.setTransform(reset);
182- }
183+
184
185 public TimedInhibitorArcComponent copy(TimedArcPetriNet tapn, DataLayer guiModel, Hashtable<PlaceTransitionObject, PlaceTransitionObject> oldToNewMapping) {
186 TimedInhibitorArcComponent arc = new TimedInhibitorArcComponent(this);
187
188=== modified file 'src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java'
189--- src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java 2018-08-11 10:29:10 +0000
190+++ src/pipe/gui/graphicElements/tapn/TimedOutputArcComponent.java 2018-12-29 11:17:56 +0000
191@@ -47,9 +47,6 @@
192 */
193 private static final long serialVersionUID = 5588142404135607382L;
194
195- protected Polygon head = new Polygon(new int[] { 0, 5, 0, -5 }, new int[] {
196- 0, -10, -7, -10 }, 4);
197-
198 private dk.aau.cs.model.tapn.TimedOutputArc outputArc;
199
200 /**
201@@ -201,53 +198,7 @@
202
203 }
204
205- @Override
206- public void paintComponent(Graphics g) {
207- super.paintComponent(g);
208- Graphics2D g2 = (Graphics2D) g;
209-
210- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
211- RenderingHints.VALUE_ANTIALIAS_ON);
212-
213- g2.translate(COMPONENT_DRAW_OFFSET + zoomGrow
214- - myPath.getBounds().getX(), COMPONENT_DRAW_OFFSET + zoomGrow
215- - myPath.getBounds().getY());
216-
217- AffineTransform reset = g2.getTransform();
218-
219- if (selected && !ignoreSelection) {
220- g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
221- this.label.setForeground(Pipe.SELECTION_LINE_COLOUR);
222- } else {
223- g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
224- this.label.setForeground(Pipe.ELEMENT_LINE_COLOUR);
225- }
226-
227- g2.setStroke(new BasicStroke(0.01f * zoom));
228- g2.draw(myPath);
229-
230- g2.translate(myPath.getPoint(myPath.getEndIndex()).getX(), myPath
231- .getPoint(myPath.getEndIndex()).getY());
232-
233- g2.rotate(myPath.getEndAngle() + Math.PI);
234- g2.setColor(java.awt.Color.WHITE);
235-
236- g2.transform(Zoomer.getTransform(zoom));
237- g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
238-
239- if (selected && !ignoreSelection) {
240- g2.setPaint(Pipe.SELECTION_LINE_COLOUR);
241- this.label.setForeground(Pipe.SELECTION_LINE_COLOUR);
242- } else {
243- g2.setPaint(Pipe.ELEMENT_LINE_COLOUR);
244- this.label.setForeground(Pipe.ELEMENT_LINE_COLOUR);
245- }
246-
247- g2.setStroke(new BasicStroke(0.8f));
248- g2.fillPolygon(head);
249-
250- g2.transform(reset);
251- }
252+
253
254 public dk.aau.cs.model.tapn.TimedOutputArc underlyingArc() {
255 return outputArc;

Subscribers

People subscribed via source and target branches