48 |
* |
* |
49 |
* @author Sascha Brawer (brawer@dandelis.ch) |
* @author Sascha Brawer (brawer@dandelis.ch) |
50 |
*/ |
*/ |
51 |
public class CompoundBorder |
public class CompoundBorder extends AbstractBorder |
|
extends AbstractBorder |
|
52 |
{ |
{ |
53 |
/** |
/** |
54 |
* Determined using the <code>serialver</code> tool |
* Determined using the <code>serialver</code> tool |
56 |
*/ |
*/ |
57 |
static final long serialVersionUID = 9054540377030555103L; |
static final long serialVersionUID = 9054540377030555103L; |
58 |
|
|
|
|
|
59 |
/** |
/** |
60 |
* The inside border, which is painted between the bordered |
* The inside border, which is painted between the bordered |
61 |
* Component and the outside border. It is valid for |
* Component and the outside border. It is valid for |
63 |
*/ |
*/ |
64 |
protected Border insideBorder; |
protected Border insideBorder; |
65 |
|
|
|
|
|
66 |
/** |
/** |
67 |
* The outside border, which is painted outside both the |
* The outside border, which is painted outside both the |
68 |
* bordered Component and the inside border. It is valid for |
* bordered Component and the inside border. It is valid for |
70 |
*/ |
*/ |
71 |
protected Border outsideBorder; |
protected Border outsideBorder; |
72 |
|
|
|
|
|
73 |
/** |
/** |
74 |
* Constructs a CompoundBorder whose inside and outside borders |
* Constructs a CompoundBorder whose inside and outside borders |
75 |
* are both <code>null</code>. While this does not really make |
* are both <code>null</code>. While this does not really make |
79 |
* |
* |
80 |
* @see EmptyBorder |
* @see EmptyBorder |
81 |
*/ |
*/ |
82 |
public CompoundBorder () |
public CompoundBorder() |
83 |
{ |
{ |
84 |
this (null, null); |
this (null, null); |
85 |
} |
} |
86 |
|
|
|
|
|
87 |
/** |
/** |
88 |
* Constructs a CompoundBorder with the specified inside and |
* Constructs a CompoundBorder with the specified inside and |
89 |
* outside borders. |
* outside borders. |
98 |
* component. It is acceptable to pass <code>null</code>, in |
* component. It is acceptable to pass <code>null</code>, in |
99 |
* which case no inside border is painted. |
* which case no inside border is painted. |
100 |
*/ |
*/ |
101 |
public CompoundBorder (Border outsideBorder, Border insideBorder) |
public CompoundBorder(Border outsideBorder, Border insideBorder) |
102 |
{ |
{ |
103 |
this.outsideBorder = outsideBorder; |
this.outsideBorder = outsideBorder; |
104 |
this.insideBorder = insideBorder; |
this.insideBorder = insideBorder; |
105 |
} |
} |
106 |
|
|
|
|
|
107 |
/** |
/** |
108 |
* Determines whether or not this border is opaque. An opaque |
* Determines whether or not this border is opaque. An opaque |
109 |
* border fills every pixel in its area when painting. Partially |
* border fills every pixel in its area when painting. Partially |
113 |
* @return <code>true</code> if both the inside and outside borders |
* @return <code>true</code> if both the inside and outside borders |
114 |
* are opaque, or <code>false</code> otherwise. |
* are opaque, or <code>false</code> otherwise. |
115 |
*/ |
*/ |
116 |
public boolean isBorderOpaque () |
public boolean isBorderOpaque() |
117 |
{ |
{ |
118 |
/* While it would be safe to assume true for the opacity of |
// While it would be safe to assume true for the opacity of |
119 |
* a null border, this behavior would not be according to |
// a null border, this behavior would not be according to |
120 |
* the API specification. Also, it is pathological to have |
// the API specification. Also, it is pathological to have |
121 |
* null borders anyway. |
// null borders anyway. |
|
*/ |
|
122 |
if ((insideBorder == null) || (outsideBorder == null)) |
if ((insideBorder == null) || (outsideBorder == null)) |
123 |
return false; |
return false; |
124 |
|
|
125 |
return insideBorder.isBorderOpaque() |
return insideBorder.isBorderOpaque() |
126 |
&& outsideBorder.isBorderOpaque(); |
&& outsideBorder.isBorderOpaque(); |
127 |
} |
} |
|
|
|
128 |
|
|
129 |
/** |
/** |
130 |
* Paints the compound border by first painting the outside border, |
* Paints the compound border by first painting the outside border, |
140 |
public void paintBorder(Component c, Graphics g, |
public void paintBorder(Component c, Graphics g, |
141 |
int x, int y, int width, int height) |
int x, int y, int width, int height) |
142 |
{ |
{ |
143 |
/* If there is an outside border, paint it and reduce the |
// If there is an outside border, paint it and reduce the |
144 |
* bounding box by its insets. |
// bounding box by its insets. |
145 |
*/ |
// |
146 |
if (outsideBorder != null) |
if (outsideBorder != null) |
147 |
{ |
{ |
148 |
Insets outsideInsets; |
Insets outsideInsets; |
153 |
x += outsideInsets.left; |
x += outsideInsets.left; |
154 |
y += outsideInsets.top; |
y += outsideInsets.top; |
155 |
|
|
156 |
/* Reduce width and height by the respective extent of the |
// Reduce width and height by the respective extent of the |
157 |
* outside border. |
// outside border. |
|
*/ |
|
158 |
width -= outsideInsets.left + outsideInsets.right; |
width -= outsideInsets.left + outsideInsets.right; |
159 |
height -= outsideInsets.top + outsideInsets.bottom; |
height -= outsideInsets.top + outsideInsets.bottom; |
160 |
} |
} |
163 |
insideBorder.paintBorder(c, g, x, y, width, height); |
insideBorder.paintBorder(c, g, x, y, width, height); |
164 |
} |
} |
165 |
|
|
|
|
|
166 |
/** |
/** |
167 |
* Changes the specified insets to the insets of this border, |
* Changes the specified insets to the insets of this border, |
168 |
* which is the sum of the insets of the inside and the outside |
* which is the sum of the insets of the inside and the outside |
182 |
else |
else |
183 |
insets.left = insets.right = insets.top = insets.bottom = 0; |
insets.left = insets.right = insets.top = insets.bottom = 0; |
184 |
|
|
185 |
/* If there is an outside border, add it to insets. */ |
// If there is an outside border, add it to insets. |
186 |
if (outsideBorder != null) |
if (outsideBorder != null) |
187 |
{ |
{ |
188 |
borderInsets = outsideBorder.getBorderInsets(c); |
borderInsets = outsideBorder.getBorderInsets(c); |
192 |
insets.bottom += borderInsets.bottom; |
insets.bottom += borderInsets.bottom; |
193 |
} |
} |
194 |
|
|
195 |
/* If there is an inside border, add it to insets. */ |
// If there is an inside border, add it to insets. |
196 |
if (insideBorder != null) |
if (insideBorder != null) |
197 |
{ |
{ |
198 |
borderInsets = insideBorder.getBorderInsets(c); |
borderInsets = insideBorder.getBorderInsets(c); |
205 |
return insets; |
return insets; |
206 |
} |
} |
207 |
|
|
|
|
|
208 |
/** |
/** |
209 |
* Determines the insets of this border, which is the sum of the |
* Determines the insets of this border, which is the sum of the |
210 |
* insets of the inside and the outside border. |
* insets of the inside and the outside border. |
211 |
* |
* |
212 |
* @param c the component in the center of this border. |
* @param c the component in the center of this border. |
213 |
*/ |
*/ |
214 |
public Insets getBorderInsets (Component c) |
public Insets getBorderInsets(Component c) |
215 |
{ |
{ |
216 |
/* It is not clear why CompoundBorder does not simply inherit |
// It is not clear why CompoundBorder does not simply inherit |
217 |
* the implementation from AbstractBorder. However, we want |
// the implementation from AbstractBorder. However, we want |
218 |
* to be compatible with the API specification, which overrides |
// to be compatible with the API specification, which overrides |
219 |
* the getBorderInsets(Component) method. |
// the getBorderInsets(Component) method. |
|
*/ |
|
220 |
return getBorderInsets (c, null); |
return getBorderInsets (c, null); |
221 |
} |
} |
222 |
|
|
|
|
|
223 |
/** |
/** |
224 |
* Returns the outside border, which is painted outside both the |
* Returns the outside border, which is painted outside both the |
225 |
* bordered Component and the inside border. It is valid for the |
* bordered Component and the inside border. It is valid for the |
226 |
* result to be <code>null</code>. |
* result to be <code>null</code>. |
227 |
*/ |
*/ |
228 |
public Border getOutsideBorder () |
public Border getOutsideBorder() |
229 |
{ |
{ |
230 |
return outsideBorder; |
return outsideBorder; |
231 |
} |
} |
232 |
|
|
|
|
|
233 |
/** |
/** |
234 |
* Returns the inside border, which is painted between the bordered |
* Returns the inside border, which is painted between the bordered |
235 |
* Component and the outside border. It is valid for the result to |
* Component and the outside border. It is valid for the result to |
240 |
return insideBorder; |
return insideBorder; |
241 |
} |
} |
242 |
} |
} |
|
|
|