KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SBoxLayout


1 /*
2  * $Id: SBoxLayout.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 box layout - a layout manager that allows multiple components
21  * to be laid out either vertically {@link <code>SConstants#VERTICAL</code>}
22  * or horizontally {@link <code>SConstants#HORIZONTAL</code>}.
23  * <p/>
24  * Nesting multiple panels with different combinations of horizontal
25  * and vertical gives an effect similar to GridBagLayout, without the complexity.
26  *
27  * @author <a HREF="mailto:engels@mercatis.de">Holger Engels</a>
28  * @version $Revision: 1.8 $
29  */

30 public class SBoxLayout
31         extends SAbstractLayoutManager {
32
33     // Constants for swing compatibility
34
public static final int X_AXIS = SConstants.HORIZONTAL;
35     public static final int Y_AXIS = SConstants.VERTICAL;
36
37     protected ArrayList JavaDoc components = new ArrayList JavaDoc(2);
38
39     protected int orientation = SConstants.HORIZONTAL;
40     protected int align = SConstants.LEFT_ALIGN;
41     protected int borderThickness = 0;
42
43     /**
44      * The horizontal gap (in pixels) specifiying the space
45      * between columns. They can be changed at any time.
46      * This should be a non-negative integer.
47      */

48     protected int hgap = 0;
49
50     /**
51      * The vertical gap (in pixels) which specifiying the space
52      * between rows. They can be changed at any time.
53      * This should be a non negative integer.
54      */

55     protected int vgap = 0;
56
57     /**
58      * creates a new box layout with the given orientation
59      *
60      * @param orientation orientation
61      */

62     public SBoxLayout(int orientation) {
63         setOrientation(orientation);
64     }
65
66     public void addComponent(SComponent c, Object JavaDoc constraint, int index) {
67         components.add(index, c);
68     }
69
70     public void removeComponent(SComponent c) {
71         components.remove(c);
72     }
73
74     /**
75      * returns a list of all components
76      *
77      * @return all components
78      */

79     public List JavaDoc getComponents() {
80         return components;
81     }
82
83     /**
84      * returns the component at the given position
85      *
86      * @param i position
87      * @return component
88      */

89     public SComponent getComponentAt(int i) {
90         return (SComponent) components.get(i);
91     }
92
93     /**
94      * Sets the orientation. Use one of the following types:
95      *
96      * @param o One of the following constants:
97      * {@link <code>SConstants#HORIZONTAL</code>} or
98      * {@link <code>SConstants#VERTICAL</code>}
99      */

100     public void setOrientation(int o) {
101         orientation = o;
102     }
103
104     /**
105      * returns the orientation
106      *
107      * @return orientation
108      */

109     public int getOrientation() {
110         return orientation;
111     }
112
113
114     /**
115      * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
116      * @param borderThickness The rendered border with in pixel
117      */

118     public void setBorder(int borderThickness) {
119         this.borderThickness = borderThickness;
120     }
121
122     /**
123      * Typical PLAFs will render this layout as invisible table (border = 0). Use this property to make it visible
124      * @return The rendered border with in pixel
125      */

126     public int getBorder() {
127         return borderThickness;
128     }
129
130     /**
131      * Gets the horizontal gap between components in pixel. Rendered half as margin left and margin right
132      * Some PLAFs might ignore this property.
133      *
134      * @return the horizontal gap between components
135      */

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

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

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

166     public void setVgap(int vgap) {
167         this.vgap = vgap;
168     }
169 }
170
171
172
Popular Tags