KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SFlowLayout


1 /*
2  * $Id: SFlowLayout.java,v 1.3 2004/12/01 07:54:07 hengels 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  * The flow layout arranges components in a left-to-right or top-to-bottom order.
21  *
22  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
23  * @version $Revision: 1.3 $
24  */

25 public class SFlowLayout
26         extends SAbstractLayoutManager {
27     /**
28      * List of layouted components.
29      */

30     protected final List JavaDoc components;
31
32     /**
33      * Orientation (horizontally or vertically) of components.
34      */

35     protected int orientation;
36
37     /**
38      * Alignment (left, center, right) of components.
39      */

40     protected int align;
41
42     /**
43      * Creates a new <code>SFlowLayout</code> with horizontal orientation and
44      * left alignment.
45      */

46     public SFlowLayout() {
47         components = new ArrayList JavaDoc(2);
48         setOrientation(SConstants.HORIZONTAL);
49         setAlignment(SConstants.LEFT_ALIGN);
50     }
51
52     /**
53      * Creates a new <code>SFlowLayout</code> with horizonal orientation and the given alignment.
54      *
55      * @param alignment the alignment
56      */

57     public SFlowLayout(int alignment) {
58         this();
59         setAlignment(alignment);
60     }
61
62     /**
63      * Adds the given component at given index.
64      *
65      * @param c component to add
66      * @param constraint is ignored in this layout manager!
67      * @param index position to add component to
68      */

69     public void addComponent(SComponent c, Object JavaDoc constraint, int index) {
70         components.add(index, c);
71     }
72
73     public void removeComponent(SComponent c) {
74         components.remove(c);
75     }
76
77     /**
78      * returns a list of all components
79      *
80      * @return all components
81      */

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

92     public SComponent getComponentAt(int i) {
93         return (SComponent) components.get(i);
94     }
95
96     /**
97      * Sets the orientation for this layout. Possible values are
98      * <ul>
99      * <li>{@link org.wings.SConstants#HORIZONTAL}
100      * <li>{@link org.wings.SConstants#VERTICAL}
101      * </ul>
102      *
103      * @param o one of the orientation values shown above
104      */

105     public void setOrientation(int o) {
106         orientation = o;
107     }
108
109     /**
110      * returns the orientation
111      *
112      * @return orientation
113      */

114     public int getOrientation() { return orientation; }
115
116     /**
117      * Sets the alignment for this layout. Possible values are
118      * <ul>
119      * <li>{@link org.wings.SConstants#LEFT_ALIGN}
120      * <li>{@link org.wings.SConstants#CENTER_ALIGN}
121      * <li>{@link org.wings.SConstants#RIGHT_ALIGN}
122      * </ul>
123      *
124      * @param a one of the allignment values shown above
125      */

126     public void setAlignment(int a) {
127         align = a;
128     }
129
130     /**
131      * returns the alignment
132      *
133      * @return alignment
134      */

135     public int getAlignment() { return align; }
136 }
137
138
139
Popular Tags