1. /*
  2. * @(#)SoftBevelBorder.java 1.9 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.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 appropriate
  20. * for short term storage or RMI between applications running the same
  21. * version of Swing. A future release of Swing will provide support for
  22. * long term persistence.
  23. *
  24. * @version 1.9 11/29/01
  25. * @author Amy Fowler
  26. * @author Chester Rose
  27. */
  28. public class SoftBevelBorder extends BevelBorder
  29. {
  30. /**
  31. * Creates a bevel border with the specified type and whose
  32. * colors will be derived from the background color of the
  33. * component passed into the paintBorder method.
  34. * @param bevelType the type of bevel for the border
  35. */
  36. public SoftBevelBorder(int bevelType) {
  37. super(bevelType);
  38. }
  39. /**
  40. * Creates a bevel border with the specified type, highlight and
  41. * shadow colors.
  42. * @param bevelType the type of bevel for the border
  43. * @param highlight the color to use for the bevel highlight
  44. * @param shadow the color to use for the bevel shadow
  45. */
  46. public SoftBevelBorder(int bevelType, Color highlight, Color shadow) {
  47. super(bevelType, highlight, shadow);
  48. }
  49. /**
  50. * Creates a bevel border with the specified type, highlight
  51. * shadow colors.
  52. * @param bevelType the type of bevel for the border
  53. * @param highlightOuter the color to use for the bevel outer highlight
  54. * @param highlightInner the color to use for the bevel inner highlight
  55. * @param shadowOuter the color to use for the bevel outer shadow
  56. * @param shadowInner the color to use for the bevel inner shadow
  57. */
  58. public SoftBevelBorder(int bevelType, Color highlightOuter, Color highlightInner,
  59. Color shadowOuter, Color shadowInner) {
  60. super(bevelType, highlightOuter, highlightInner, shadowOuter, shadowInner);
  61. }
  62. /**
  63. * Paints the border for the specified component with the specified
  64. * position and size.
  65. * @param c the component for which this border is being painted
  66. * @param g the paint graphics
  67. * @param x the x position of the painted border
  68. * @param y the y position of the painted border
  69. * @param width the width of the painted border
  70. * @param height the height of the painted border
  71. */
  72. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  73. Color oldColor = g.getColor();
  74. g.translate(x, y);
  75. if (bevelType == RAISED) {
  76. g.setColor(getHighlightOuterColor(c));
  77. g.drawLine(0, 0, width-2, 0);
  78. g.drawLine(0, 0, 0, height-2);
  79. g.drawLine(1, 1, 1, 1);
  80. g.setColor(getHighlightInnerColor(c));
  81. g.drawLine(2, 1, width-2, 1);
  82. g.drawLine(1, 2, 1, height-2);
  83. g.drawLine(2, 2, 2, 2);
  84. g.drawLine(0, height-1, 0, height-2);
  85. g.drawLine(width-1, 0, width-1, 0);
  86. g.setColor(getShadowOuterColor(c));
  87. g.drawLine(2, height-1, width-1, height-1);
  88. g.drawLine(width-1, 2, width-1, height-1);
  89. g.setColor(getShadowInnerColor(c));
  90. g.drawLine(width-2, height-2, width-2, height-2);
  91. } else if (bevelType == LOWERED) {
  92. g.setColor(getShadowOuterColor(c));
  93. g.drawLine(0, 0, width-2, 0);
  94. g.drawLine(0, 0, 0, height-2);
  95. g.drawLine(1, 1, 1, 1);
  96. g.setColor(getShadowInnerColor(c));
  97. g.drawLine(2, 1, width-2, 1);
  98. g.drawLine(1, 2, 1, height-2);
  99. g.drawLine(2, 2, 2, 2);
  100. g.drawLine(0, height-1, 0, height-2);
  101. g.drawLine(width-1, 0, width-1, 0);
  102. g.setColor(getHighlightOuterColor(c));
  103. g.drawLine(2, height-1, width-1, height-1);
  104. g.drawLine(width-1, 2, width-1, height-1);
  105. g.setColor(getHighlightInnerColor(c));
  106. g.drawLine(width-2, height-2, width-2, height-2);
  107. }
  108. g.translate(-x, -y);
  109. g.setColor(oldColor);
  110. }
  111. /**
  112. * Returns the insets of the border.
  113. * @param c the component for which this border insets value applies
  114. */
  115. public Insets getBorderInsets(Component c) {
  116. return new Insets(3, 3, 3, 3);
  117. }
  118. /**
  119. * Returns whether or not the border is opaque.
  120. */
  121. public boolean isBorderOpaque() { return false; }
  122. }