-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRoutingEdgeStyle.java
More file actions
325 lines (286 loc) · 9.58 KB
/
RoutingEdgeStyle.java
File metadata and controls
325 lines (286 loc) · 9.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/****************************************************************************
**
** This demo file is part of yFiles for JavaFX 3.6.
**
** Copyright (c) 2000-2023 by yWorks GmbH, Vor dem Kreuzberg 28,
** 72070 Tuebingen, Germany. All rights reserved.
**
** yFiles demo files exhibit yFiles for JavaFX functionalities. Any redistribution
** of demo files in source code or binary form, with or without
** modification, is not permitted.
**
** Owners of a valid software license for a yFiles for JavaFX version that this
** demo is shipped with are allowed to use the demo source code as basis
** for their own yFiles for JavaFX powered applications. Use of such programs is
** governed by the rights and conditions as set out in the yFiles for JavaFX
** license agreement.
**
** THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
** NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
***************************************************************************/
package viewer.ganttchart;
import com.yworks.yfiles.geometry.GeneralPath;
import com.yworks.yfiles.geometry.PointD;
import com.yworks.yfiles.geometry.Tangent;
import com.yworks.yfiles.graph.IEdge;
import com.yworks.yfiles.graph.styles.Arrow;
import com.yworks.yfiles.graph.styles.ArrowType;
import com.yworks.yfiles.graph.styles.IArrow;
import com.yworks.yfiles.graph.styles.IEdgeStyle;
import com.yworks.yfiles.graph.styles.IEdgeStyleRenderer;
import com.yworks.yfiles.graph.styles.PathBasedEdgeStyleRenderer;
import com.yworks.yfiles.view.Pen;
import javafx.scene.paint.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Visualizes an edge in a pre-determined orthogonal fashion.
* All existing bends of the edge are ignored.
*/
public class RoutingEdgeStyle implements IEdgeStyle {
private int outSegmentLength;
private int inSegmentLength;
private int middleSegmentOffset;
private int smoothing;
private Pen pen;
private IArrow tgtArrow;
private IArrow srcArrow;
/**
* Initializes a new {@code RoutingEdgeStyle} instance.
*/
public RoutingEdgeStyle() {
this(20, 10);
}
/**
* Initializes a new {@code RoutingEdgeStyle} instance.
* @param outSegmentLength The length of the horizontal segment that connects to the source node.
* @param inSegmentLength The length of the horizontal segment that connects to the target node.
*/
public RoutingEdgeStyle( int outSegmentLength, int inSegmentLength ) {
this(outSegmentLength, inSegmentLength, Color.rgb(100, 100, 100), 2);
}
/**
* Initializes a new {@code RoutingEdgeStyle} instance.
* @param outSegmentLength The length of the horizontal segment that connects to the source node.
* @param inSegmentLength The length of the horizontal segment that connects to the target node.
*/
public RoutingEdgeStyle( int outSegmentLength, int inSegmentLength, Color fill, int thickness) {
this.inSegmentLength = inSegmentLength;
this.outSegmentLength = outSegmentLength;
this.middleSegmentOffset = 32;
this.smoothing = 10;
this.pen = new Pen(fill, thickness);
this.srcArrow = Arrow.NONE;
this.tgtArrow = new Arrow(ArrowType.TRIANGLE, fill);
}
/**
* Gets the length of the horizontal segment that connects to the source node.
*/
public int getOutSegmentLength() {
return outSegmentLength;
}
/**
* Sets the length of the horizontal segment that connects to the source node.
*/
public void setOutSegmentLength( int outSegmentLength ) {
this.outSegmentLength = outSegmentLength;
}
/**
* Gets the length of the horizontal segment that connects to the target node.
*/
public int getInSegmentLength() {
return inSegmentLength;
}
/**
* Sets the length of the horizontal segment that connects to the target node.
*/
public void setInSegmentLength( int inSegmentLength ) {
this.inSegmentLength = inSegmentLength;
}
/**
* Gets the vertical distance between the source port and the horizontal middle segment.
* This only has an effect when the source location is right of the target location.
*/
public int getMiddleSegmentOffset() {
return middleSegmentOffset;
}
/**
* Sets the vertical distance between the source port and the horizontal middle segment.
* This only has an effect when the source location is right of the target location.
*/
public void setMiddleSegmentOffset( int middleSegmentOffset ) {
this.middleSegmentOffset = middleSegmentOffset;
}
/**
* Gets the amount of corner rounding.
*/
public int getSmoothing() {
return smoothing;
}
/**
* Sets the amount of corner rounding.
*/
public void setSmoothing( int smoothing ) {
this.smoothing = smoothing;
}
/**
* Gets the source arrow.
*/
public IArrow getSrcArrow() {
return srcArrow;
}
/**
* Sets the source arrow.
*/
public void setSrcArrow( IArrow srcArrow ) {
this.srcArrow = srcArrow;
}
/**
* Gets the target arrow.
*/
public IArrow getTgtArrow() {
return tgtArrow;
}
/**
* Sets the target arrow.
*/
public void setTgtArrow( IArrow tgtArrow ) {
this.tgtArrow = tgtArrow;
}
/**
* Gets the Pen used to draw the edge.
*/
public Pen getPen() {
return pen;
}
/**
* Sets the Pen used to draw the edge.
*/
public void setPen( Pen pen ) {
this.pen = pen;
}
/**
* @return {@link RoutingEdgeStyleRenderer}
*/
@Override
public IEdgeStyleRenderer getRenderer() {
return new RoutingEdgeStyleRenderer();
}
/**
* @return {@link RoutingEdgeStyleRenderer}
*/
@Override
public Object clone() {
return new RoutingEdgeStyle(outSegmentLength, inSegmentLength, null, -1);
}
private static class RoutingEdgeStyleRenderer extends PathBasedEdgeStyleRenderer<RoutingEdgeStyle> {
/**
* Initializes a new {@code RoutingEdgeStyleRenderer} instance.
*/
RoutingEdgeStyleRenderer() {
super(RoutingEdgeStyle.class);
}
/**
* Calculates the points that define the edge path.
* @return A list of points that define the edge path.
*/
private List<PointD> getEdgePoints( IEdge edge ){
PointD srcLocation = edge.getSourcePort().getLocation();
PointD tgtLocation = edge.getTargetPort().getLocation();
ArrayList<PointD> points = new ArrayList<PointD>();
points.add(srcLocation);
// the source location with the x-offset
double srcX = srcLocation.getX() + this.getStyle().getOutSegmentLength();
// the target location with the x-offset
double tgtX = tgtLocation.getX() - this.getStyle().getInSegmentLength();
// check if source and target are not exactly in the same row - in this case we just draw a straight line
if (srcX > tgtX) {
// source is right of target
// get the y-coordinate of the vertical middle segment
double middleSegmentY = srcLocation.getY() <= tgtLocation.getY()
? srcLocation.getY() + getStyle().getMiddleSegmentOffset()
: srcLocation.getY() - getStyle().getMiddleSegmentOffset();
points.add(new PointD(srcX, srcLocation.getY()));
points.add(new PointD(srcX, middleSegmentY));
points.add(new PointD(tgtX, middleSegmentY));
points.add(new PointD(tgtX, tgtLocation.getY()));
} else {
if (srcLocation.getY() != tgtLocation.getY()) {
// source is left of target
points.add(new PointD(srcX, srcLocation.getY()));
points.add(new PointD(srcX, tgtLocation.getY()));
}
}
points.add(tgtLocation);
return points;
}
/**
* Constructs the orthogonal edge path.
*/
@Override
protected GeneralPath createPath() {
// create a new GeneralPath with the edge points
GeneralPath generalPath = new GeneralPath();
Iterator<PointD> points = getEdgePoints(getEdge()).iterator();
if (points.hasNext()) {
generalPath.moveTo(points.next());
}
while (points.hasNext()) {
generalPath.lineTo(points.next());
}
return generalPath;
}
/**
* Get the tangent on this path at the given ratio.
*/
@Override
public Tangent getTangent( double ratio ) {
return getPath().getTangent(ratio);
}
/**
* Gets the tangent on this path instance at the segment and segment ratio.
*/
@Override
public Tangent getTangent( int segmentIndex, double ratio ) {
return getPath().getTangent(segmentIndex, ratio);
}
/**
* Gets the segment count which is the number of edge points -1.
*/
@Override
public int getSegmentCount() {
return getEdgePoints(getEdge()).size() - 1;
}
/**
* Gets the target arrow.
*/
@Override
protected IArrow getTargetArrow() {
return getStyle().getTgtArrow();
}
/**
* Gets the source arrow.
*/
@Override
protected IArrow getSourceArrow() {
return getStyle().getSrcArrow();
}
/**
* Gets the pen used by style.
*/
@Override
protected Pen getPen() {
return getStyle().getPen();
}
}
}