KickJava   Java API By Example, From Geeks To Geeks.

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


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 the
9  * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13  * the specific language governing rights and limitations under the License.
14  *
15  * Alternatively, the contents of this file may be used under the terms of
16  * either the GNU General Public License Version 2 or later (the "GPL"), or the
17  * GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
18  * case the provisions of the GPL or the LGPL are applicable instead of those
19  * above. If you wish to allow use of your version of this file only under the
20  * terms of either the GPL or the LGPL, and not to allow others to use your
21  * version of this file under the terms of the MPL, indicate your decision by
22  * deleting the provisions above and replace them with the notice and other
23  * provisions required by the GPL or the LGPL. If you do not delete the
24  * provisions above, a recipient may use your version of this file under the
25  * terms of any one of the MPL, the GPL or the LGPL.
26  */

27
28 package nextapp.echo2.app;
29
30 import java.io.Serializable JavaDoc;
31
32 /**
33  * A representation of a graphical border drawn using a series of
34  * eight <code>FillImage</code>s. The eight images are used to describe
35  * the four corners and four sides of the border.
36  * The <code>BorderInsets</code> property is used to describe the width and
37  * height of the border images, i.e. the inset to which the border images
38  * extend inward from the outer edges of the box.
39  * The <code>ContentInsets</code> property is used to describe the inset of
40  * the content displayed within the border. If the content inset is less
41  * than the border inset, the content will be drawn above the border.
42  * The <code>Color</code> property may be used in addition to or in lieu of
43  * setting <code>FillImage</code>s. The color will be drawn <em>behind</em>
44  * the <code>FillImage</code>s in the case where both are used.
45  */

46 public class FillImageBorder
47 implements Serializable JavaDoc {
48
49     public static final int TOP_LEFT = 0;
50     public static final int TOP = 1;
51     public static final int TOP_RIGHT= 2;
52     public static final int LEFT = 3;
53     public static final int RIGHT = 4;
54     public static final int BOTTOM_LEFT= 5;
55     public static final int BOTTOM = 6;
56     public static final int BOTTOM_RIGHT = 7;
57     
58     private Insets contentInsets, borderInsets;
59     private Color color;
60     private FillImage[] fillImages;
61
62     /**
63      * Creates a new <code>FillImageBorder</code>.
64      */

65     public FillImageBorder() {
66         super();
67     }
68     
69     /**
70      * Creates a new <code>FillImageBorder</code> with the specified color,
71      * border inset, and content inset.
72      *
73      * @param color the solid color background of the border
74      * @param borderInsets the border inset
75      * @param contentInsets the content inset
76      * @see #setBorderInsets(nextapp.echo2.app.Insets)
77      * @see #setContentInsets(nextapp.echo2.app.Insets)
78      * @see #setColor(nextapp.echo2.app.Color)
79      */

80     public FillImageBorder(Color color, Insets borderInsets, Insets contentInsets) {
81         super();
82         this.color = color;
83         this.borderInsets = borderInsets;
84         this.contentInsets = contentInsets;
85     }
86     
87     /**
88      * @see java.lang.Object#equals(java.lang.Object)
89      */

90     public boolean equals(Object JavaDoc o) {
91         if (!(o instanceof FillImageBorder)) {
92             return false;
93         }
94         FillImageBorder that = (FillImageBorder) o;
95         if (!(this.color == that.color ||
96                 (this.color != null && this.color.equals(that.color)))) {
97             return false;
98         }
99         if (!(this.borderInsets == that.borderInsets ||
100                 (this.borderInsets != null && this.borderInsets.equals(that.borderInsets)))) {
101             return false;
102         }
103         if (!(this.contentInsets == that.contentInsets ||
104                 (this.contentInsets != null && this.contentInsets.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] ||
113                         (this.fillImages[i] != null && this.fillImages[i].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 }
Popular Tags