21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.swing.plaf;
27
28 import java.awt.Component;
29 import java.awt.Insets;
30 import java.awt.Color;
31 import java.awt.Font;
32 import java.awt.Graphics;
33 import java.io.Serializable;
34
35 import java.beans.ConstructorProperties;
36 import javax.swing.border.*;
37 import javax.swing.Icon;
38 import javax.swing.plaf.UIResource;
39
40
41 /*
42 * A Border wrapper class which implements UIResource. UI
43 * classes which set border properties should use this class
44 * to wrap any borders specified as defaults.
45 *
46 * This class delegates all method invocations to the
47 * Border "delegate" object specified at construction.
48 * <p>
49 * <strong>Warning:</strong>
50 * Serialized objects of this class will not be compatible with
51 * future Swing releases. The current serialization support is
52 * appropriate for short term storage or RMI between applications running
53 * the same version of Swing. As of 1.4, support for long term storage
54 * of all JavaBeans™
55 * has been added to the <code>java.beans</code> package.
56 * Please see {@link java.beans.XMLEncoder}.
57 *
58 * @see javax.swing.plaf.UIResource
59 * @author Amy Fowler
60 *
61 */
62 @SuppressWarnings("serial") // Same-version serialization only
63 public class BorderUIResource implements Border, UIResource, Serializable
64 {
65 static Border etched;
66 static Border loweredBevel;
67 static Border raisedBevel;
68 static Border blackLine;
69
70 public static Border getEtchedBorderUIResource() {
71 if (etched == null) {
72 etched = new EtchedBorderUIResource();
73 }
74 return etched;
75 }
76
77 public static Border getLoweredBevelBorderUIResource() {
78 if (loweredBevel == null) {
79 loweredBevel = new BevelBorderUIResource(BevelBorder.LOWERED);
80 }
81 return loweredBevel;
82 }
83
84 public static Border getRaisedBevelBorderUIResource() {
85 if (raisedBevel == null) {
86 raisedBevel = new BevelBorderUIResource(BevelBorder.RAISED);
87 }
88 return raisedBevel;
89 }
90
91 public static Border getBlackLineBorderUIResource() {
92 if (blackLine == null) {
93 blackLine = new LineBorderUIResource(Color.black);
94 }
95 return blackLine;
96 }
97
98 private Border delegate;
99
100 /**
101 * Creates a UIResource border object which wraps
102 * an existing Border instance.
103 * @param delegate the border being wrapped
104 */
105 public BorderUIResource(Border delegate) {
106 if (delegate == null) {
107 throw new IllegalArgumentException("null border delegate argument");
108 }
109 this.delegate = delegate;
110 }
111
112 public void paintBorder(Component c, Graphics g, int x, int y,
113 int width, int height) {
114 delegate.paintBorder(c, g, x, y, width, height);
115 }
116
117 public Insets getBorderInsets(Component c) {
118 return delegate.getBorderInsets(c);
119 }
120
121 public boolean isBorderOpaque() {
122 return delegate.isBorderOpaque();
123 }
124
125 public static class CompoundBorderUIResource extends CompoundBorder implements UIResource {
126 @ConstructorProperties({"outsideBorder", "insideBorder"})
127 public CompoundBorderUIResource(Border outsideBorder, Border insideBorder) {
128 super(outsideBorder, insideBorder);
129 }
130
131 }
132
133 public static class EmptyBorderUIResource extends EmptyBorder implements UIResource {
134
135 public EmptyBorderUIResource(int top, int left, int bottom, int right) {
136 super(top, left, bottom, right);
137 }
138 @ConstructorProperties({"borderInsets"})
139 public EmptyBorderUIResource(Insets insets) {
140 super(insets);
141 }
142 }
143
144 public static class LineBorderUIResource extends LineBorder implements UIResource {
145
146 public LineBorderUIResource(Color color) {
147 super(color);
148 }
149
150 @ConstructorProperties({"lineColor", "thickness"})
151 public LineBorderUIResource(Color color, int thickness) {
152 super(color, thickness);
153 }
154 }
155
156
157 public static class BevelBorderUIResource extends BevelBorder implements UIResource {
158
159 public BevelBorderUIResource(int bevelType) {
160 super(bevelType);
161 }
162
163 public BevelBorderUIResource(int bevelType, Color highlight, Color shadow) {
164 super(bevelType, highlight, shadow);
165 }
166
167 @ConstructorProperties({"bevelType", "highlightOuterColor", "highlightInnerColor", "shadowOuterColor", "shadowInnerColor"})
168 public BevelBorderUIResource(int bevelType,
169 Color highlightOuter, Color highlightInner,
170 Color shadowOuter, Color shadowInner) {
171 super(bevelType, highlightOuter, highlightInner, shadowOuter, shadowInner);
172 }
173 }
174
175 public static class EtchedBorderUIResource extends EtchedBorder implements UIResource {
176
177 public EtchedBorderUIResource() {
178 super();
179 }
180
181 public EtchedBorderUIResource(int etchType) {
182 super(etchType);
183 }
184
185 public EtchedBorderUIResource(Color highlight, Color shadow) {
186 super(highlight, shadow);
187 }
188
189 @ConstructorProperties({"etchType", "highlightColor", "shadowColor"})
190 public EtchedBorderUIResource(int etchType, Color highlight, Color shadow) {
191 super(etchType, highlight, shadow);
192 }
193 }
194
195 public static class MatteBorderUIResource extends MatteBorder implements UIResource {
196
197 public MatteBorderUIResource(int top, int left, int bottom, int right,
198 Color color) {
199 super(top, left, bottom, right, color);
200 }
201
202 public MatteBorderUIResource(int top, int left, int bottom, int right,
203 Icon tileIcon) {
204 super(top, left, bottom, right, tileIcon);
205 }
206
207 public MatteBorderUIResource(Icon tileIcon) {
208 super(tileIcon);
209 }
210 }
211
212 public static class TitledBorderUIResource extends TitledBorder implements UIResource {
213
214 public TitledBorderUIResource(String title) {
215 super(title);
216 }
217
218 public TitledBorderUIResource(Border border) {
219 super(border);
220 }
221
222 public TitledBorderUIResource(Border border, String title) {
223 super(border, title);
224 }
225
226 public TitledBorderUIResource(Border border,
227 String title,
228 int titleJustification,
229 int titlePosition) {
230 super(border, title, titleJustification, titlePosition);
231 }
232
233 public TitledBorderUIResource(Border border,
234 String title,
235 int titleJustification,
236 int titlePosition,
237 Font titleFont) {
238 super(border, title, titleJustification, titlePosition, titleFont);
239 }
240
241 @ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
242 public TitledBorderUIResource(Border border,
243 String title,
244 int titleJustification,
245 int titlePosition,
246 Font titleFont,
247 Color titleColor) {
248 super(border, title, titleJustification, titlePosition, titleFont, titleColor);
249 }
250 }
251
252 }
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.swing.plaf;
27
28 import java.awt.Component;
29 import java.awt.Insets;
30 import java.awt.Color;
31 import java.awt.Font;
32 import java.awt.Graphics;
33 import java.io.Serializable;
34
35 import java.beans.ConstructorProperties;
36 import javax.swing.border.*;
37 import javax.swing.Icon;
38 import javax.swing.plaf.UIResource;
39
40
41 /**
42 * A Border wrapper class which implements UIResource. UI
43 * classes which set border properties should use this class
44 * to wrap any borders specified as defaults.
45 *
46 * This class delegates all method invocations to the
47 * Border "delegate" object specified at construction.
48 * <p>
49 * <strong>Warning:</strong>
50 * Serialized objects of this class will not be compatible with
51 * future Swing releases. The current serialization support is
52 * appropriate for short term storage or RMI between applications running
53 * the same version of Swing. As of 1.4, support for long term storage
54 * of all JavaBeans™
55 * has been added to the <code>java.beans</code> package.
56 * Please see {@link java.beans.XMLEncoder}.
57 *
58 * @see javax.swing.plaf.UIResource
59 * @author Amy Fowler
60 *
61 */
62 @SuppressWarnings("serial") // Same-version serialization only
63 public class BorderUIResource implements Border, UIResource, Serializable
64 {
65 static Border etched;
66 static Border loweredBevel;
67 static Border raisedBevel;
68 static Border blackLine;
69
70 /**
71 * Returns a etched border UI resource.
72 * @return a etched border UI resource
73 */
74 public static Border getEtchedBorderUIResource() {
75 if (etched == null) {
76 etched = new EtchedBorderUIResource();
77 }
78 return etched;
79 }
80
81 /**
82 * Returns a lowered bevel border UI resource.
83 * @return a lowered bevel border UI resource
84 */
85 public static Border getLoweredBevelBorderUIResource() {
86 if (loweredBevel == null) {
87 loweredBevel = new BevelBorderUIResource(BevelBorder.LOWERED);
88 }
89 return loweredBevel;
90 }
91
92 /**
93 * Returns a raised bevel border UI resource.
94 * @return a raised bevel border UI resource
95 */
96 public static Border getRaisedBevelBorderUIResource() {
97 if (raisedBevel == null) {
98 raisedBevel = new BevelBorderUIResource(BevelBorder.RAISED);
99 }
100 return raisedBevel;
101 }
102
103 /**
104 * Returns a black line border UI resource.
105 * @return a black line border UI resource
106 */
107 public static Border getBlackLineBorderUIResource() {
108 if (blackLine == null) {
109 blackLine = new LineBorderUIResource(Color.black);
110 }
111 return blackLine;
112 }
113
114 private Border delegate;
115
116 /**
117 * Creates a UIResource border object which wraps
118 * an existing Border instance.
119 * @param delegate the border being wrapped
120 */
121 public BorderUIResource(Border delegate) {
122 if (delegate == null) {
123 throw new IllegalArgumentException("null border delegate argument");
124 }
125 this.delegate = delegate;
126 }
127
128 public void paintBorder(Component c, Graphics g, int x, int y,
129 int width, int height) {
130 delegate.paintBorder(c, g, x, y, width, height);
131 }
132
133 public Insets getBorderInsets(Component c) {
134 return delegate.getBorderInsets(c);
135 }
136
137 public boolean isBorderOpaque() {
138 return delegate.isBorderOpaque();
139 }
140
141 /**
142 * A compound border UI resource.
143 */
144 public static class CompoundBorderUIResource extends CompoundBorder implements UIResource {
145 /**
146 * Constructs a {@code CompoundBorderUIResource}.
147 * @param outsideBorder the outside border
148 * @param insideBorder the inside border
149 */
150 @ConstructorProperties({"outsideBorder", "insideBorder"})
151 public CompoundBorderUIResource(Border outsideBorder, Border insideBorder) {
152 super(outsideBorder, insideBorder);
153 }
154
155 }
156
157 /**
158 * An empty border UI resource.
159 */
160 public static class EmptyBorderUIResource extends EmptyBorder implements UIResource {
161
162 /**
163 * Constructs a {@code EmptyBorderUIResource}.
164 * @param top the top inset of the border
165 * @param left the left inset of the border
166 * @param bottom the bottom inset of the border
167 * @param right the right inset of the border
168 */
169 public EmptyBorderUIResource(int top, int left, int bottom, int right) {
170 super(top, left, bottom, right);
171 }
172 /**
173 * Constructs a {@code EmptyBorderUIResource}.
174 * @param insets the insets of the border
175 */
176 @ConstructorProperties({"borderInsets"})
177 public EmptyBorderUIResource(Insets insets) {
178 super(insets);
179 }
180 }
181
182 /**
183 * A line border UI resource.
184 */
185 public static class LineBorderUIResource extends LineBorder implements UIResource {
186
187 /**
188 * Constructs a {@code LineBorderUIResource}.
189 * @param color the color for the border
190 */
191 public LineBorderUIResource(Color color) {
192 super(color);
193 }
194
195 /**
196 * Constructs a {@code LineBorderUIResource}.
197 * @param color the color for the border
198 * @param thickness the thickness of the border
199 */
200 @ConstructorProperties({"lineColor", "thickness"})
201 public LineBorderUIResource(Color color, int thickness) {
202 super(color, thickness);
203 }
204 }
205
206
207 /**
208 * A bevel border UI resource.
209 */
210 public static class BevelBorderUIResource extends BevelBorder implements UIResource {
211
212 /**
213 * Constructs a {@code BevelBorderUIResource}.
214 * @param bevelType the type of bevel for the border
215 */
216 public BevelBorderUIResource(int bevelType) {
217 super(bevelType);
218 }
219
220 /**
221 * Constructs a {@code BevelBorderUIResource}.
222 * @param bevelType the type of bevel for the border
223 * @param highlight the color to use for the bevel highlight
224 * @param shadow the color to use for the bevel shadow
225 */
226 public BevelBorderUIResource(int bevelType, Color highlight, Color shadow) {
227 super(bevelType, highlight, shadow);
228 }
229
230 /**
231 * Constructs a {@code BevelBorderUIResource}.
232 * @param bevelType the type of bevel for the border
233 * @param highlightOuter the color to use for the bevel outer highlight
234 * @param highlightInner the color to use for the bevel inner highlight
235 * @param shadowOuter the color to use for the bevel outer shadow
236 * @param shadowInner the color to use for the bevel inner shadow
237 */
238 @ConstructorProperties({"bevelType", "highlightOuterColor", "highlightInnerColor", "shadowOuterColor", "shadowInnerColor"})
239 public BevelBorderUIResource(int bevelType,
240 Color highlightOuter, Color highlightInner,
241 Color shadowOuter, Color shadowInner) {
242 super(bevelType, highlightOuter, highlightInner, shadowOuter, shadowInner);
243 }
244 }
245
246 /**
247 * An etched border UI resource.
248 */
249 public static class EtchedBorderUIResource extends EtchedBorder implements UIResource {
250
251 /**
252 * Constructs an {@code EtchedBorderUIResource}.
253 */
254 public EtchedBorderUIResource() {
255 super();
256 }
257
258 /**
259 * Constructs an {@code EtchedBorderUIResource}.
260 * @param etchType the type of etch to be drawn by the border
261 */
262 public EtchedBorderUIResource(int etchType) {
263 super(etchType);
264 }
265
266 /**
267 * Constructs an {@code EtchedBorderUIResource}.
268 * @param highlight the color to use for the etched highlight
269 * @param shadow the color to use for the etched shadow
270 */
271 public EtchedBorderUIResource(Color highlight, Color shadow) {
272 super(highlight, shadow);
273 }
274
275 /**
276 * Constructs an {@code EtchedBorderUIResource}.
277 * @param etchType the type of etch to be drawn by the border
278 * @param highlight the color to use for the etched highlight
279 * @param shadow the color to use for the etched shadow
280 */
281 @ConstructorProperties({"etchType", "highlightColor", "shadowColor"})
282 public EtchedBorderUIResource(int etchType, Color highlight, Color shadow) {
283 super(etchType, highlight, shadow);
284 }
285 }
286
287 /**
288 * A matte border UI resource.
289 */
290 public static class MatteBorderUIResource extends MatteBorder implements UIResource {
291
292 /**
293 * Constructs a {@code MatteBorderUIResource}.
294 * @param top the top inset of the border
295 * @param left the left inset of the border
296 * @param bottom the bottom inset of the border
297 * @param right the right inset of the border
298 * @param color the color rendered for the border
299 */
300 public MatteBorderUIResource(int top, int left, int bottom, int right,
301 Color color) {
302 super(top, left, bottom, right, color);
303 }
304
305 /**
306 * Constructs a {@code MatteBorderUIResource}.
307 * @param top the top inset of the border
308 * @param left the left inset of the border
309 * @param bottom the bottom inset of the border
310 * @param right the right inset of the border
311 * @param tileIcon the icon to be used for tiling the border
312 */
313 public MatteBorderUIResource(int top, int left, int bottom, int right,
314 Icon tileIcon) {
315 super(top, left, bottom, right, tileIcon);
316 }
317
318 /**
319 * Constructs a {@code MatteBorderUIResource}.
320 * @param tileIcon the icon to be used for tiling the border
321 */
322 public MatteBorderUIResource(Icon tileIcon) {
323 super(tileIcon);
324 }
325 }
326
327 /**
328 * A titled border UI resource.
329 */
330 public static class TitledBorderUIResource extends TitledBorder implements UIResource {
331
332 /**
333 * Constructs a {@code TitledBorderUIResource}.
334 * @param title the title the border should display
335 */
336 public TitledBorderUIResource(String title) {
337 super(title);
338 }
339
340 /**
341 * Constructs a {@code TitledBorderUIResource}.
342 * @param border the border
343 */
344 public TitledBorderUIResource(Border border) {
345 super(border);
346 }
347
348 /**
349 * Constructs a {@code TitledBorderUIResource}.
350 * @param border the border
351 * @param title the title the border should display
352 */
353 public TitledBorderUIResource(Border border, String title) {
354 super(border, title);
355 }
356
357 /**
358 * Constructs a {@code TitledBorderUIResource}.
359 * @param border the border
360 * @param title the title the border should display
361 * @param titleJustification the justification fro the title
362 * @param titlePosition the position for the title
363 */
364 public TitledBorderUIResource(Border border,
365 String title,
366 int titleJustification,
367 int titlePosition) {
368 super(border, title, titleJustification, titlePosition);
369 }
370
371 /**
372 * Constructs a {@code TitledBorderUIResource}.
373 * @param border the border
374 * @param title the title the border should display
375 * @param titleJustification the justification fro the title
376 * @param titlePosition the position for the title
377 * @param titleFont the font for rendering the title
378 */
379 public TitledBorderUIResource(Border border,
380 String title,
381 int titleJustification,
382 int titlePosition,
383 Font titleFont) {
384 super(border, title, titleJustification, titlePosition, titleFont);
385 }
386
387 /**
388 * Constructs a {@code TitledBorderUIResource}.
389 * @param border the border
390 * @param title the title the border should display
391 * @param titleJustification the justification fro the title
392 * @param titlePosition the position for the title
393 * @param titleFont the font for rendering the title
394 * @param titleColor the color of the title
395 */
396 @ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
397 public TitledBorderUIResource(Border border,
398 String title,
399 int titleJustification,
400 int titlePosition,
401 Font titleFont,
402 Color titleColor) {
403 super(border, title, titleJustification, titlePosition, titleFont, titleColor);
404 }
405 }
406
407 }
|