forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxCylinderShape.java
More file actions
49 lines (41 loc) · 1.3 KB
/
mxCylinderShape.java
File metadata and controls
49 lines (41 loc) · 1.3 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
package com.mxgraph.shape;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.view.mxCellState;
public class mxCylinderShape extends mxBasicShape
{
/**
* Draws a cylinder for the given parameters.
*/
public void paintShape(mxGraphics2DCanvas canvas, mxCellState state)
{
Rectangle rect = state.getRectangle();
int x = rect.x;
int y = rect.y;
int w = rect.width;
int h = rect.height;
int h4 = h / 4;
int h2 = h4 / 2;
int r = w;
// Paints the background
if (configureGraphics(canvas, state, true))
{
Area area = new Area(new Rectangle(x, y + h4 / 2, r, h - h4));
area.add(new Area(new Rectangle(x, y + h4 / 2, r, h - h4)));
area.add(new Area(new Ellipse2D.Float(x, y, r, h4)));
area.add(new Area(new Ellipse2D.Float(x, y + h - h4, r, h4)));
canvas.fillShape(area, hasShadow(canvas, state));
}
// Paints the foreground
if (configureGraphics(canvas, state, false))
{
canvas.getGraphics().drawOval(x, y, r, h4);
canvas.getGraphics().drawLine(x, y + h2, x, y + h - h2);
canvas.getGraphics().drawLine(x + w, y + h2, x + w, y + h - h2);
// TODO: Use QuadCurve2D.Float() for painting the arc
canvas.getGraphics().drawArc(x, y + h - h4, r, h4, 0, -180);
}
}
}