1. /*
  2. * @(#)SoftBevelBorder.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.border;
  8. import java.awt.Graphics;
  9. import java.awt.Insets;
  10. import java.awt.Rectangle;
  11. import java.awt.Color;
  12. import java.awt.Component;
  13. /**
  14. * A class which implements a raised or lowered bevel with
  15. * softened corners.
  16. * <p>
  17. * <strong>Warning:</strong>
  18. * Serialized objects of this class will not be compatible with
  19. * future Swing releases. The current serialization support is
  20. * appropriate for short term storage or RMI between applications running
  21. * the same version of Swing. As of 1.4, support for long term storage
  22. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  23. * has been added to the <code>java.beans</code> package.
  24. * Please see {@link java.beans.XMLEncoder}.
  25. *
  26. * @version 1.16 12/19/03
  27. * @author Amy Fowler
  28. * @author Chester Rose
  29. */
  30. public class SoftBevelBorder extends BevelBorder
  31. {
  32. /**
  33. * Creates a bevel border with the specified type and whose
  34. * colors will be derived from the background color of the
  35. * component passed into the paintBorder method.
  36. * @param bevelType the type of bevel for the border
  37. */
  38. public SoftBevelBorder(int bevelType) {
  39. super(bevelType);
  40. }
  41. /**
  42. * Creates a bevel border with the specified type, highlight and
  43. * shadow colors.
  44. * @param bevelType the type of bevel for the border
  45. * @param highlight the color to use for the bevel highlight
  46. * @param shadow the color to use for the bevel shadow
  47. */
  48. public SoftBevelBorder(int bevelType, Color highlight, Color shadow) {
  49. super(bevelType, highlight, shadow);
  50. }
  51. /**
  52. * Creates a bevel border with the specified type, highlight
  53. * shadow colors.
  54. * @param bevelType the type of bevel for the border
  55. * @param highlightOuterColor the color to use for the bevel outer highlight
  56. * @param highlightInnerColor the color to use for the bevel inner highlight
  57. * @param shadowOuterColor the color to use for the bevel outer shadow
  58. * @param shadowInnerColor the color to use for the bevel inner shadow
  59. */
  60. public SoftBevelBorder(int bevelType, Color highlightOuterColor,
  61. Color highlightInnerColor, Color shadowOuterColor,
  62. Color shadowInnerColor) {
  63. super(bevelType, highlightOuterColor, highlightInnerColor,
  64. shadowOuterColor, shadowInnerColor);
  65. }
  66. /**
  67. * Paints the border for the specified component with the specified
  68. * position and size.
  69. * @param c the component for which this border is being painted
  70. * @param g the paint graphics
  71. * @param x the x position of the painted border
  72. * @param y the y position of the painted border
  73. * @param width the width of the painted border
  74. * @param height the height of the painted border
  75. */
  76. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  77. Color oldColor = g.getColor();
  78. g.translate(x, y);
  79. if (bevelType == RAISED) {
  80. g.setColor(getHighlightOuterColor(c));
  81. g.drawLine(0, 0, width-2, 0);
  82. g.drawLine(0, 0, 0, height-2);
  83. g.drawLine(1, 1, 1, 1);
  84. g.setColor(getHighlightInnerColor(c));
  85. g.drawLine(2, 1, width-2, 1);
  86. g.drawLine(1, 2, 1, height-2);
  87. g.drawLine(2, 2, 2, 2);
  88. g.drawLine(0, height-1, 0, height-2);
  89. g.drawLine(width-1, 0, width-1, 0);
  90. g.setColor(getShadowOuterColor(c));
  91. g.drawLine(2, height-1, width-1, height-1);
  92. g.drawLine(width-1, 2, width-1, height-1);
  93. g.setColor(getShadowInnerColor(c));
  94. g.drawLine(width-2, height-2, width-2, height-2);
  95. } else if (bevelType == LOWERED) {
  96. g.setColor(getShadowOuterColor(c));
  97. g.drawLine(0, 0, width-2, 0);
  98. g.drawLine(0, 0, 0, height-2);
  99. g.drawLine(1, 1, 1, 1);
  100. g.setColor(getShadowInnerColor(c));
  101. g.drawLine(2, 1, width-2, 1);
  102. g.drawLine(1, 2, 1, height-2);
  103. g.drawLine(2, 2, 2, 2);
  104. g.drawLine(0, height-1, 0, height-2);
  105. g.drawLine(width-1, 0, width-1, 0);
  106. g.setColor(getHighlightOuterColor(c));
  107. g.drawLine(2, height-1, width-1, height-1);
  108. g.drawLine(width-1, 2, width-1, height-1);
  109. g.setColor(getHighlightInnerColor(c));
  110. g.drawLine(width-2, height-2, width-2, height-2);
  111. }
  112. g.translate(-x, -y);
  113. g.setColor(oldColor);
  114. }
  115. /**
  116. * Returns the insets of the border.
  117. * @param c the component for which this border insets value applies
  118. */
  119. public Insets getBorderInsets(Component c) {
  120. return getBorderInsets(c, new Insets(0,0,0,0));
  121. }
  122. /**
  123. * Reinitialize the insets parameter with this Border's current Insets.
  124. * @param c the component for which this border insets value applies
  125. * @param insets the object to be reinitialized
  126. */
  127. public Insets getBorderInsets(Component c, Insets insets) {
  128. insets.top = insets.left = insets.bottom = insets.right = 3;
  129. return insets;
  130. }
  131. /**
  132. * Returns whether or not the border is opaque.
  133. */
  134. public boolean isBorderOpaque() { return false; }
  135. }