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 the
009: * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
013: * the specific language governing rights and limitations under the License.
014: *
015: * Alternatively, the contents of this file may be used under the terms of
016: * either the GNU General Public License Version 2 or later (the "GPL"), or the
017: * GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
018: * case the provisions of the GPL or the LGPL are applicable instead of those
019: * above. If you wish to allow use of your version of this file only under the
020: * terms of either the GPL or the LGPL, and not to allow others to use your
021: * version of this file under the terms of the MPL, indicate your decision by
022: * deleting the provisions above and replace them with the notice and other
023: * provisions required by the GPL or the LGPL. If you do not delete the
024: * provisions above, a recipient may use your version of this file under the
025: * terms of any one of the MPL, the GPL or the LGPL.
026: */
027:
028: package nextapp.echo2.app;
029:
030: import java.io.Serializable;
031:
032: /**
033: * A representation of a graphical border drawn using a series of
034: * eight <code>FillImage</code>s. The eight images are used to describe
035: * the four corners and four sides of the border.
036: * The <code>BorderInsets</code> property is used to describe the width and
037: * height of the border images, i.e. the inset to which the border images
038: * extend inward from the outer edges of the box.
039: * The <code>ContentInsets</code> property is used to describe the inset of
040: * the content displayed within the border. If the content inset is less
041: * than the border inset, the content will be drawn above the border.
042: * The <code>Color</code> property may be used in addition to or in lieu of
043: * setting <code>FillImage</code>s. The color will be drawn <em>behind</em>
044: * the <code>FillImage</code>s in the case where both are used.
045: */
046: public class FillImageBorder implements Serializable {
047:
048: public static final int TOP_LEFT = 0;
049: public static final int TOP = 1;
050: public static final int TOP_RIGHT = 2;
051: public static final int LEFT = 3;
052: public static final int RIGHT = 4;
053: public static final int BOTTOM_LEFT = 5;
054: public static final int BOTTOM = 6;
055: public static final int BOTTOM_RIGHT = 7;
056:
057: private Insets contentInsets, borderInsets;
058: private Color color;
059: private FillImage[] fillImages;
060:
061: /**
062: * Creates a new <code>FillImageBorder</code>.
063: */
064: public FillImageBorder() {
065: super ();
066: }
067:
068: /**
069: * Creates a new <code>FillImageBorder</code> with the specified color,
070: * border inset, and content inset.
071: *
072: * @param color the solid color background of the border
073: * @param borderInsets the border inset
074: * @param contentInsets the content inset
075: * @see #setBorderInsets(nextapp.echo2.app.Insets)
076: * @see #setContentInsets(nextapp.echo2.app.Insets)
077: * @see #setColor(nextapp.echo2.app.Color)
078: */
079: public FillImageBorder(Color color, Insets borderInsets,
080: Insets contentInsets) {
081: super ();
082: this .color = color;
083: this .borderInsets = borderInsets;
084: this .contentInsets = contentInsets;
085: }
086:
087: /**
088: * @see java.lang.Object#equals(java.lang.Object)
089: */
090: public boolean equals(Object o) {
091: if (!(o instanceof FillImageBorder)) {
092: return false;
093: }
094: FillImageBorder that = (FillImageBorder) o;
095: if (!(this .color == that.color || (this .color != null && this .color
096: .equals(that.color)))) {
097: return false;
098: }
099: if (!(this .borderInsets == that.borderInsets || (this .borderInsets != null && this .borderInsets
100: .equals(that.borderInsets)))) {
101: return false;
102: }
103: if (!(this .contentInsets == that.contentInsets || (this .contentInsets != null && this .contentInsets
104: .equals(that.contentInsets)))) {
105: return false;
106: }
107: if (this .fillImages != null || that.fillImages != null) {
108: if (this .fillImages == null || that.fillImages == null) {
109: return false;
110: }
111: for (int i = 0; i < fillImages.length; ++i) {
112: if (!(this .fillImages[i] == that.fillImages[i] || (this .fillImages[i] != null && this .fillImages[i]
113: .equals(that.fillImages[i])))) {
114: return false;
115: }
116: }
117: }
118: return true;
119: }
120:
121: /**
122: * Returns the content inset.
123: *
124: * @see #setBorderInsets(nextapp.echo2.app.Insets)
125: * @return the border inset
126: */
127: public Insets getBorderInsets() {
128: return borderInsets;
129: }
130:
131: /**
132: * Returns the solid color background of the border.
133: *
134: * @see #setColor(nextapp.echo2.app.Color)
135: * @return the color
136: */
137: public Color getColor() {
138: return color;
139: }
140:
141: /**
142: * Sets the content inset.
143: *
144: * @see #setContentInsets(nextapp.echo2.app.Insets)
145: * @return the content inset
146: */
147: public Insets getContentInsets() {
148: return contentInsets;
149: }
150:
151: /**
152: * Retrieves the <code>FillImage</code> at the specified position.
153: *
154: * @param position the position, one of the following values:
155: * <ul>
156: * <li><code>TOP_LEFT</code> the top left corner image</li>
157: * <li><code>TOP</code> the top side image</li>
158: * <li><code>TOP_RIGHT</code> the top right corner image</li>
159: * <li><code>LEFT</code> the left side image</li>
160: * <li><code>RIGHT</code> the right side image</li>
161: * <li><code>BOTTOM_LFET</code> the bottom left corner image</li>
162: * <li><code>BOTTOM</code> the bottom side image</li>
163: * <li><code>BOTTOM_RIGHT</code> the bottom right corner image</li>
164: * </ul>
165: * @return the <code>FillImage</code>
166: */
167: public FillImage getFillImage(int position) {
168: if (fillImages == null) {
169: return null;
170: } else {
171: return fillImages[position];
172: }
173: }
174:
175: /**
176: * Sets the inset of the border images, thus defining the width and
177: * height of the border images.
178: * The provided <code>Insets</code> value must only contain margins defined
179: * in pixel units.
180: *
181: * @param borderInsets the new border inset
182: */
183: public void setBorderInsets(Insets borderInsets) {
184: this .borderInsets = borderInsets;
185: }
186:
187: /**
188: * Sets the solid color background of the border.
189: * Note that setting a solid background color for the border will cause
190: * the alpha channel of any <code>FillImage</code>s to be rendered against
191: * this color.
192: *
193: * @param color the color
194: */
195: public void setColor(Color color) {
196: this .color = color;
197: }
198:
199: /**
200: * Sets the inset of the content that is contained within the border
201: * relative to the outside of the border. If this inset value is smaller
202: * than the the border inset, the content will be rendered partially on top
203: * of the border. A null value for this property specifies that the
204: * content should be drawn at the border inset.
205: * The provided <code>Insets</code> value must only contain margins defined
206: * in pixel units.
207: *
208: * @param contentInsets the new content inset
209: */
210: public void setContentInsets(Insets contentInsets) {
211: this .contentInsets = contentInsets;
212: }
213:
214: /**
215: * Sets the <code>FillImage</code> at the specified position.
216: *
217: * @param position the position, one of the following values:
218: * <ul>
219: * <li><code>TOP_LEFT</code> the top left corner image</li>
220: * <li><code>TOP</code> the top side image</li>
221: * <li><code>TOP_RIGHT</code> the top right corner image</li>
222: * <li><code>LEFT</code> the left side image</li>
223: * <li><code>RIGHT</code> the right side image</li>
224: * <li><code>BOTTOM_LFET</code> the bottom left corner image</li>
225: * <li><code>BOTTOM</code> the bottom side image</li>
226: * <li><code>BOTTOM_RIGHT</code> the bottom right corner image</li>
227: * </ul>
228: * @param fillImage the new <code>FillIamge</code>
229: */
230: public void setFillImage(int position, FillImage fillImage) {
231: if (fillImages == null) {
232: if (fillImage == null) {
233: return;
234: }
235: fillImages = new FillImage[8];
236: }
237: fillImages[position] = fillImage;
238: }
239: }
|