001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import java.util.ArrayList;
016: import java.util.List;
017:
018: /**
019: * Swing-like grid layout.
020: *
021: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
022: */
023: public class SGridLayout extends SAbstractLayoutManager {
024: protected ArrayList components = new ArrayList(2);
025: protected int rows = 1;
026: protected int cols = 1;
027: protected int border = 0;
028: protected boolean renderFirstLineAsHeader = false;
029:
030: /**
031: * The horizontal gap (in pixels) specifiying the space
032: * between columns. They can be changed at any time.
033: * This should be a non-negative integer.
034: */
035: protected int hgap = 0;
036:
037: /**
038: * The vertical gap (in pixels) which specifiying the space
039: * between rows. They can be changed at any time.
040: * This should be a non negative integer.
041: */
042: protected int vgap = 0;
043:
044: /**
045: * creates a new grid layout with 1 row and 1 column extent
046: */
047: public SGridLayout() {
048: }
049:
050: /**
051: * creats a new grid layout with the given number of columns
052: *
053: * @param cols number of columns
054: */
055: public SGridLayout(int cols) {
056: this ();
057: setColumns(cols);
058: }
059:
060: /**
061: * creats a new grid layout with the given number of columns and rows
062: *
063: * @param rows number of rows
064: * @param cols number of columns
065: */
066: public SGridLayout(int rows, int cols) {
067: this (cols);
068: setRows(rows);
069: }
070:
071: /**
072: * creats a new grid layout with the given number of columns and rows and the given gaps
073: *
074: * @param rows number of rows
075: * @param cols number of columns
076: * @param hgap horizontal gap
077: * @param vgap vertical gap
078: */
079: public SGridLayout(int rows, int cols, int hgap, int vgap) {
080: this (rows, cols);
081: setHgap(hgap);
082: setVgap(vgap);
083: }
084:
085: /**
086: * sets the number of columns
087: *
088: * @param c number of columns
089: */
090: public void setColumns(int c) {
091: cols = c;
092: }
093:
094: /**
095: * returns the number of columns
096: *
097: * @return number of columns
098: */
099: public int getColumns() {
100: return cols;
101: }
102:
103: /**
104: * sets the number of rows
105: *
106: * @param r number of rows
107: */
108: public void setRows(int r) {
109: rows = r;
110: }
111:
112: /**
113: * returns the number of rows
114: *
115: * @return number of rows
116: */
117: public int getRows() {
118: return rows;
119: }
120:
121: public void addComponent(SComponent c, Object constraint, int index) {
122: components.add(index, c);
123: }
124:
125: public void removeComponent(SComponent c) {
126: components.remove(c);
127: }
128:
129: /**
130: * returns a list of all components
131: *
132: * @return all components
133: */
134: public List getComponents() {
135: return components;
136: }
137:
138: /**
139: * Gets the horizontal gap between components in pixel. Rendered half as margin left and margin right
140: * Some PLAFs might ignore this property.
141: *
142: * @return the horizontal gap between components
143: */
144: public int getHgap() {
145: return hgap;
146: }
147:
148: /**
149: * Sets the horizontal gap between components to the specified value in pixe. Rendered half as margin left and margin right
150: * Some PLAFs might ignore this property.
151: *
152: * @param hgap the horizontal gap between components
153: */
154: public void setHgap(int hgap) {
155: this .hgap = hgap;
156: }
157:
158: /**
159: * Gets the vertical gap between components in pixel. Rendered half as margin top and margin bottom
160: * Some PLAFs might ignore this property.
161: *
162: * @return the vertical gap between components
163: */
164: public int getVgap() {
165: return vgap;
166: }
167:
168: /**
169: * Sets the vertical gap between components to the specified value in pixel.
170: * Rendered half as margin top and margin bottom. Some PLAFs might ignore this property.
171: *
172: * @param vgap the vertical gap between components
173: */
174: public void setVgap(int vgap) {
175: this .vgap = vgap;
176: }
177:
178: // /**
179: // * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
180: // * @param cellPadding cell padding in pixel
181: // */
182: // public void setCellPadding(int cellPadding) {
183: // this.cellPadding = cellPadding;
184: // }
185: //
186: // /**
187: // * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
188: // * @return cell padding in pixel
189: // */
190: // public int getCellPadding() {
191: // return cellPadding;
192: // }
193: //
194: // /**
195: // * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
196: // * @param cellSpacing The spacing between the layout cells. pixel
197: // */
198: // public void setCellSpacing(int cellSpacing) {
199: // this.cellSpacing = cellSpacing;
200: // }
201: //
202: // /**
203: // * The paddding between the layout cells in pixel. Some PLAFs might ignore this property.
204: // * @return The spacing between the layout cells. pixel
205: // */
206: // public int getCellSpacing() {
207: // return cellSpacing;
208: // }
209:
210: /**
211: * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
212: *
213: * @param borderWidth The rendered border with in pixel
214: */
215: public void setBorder(int borderWidth) {
216: border = borderWidth;
217: }
218:
219: /**
220: * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
221: *
222: * @return The rendered border with in pixel
223: */
224: public int getBorder() {
225: return border;
226: }
227:
228: /**
229: * Renders the first line as HTML <code><th></code> instead regular <code><tr></code>.
230: *
231: * @param renderAsTH true if first line should be rendered as header
232: */
233: public void setRenderFirstLineAsHeader(boolean renderAsTH) {
234: renderFirstLineAsHeader = renderAsTH;
235: }
236:
237: /**
238: * {@link #setRenderFirstLineAsHeader(boolean)}
239: */
240: public boolean getRenderFirstLineAsHeader() {
241: return renderFirstLineAsHeader;
242: }
243: }
|