2
* Copyright (c) 2002-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
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.
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.
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.
31
package com.jgoodies.forms.layout;
33
import java.util.StringTokenizer;
36
* Specifies rows in in {@link FormLayout} by their default orientation, start
37
* size and resizing behavior.<p>
39
* <strong>Examples:</strong><br>
40
* The following examples specify a centered row with a size of 14 dlu
43
* new RowSpec(Sizes.dluX(14));
44
* new RowSpec(RowSpec.CENTER, Sizes.dluX(14), 0.0);
45
* new RowSpec(rowSpec.CENTER, Sizes.dluX(14), RowSpec.NO_GROW);
46
* new RowSpec("14dlu");
47
* new RowSpec("14dlu:0");
48
* new RowSpec("center:14dlu:0");
51
* The {@link com.jgoodies.forms.factories.FormFactory} provides
52
* predefined frequently used <code>RowSpec</code> instances.
54
* @author Karsten Lentzsch
55
* @version $Revision: 1.5 $
57
* @see com.jgoodies.forms.factories.FormFactory
60
public final class RowSpec extends FormSpec {
63
// Vertical Orientations ************************************************
66
* By default put the components in the top.
68
public static final DefaultAlignment TOP = FormSpec.TOP_ALIGN;
71
* By default put the components in the center.
73
public static final DefaultAlignment CENTER = FormSpec.CENTER_ALIGN;
76
* By default put the components in the bottom.
78
public static final DefaultAlignment BOTTOM = FormSpec.BOTTOM_ALIGN;
81
* By default fill the component into the row.
83
public static final DefaultAlignment FILL = FormSpec.FILL_ALIGN;
86
* Unless overridden the default alignment for a row is CENTER.
88
public static final DefaultAlignment DEFAULT = CENTER;
91
// Instance Creation ****************************************************
94
* Constructs a <code>RowSpec</code> from the given default orientation,
95
* size, and resize weight.
97
* The resize weight must be a non-negative double; you can use
98
* <code>NO_FILL</code> as a convenience value for no resize.
100
* @param defaultAlignment the row's default alignment
101
* @param size the row's size as value with unit
102
* @param resizeWeight the row's resize weight
104
public RowSpec(DefaultAlignment defaultAlignment,
106
double resizeWeight) {
107
super(defaultAlignment, size, resizeWeight);
111
* Constructs a <code>RowSpec</code> for the given size using the
112
* default alignment, and no resizing.
114
* @param size constant size, component size, or bounded size
115
* @throws IllegalArgumentException if the pixel size is invalid or the
116
* resize weight is negative
118
public RowSpec(Size size) {
119
super(DEFAULT, size, NO_GROW);
123
* Constructs a <code>RowSpec</code> from the specified encoded
124
* description. The description will be parsed to set initial values.
126
* @param encodedDescription the encoded description
128
public RowSpec(String encodedDescription) {
129
super(DEFAULT, encodedDescription);
133
// Implementing Abstract Behavior ***************************************
136
* Returns if this is a horizontal specification (vs. vertical).
137
* Used to distinct between horizontal and vertical dialog units,
138
* which have different conversion factors.
140
* @return true for horizontal, false for vertical
142
protected final boolean isHorizontal() { return false; }
145
// Parsing and Decoding of Row Descriptions *****************************
148
* Parses and splits encoded row specifications and returns
149
* an array of <code>RowSpec</code> objects.
151
* @param encodedRowSpecs comma separated encoded row specifications
152
* @return an array of decoded row specifications
153
* @throws NullPointerException if the encoded row specifications string
154
* is <code>null</code>
156
* @see RowSpec#RowSpec(String)
158
public static RowSpec[] decodeSpecs(String encodedRowSpecs) {
159
if (encodedRowSpecs == null)
160
throw new NullPointerException("The row description must not be null.");
162
StringTokenizer tokenizer = new StringTokenizer(encodedRowSpecs, ", ");
163
int rowCount = tokenizer.countTokens();
164
RowSpec[] rowSpecs = new RowSpec[rowCount];
165
for (int i = 0; i < rowCount; i++) {
166
rowSpecs[i] = new RowSpec(tokenizer.nextToken());