forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxMarkerRegistry.java
More file actions
149 lines (125 loc) · 3.98 KB
/
mxMarkerRegistry.java
File metadata and controls
149 lines (125 loc) · 3.98 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
package com.mxgraph.shape;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.util.Hashtable;
import java.util.Map;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxPoint;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
public class mxMarkerRegistry
{
/**
*
*/
protected static Map<String, mxIMarker> markers = new Hashtable<String, mxIMarker>();
static
{
mxIMarker tmp = new mxIMarker()
{
public mxPoint paintMarker(mxGraphics2DCanvas canvas,
mxCellState state, String type, mxPoint pe, double nx,
double ny, double size, boolean source)
{
Polygon poly = new Polygon();
poly.addPoint((int) Math.round(pe.getX()),
(int) Math.round(pe.getY()));
poly.addPoint((int) Math.round(pe.getX() - nx - ny / 2),
(int) Math.round(pe.getY() - ny + nx / 2));
if (type.equals(mxConstants.ARROW_CLASSIC))
{
poly.addPoint((int) Math.round(pe.getX() - nx * 3 / 4),
(int) Math.round(pe.getY() - ny * 3 / 4));
}
poly.addPoint((int) Math.round(pe.getX() + ny / 2 - nx),
(int) Math.round(pe.getY() - ny - nx / 2));
if (mxUtils.isTrue(state.getStyle(), (source) ? "startFill" : "endFill", true))
{
canvas.fillShape(poly);
}
canvas.getGraphics().draw(poly);
return new mxPoint(-nx, -ny);
}
};
registerMarker(mxConstants.ARROW_CLASSIC, tmp);
registerMarker(mxConstants.ARROW_BLOCK, tmp);
registerMarker(mxConstants.ARROW_OPEN, new mxIMarker()
{
public mxPoint paintMarker(mxGraphics2DCanvas canvas,
mxCellState state, String type, mxPoint pe, double nx,
double ny, double size, boolean source)
{
canvas.getGraphics().draw(
new Line2D.Float((int) Math.round(pe.getX() - nx - ny
/ 2),
(int) Math.round(pe.getY() - ny + nx / 2),
(int) Math.round(pe.getX() - nx / 6),
(int) Math.round(pe.getY() - ny / 6)));
canvas.getGraphics().draw(
new Line2D.Float((int) Math.round(pe.getX() - nx / 6),
(int) Math.round(pe.getY() - ny / 6),
(int) Math.round(pe.getX() + ny / 2 - nx),
(int) Math.round(pe.getY() - ny - nx / 2)));
return new mxPoint(-nx / 2, -ny / 2);
}
});
registerMarker(mxConstants.ARROW_OVAL, new mxIMarker()
{
public mxPoint paintMarker(mxGraphics2DCanvas canvas,
mxCellState state, String type, mxPoint pe, double nx,
double ny, double size, boolean source)
{
double cx = pe.getX() - nx / 2;
double cy = pe.getY() - ny / 2;
double a = size / 2;
Shape shape = new Ellipse2D.Double(cx - a, cy - a, size, size);
if (mxUtils.isTrue(state.getStyle(), (source) ? "startFill" : "endFill", true))
{
canvas.fillShape(shape);
}
canvas.getGraphics().draw(shape);
return new mxPoint(-nx / 2, -ny / 2);
}
});
registerMarker(mxConstants.ARROW_DIAMOND, new mxIMarker()
{
public mxPoint paintMarker(mxGraphics2DCanvas canvas,
mxCellState state, String type, mxPoint pe, double nx,
double ny, double size, boolean source)
{
Polygon poly = new Polygon();
poly.addPoint((int) Math.round(pe.getX()),
(int) Math.round(pe.getY()));
poly.addPoint((int) Math.round(pe.getX() - nx / 2 - ny / 2),
(int) Math.round(pe.getY() + nx / 2 - ny / 2));
poly.addPoint((int) Math.round(pe.getX() - nx),
(int) Math.round(pe.getY() - ny));
poly.addPoint((int) Math.round(pe.getX() - nx / 2 + ny / 2),
(int) Math.round(pe.getY() - ny / 2 - nx / 2));
if (mxUtils.isTrue(state.getStyle(), (source) ? "startFill" : "endFill", true))
{
canvas.fillShape(poly);
}
canvas.getGraphics().draw(poly);
return new mxPoint(-nx / 2, -ny / 2);
}
});
}
/**
*
*/
public static mxIMarker getMarker(String name)
{
return markers.get(name);
}
/**
*
*/
public static void registerMarker(String name, mxIMarker marker)
{
markers.put(name, marker);
}
}