KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SGridLayout


1 /*
2  * $Id: SGridLayout.java,v 1.8 2005/06/03 13:16:16 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
18
19 /**
20  * This is a grid layout
21  *
22  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
23  * @version $Revision: 1.8 $
24  */

25 public class SGridLayout extends SAbstractLayoutManager {
26     protected ArrayList JavaDoc components = new ArrayList JavaDoc(2);
27     protected int rows = 1;
28     protected int cols = 1;
29     protected int border = 0;
30     protected boolean renderFirstLineAsHeader = false;
31
32     /**
33      * The horizontal gap (in pixels) specifiying the space
34      * between columns. They can be changed at any time.
35      * This should be a non-negative integer.
36      */

37     protected int hgap = 0;
38
39     /**
40      * The vertical gap (in pixels) which specifiying the space
41      * between rows. They can be changed at any time.
42      * This should be a non negative integer.
43      */

44     protected int vgap = 0;
45
46     /**
47      * creates a new grid layout with 1 row and 1 column extent
48      */

49     public SGridLayout() {
50         this.setPreferredSize(new SDimension("100%", "100%"));
51     }
52
53     /**
54      * creats a new grid layout with the given number of columns
55      *
56      * @param cols number of columns
57      */

58     public SGridLayout(int cols) {
59         this();
60         setColumns(cols);
61     }
62
63     /**
64      * creats a new grid layout with the given number of columns and rows
65      *
66      * @param rows number of rows
67      * @param cols number of columns
68      */

69     public SGridLayout(int rows, int cols) {
70         this(cols);
71         setRows(rows);
72     }
73
74     /**
75      * sets the number of columns
76      *
77      * @param c number of columns
78      */

79     public void setColumns(int c) {
80         cols = c;
81     }
82
83     /**
84      * returns the number of columns
85      *
86      * @return number of columns
87      */

88     public int getColumns() {
89         return cols;
90     }
91
92     /**
93      * sets the number of rows
94      *
95      * @param r number of rows
96      */

97     public void setRows(int r) {
98         rows = r;
99     }
100
101     /**
102      * returns the number of rows
103      *
104      * @return number of rows
105      */

106     public int getRows() {
107         return rows;
108     }
109
110     public void addComponent(SComponent c, Object JavaDoc constraint, int index) {
111         components.add(index, c);
112     }
113
114     public void removeComponent(SComponent c) {
115         components.remove(c);
116     }
117
118     /**
119      * returns a list of all components
120      *
121      * @return all components
122      */

123     public List JavaDoc getComponents() {
124         return components;
125     }
126
127     /**
128      * Gets the horizontal gap between components in pixel. Rendered half as margin left and margin right
129      * Some PLAFs might ignore this property.
130      *
131      * @return the horizontal gap between components
132      */

133     public int getHgap() {
134         return hgap;
135     }
136
137     /**
138      * Sets the horizontal gap between components to the specified value in pixe. Rendered half as margin left and margin right
139      * Some PLAFs might ignore this property.
140      *
141      * @param hgap the horizontal gap between components
142      */

143     public void setHgap(int hgap) {
144         this.hgap = hgap;
145     }
146
147     /**
148      * Gets the vertical gap between components in pixel. Rendered half as margin top and margin bottom
149      * Some PLAFs might ignore this property.
150      *
151      * @return the vertical gap between components
152      */

153     public int getVgap() {
154         return vgap;
155     }
156
157     /**
158      * Sets the vertical gap between components to the specified value in pixel.
159      * Rendered half as margin top and margin bottom. Some PLAFs might ignore this property.
160      *
161      * @param vgap the vertical gap between components
162      */

163     public void setVgap(int vgap) {
164         this.vgap = vgap;
165     }
166
167 // /**
168
// * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
169
// * @param cellPadding cell padding in pixel
170
// */
171
// public void setCellPadding(int cellPadding) {
172
// this.cellPadding = cellPadding;
173
// }
174
//
175
// /**
176
// * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
177
// * @return cell padding in pixel
178
// */
179
// public int getCellPadding() {
180
// return cellPadding;
181
// }
182
//
183
// /**
184
// * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
185
// * @param cellSpacing The spacing between the layout cells. pixel
186
// */
187
// public void setCellSpacing(int cellSpacing) {
188
// this.cellSpacing = cellSpacing;
189
// }
190
//
191
// /**
192
// * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
193
// * @return The spacing between the layout cells. pixel
194
// */
195
// public int getCellSpacing() {
196
// return cellSpacing;
197
// }
198

199
200     /**
201      * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
202      *
203      * @param borderWidth The rendered border with in pixel
204      */

205     public void setBorder(int borderWidth) {
206         border = borderWidth;
207     }
208
209     /**
210      * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
211      *
212      * @return The rendered border with in pixel
213      */

214     public int getBorder() {
215         return border;
216     }
217
218     /**
219      * Renders the first line as HTML <code>&lt;th&gt;</code> instead regular <code>&lt;tr&gt;</code>.
220      *
221      * @param renderAsTH true if first line should be rendered as header
222      */

223     public void setRenderFirstLineAsHeader(boolean renderAsTH) {
224         renderFirstLineAsHeader = renderAsTH;
225     }
226
227     /**
228      * {@link #setRenderFirstLineAsHeader(boolean)}
229      */

230     public boolean getRenderFirstLineAsHeader() {
231         return renderFirstLineAsHeader;
232     }
233 }
234
235
236
Popular Tags