blob: c18ec23bdd967fa47d3001f7a729b5625b30f004 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package javax.swing.plaf;
27
28import java.awt.Component;
29import java.awt.Insets;
30import java.awt.Color;
31import java.awt.Font;
32import java.awt.Graphics;
33import java.io.Serializable;
34
35import java.beans.ConstructorProperties;
36import javax.swing.border.*;
37import javax.swing.Icon;
38import 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<sup><font size="-2">TM</font></sup>
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 */
62public class BorderUIResource implements Border, UIResource, Serializable
63{
64 static Border etched;
65 static Border loweredBevel;
66 static Border raisedBevel;
67 static Border blackLine;
68
69 public static Border getEtchedBorderUIResource() {
70 if (etched == null) {
71 etched = new EtchedBorderUIResource();
72 }
73 return etched;
74 }
75
76 public static Border getLoweredBevelBorderUIResource() {
77 if (loweredBevel == null) {
78 loweredBevel = new BevelBorderUIResource(BevelBorder.LOWERED);
79 }
80 return loweredBevel;
81 }
82
83 public static Border getRaisedBevelBorderUIResource() {
84 if (raisedBevel == null) {
85 raisedBevel = new BevelBorderUIResource(BevelBorder.RAISED);
86 }
87 return raisedBevel;
88 }
89
90 public static Border getBlackLineBorderUIResource() {
91 if (blackLine == null) {
92 blackLine = new LineBorderUIResource(Color.black);
93 }
94 return blackLine;
95 }
96
97 private Border delegate;
98
99 /**
100 * Creates a UIResource border object which wraps
101 * an existing Border instance.
102 * @param delegate the border being wrapped
103 */
104 public BorderUIResource(Border delegate) {
105 if (delegate == null) {
106 throw new IllegalArgumentException("null border delegate argument");
107 }
108 this.delegate = delegate;
109 }
110
111 public void paintBorder(Component c, Graphics g, int x, int y,
112 int width, int height) {
113 delegate.paintBorder(c, g, x, y, width, height);
114 }
115
116 public Insets getBorderInsets(Component c) {
117 return delegate.getBorderInsets(c);
118 }
119
120 public boolean isBorderOpaque() {
121 return delegate.isBorderOpaque();
122 }
123
124 public static class CompoundBorderUIResource extends CompoundBorder implements UIResource {
125 @ConstructorProperties({"outsideBorder", "insideBorder"})
126 public CompoundBorderUIResource(Border outsideBorder, Border insideBorder) {
127 super(outsideBorder, insideBorder);
128 }
129
130 }
131
132 public static class EmptyBorderUIResource extends EmptyBorder implements UIResource {
133
134 public EmptyBorderUIResource(int top, int left, int bottom, int right) {
135 super(top, left, bottom, right);
136 }
137 @ConstructorProperties({"borderInsets"})
138 public EmptyBorderUIResource(Insets insets) {
139 super(insets);
140 }
141 }
142
143 public static class LineBorderUIResource extends LineBorder implements UIResource {
144
145 public LineBorderUIResource(Color color) {
146 super(color);
147 }
148
149 @ConstructorProperties({"lineColor", "thickness"})
150 public LineBorderUIResource(Color color, int thickness) {
151 super(color, thickness);
152 }
153 }
154
155
156 public static class BevelBorderUIResource extends BevelBorder implements UIResource {
157
158 public BevelBorderUIResource(int bevelType) {
159 super(bevelType);
160 }
161
162 public BevelBorderUIResource(int bevelType, Color highlight, Color shadow) {
163 super(bevelType, highlight, shadow);
164 }
165
166 @ConstructorProperties({"bevelType", "highlightOuterColor", "highlightInnerColor", "shadowOuterColor", "shadowInnerColor"})
167 public BevelBorderUIResource(int bevelType,
168 Color highlightOuter, Color highlightInner,
169 Color shadowOuter, Color shadowInner) {
170 super(bevelType, highlightOuter, highlightInner, shadowOuter, shadowInner);
171 }
172 }
173
174 public static class EtchedBorderUIResource extends EtchedBorder implements UIResource {
175
176 public EtchedBorderUIResource() {
177 super();
178 }
179
180 public EtchedBorderUIResource(int etchType) {
181 super(etchType);
182 }
183
184 public EtchedBorderUIResource(Color highlight, Color shadow) {
185 super(highlight, shadow);
186 }
187
188 @ConstructorProperties({"etchType", "highlightColor", "shadowColor"})
189 public EtchedBorderUIResource(int etchType, Color highlight, Color shadow) {
190 super(etchType, highlight, shadow);
191 }
192 }
193
194 public static class MatteBorderUIResource extends MatteBorder implements UIResource {
195
196 public MatteBorderUIResource(int top, int left, int bottom, int right,
197 Color color) {
198 super(top, left, bottom, right, color);
199 }
200
201 public MatteBorderUIResource(int top, int left, int bottom, int right,
202 Icon tileIcon) {
203 super(top, left, bottom, right, tileIcon);
204 }
205
206 public MatteBorderUIResource(Icon tileIcon) {
207 super(tileIcon);
208 }
209 }
210
211 public static class TitledBorderUIResource extends TitledBorder implements UIResource {
212
213 public TitledBorderUIResource(String title) {
214 super(title);
215 }
216
217 public TitledBorderUIResource(Border border) {
218 super(border);
219 }
220
221 public TitledBorderUIResource(Border border, String title) {
222 super(border, title);
223 }
224
225 public TitledBorderUIResource(Border border,
226 String title,
227 int titleJustification,
228 int titlePosition) {
229 super(border, title, titleJustification, titlePosition);
230 }
231
232 public TitledBorderUIResource(Border border,
233 String title,
234 int titleJustification,
235 int titlePosition,
236 Font titleFont) {
237 super(border, title, titleJustification, titlePosition, titleFont);
238 }
239
240 @ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
241 public TitledBorderUIResource(Border border,
242 String title,
243 int titleJustification,
244 int titlePosition,
245 Font titleFont,
246 Color titleColor) {
247 super(border, title, titleJustification, titlePosition, titleFont, titleColor);
248 }
249 }
250
251}