KickJava   Java API By Example, From Geeks To Geeks.

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


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
32 /**
33  * A layout <code>Component</code> which renders its contents in a grid. Each
34  * component is contained within a "cell" of the grid.
35  * <code>GridLayoutData</code> layout data objects may used to cause cells to
36  * expand to fill multiple columns or rows.
37  * <p>
38  * <b>Child LayoutData</b>: Children of this component may provide layout
39  * information using the <code>nextapp.echo2.app.layout.GridLayoutData</code>
40  * layout data object.
41  *
42  * @see nextapp.echo2.app.layout.GridLayoutData
43  */

44 public class Grid extends Component {
45
46     public static final int DEFAULT_SIZE = 2;
47     
48     /**
49      * Constant value for <code>orientation</code> property indicating cells
50      * should be laid out horizontally and then vertically.
51      * <code>ORIENTATION_HORIZONTAL</code> is the default orientation setting.
52      */

53     public static final int ORIENTATION_HORIZONTAL = 0;
54
55     /**
56      * Constant value for <code>orientation</code> property indicating cells
57      * should be laid out vertically and then horizontally.
58      */

59     public static final int ORIENTATION_VERTICAL = 1;
60     
61     public static final String JavaDoc PROPERTY_BORDER = "border";
62     public static final String JavaDoc PROPERTY_COLUMN_WIDTH = "columnWidth";
63     public static final String JavaDoc PROPERTY_HEIGHT = "height";
64     public static final String JavaDoc PROPERTY_INSETS = "insets";
65     public static final String JavaDoc PROPERTY_ORIENTATION = "orientation";
66     public static final String JavaDoc PROPERTY_ROW_HEIGHT = "rowHeight";
67     public static final String JavaDoc PROPERTY_SIZE = "size";
68     public static final String JavaDoc PROPERTY_WIDTH = "width";
69
70     /**
71      * Creates a new horizontally-oriented <code>Grid</code> with the
72      * default size (2).
73      */

74     public Grid() {
75         super();
76     }
77     
78     /**
79      * Creates a new hoirzontally-oriented <code>Grid</code> with the
80      * specified size.
81      *
82      * @param size the number of columns
83      * @see #getSize()
84      */

85     public Grid(int size) {
86         super();
87         setSize(size);
88     }
89
90     /**
91      * Returns the <code>Border</code>.
92      *
93      * @return the border
94      */

95     public Border getBorder() {
96         return (Border) getProperty(PROPERTY_BORDER);
97     }
98
99     /**
100      * Returns the width of the specified column.
101      * This property supports <code>Extent</code>s with
102      * fixed or percentile units.
103      *
104      * @param columnIndex the column index
105      * @return the width
106      */

107     public Extent getColumnWidth(int columnIndex) {
108         return (Extent) getIndexedProperty(PROPERTY_COLUMN_WIDTH, columnIndex);
109     }
110     
111     /**
112      * Returns the overall height.
113      * This property only supports <code>Extent</code>s with
114      * fixed (i.e., not percent) units.
115      *
116      * @return the height
117      */

118     public Extent getHeight() {
119         return (Extent) getProperty(PROPERTY_HEIGHT);
120     }
121     
122     /**
123      * Returns the default cell insets. The default cell insets will be used for
124      * individual child cells that do not provide an <code>Insets</code> value
125      * in their <code>GridLayoutData</code>.
126      *
127      * @return the default cell insets
128      */

129     public Insets getInsets() {
130         return (Insets) getProperty(PROPERTY_INSETS);
131     }
132     
133     /**
134      * Returns the orientation of the grid (either horizontal or vertical).
135      * The orientation describes the direction in which cells are laid out.
136      * An orientation of <code>ORIENTATION_HORIZONTAL</code> (the default)
137      * specifies that cells should be laid out in horizontal rows
138      * with the <code>size</code> property specifying the number of columns
139      * per row.
140      * An orientation of <code>ORIENTATION_VERTICAL</code>
141      * specifies that cells should be laid out in vertical columns
142      * with the <code>size</code> property specifying the number of rows
143      * per column.
144      *
145      * @return the orientation, one of the following values:
146      * <ul>
147      * <li><code>ORIENTATION_HORIZONTAL</code> (the default)</li>
148      * <li><code>ORIENTATION_VERTICAL</code></li>
149      * </ul>
150      * @see #setOrientation
151      */

152     public int getOrientation() {
153         Integer JavaDoc orientationValue = (Integer JavaDoc) getProperty(PROPERTY_ORIENTATION);
154         return orientationValue == null ? ORIENTATION_HORIZONTAL : orientationValue.intValue();
155     }
156     
157     /**
158      * Returns the height of the specified row.
159      * This property only supports <code>Extent</code>s with
160      * fixed (i.e., not percent) units.
161      *
162      * @param rowIndex the row index
163      * @return the height
164      */

165     public Extent getRowHeight(int rowIndex) {
166         return (Extent) getIndexedProperty(PROPERTY_ROW_HEIGHT, rowIndex);
167     }
168     
169     /**
170      * Returns the number of columns or rows in the <code>Grid</code>.
171      * If the <code>orientation</code> property is set to
172      * <code>ORIENTATION_HORIZONTAL</code>, this property represents the
173      * number of columns in the <code>Grid</code>.
174      * If the <code>orientation</code> property is set to
175      * <code>ORIENTATION_VERTICAL</code>, this property represents the
176      * number of rows in the <code>Grid</code>.
177      *
178      * @return the number of columns or rows
179      */

180     public int getSize() {
181         Integer JavaDoc sizeValue = (Integer JavaDoc) getProperty(PROPERTY_SIZE);
182         if (sizeValue == null) {
183             return DEFAULT_SIZE;
184         } else {
185             return sizeValue.intValue();
186         }
187     }
188     
189     /**
190      * Returns the overall width of the grid.
191      * This property supports <code>Extent</code>s with
192      * fixed or percentile units.
193      *
194      * @return the width
195      */

196     public Extent getWidth() {
197         return (Extent) getProperty(PROPERTY_WIDTH);
198     }
199     
200     /**
201      * Sets the <code>Border</code>.
202      *
203      * @param newValue the new border
204      */

205     public void setBorder(Border newValue) {
206         setProperty(PROPERTY_BORDER, newValue);
207     }
208     
209     /**
210      * Sets the width of the specified column.
211      * This property supports <code>Extent</code>s with
212      * fixed or percentile units.
213      *
214      * @param columnIndex the column index
215      * @param newValue the new width
216      */

217     public void setColumnWidth(int columnIndex, Extent newValue) {
218         setIndexedProperty(PROPERTY_COLUMN_WIDTH, columnIndex, newValue);
219     }
220     
221     /**
222      * Sets the overall height of the grid.
223      * This property only supports <code>Extent</code>s with
224      * fixed (i.e., not percent) units.
225      *
226      * @param newValue the new height
227      */

228     public void setHeight(Extent newValue) {
229         setProperty(PROPERTY_HEIGHT, newValue);
230     }
231     
232     /**
233      * Sets the default cell insets. The default cell insets will be used for
234      * individual child cells that do not provide an <code>Insets</code> value
235      * in their <code>GridLayoutData</code>.
236      *
237      * @param newValue the new default cell insets
238      */

239     public void setInsets(Insets newValue) {
240         setProperty(PROPERTY_INSETS, newValue);
241     }
242
243     /**
244      * Sets the orientation of the grid (either horizontal or vertical).
245      * The orientation describes the direction in which cells are laid out.
246      * An orientation of <code>ORIENTATION_HORIZONTAL</code> (the default)
247      * specifies that cells should be laid out in horizontal rows
248      * with the <code>size</code> property specifying the number of columns
249      * per row.
250      * An orientation of <code>ORIENTATION_VERTICAL</code>
251      * specifies that cells should be laid out in vertical columns
252      * with the <code>size</code> property specifying the number of rows
253      * per column.
254      *
255      * @param newValue the new orientation, one of the following values:
256      * <ul>
257      * <li><code>ORIENTATION_HORIZONTAL</code> (the default)</li>
258      * <li><code>ORIENTATION_VERTICAL</code></li>
259      * </ul>
260      */

261     public void setOrientation(int newValue) {
262         setProperty(PROPERTY_ORIENTATION, new Integer JavaDoc(newValue));
263     }
264     
265     /**
266      * Sets the height of the specified row.
267      * This property only supports <code>Extent</code>s with
268      * fixed (i.e., not percent) units.
269      *
270      * @param rowIndex the row index
271      * @param newValue the new height
272      */

273     public void setRowHeight(int rowIndex, Extent newValue) {
274         setIndexedProperty(PROPERTY_ROW_HEIGHT, rowIndex, newValue);
275     }
276     
277     /**
278      * Sets the number of columns or rows in the grid.
279      * If the <code>orientation</code> property is set to
280      * <code>ORIENTATION_HORIZONTAL</code>, this property represents the
281      * number of columns in the <code>Grid</code>.
282      * If the <code>orientation</code> property is set to
283      * <code>ORIENTATION_VERTICAL</code>, this property represents the
284      * number of rows in the <code>Grid</code>.
285      *
286      * @param newValue the number of columns or rows
287      * @see #getSize()
288      */

289     public void setSize(int newValue) {
290         setProperty(PROPERTY_SIZE, new Integer JavaDoc(newValue));
291     }
292     
293     /**
294      * Sets the overall width of the grid.
295      * This property supports <code>Extent</code>s with
296      * fixed or percentile units.
297      *
298      * @param newValue the new width
299      */

300     public void setWidth(Extent newValue) {
301         setProperty(PROPERTY_WIDTH, newValue);
302     }
303 }
304
Popular Tags