01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Dmitry A. Durnev
19: * @version $Revision$
20: */package java.awt;
21:
22: import java.io.Serializable;
23:
24: import org.apache.harmony.misc.HashCode;
25:
26: public class Insets implements Cloneable, Serializable {
27:
28: private static final long serialVersionUID = -2272572637695466749L;
29:
30: public int top;
31:
32: public int left;
33:
34: public int bottom;
35:
36: public int right;
37:
38: public Insets(int top, int left, int bottom, int right) {
39: setValues(top, left, bottom, right);
40: }
41:
42: @Override
43: public int hashCode() {
44: int hashCode = HashCode.EMPTY_HASH_CODE;
45: hashCode = HashCode.combine(hashCode, top);
46: hashCode = HashCode.combine(hashCode, left);
47: hashCode = HashCode.combine(hashCode, bottom);
48: hashCode = HashCode.combine(hashCode, right);
49: return hashCode;
50: }
51:
52: @Override
53: public Object clone() {
54: return new Insets(top, left, bottom, right);
55: }
56:
57: @Override
58: public boolean equals(Object o) {
59: if (o == this ) {
60: return true;
61: }
62: if (o instanceof Insets) {
63: Insets i = (Insets) o;
64: return ((i.left == left) && (i.bottom == bottom)
65: && (i.right == right) && (i.top == top));
66: }
67: return false;
68: }
69:
70: @Override
71: public String toString() {
72: /* The format is based on 1.5 release behavior
73: * which can be revealed by the following code:
74: * System.out.println(new Insets(1, 2, 3, 4));
75: */
76:
77: return (getClass().getName() + "[left=" + left + ",top=" + top + //$NON-NLS-1$ //$NON-NLS-2$
78: ",right=" + right + ",bottom=" + bottom + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
79: }
80:
81: public void set(int top, int left, int bottom, int right) {
82: setValues(top, left, bottom, right);
83: }
84:
85: private void setValues(int top, int left, int bottom, int right) {
86: this.top = top;
87: this.left = left;
88: this.bottom = bottom;
89: this.right = right;
90: }
91: }
|