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