1. /*
  2. * @(#)BorderUIResource.java 1.16 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf;
  8. import java.awt.Component;
  9. import java.awt.Insets;
  10. import java.awt.Color;
  11. import java.awt.Font;
  12. import java.awt.Graphics;
  13. import java.io.Serializable;
  14. import javax.swing.BorderFactory;
  15. import javax.swing.border.*;
  16. import javax.swing.Icon;
  17. import javax.swing.plaf.UIResource;
  18. /*
  19. * A Border wrapper class which implements UIResource. UI
  20. * classes which set border properties should use this class
  21. * to wrap any borders specified as defaults.
  22. *
  23. * This class delegates all method invocations to the
  24. * Border "delegate" object specified at construction.
  25. * <p>
  26. * <strong>Warning:</strong>
  27. * Serialized objects of this class will not be compatible with
  28. * future Swing releases. The current serialization support is
  29. * appropriate for short term storage or RMI between applications running
  30. * the same version of Swing. As of 1.4, support for long term storage
  31. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  32. * has been added to the <code>java.beans</code> package.
  33. * Please see {@link java.beans.XMLEncoder}.
  34. *
  35. * @see javax.swing.plaf.UIResource
  36. * @version 1.16 12/19/03
  37. * @author Amy Fowler
  38. *
  39. */
  40. public class BorderUIResource implements Border, UIResource, Serializable
  41. {
  42. static Border etched;
  43. static Border loweredBevel;
  44. static Border raisedBevel;
  45. static Border blackLine;
  46. public static Border getEtchedBorderUIResource() {
  47. if (etched == null) {
  48. etched = new EtchedBorderUIResource();
  49. }
  50. return etched;
  51. }
  52. public static Border getLoweredBevelBorderUIResource() {
  53. if (loweredBevel == null) {
  54. loweredBevel = new BevelBorderUIResource(BevelBorder.LOWERED);
  55. }
  56. return loweredBevel;
  57. }
  58. public static Border getRaisedBevelBorderUIResource() {
  59. if (raisedBevel == null) {
  60. raisedBevel = new BevelBorderUIResource(BevelBorder.RAISED);
  61. }
  62. return raisedBevel;
  63. }
  64. public static Border getBlackLineBorderUIResource() {
  65. if (blackLine == null) {
  66. blackLine = new LineBorderUIResource(Color.black);
  67. }
  68. return blackLine;
  69. }
  70. private Border delegate;
  71. /**
  72. * Creates a UIResource border object which wraps
  73. * an existing Border instance.
  74. * @param delegate the border being wrapped
  75. */
  76. public BorderUIResource(Border delegate) {
  77. if (delegate == null) {
  78. throw new IllegalArgumentException("null border delegate argument");
  79. }
  80. this.delegate = delegate;
  81. }
  82. public void paintBorder(Component c, Graphics g, int x, int y,
  83. int width, int height) {
  84. delegate.paintBorder(c, g, x, y, width, height);
  85. }
  86. public Insets getBorderInsets(Component c) {
  87. return delegate.getBorderInsets(c);
  88. }
  89. public boolean isBorderOpaque() {
  90. return delegate.isBorderOpaque();
  91. }
  92. public static class CompoundBorderUIResource extends CompoundBorder implements UIResource {
  93. public CompoundBorderUIResource(Border outsideBorder, Border insideBorder) {
  94. super(outsideBorder, insideBorder);
  95. }
  96. }
  97. public static class EmptyBorderUIResource extends EmptyBorder implements UIResource {
  98. public EmptyBorderUIResource(int top, int left, int bottom, int right) {
  99. super(top, left, bottom, right);
  100. }
  101. public EmptyBorderUIResource(Insets insets) {
  102. super(insets);
  103. }
  104. }
  105. public static class LineBorderUIResource extends LineBorder implements UIResource {
  106. public LineBorderUIResource(Color color) {
  107. super(color);
  108. }
  109. public LineBorderUIResource(Color color, int thickness) {
  110. super(color, thickness);
  111. }
  112. }
  113. public static class BevelBorderUIResource extends BevelBorder implements UIResource {
  114. public BevelBorderUIResource(int bevelType) {
  115. super(bevelType);
  116. }
  117. public BevelBorderUIResource(int bevelType, Color highlight, Color shadow) {
  118. super(bevelType, highlight, shadow);
  119. }
  120. public BevelBorderUIResource(int bevelType,
  121. Color highlightOuter, Color highlightInner,
  122. Color shadowOuter, Color shadowInner) {
  123. super(bevelType, highlightOuter, highlightInner, shadowOuter, shadowInner);
  124. }
  125. }
  126. public static class EtchedBorderUIResource extends EtchedBorder implements UIResource {
  127. public EtchedBorderUIResource() {
  128. super();
  129. }
  130. public EtchedBorderUIResource(int etchType) {
  131. super(etchType);
  132. }
  133. public EtchedBorderUIResource(Color highlight, Color shadow) {
  134. super(highlight, shadow);
  135. }
  136. public EtchedBorderUIResource(int etchType, Color highlight, Color shadow) {
  137. super(etchType, highlight, shadow);
  138. }
  139. }
  140. public static class MatteBorderUIResource extends MatteBorder implements UIResource {
  141. public MatteBorderUIResource(int top, int left, int bottom, int right,
  142. Color color) {
  143. super(top, left, bottom, right, color);
  144. }
  145. public MatteBorderUIResource(int top, int left, int bottom, int right,
  146. Icon tileIcon) {
  147. super(top, left, bottom, right, tileIcon);
  148. }
  149. public MatteBorderUIResource(Icon tileIcon) {
  150. super(tileIcon);
  151. }
  152. }
  153. public static class TitledBorderUIResource extends TitledBorder implements UIResource {
  154. public TitledBorderUIResource(String title) {
  155. super(title);
  156. }
  157. public TitledBorderUIResource(Border border) {
  158. super(border);
  159. }
  160. public TitledBorderUIResource(Border border, String title) {
  161. super(border, title);
  162. }
  163. public TitledBorderUIResource(Border border,
  164. String title,
  165. int titleJustification,
  166. int titlePosition) {
  167. super(border, title, titleJustification, titlePosition);
  168. }
  169. public TitledBorderUIResource(Border border,
  170. String title,
  171. int titleJustification,
  172. int titlePosition,
  173. Font titleFont) {
  174. super(border, title, titleJustification, titlePosition, titleFont);
  175. }
  176. public TitledBorderUIResource(Border border,
  177. String title,
  178. int titleJustification,
  179. int titlePosition,
  180. Font titleFont,
  181. Color titleColor) {
  182. super(border, title, titleJustification, titlePosition, titleFont, titleColor);
  183. }
  184. }
  185. }