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: * Allows multiple components to be laid out either vertically or horizontally.
020: * <p/>
021: * Nesting multiple panels with different combinations of horizontal
022: * and vertical gives an effect similar to GridBagLayout, without the complexity.
023: *
024: * @author <a href="mailto:engels@mercatis.de">Holger Engels</a>
025: */
026: public class SBoxLayout extends SAbstractLayoutManager {
027:
028: // Constants for swing compatibility
029: public static final int X_AXIS = SConstants.HORIZONTAL;
030: public static final int Y_AXIS = SConstants.VERTICAL;
031:
032: protected ArrayList components = new ArrayList(2);
033:
034: protected int orientation = SConstants.HORIZONTAL;
035: protected int align = SConstants.LEFT_ALIGN;
036: protected int borderThickness = 0;
037:
038: /**
039: * The horizontal gap (in pixels) specifiying the space
040: * between columns. They can be changed at any time.
041: * This should be a non-negative integer.
042: */
043: protected int hgap = 0;
044:
045: /**
046: * The vertical gap (in pixels) which specifiying the space
047: * between rows. They can be changed at any time.
048: * This should be a non negative integer.
049: */
050: protected int vgap = 0;
051:
052: /**
053: * creates a new box layout with the given orientation
054: * @param orientation either {@link <code>SConstants#VERTICAL</code>} or {@link <code>SConstants#HORIZONTAL</code>}
055: * @deprecated This constructor mismatch the swing api. Better use SBoxLayout( SContainer c, int orientation )
056: */
057: public SBoxLayout(int orientation) {
058: setOrientation(orientation);
059: }
060:
061: /**
062: * creates a new box layout with the given orientation
063: *
064: * @param c - the container that needs to be laid out
065: * @param orientation either {@link <code>SConstants#VERTICAL</code>} or {@link <code>SConstants#HORIZONTAL</code>}
066: *
067: */
068: public SBoxLayout(SContainer c, int orientation) {
069: setOrientation(orientation);
070: }
071:
072: public void addComponent(SComponent c, Object constraint, int index) {
073: components.add(index, c);
074: }
075:
076: public void removeComponent(SComponent c) {
077: components.remove(c);
078: }
079:
080: /**
081: * returns a list of all components
082: *
083: * @return all components
084: */
085: public List getComponents() {
086: return components;
087: }
088:
089: /**
090: * returns the component at the given position
091: *
092: * @param i position
093: * @return component
094: */
095: public SComponent getComponentAt(int i) {
096: return (SComponent) components.get(i);
097: }
098:
099: /**
100: * Sets the orientation. Use one of the following types:
101: *
102: * @param o One of the following constants:
103: * {@link <code>SConstants#HORIZONTAL</code>} or
104: * {@link <code>SConstants#VERTICAL</code>}
105: */
106: public void setOrientation(int o) {
107: orientation = o;
108: }
109:
110: /**
111: * returns the orientation
112: *
113: * @return orientation
114: */
115: public int getOrientation() {
116: return orientation;
117: }
118:
119: /**
120: * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
121: * @param borderThickness The rendered border with in pixel
122: */
123: public void setBorder(int borderThickness) {
124: this .borderThickness = borderThickness;
125: }
126:
127: /**
128: * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
129: * @return The rendered border with in pixel
130: */
131: public int getBorder() {
132: return borderThickness;
133: }
134:
135: /**
136: * Gets the horizontal gap between components in pixel. Rendered half as margin left and margin right
137: * Some PLAFs might ignore this property.
138: *
139: * @return the horizontal gap between components
140: */
141: public int getHgap() {
142: return hgap;
143: }
144:
145: /**
146: * Sets the horizontal gap between components to the specified value in pixe. Rendered half as margin left and margin right
147: * Some PLAFs might ignore this property.
148: *
149: * @param hgap the horizontal gap between components
150: */
151: public void setHgap(int hgap) {
152: this .hgap = hgap;
153: }
154:
155: /**
156: * Gets the vertical gap between components in pixel. Rendered half as margin top and margin bottom
157: * Some PLAFs might ignore this property.
158: *
159: * @return the vertical gap between components
160: */
161: public int getVgap() {
162: return vgap;
163: }
164:
165: /**
166: * Sets the vertical gap between components to the specified value in pixel.
167: * Rendered half as margin top and margin bottom. Some PLAFs might ignore this property.
168: *
169: * @param vgap the vertical gap between components
170: */
171: public void setVgap(int vgap) {
172: this.vgap = vgap;
173: }
174: }
|