1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2007</p>
22 * <p>Company: Ontotext Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.bpmo.figures;
26
27 import org.eclipse.draw2d.ColorConstants;
28 import org.eclipse.draw2d.Figure;
29 import org.eclipse.draw2d.Graphics;
30 import org.eclipse.draw2d.geometry.PointList;
31 import org.eclipse.draw2d.geometry.Rectangle;
32
33 /***
34 * A figure that has a bent corner in the top right hand. Typically used for sticky notes.
35 */
36 public class BentCornerFigure
37 extends Figure
38 {
39
40 /***
41 * The default amount of pixels subtracted from the figure's height and width to determine
42 * the size of the corner.
43 */
44 protected static int DEFAULT_CORNER_SIZE = 10;
45
46 private int cornerSize;
47
48 /***
49 * Constructs an empty BentCornerFigure with default background color of
50 * ColorConstants.tooltipBackground and default corner size.
51 */
52 public BentCornerFigure() {
53 setBackgroundColor(ColorConstants.tooltipBackground);
54 setForegroundColor(ColorConstants.tooltipForeground);
55 setCornerSize(DEFAULT_CORNER_SIZE);
56 }
57
58 /***
59 * Returns the size, in pixels, that the figure should use to draw its bent corner.
60 *
61 * @return size of the corner
62 */
63 public int getCornerSize() {
64 return cornerSize;
65 }
66
67 /***
68 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
69 */
70 protected void paintFigure(Graphics graphics) {
71 Rectangle rect = getBounds().getCopy();
72
73 graphics.translate(getLocation());
74
75
76 PointList outline = new PointList();
77
78 outline.addPoint(0, 0);
79 outline.addPoint(rect.width - cornerSize, 0);
80 outline.addPoint(rect.width - 1, cornerSize);
81 outline.addPoint(rect.width - 1, rect.height - 1);
82 outline.addPoint(0, rect.height - 1);
83
84 graphics.fillPolygon(outline);
85
86
87 PointList innerLine = new PointList();
88
89 innerLine.addPoint(rect.width - cornerSize - 1, 0);
90 innerLine.addPoint(rect.width - cornerSize - 1, cornerSize);
91 innerLine.addPoint(rect.width - 1, cornerSize);
92 innerLine.addPoint(rect.width - cornerSize - 1, 0);
93 innerLine.addPoint(0, 0);
94 innerLine.addPoint(0, rect.height - 1);
95 innerLine.addPoint(rect.width - 1, rect.height - 1);
96 innerLine.addPoint(rect.width - 1, cornerSize);
97
98 graphics.drawPolygon(innerLine);
99
100 graphics.translate(getLocation().getNegated());
101 }
102
103 /***
104 * Sets the size of the figure's corner to the given offset.
105 *
106 * @param newSize the new size to use.
107 */
108 public void setCornerSize(int newSize) {
109 cornerSize = newSize;
110 }
111
112 }
113
114
115
116
117
118
119