forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxHexagonShape.java
More file actions
52 lines (45 loc) · 1.37 KB
/
mxHexagonShape.java
File metadata and controls
52 lines (45 loc) · 1.37 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
package com.mxgraph.shape;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Shape;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
public class mxHexagonShape extends mxBasicShape
{
/**
*
*/
public Shape createShape(mxGraphics2DCanvas canvas, mxCellState state)
{
Rectangle temp = state.getRectangle();
int x = temp.x;
int y = temp.y;
int w = temp.width;
int h = temp.height;
String direction = mxUtils.getString(state.getStyle(),
mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
Polygon hexagon = new Polygon();
if (direction.equals(mxConstants.DIRECTION_NORTH)
|| direction.equals(mxConstants.DIRECTION_SOUTH))
{
hexagon.addPoint(x + (int) (0.5 * w), y);
hexagon.addPoint(x + w, y + (int) (0.25 * h));
hexagon.addPoint(x + w, y + (int) (0.75 * h));
hexagon.addPoint(x + (int) (0.5 * w), y + h);
hexagon.addPoint(x, y + (int) (0.75 * h));
hexagon.addPoint(x, y + (int) (0.25 * h));
}
else
{
hexagon.addPoint(x + (int) (0.25 * w), y);
hexagon.addPoint(x + (int) (0.75 * w), y);
hexagon.addPoint(x + w, y + (int) (0.5 * h));
hexagon.addPoint(x + (int) (0.75 * w), y + h);
hexagon.addPoint(x + (int) (0.25 * w), y + h);
hexagon.addPoint(x, y + (int) (0.5 * h));
}
return hexagon;
}
}