KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > forms > layout > ColumnSpec


1 /*
2  * Copyright (c) 2003 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.forms.layout;
32
33
34 /**
35  * Specifies columns in {@link FormLayout} by their default orientation, start
36  * size and resizing behavior.
37  * <p>
38  * <b>Examples:</b><br>
39  * The following examples specify a column with FILL alignment, a size of
40  * 10&nbsp;dlu that won't grow.
41  * <pre>
42  * new ColumnSpec(Sizes.dluX(10));
43  * new ColumnSpec(ColumnSpec.FILL, Sizes.dluX(10), 0.0);
44  * new ColumnSpec(ColumnSpec.FILL, Sizes.dluX(10), ColumnSpec.NO_GROW);
45  * new ColumnSpec("10dlu");
46  * new ColumnSpec("10dlu:0");
47  * new ColumnSpec("fill:10dlu:0");
48  * </pre>
49  * <p>
50  * The {@link com.jgoodies.forms.factories.FormFactory} provides
51  * predefined frequently used <code>ColumnSpec</code> instances.
52  *
53  * @author Karsten Lentzsch
54  * @version $Revision: 1.2 $
55  * @see com.jgoodies.forms.factories.FormFactory
56  */

57
58 public class ColumnSpec extends FormSpec {
59     
60     
61     // Horizontal Orientations *********************************************
62

63     /**
64      * By default put components in the left.
65      */

66     public static final DefaultAlignment LEFT = FormSpec.LEFT_ALIGN;
67
68     /**
69      * By default put the components in the center.
70      */

71     public static final DefaultAlignment CENTER = FormSpec.CENTER_ALIGN;
72
73     /**
74      * By default put components in the middle.
75      */

76     public static final DefaultAlignment MIDDLE = CENTER;
77
78     /**
79      * By default put components in the right.
80      */

81     public static final DefaultAlignment RIGHT = FormSpec.RIGHT_ALIGN;
82
83     /**
84      * By default fill the component into the column.
85      */

86     public static final DefaultAlignment FILL = FormSpec.FILL_ALIGN;
87     
88     /**
89      * Unless overridden the default alignment for a column is FILL.
90      */

91     public static final DefaultAlignment DEFAULT = FILL;
92
93
94     // Instance Creation ****************************************************
95

96     /**
97      * Constructs a <code>ColumnSpec</code> for the given default alignment,
98      * size and resize weight.
99      * <p>
100      * The resize weight must be a non-negative double; you can use
101      * <code>NO_GROW</code> as a convenience value for no resize.
102      *
103      * @param defaultAlignment the spec's default alignment
104      * @param size constant, component size or bounded size
105      * @param resizeWeight the spec resize weight
106      * @throws IllegalArgumentException if the resize weight is negative
107      */

108     public ColumnSpec(DefaultAlignment defaultAlignment,
109                         Size size,
110                         double resizeWeight) {
111         super(defaultAlignment, size, resizeWeight);
112     }
113     
114     
115     /**
116      * Constructs a <code>ColumnSpec</code> for the given size using the
117      * default alignment, and no resizing.
118      *
119      * @param size constant size, component size, or bounded size
120      * @throws IllegalArgumentException if the pixel size is invalid or the
121      * resize weight is negative
122      */

123     public ColumnSpec(Size size) {
124         super(DEFAULT, size, NO_GROW);
125     }
126     
127     /**
128      * Constructs a <code>ColumnSpec</code> from the specified encoded
129      * description. The description will be parsed to set initial values.
130      *
131      * @param encodedDescription the encoded description
132      */

133     public ColumnSpec(String JavaDoc encodedDescription) {
134         super(DEFAULT, encodedDescription);
135     }
136
137     /**
138      * Creates and answers an unmodifyable version of this
139      * <code>ColumnSpec</code>.
140      *
141      * @return an unmodifyable version of this <code>ColumnSpec</code>
142      */

143     public ColumnSpec asUnmodifyable() {
144         return new UnmodifyableColumnSpec(this);
145     }
146
147
148     // Implementing Abstract Behavior ***************************************
149

150     /**
151      * Returns if this is a horizontal specification (vs. vertical).
152      * Used to distinct between horizontal and vertical dialog units,
153      * which have different conversion factors.
154      *
155      * @return always true (for horizontal)
156      */

157     protected final boolean isHorizontal() {
158         return true;
159     }
160
161
162     // An Unmodifyable Version of ColumnSpec *********************************
163

164     private static final class UnmodifyableColumnSpec extends ColumnSpec {
165         
166         private UnmodifyableColumnSpec(ColumnSpec columnSpec) {
167             super(columnSpec.getDefaultAlignment(),
168                    columnSpec.getSize(),
169                    columnSpec.getResizeWeight());
170         }
171
172         /**
173          * @throws UnsupportedOperationException always
174          */

175         public void setDefaultAlignment(DefaultAlignment newDefaultAlignment) {
176             throw new UnsupportedOperationException JavaDoc();
177         }
178
179         /**
180          * @throws UnsupportedOperationException always
181          */

182         public void setSize(Size size) {
183             throw new UnsupportedOperationException JavaDoc();
184         }
185         
186         /**
187          * @throws UnsupportedOperationException always
188          */

189         public void setResizeWeight(double weight) {
190             throw new UnsupportedOperationException JavaDoc();
191         }
192         
193         /**
194          * Returns this <code>ColumnSpec</code>; it already is unmodifyable.
195          *
196          * @return this <code>ColumnSpec</code>
197          */

198         public ColumnSpec asUnmodifyable() {
199             return this;
200         }
201     
202     }
203     
204         
205 }
206
207
Popular Tags