1. /*
  2. * @(#)BorderUIResource.java 1.11 01/11/29
  3. *
  4. * Copyright 2002 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 appropriate
  29. * for short term storage or RMI between applications running the same
  30. * version of Swing. A future release of Swing will provide support for
  31. * long term persistence.
  32. *
  33. * @see javax.swing.plaf.UIResource
  34. * @version 1.11 11/29/01
  35. * @author Amy Fowler
  36. *
  37. */
  38. public class BorderUIResource implements Border, UIResource, Serializable
  39. {
  40. static Border etched;
  41. static Border loweredBevel;
  42. static Border raisedBevel;
  43. static Border blackLine;
  44. public static Border getEtchedBorderUIResource() {
  45. if (etched == null) {
  46. etched = new EtchedBorderUIResource();
  47. }
  48. return etched;
  49. }
  50. public static Border getLoweredBevelBorderUIResource() {
  51. if (loweredBevel == null) {
  52. loweredBevel = new BevelBorderUIResource(BevelBorder.LOWERED);
  53. }
  54. return loweredBevel;
  55. }
  56. public static Border getRaisedBevelBorderUIResource() {
  57. if (raisedBevel == null) {
  58. raisedBevel = new BevelBorderUIResource(BevelBorder.RAISED);
  59. }
  60. return raisedBevel;
  61. }
  62. public static Border getBlackLineBorderUIResource() {
  63. if (blackLine == null) {
  64. blackLine = new LineBorderUIResource(Color.black);
  65. }
  66. return blackLine;
  67. }
  68. private Border delegate;
  69. /**
  70. * Creates a UIResource border object which wraps
  71. * an existing Border instance.
  72. * @param delegate the border being wrapped
  73. */
  74. public BorderUIResource(Border delegate) {
  75. if (delegate == null) {
  76. throw new IllegalArgumentException("null border delegate argument");
  77. }
  78. this.delegate = delegate;
  79. }
  80. public void paintBorder(Component c, Graphics g, int x, int y,
  81. int width, int height) {
  82. delegate.paintBorder(c, g, x, y, width, height);
  83. }
  84. public Insets getBorderInsets(Component c) {
  85. return delegate.getBorderInsets(c);
  86. }
  87. public boolean isBorderOpaque() {
  88. return delegate.isBorderOpaque();
  89. }
  90. public static class CompoundBorderUIResource extends CompoundBorder implements UIResource {
  91. public CompoundBorderUIResource(Border outsideBorder, Border insideBorder) {
  92. super(outsideBorder, insideBorder);
  93. }
  94. }
  95. public static class EmptyBorderUIResource extends EmptyBorder implements UIResource {
  96. public EmptyBorderUIResource(int top, int left, int bottom, int right) {
  97. super(top, left, bottom, right);
  98. }
  99. public EmptyBorderUIResource(Insets insets) {
  100. super(insets);
  101. }
  102. }
  103. public static class LineBorderUIResource extends LineBorder implements UIResource {
  104. public LineBorderUIResource(Color color) {
  105. super(color);
  106. }
  107. public LineBorderUIResource(Color color, int thickness) {
  108. super(color, thickness);
  109. }
  110. }
  111. public static class BevelBorderUIResource extends BevelBorder implements UIResource {
  112. public BevelBorderUIResource(int bevelType) {
  113. super(bevelType);
  114. }
  115. public BevelBorderUIResource(int bevelType, Color highlight, Color shadow) {
  116. super(bevelType, highlight, shadow);
  117. }
  118. public BevelBorderUIResource(int bevelType,
  119. Color highlightOuter, Color highlightInner,
  120. Color shadowOuter, Color shadowInner) {
  121. super(bevelType, highlightOuter, highlightInner, shadowOuter, shadowInner);
  122. }
  123. }
  124. public static class EtchedBorderUIResource extends EtchedBorder implements UIResource {
  125. public EtchedBorderUIResource() {
  126. super();
  127. }
  128. public EtchedBorderUIResource(int etchType) {
  129. super(etchType);
  130. }
  131. public EtchedBorderUIResource(Color highlight, Color shadow) {
  132. super(highlight, shadow);
  133. }
  134. public EtchedBorderUIResource(int etchType, Color highlight, Color shadow) {
  135. super(etchType, highlight, shadow);
  136. }
  137. }
  138. public static class MatteBorderUIResource extends MatteBorder implements UIResource {
  139. public MatteBorderUIResource(int top, int left, int bottom, int right,
  140. Color color) {
  141. super(top, left, bottom, right, color);
  142. }
  143. public MatteBorderUIResource(int top, int left, int bottom, int right,
  144. Icon tileIcon) {
  145. super(top, left, bottom, right, tileIcon);
  146. }
  147. public MatteBorderUIResource(Icon tileIcon) {
  148. super(tileIcon);
  149. }
  150. }
  151. public static class TitledBorderUIResource extends TitledBorder implements UIResource {
  152. public TitledBorderUIResource(String title) {
  153. super(title);
  154. }
  155. public TitledBorderUIResource(Border border) {
  156. super(border);
  157. }
  158. public TitledBorderUIResource(Border border, String title) {
  159. super(border, title);
  160. }
  161. public TitledBorderUIResource(Border border,
  162. String title,
  163. int titleJustification,
  164. int titlePosition) {
  165. super(border, title, titleJustification, titlePosition);
  166. }
  167. public TitledBorderUIResource(Border border,
  168. String title,
  169. int titleJustification,
  170. int titlePosition,
  171. Font titleFont) {
  172. super(border, title, titleJustification, titlePosition, titleFont);
  173. }
  174. public TitledBorderUIResource(Border border,
  175. String title,
  176. int titleJustification,
  177. int titlePosition,
  178. Font titleFont,
  179. Color titleColor) {
  180. super(border, title, titleJustification, titlePosition, titleFont, titleColor);
  181. }
  182. }
  183. }