KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > Insets


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.app;
31 import java.io.Serializable JavaDoc;
32
33 /**
34  * A property which describes an "inset" within a rectangular
35  * region. This property is commonly used to specify margins of a
36  * <code>Component</code> relative to its container.
37  * Null values for top/left/right/bottom margins indicate a 0-pixel inset
38  * for that margin.
39  */

40 public class Insets
41 implements Serializable JavaDoc {
42
43     private Extent top;
44     private Extent bottom;
45     private Extent left;
46     private Extent right;
47     
48     /**
49      * Creates a new Insets object with the given pixel margin sizes.
50      *
51      * @param leftPx the size of the left margin in pixels
52      * @param topPx the size of the top margin in pixels
53      * @param rightPx the size of the right margin in pixels
54      * @param bottomPx the size of the bottom margin in pixels
55      */

56     public Insets(int leftPx, int topPx, int rightPx, int bottomPx) {
57         super();
58         
59         this.left = leftPx == 0 ? null : new Extent(leftPx, Extent.PX);
60         this.top = topPx == 0 ? null : new Extent(topPx, Extent.PX);
61         this.right = rightPx == 0 ? null : new Extent(rightPx, Extent.PX);
62         this.bottom = bottomPx == 0 ? null : new Extent(bottomPx, Extent.PX);
63     }
64     
65     /**
66      * Creates a new Insets object with the given margin sizes.
67      * <code>Insets</code> only supports <code>Extent</code>s with
68      * fixed (i.e., not percent) units.
69      *
70      * @param left the size of the left margin
71      * @param top the size of the top margin
72      * @param right the size of the right margin
73      * @param bottom the size of the bottom margin
74      */

75     public Insets(Extent left, Extent top, Extent right, Extent bottom) {
76         super();
77         
78         this.left = left;
79         this.top = top;
80         this.right = right;
81         this.bottom = bottom;
82     }
83     
84     /**
85      * Creates a new Insets object, defining all margins to be the provided
86      * value.
87      *
88      * @param sizePx the margin size in pixels
89      */

90     public Insets(int sizePx) {
91         this(new Extent(sizePx, Extent.PX));
92     }
93     
94     /**
95      * Creates a new Insets object, defining all margins to be the provided
96      * value.
97      * <code>Insets</code> only supports <code>Extent</code>s with
98      * fixed (i.e., not percent) units.
99      *
100      * @param size the margin size
101      */

102     public Insets(Extent size) {
103         this(size, size, size, size);
104     }
105     
106     /**
107      * Creates a new Insets object by defining values for the horizontal and
108      * vertical margins.
109      *
110      * @param horizontal the size of the horizontal (left and right) margins in pixels
111      * @param vertical the size of the vertical (top and bottom) margins in pixels
112      */

113     public Insets(int horizontal, int vertical) {
114         this(new Extent(horizontal, Extent.PX), new Extent(vertical, Extent.PX));
115     }
116     
117     /**
118      * Creates a new Insets object by defining values for the horizontal and
119      * vertical margins.
120      *
121      * @param horizontal the size of the horizontal (left and right) margins
122      * @param vertical the size of the vertical (top and bottom) margins
123      */

124     public Insets(Extent horizontal, Extent vertical) {
125         this(horizontal, vertical, horizontal, vertical);
126     }
127     
128     /**
129      * @see java.lang.Object#equals(java.lang.Object)
130      */

131     public boolean equals(Object JavaDoc o) {
132         if (!(o instanceof Insets)) {
133             return false;
134         }
135         Insets that = (Insets) o;
136         if (this.left != that.left && (this.left == null || !this.left.equals(that.left))) {
137             return false;
138         }
139         if (this.top != that.top && (this.top == null || !this.top.equals(that.top))) {
140             return false;
141         }
142         if (this.right != that.right && (this.right == null || !this.right.equals(that.right))) {
143             return false;
144         }
145         if (this.bottom != that.bottom && (this.bottom == null || !this.bottom.equals(that.bottom))) {
146             return false;
147         }
148         return true;
149     }
150     
151     /**
152      * Returns the size of the bottom margin.
153      * <code>Insets</code> only supports <code>Extent</code>s with
154      * fixed (i.e., not percent) units.
155      *
156      * @return the size of the bottom margin
157      */

158     public Extent getBottom() {
159         return bottom;
160     }
161     
162     /**
163      * Returns the size of the left margin.
164      * <code>Insets</code> only supports <code>Extent</code>s with
165      * fixed (i.e., not percent) units.
166      *
167      * @return the size of the left margin
168      */

169     public Extent getLeft() {
170         return left;
171     }
172     
173     /**
174      * Returns the size of the right margin.
175      * <code>Insets</code> only supports <code>Extent</code>s with
176      * fixed (i.e., not percent) units.
177      *
178      * @return the size of the right margin
179      */

180     public Extent getRight() {
181         return right;
182     }
183
184     /**
185      * Returns the size of the top margin.
186      * <code>Insets</code> only supports <code>Extent</code>s with
187      * fixed (i.e., not percent) units.
188      *
189      * @return the size of the top margin
190      */

191     public Extent getTop() {
192         return top;
193     }
194 }
195
Popular Tags