1. /*
  2. * @(#)AbstractBorder.java 1.22 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.Component;
  12. import java.io.Serializable;
  13. /**
  14. * A class which implements an empty border with no size.
  15. * This provides a convenient base class from which other border
  16. * classes can be easily derived.
  17. * <p>
  18. * <strong>Warning:</strong>
  19. * Serialized objects of this class will not be compatible with
  20. * future Swing releases. The current serialization support is appropriate
  21. * for short term storage or RMI between applications running the same
  22. * version of Swing. A future release of Swing will provide support for
  23. * long term persistence.
  24. *
  25. * @version 1.22 11/29/01
  26. * @author David Kloba
  27. */
  28. public abstract class AbstractBorder implements Border, Serializable
  29. {
  30. /** This default implementation does no painting. */
  31. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  32. }
  33. /** This default implementation returns the value of getBorderMargins. */
  34. public Insets getBorderInsets(Component c) {
  35. return new Insets(0, 0, 0, 0);
  36. }
  37. /**
  38. * Reinitialize the insets parameter with this Border's current Insets.
  39. * @param c the component for which this border insets value applies
  40. * @param insets the object to be reinitialized
  41. */
  42. public Insets getBorderInsets(Component c, Insets insets) {
  43. insets.left = insets.top = insets.right = insets.bottom = 0;
  44. return insets;
  45. }
  46. /** This default implementation returns false. */
  47. public boolean isBorderOpaque() { return false; }
  48. /** This is a convience method that calls the static method. */
  49. public Rectangle getInteriorRectangle(Component c, int x, int y, int width, int height) {
  50. return getInteriorRectangle(c, this, x, y, width, height);
  51. }
  52. /** This method returns a rectangle using the arguements minus the
  53. * insets of the border. This is useful for determining the area
  54. * that components should draw in that will not intersect the border.
  55. */
  56. public static Rectangle getInteriorRectangle(Component c, Border b, int x, int y, int width, int height) {
  57. Insets insets;
  58. if(b != null)
  59. insets = b.getBorderInsets(c);
  60. else
  61. insets = new Insets(0, 0, 0, 0);
  62. return new Rectangle(x + insets.left,
  63. y + insets.top,
  64. width - insets.right - insets.left,
  65. height - insets.top - insets.bottom);
  66. }
  67. }