forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxRectangleShape.java
More file actions
executable file
·121 lines (104 loc) · 2.6 KB
/
mxRectangleShape.java
File metadata and controls
executable file
·121 lines (104 loc) · 2.6 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
/**
* $Id: mxRectangleShape.java,v 1.5 2012/01/13 13:12:37 david Exp $
* Copyright (c) 2007-2012, JGraph Ltd
*/
package com.mxgraph.shape;
import java.awt.Rectangle;
import java.util.Map;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.swing.util.mxSwingConstants;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
public class mxRectangleShape extends mxBasicShape
{
/**
*
*/
public void paintShape(mxGraphics2DCanvas canvas, mxCellState state)
{
Map<String, Object> style = state.getStyle();
if (mxUtils.isTrue(style, mxConstants.STYLE_ROUNDED, false))
{
Rectangle tmp = state.getRectangle();
int x = tmp.x;
int y = tmp.y;
int w = tmp.width;
int h = tmp.height;
int radius = getArcSize(w, h);
boolean shadow = hasShadow(canvas, state);
int shadowOffsetX = (shadow) ? mxConstants.SHADOW_OFFSETX : 0;
int shadowOffsetY = (shadow) ? mxConstants.SHADOW_OFFSETY : 0;
if (canvas.getGraphics().hitClip(x, y, w + shadowOffsetX,
h + shadowOffsetY))
{
// Paints the optional shadow
if (shadow)
{
canvas.getGraphics().setColor(mxSwingConstants.SHADOW_COLOR);
canvas.getGraphics().fillRoundRect(
x + mxConstants.SHADOW_OFFSETX,
y + mxConstants.SHADOW_OFFSETY, w, h, radius,
radius);
}
// Paints the background
if (configureGraphics(canvas, state, true))
{
canvas.getGraphics().fillRoundRect(x, y, w, h, radius,
radius);
}
// Paints the foreground
if (configureGraphics(canvas, state, false))
{
canvas.getGraphics().drawRoundRect(x, y, w, h, radius,
radius);
}
}
}
else
{
Rectangle rect = state.getRectangle();
// Paints the background
if (configureGraphics(canvas, state, true))
{
canvas.fillShape(rect, hasShadow(canvas, state));
}
// Paints the foreground
if (configureGraphics(canvas, state, false))
{
canvas.getGraphics().drawRect(rect.x, rect.y, rect.width,
rect.height);
}
}
}
/**
* Computes the arc size for the given dimension.
*
* @param w Width of the rectangle.
* @param h Height of the rectangle.
* @return Returns the arc size for the given dimension.
*/
public int getArcSize(int w, int h)
{
int arcSize;
if (w <= h)
{
arcSize = (int) Math.round(h
* mxConstants.RECTANGLE_ROUNDING_FACTOR);
if (arcSize > (w / 2))
{
arcSize = w / 2;
}
}
else
{
arcSize = (int) Math.round(w
* mxConstants.RECTANGLE_ROUNDING_FACTOR);
if (arcSize > (h / 2))
{
arcSize = h / 2;
}
}
return arcSize;
}
}