001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app;
031:
032: import java.io.Serializable;
033:
034: /**
035: * A property which describes an "inset" within a rectangular
036: * region. This property is commonly used to specify margins of a
037: * <code>Component</code> relative to its container.
038: * Null values for top/left/right/bottom margins indicate a 0-pixel inset
039: * for that margin.
040: */
041: public class Insets implements Serializable {
042:
043: private Extent top;
044: private Extent bottom;
045: private Extent left;
046: private Extent right;
047:
048: /**
049: * Creates a new Insets object with the given pixel margin sizes.
050: *
051: * @param leftPx the size of the left margin in pixels
052: * @param topPx the size of the top margin in pixels
053: * @param rightPx the size of the right margin in pixels
054: * @param bottomPx the size of the bottom margin in pixels
055: */
056: public Insets(int leftPx, int topPx, int rightPx, int bottomPx) {
057: super ();
058:
059: this .left = leftPx == 0 ? null : new Extent(leftPx, Extent.PX);
060: this .top = topPx == 0 ? null : new Extent(topPx, Extent.PX);
061: this .right = rightPx == 0 ? null : new Extent(rightPx,
062: Extent.PX);
063: this .bottom = bottomPx == 0 ? null : new Extent(bottomPx,
064: Extent.PX);
065: }
066:
067: /**
068: * Creates a new Insets object with the given margin sizes.
069: * <code>Insets</code> only supports <code>Extent</code>s with
070: * fixed (i.e., not percent) units.
071: *
072: * @param left the size of the left margin
073: * @param top the size of the top margin
074: * @param right the size of the right margin
075: * @param bottom the size of the bottom margin
076: */
077: public Insets(Extent left, Extent top, Extent right, Extent bottom) {
078: super ();
079:
080: this .left = left;
081: this .top = top;
082: this .right = right;
083: this .bottom = bottom;
084: }
085:
086: /**
087: * Creates a new Insets object, defining all margins to be the provided
088: * value.
089: *
090: * @param sizePx the margin size in pixels
091: */
092: public Insets(int sizePx) {
093: this (new Extent(sizePx, Extent.PX));
094: }
095:
096: /**
097: * Creates a new Insets object, defining all margins to be the provided
098: * value.
099: * <code>Insets</code> only supports <code>Extent</code>s with
100: * fixed (i.e., not percent) units.
101: *
102: * @param size the margin size
103: */
104: public Insets(Extent size) {
105: this (size, size, size, size);
106: }
107:
108: /**
109: * Creates a new Insets object by defining values for the horizontal and
110: * vertical margins.
111: *
112: * @param horizontal the size of the horizontal (left and right) margins in pixels
113: * @param vertical the size of the vertical (top and bottom) margins in pixels
114: */
115: public Insets(int horizontal, int vertical) {
116: this (new Extent(horizontal, Extent.PX), new Extent(vertical,
117: Extent.PX));
118: }
119:
120: /**
121: * Creates a new Insets object by defining values for the horizontal and
122: * vertical margins.
123: *
124: * @param horizontal the size of the horizontal (left and right) margins
125: * @param vertical the size of the vertical (top and bottom) margins
126: */
127: public Insets(Extent horizontal, Extent vertical) {
128: this (horizontal, vertical, horizontal, vertical);
129: }
130:
131: /**
132: * @see java.lang.Object#equals(java.lang.Object)
133: */
134: public boolean equals(Object o) {
135: if (!(o instanceof Insets)) {
136: return false;
137: }
138: Insets that = (Insets) o;
139: if (this .left != that.left
140: && (this .left == null || !this .left.equals(that.left))) {
141: return false;
142: }
143: if (this .top != that.top
144: && (this .top == null || !this .top.equals(that.top))) {
145: return false;
146: }
147: if (this .right != that.right
148: && (this .right == null || !this .right
149: .equals(that.right))) {
150: return false;
151: }
152: if (this .bottom != that.bottom
153: && (this .bottom == null || !this .bottom
154: .equals(that.bottom))) {
155: return false;
156: }
157: return true;
158: }
159:
160: /**
161: * Returns the size of the bottom margin.
162: * <code>Insets</code> only supports <code>Extent</code>s with
163: * fixed (i.e., not percent) units.
164: *
165: * @return the size of the bottom margin
166: */
167: public Extent getBottom() {
168: return bottom;
169: }
170:
171: /**
172: * Returns the size of the left margin.
173: * <code>Insets</code> only supports <code>Extent</code>s with
174: * fixed (i.e., not percent) units.
175: *
176: * @return the size of the left margin
177: */
178: public Extent getLeft() {
179: return left;
180: }
181:
182: /**
183: * Returns the size of the right margin.
184: * <code>Insets</code> only supports <code>Extent</code>s with
185: * fixed (i.e., not percent) units.
186: *
187: * @return the size of the right margin
188: */
189: public Extent getRight() {
190: return right;
191: }
192:
193: /**
194: * Returns the size of the top margin.
195: * <code>Insets</code> only supports <code>Extent</code>s with
196: * fixed (i.e., not percent) units.
197: *
198: * @return the size of the top margin
199: */
200: public Extent getTop() {
201: return top;
202: }
203: }
|