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