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
|
package com.c2kernel.gui.lifecycle.instance;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import com.c2kernel.graph.model.DirectedEdge;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.gui.graph.view.DirectedEdgeRenderer;
import com.c2kernel.lifecycle.instance.Next;
public class WfDirectedEdgeRenderer implements DirectedEdgeRenderer
{
private GeneralPath mArrowTemplate = new GeneralPath();
public WfDirectedEdgeRenderer()
{
mArrowTemplate.moveTo(-5, 5);
mArrowTemplate.lineTo(0, 0);
mArrowTemplate.lineTo(5, 5);
}
@Override
public void draw(Graphics2D g2d, DirectedEdge directedEdge)
{
GraphPoint originPoint = directedEdge.getOriginPoint();
GraphPoint terminusPoint = directedEdge.getTerminusPoint();
GraphPoint midPoint = new GraphPoint();
AffineTransform transform = new AffineTransform();
Shape arrow = null;
Next next = (Next) directedEdge;
String text = (String) next.getProperties().get("Alias");
g2d.setPaint(Color.black);
if (("Broken +".equals(next.getProperties().get("Type"))))
{
g2d.drawLine(originPoint.x, originPoint.y, originPoint.x, (originPoint.y + terminusPoint.y) / 2);
g2d.drawLine(originPoint.x, (originPoint.y + terminusPoint.y) / 2, terminusPoint.x, (originPoint.y + terminusPoint.y) / 2);
g2d.drawLine(terminusPoint.x, (originPoint.y + terminusPoint.y) / 2, terminusPoint.x, terminusPoint.y);
midPoint.x = (originPoint.x + terminusPoint.x) / 2;
midPoint.y = (originPoint.y + terminusPoint.y) / 2;
transform.translate(midPoint.x, midPoint.y);
transform.rotate(
calcArrowAngle(
originPoint.x,
originPoint.x - terminusPoint.x > -5
&& originPoint.x - terminusPoint.x < 5 ? originPoint.y : (originPoint.y + terminusPoint.y) / 2,
terminusPoint.x,
originPoint.x - terminusPoint.x > -5
&& originPoint.x - terminusPoint.x < 5 ? terminusPoint.y : (originPoint.y + terminusPoint.y) / 2));
}
else if (("Broken -".equals(next.getProperties().get("Type"))))
{
g2d.drawLine(originPoint.x, originPoint.y, terminusPoint.x, originPoint.y);
g2d.drawLine(terminusPoint.x, originPoint.y, terminusPoint.x, terminusPoint.y);
boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
midPoint.x = arrowOnY ? terminusPoint.x : (originPoint.x + terminusPoint.x) / 2;
midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : originPoint.y;
transform.translate(midPoint.x, midPoint.y);
transform.rotate(
calcArrowAngle(
arrowOnY ? terminusPoint.x : originPoint.x,
arrowOnY ? originPoint.y : originPoint.y,
arrowOnY ? terminusPoint.x : terminusPoint.x,
arrowOnY ? terminusPoint.y : originPoint.y));
}
else if (("Broken |".equals(next.getProperties().get("Type"))))
{
g2d.drawLine(originPoint.x, originPoint.y, originPoint.x, terminusPoint.y);
g2d.drawLine(originPoint.x, terminusPoint.y, terminusPoint.x, terminusPoint.y);
boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
midPoint.x = arrowOnY ? originPoint.x : (originPoint.x + terminusPoint.x) / 2;
midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : terminusPoint.y;
transform.translate(midPoint.x, midPoint.y);
transform.rotate(
calcArrowAngle(
arrowOnY ? terminusPoint.x : originPoint.x,
arrowOnY ? originPoint.y : originPoint.y,
arrowOnY ? terminusPoint.x : terminusPoint.x,
arrowOnY ? terminusPoint.y : originPoint.y));
}
else
{
g2d.drawLine(originPoint.x, originPoint.y, terminusPoint.x, terminusPoint.y);
midPoint.x = originPoint.x + (terminusPoint.x - originPoint.x) / 2;
midPoint.y = originPoint.y + (terminusPoint.y - originPoint.y) / 2;
transform.translate(midPoint.x, midPoint.y);
transform.rotate(calcArrowAngle(originPoint.x, originPoint.y, terminusPoint.x, terminusPoint.y));
}
arrow = mArrowTemplate.createTransformedShape(transform);
g2d.draw(arrow);
if (text != null)
g2d.drawString(text, midPoint.x + 10, midPoint.y);
}
private static double calcArrowAngle(int originX, int originY, int terminusX, int terminusY)
{
double width = terminusX - originX;
double height = terminusY - originY;
if ((width == 0) && (height > 0))
{
return Math.PI;
}
if ((width == 0) && (height < 0))
{
return 0;
}
if ((width > 0) && (height == 0))
{
return Math.PI / 2.0;
}
if ((width < 0) && (height == 0))
{
return -1.0 * Math.PI / 2.0;
}
if ((width > 0) && (height > 0))
{
return Math.PI / 2.0 + Math.atan(Math.abs(height) / Math.abs(width));
}
if ((width > 0) && (height < 0))
{
return Math.atan(Math.abs(width) / Math.abs(height));
}
if ((width < 0) && (height < 0))
{
return -1.0 * Math.atan(Math.abs(width) / Math.abs(height));
}
if ((width < 0) && (height > 0))
{
return -1.0 * (Math.PI / 2.0 + Math.atan(Math.abs(height) / Math.abs(width)));
}
return 0.0;
}
}
|