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