KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > Insets


1 /*
2  * @(#)Insets.java 1.30 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
8 package java.awt;
9
10 /**
11  * An <code>Insets</code> object is a representation of the borders
12  * of a container. It specifies the space that a container must leave
13  * at each of its edges. The space can be a border, a blank space, or
14  * a title.
15  *
16  * @version 1.30, 12/19/03
17  * @author Arthur van Hoff
18  * @author Sami Shaio
19  * @see java.awt.LayoutManager
20  * @see java.awt.Container
21  * @since JDK1.0
22  */

23 public class Insets implements Cloneable JavaDoc, java.io.Serializable JavaDoc {
24
25     /**
26      * The inset from the top.
27      * This value is added to the Top of the rectangle
28      * to yield a new location for the Top.
29      *
30      * @serial
31      * @see #clone()
32      */

33     public int top;
34
35     /**
36      * The inset from the left.
37      * This value is added to the Left of the rectangle
38      * to yield a new location for the Left edge.
39      *
40      * @serial
41      * @see #clone()
42      */

43     public int left;
44
45     /**
46      * The inset from the bottom.
47      * This value is subtracted from the Bottom of the rectangle
48      * to yield a new location for the Bottom.
49      *
50      * @serial
51      * @see #clone()
52      */

53     public int bottom;
54
55     /**
56      * The inset from the right.
57      * This value is subtracted from the Right of the rectangle
58      * to yield a new location for the Right edge.
59      *
60      * @serial
61      * @see #clone()
62      */

63     public int right;
64
65     /*
66      * JDK 1.1 serialVersionUID
67      */

68     private static final long serialVersionUID = -2272572637695466749L;
69   
70     static {
71         /* ensure that the necessary native libraries are loaded */
72     Toolkit.loadLibraries();
73         if (!GraphicsEnvironment.isHeadless()) {
74             initIDs();
75         }
76     }
77
78     /**
79      * Creates and initializes a new <code>Insets</code> object with the
80      * specified top, left, bottom, and right insets.
81      * @param top the inset from the top.
82      * @param left the inset from the left.
83      * @param bottom the inset from the bottom.
84      * @param right the inset from the right.
85      */

86     public Insets(int top, int left, int bottom, int right) {
87     this.top = top;
88     this.left = left;
89     this.bottom = bottom;
90     this.right = right;
91     }
92
93     /**
94      * Set top, left, bottom, and right to the specified values
95      *
96      * @param top the inset from the top.
97      * @param left the inset from the left.
98      * @param bottom the inset from the bottom.
99      * @param right the inset from the right.
100      * @since 1.5
101      */

102     public void set(int top, int left, int bottom, int right) {
103         this.top = top;
104         this.left = left;
105         this.bottom = bottom;
106         this.right = right;
107     }
108
109     /**
110      * Checks whether two insets objects are equal. Two instances
111      * of <code>Insets</code> are equal if the four integer values
112      * of the fields <code>top</code>, <code>left</code>,
113      * <code>bottom</code>, and <code>right</code> are all equal.
114      * @return <code>true</code> if the two insets are equal;
115      * otherwise <code>false</code>.
116      * @since JDK1.1
117      */

118     public boolean equals(Object JavaDoc obj) {
119     if (obj instanceof Insets JavaDoc) {
120         Insets JavaDoc insets = (Insets JavaDoc)obj;
121         return ((top == insets.top) && (left == insets.left) &&
122             (bottom == insets.bottom) && (right == insets.right));
123     }
124     return false;
125     }
126
127     /**
128      * Returns the hash code for this Insets.
129      *
130      * @return a hash code for this Insets.
131      */

132     public int hashCode() {
133         int sum1 = left + bottom;
134         int sum2 = right + top;
135         int val1 = sum1 * (sum1 + 1)/2 + left;
136         int val2 = sum2 * (sum2 + 1)/2 + top;
137         int sum3 = val1 + val2;
138         return sum3 * (sum3 + 1)/2 + val2;
139     }
140
141     /**
142      * Returns a string representation of this <code>Insets</code> object.
143      * This method is intended to be used only for debugging purposes, and
144      * the content and format of the returned string may vary between
145      * implementations. The returned string may be empty but may not be
146      * <code>null</code>.
147      *
148      * @return a string representation of this <code>Insets</code> object.
149      */

150     public String JavaDoc toString() {
151     return getClass().getName() + "[top=" + top + ",left=" + left + ",bottom=" + bottom + ",right=" + right + "]";
152     }
153
154     /**
155      * Create a copy of this object.
156      * @return a copy of this <code>Insets</code> object.
157      */

158     public Object JavaDoc clone() {
159     try {
160         return super.clone();
161     } catch (CloneNotSupportedException JavaDoc e) {
162         // this shouldn't happen, since we are Cloneable
163
throw new InternalError JavaDoc();
164     }
165     }
166     /**
167      * Initialize JNI field and method IDs
168      */

169     private static native void initIDs();
170
171 }
172
Popular Tags