1 /* 2 * Copyright (c) 1997, 2014, 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 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 }