KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > border > AbstractBorder


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
9 import java.awt.Graphics JavaDoc;
10 import java.awt.Insets JavaDoc;
11 import java.awt.Rectangle JavaDoc;
12 import java.awt.Component JavaDoc;
13 import java.io.Serializable JavaDoc;
14
15 /**
16  * A class that implements an empty border with no size.
17  * This provides a convenient base class from which other border
18  * classes can be easily derived.
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
23  * appropriate for short term storage or RMI between applications running
24  * the same version of Swing. As of 1.4, support for long term storage
25  * of all JavaBeans<sup><font size="-2">TM</font></sup>
26  * has been added to the <code>java.beans</code> package.
27  * Please see {@link java.beans.XMLEncoder}.
28  *
29  * @version 1.33 12/19/03
30  * @author David Kloba
31  */

32 public abstract class AbstractBorder implements Border JavaDoc, Serializable JavaDoc
33 {
34
35     /**
36      * This default implementation does no painting.
37      * @param c the component for which this border is being painted
38      * @param g the paint graphics
39      * @param x the x position of the painted border
40      * @param y the y position of the painted border
41      * @param width the width of the painted border
42      * @param height the height of the painted border
43      */

44     public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int width, int height) {
45     }
46
47     /**
48      * This default implementation returns a new <code>Insets</code>
49      * instance where the <code>top</code>, <code>left</code>,
50      * <code>bottom</code>, and
51      * <code>right</code> fields are set to <code>0</code>.
52      * @param c the component for which this border insets value applies
53      * @return the new <code>Insets</code> object initialized to 0
54      */

55     public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
56         return new Insets JavaDoc(0, 0, 0, 0);
57     }
58
59     /**
60      * Reinitializes the insets parameter with this Border's current Insets.
61      * @param c the component for which this border insets value applies
62      * @param insets the object to be reinitialized
63      * @return the <code>insets</code> object
64      */

65     public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc insets) {
66         insets.left = insets.top = insets.right = insets.bottom = 0;
67         return insets;
68     }
69
70     /**
71      * This default implementation returns false.
72      * @return false
73      */

74     public boolean isBorderOpaque() { return false; }
75
76     /**
77      * This convenience method calls the static method.
78      * @param c the component for which this border is being computed
79      * @param x the x position of the border
80      * @param y the y position of the border
81      * @param width the width of the border
82      * @param height the height of the border
83      * @return a <code>Rectangle</code> containing the interior coordinates
84      */

85     public Rectangle JavaDoc getInteriorRectangle(Component JavaDoc c, int x, int y, int width, int height) {
86     return getInteriorRectangle(c, this, x, y, width, height);
87     }
88
89     /**
90      * Returns a rectangle using the arguments minus the
91      * insets of the border. This is useful for determining the area
92      * that components should draw in that will not intersect the border.
93      * @param c the component for which this border is being computed
94      * @param b the <code>Border</code> object
95      * @param x the x position of the border
96      * @param y the y position of the border
97      * @param width the width of the border
98      * @param height the height of the border
99      * @return a <code>Rectangle</code> containing the interior coordinates
100      */

101     public static Rectangle JavaDoc getInteriorRectangle(Component JavaDoc c, Border JavaDoc b, int x, int y, int width, int height) {
102         Insets JavaDoc insets;
103     if(b != null)
104         insets = b.getBorderInsets(c);
105     else
106         insets = new Insets JavaDoc(0, 0, 0, 0);
107         return new Rectangle JavaDoc(x + insets.left,
108                                 y + insets.top,
109                                 width - insets.right - insets.left,
110                                 height - insets.top - insets.bottom);
111     }
112
113     /*
114      * Convenience function for determining ComponentOrientation.
115      * Helps us avoid having Munge directives throughout the code.
116      */

117     static boolean isLeftToRight( Component JavaDoc c ) {
118         return c.getComponentOrientation().isLeftToRight();
119     }
120     
121 }
122
Popular Tags