1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.draw2d;
|
12
|
|
13
|
import org.eclipse.swt.graphics.Color;
|
14
|
|
15
|
import org.eclipse.draw2d.geometry.Insets;
|
16
|
|
17
|
/**
|
18
|
* Provides for a line border with sides of equal widths.
|
19
|
*/
|
20
|
public class LineBorder extends AbstractBorder {
|
21
|
|
22
|
private int width = 1;
|
23
|
private Color color;
|
24
|
private int style = Graphics.LINE_SOLID;
|
25
|
|
26
|
/**
|
27
|
* Constructs a LineBorder with the specified color and of the specified
|
28
|
* width and style.
|
29
|
*
|
30
|
* @param color
|
31
|
* The color of the border.
|
32
|
* @param width
|
33
|
* The width of the border in pixels.
|
34
|
* @param style
|
35
|
* The style of the border. For the list of valid values, see
|
36
|
* {@link org.eclipse.draw2d.Graphics}
|
37
|
* @since 3.5
|
38
|
*/
|
39
|
public LineBorder(Color color, int width, int style) {
|
40
|
setColor(color);
|
41
|
setWidth(width);
|
42
|
setStyle(style);
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Constructs a LineBorder with the specified color and of the specified
|
47
|
* width.
|
48
|
*
|
49
|
* @param color
|
50
|
* The color of the border.
|
51
|
* @param width
|
52
|
* The width of the border in pixels.
|
53
|
* @since 2.0
|
54
|
*/
|
55
|
public LineBorder(Color color, int width) {
|
56
|
this(color, width, Graphics.LINE_SOLID);
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* Constructs a LineBorder with the specified color and a width of 1 pixel.
|
61
|
*
|
62
|
* @param color
|
63
|
* The color of the border.
|
64
|
* @since 2.0
|
65
|
*/
|
66
|
public LineBorder(Color color) {
|
67
|
this(color, 1);
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Constructs a black LineBorder with the specified width.
|
72
|
*
|
73
|
* @param width
|
74
|
* The width of the border in pixels.
|
75
|
* @since 2.0
|
76
|
*/
|
77
|
public LineBorder(int width) {
|
78
|
this(null, width);
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* Constructs a default black LineBorder with a width of one pixel.
|
83
|
*
|
84
|
* @since 2.0
|
85
|
*/
|
86
|
public LineBorder() {
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Returns the line color of this border.
|
91
|
*
|
92
|
* @return The line color of this border
|
93
|
*/
|
94
|
public Color getColor() {
|
95
|
return color;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Returns the space used by the border for the figure provided as input. In
|
100
|
* this border all sides always have equal width.
|
101
|
*
|
102
|
* @param figure
|
103
|
* The figure this border belongs to
|
104
|
* @return This border's insets
|
105
|
*/
|
106
|
public Insets getInsets(IFigure figure) {
|
107
|
return new Insets(getWidth());
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Returns the line width of this border.
|
112
|
*
|
113
|
* @return The line width of this border
|
114
|
*/
|
115
|
public int getWidth() {
|
116
|
return width;
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* Returns <code>true</code> since this border is opaque. Being opaque it is
|
121
|
* responsible to fill in the area within its boundaries.
|
122
|
*
|
123
|
* @return <code>true</code> since this border is opaque
|
124
|
*/
|
125
|
public boolean isOpaque() {
|
126
|
return true;
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* @see org.eclipse.draw2d.Border#paint(IFigure, Graphics, Insets)
|
131
|
*/
|
132
|
public void paint(IFigure figure, Graphics graphics, Insets insets) {
|
133
|
tempRect.setBounds(getPaintRectangle(figure, insets));
|
134
|
if (getWidth() % 2 == 1) {
|
135
|
tempRect.width--;
|
136
|
tempRect.height--;
|
137
|
}
|
138
|
tempRect.shrink(getWidth() / 2, getWidth() / 2);
|
139
|
graphics.setLineWidth(getWidth());
|
140
|
graphics.setLineStyle(getStyle());
|
141
|
if (getColor() != null)
|
142
|
graphics.setForegroundColor(getColor());
|
143
|
graphics.drawRectangle(tempRect);
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* Sets the line color for this border.
|
148
|
*
|
149
|
* @param color
|
150
|
* The line color
|
151
|
*/
|
152
|
public void setColor(Color color) {
|
153
|
this.color = color;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Sets the line width for this border.
|
158
|
*
|
159
|
* @param width
|
160
|
* The line width
|
161
|
*/
|
162
|
public void setWidth(int width) {
|
163
|
if (width > 0) {
|
164
|
this.width = width;
|
165
|
}
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* Returns the line style for this border.
|
170
|
*
|
171
|
* @return The line style for this border
|
172
|
* @since 3.5
|
173
|
*/
|
174
|
public int getStyle() {
|
175
|
return style;
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* Sets the line type of this border.
|
180
|
*
|
181
|
* @param style
|
182
|
* For the list of valid values, see
|
183
|
* {@link org.eclipse.draw2d.Graphics}
|
184
|
* @since 3.5
|
185
|
*/
|
186
|
public void setStyle(int style) {
|
187
|
this.style = style;
|
188
|
}
|
189
|
|
190
|
}
|