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
|
package org.eclipse.papyrus.diagram.common.figure.node;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
public class RoundedRectangleDashedShadowBorder extends RectangularShadowBorder {
/** the width of the rounded corner */
protected int cornerWidth;
/** the height of the rounded corner */
protected int cornerHeight;
/**
* Creates an instance of this class with the given arc width and arc height in pixels
*
* @param borderwidth
* the width of the border line
* @param color
* the color or the line
* @param arcWidth
* the width of the corner arc
* @param arcHeight
* the height of the corner arc
*/
public RoundedRectangleDashedShadowBorder(int borderwidth, Color color, int arcWidth, int arcHeight) {
super(borderwidth, color);
cornerWidth = arcWidth;
cornerHeight = arcHeight;
setWidth(1);
}
/**
* @see org.eclipse.draw2d.Border#paint(IFigure, Graphics, Insets)
*/
@Override
public void paint(IFigure figure, Graphics graphics, Insets insets) {
graphics.setLineStyle(SWT.LINE_DASH);
graphics.pushState();
// draw the normal line border
tempRect.setBounds(getPaintRectangle(figure, insets));
if(getWidth() % 2 == 1) {
tempRect.width--;
tempRect.height--;
}
tempRect.shrink(getWidth() / 2, getWidth() / 2);
graphics.setLineWidth(getWidth());
if(getColor() != null)
graphics.setForegroundColor(getColor());
graphics.drawRoundRectangle(tempRect, cornerWidth, cornerHeight);
// draw the shadow
// first expand the clip rectangle
Rectangle newRect = new Rectangle(tempRect);
newRect.width = newRect.width + borderwidth;
newRect.height = newRect.height + borderwidth;
graphics.setClip(newRect);
// paint the shadow, a nice rectangular one with soft corners
PointList plt = new PointList();
plt.addPoint(tempRect.x + tempRect.width, tempRect.y + cornerHeight / 2);
plt.addPoint(tempRect.x + tempRect.width, tempRect.y + tempRect.height - cornerHeight / 2);
plt.addPoint(tempRect.x + tempRect.width - cornerWidth / 2, tempRect.y + tempRect.height);
plt.addPoint(tempRect.x + cornerWidth / 2, tempRect.y + tempRect.height);
plt.addPoint(tempRect.x + cornerWidth, tempRect.y + tempRect.height + borderwidth);
plt.addPoint(tempRect.x + tempRect.width, tempRect.y + tempRect.height + borderwidth);
plt.addPoint(tempRect.x + tempRect.width + borderwidth, tempRect.y + tempRect.height);
plt.addPoint(tempRect.x + tempRect.width + borderwidth, tempRect.y + cornerHeight);
plt.addPoint(tempRect.x + tempRect.width, tempRect.y + cornerHeight / 2);
if(getColor() != null) {
graphics.setBackgroundColor(getColor());
} else {
graphics.setBackgroundColor(ColorConstants.black);
}
graphics.fillPolygon(plt);
graphics.popState();
}
}
|