001 /*
002 * Copyright 1995-2003 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.awt;
027
028 /**
029 * An <code>Insets</code> object is a representation of the borders
030 * of a container. It specifies the space that a container must leave
031 * at each of its edges. The space can be a border, a blank space, or
032 * a title.
033 *
034 * @version 1.37, 05/05/07
035 * @author Arthur van Hoff
036 * @author Sami Shaio
037 * @see java.awt.LayoutManager
038 * @see java.awt.Container
039 * @since JDK1.0
040 */
041 public class Insets implements Cloneable, java.io.Serializable {
042
043 /**
044 * The inset from the top.
045 * This value is added to the Top of the rectangle
046 * to yield a new location for the Top.
047 *
048 * @serial
049 * @see #clone()
050 */
051 public int top;
052
053 /**
054 * The inset from the left.
055 * This value is added to the Left of the rectangle
056 * to yield a new location for the Left edge.
057 *
058 * @serial
059 * @see #clone()
060 */
061 public int left;
062
063 /**
064 * The inset from the bottom.
065 * This value is subtracted from the Bottom of the rectangle
066 * to yield a new location for the Bottom.
067 *
068 * @serial
069 * @see #clone()
070 */
071 public int bottom;
072
073 /**
074 * The inset from the right.
075 * This value is subtracted from the Right of the rectangle
076 * to yield a new location for the Right edge.
077 *
078 * @serial
079 * @see #clone()
080 */
081 public int right;
082
083 /*
084 * JDK 1.1 serialVersionUID
085 */
086 private static final long serialVersionUID = -2272572637695466749L;
087
088 static {
089 /* ensure that the necessary native libraries are loaded */
090 Toolkit.loadLibraries();
091 if (!GraphicsEnvironment.isHeadless()) {
092 initIDs();
093 }
094 }
095
096 /**
097 * Creates and initializes a new <code>Insets</code> object with the
098 * specified top, left, bottom, and right insets.
099 * @param top the inset from the top.
100 * @param left the inset from the left.
101 * @param bottom the inset from the bottom.
102 * @param right the inset from the right.
103 */
104 public Insets(int top, int left, int bottom, int right) {
105 this .top = top;
106 this .left = left;
107 this .bottom = bottom;
108 this .right = right;
109 }
110
111 /**
112 * Set top, left, bottom, and right to the specified values
113 *
114 * @param top the inset from the top.
115 * @param left the inset from the left.
116 * @param bottom the inset from the bottom.
117 * @param right the inset from the right.
118 * @since 1.5
119 */
120 public void set(int top, int left, int bottom, int right) {
121 this .top = top;
122 this .left = left;
123 this .bottom = bottom;
124 this .right = right;
125 }
126
127 /**
128 * Checks whether two insets objects are equal. Two instances
129 * of <code>Insets</code> are equal if the four integer values
130 * of the fields <code>top</code>, <code>left</code>,
131 * <code>bottom</code>, and <code>right</code> are all equal.
132 * @return <code>true</code> if the two insets are equal;
133 * otherwise <code>false</code>.
134 * @since JDK1.1
135 */
136 public boolean equals(Object obj) {
137 if (obj instanceof Insets) {
138 Insets insets = (Insets) obj;
139 return ((top == insets.top) && (left == insets.left)
140 && (bottom == insets.bottom) && (right == insets.right));
141 }
142 return false;
143 }
144
145 /**
146 * Returns the hash code for this Insets.
147 *
148 * @return a hash code for this Insets.
149 */
150 public int hashCode() {
151 int sum1 = left + bottom;
152 int sum2 = right + top;
153 int val1 = sum1 * (sum1 + 1) / 2 + left;
154 int val2 = sum2 * (sum2 + 1) / 2 + top;
155 int sum3 = val1 + val2;
156 return sum3 * (sum3 + 1) / 2 + val2;
157 }
158
159 /**
160 * Returns a string representation of this <code>Insets</code> object.
161 * This method is intended to be used only for debugging purposes, and
162 * the content and format of the returned string may vary between
163 * implementations. The returned string may be empty but may not be
164 * <code>null</code>.
165 *
166 * @return a string representation of this <code>Insets</code> object.
167 */
168 public String toString() {
169 return getClass().getName() + "[top=" + top + ",left=" + left
170 + ",bottom=" + bottom + ",right=" + right + "]";
171 }
172
173 /**
174 * Create a copy of this object.
175 * @return a copy of this <code>Insets</code> object.
176 */
177 public Object clone() {
178 try {
179 return super .clone();
180 } catch (CloneNotSupportedException e) {
181 // this shouldn't happen, since we are Cloneable
182 throw new InternalError();
183 }
184 }
185
186 /**
187 * Initialize JNI field and method IDs
188 */
189 private static native void initIDs();
190
191 }
|