1. /*
  2. * @(#)AbstractBorder.java 1.33 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.Component;
  12. import java.io.Serializable;
  13. /**
  14. * A class that 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
  21. * appropriate for short term storage or RMI between applications running
  22. * the same version of Swing. As of 1.4, support for long term storage
  23. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  24. * has been added to the <code>java.beans</code> package.
  25. * Please see {@link java.beans.XMLEncoder}.
  26. *
  27. * @version 1.33 12/19/03
  28. * @author David Kloba
  29. */
  30. public abstract class AbstractBorder implements Border, Serializable
  31. {
  32. /**
  33. * This default implementation does no painting.
  34. * @param c the component for which this border is being painted
  35. * @param g the paint graphics
  36. * @param x the x position of the painted border
  37. * @param y the y position of the painted border
  38. * @param width the width of the painted border
  39. * @param height the height of the painted border
  40. */
  41. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  42. }
  43. /**
  44. * This default implementation returns a new <code>Insets</code>
  45. * instance where the <code>top</code>, <code>left</code>,
  46. * <code>bottom</code>, and
  47. * <code>right</code> fields are set to <code>0</code>.
  48. * @param c the component for which this border insets value applies
  49. * @return the new <code>Insets</code> object initialized to 0
  50. */
  51. public Insets getBorderInsets(Component c) {
  52. return new Insets(0, 0, 0, 0);
  53. }
  54. /**
  55. * Reinitializes the insets parameter with this Border's current Insets.
  56. * @param c the component for which this border insets value applies
  57. * @param insets the object to be reinitialized
  58. * @return the <code>insets</code> object
  59. */
  60. public Insets getBorderInsets(Component c, Insets insets) {
  61. insets.left = insets.top = insets.right = insets.bottom = 0;
  62. return insets;
  63. }
  64. /**
  65. * This default implementation returns false.
  66. * @return false
  67. */
  68. public boolean isBorderOpaque() { return false; }
  69. /**
  70. * This convenience method calls the static method.
  71. * @param c the component for which this border is being computed
  72. * @param x the x position of the border
  73. * @param y the y position of the border
  74. * @param width the width of the border
  75. * @param height the height of the border
  76. * @return a <code>Rectangle</code> containing the interior coordinates
  77. */
  78. public Rectangle getInteriorRectangle(Component c, int x, int y, int width, int height) {
  79. return getInteriorRectangle(c, this, x, y, width, height);
  80. }
  81. /**
  82. * Returns a rectangle using the arguments minus the
  83. * insets of the border. This is useful for determining the area
  84. * that components should draw in that will not intersect the border.
  85. * @param c the component for which this border is being computed
  86. * @param b the <code>Border</code> object
  87. * @param x the x position of the border
  88. * @param y the y position of the border
  89. * @param width the width of the border
  90. * @param height the height of the border
  91. * @return a <code>Rectangle</code> containing the interior coordinates
  92. */
  93. public static Rectangle getInteriorRectangle(Component c, Border b, int x, int y, int width, int height) {
  94. Insets insets;
  95. if(b != null)
  96. insets = b.getBorderInsets(c);
  97. else
  98. insets = new Insets(0, 0, 0, 0);
  99. return new Rectangle(x + insets.left,
  100. y + insets.top,
  101. width - insets.right - insets.left,
  102. height - insets.top - insets.bottom);
  103. }
  104. /*
  105. * Convenience function for determining ComponentOrientation.
  106. * Helps us avoid having Munge directives throughout the code.
  107. */
  108. static boolean isLeftToRight( Component c ) {
  109. return c.getComponentOrientation().isLeftToRight();
  110. }
  111. }