1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 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 an {@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 an {@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 }