~ubuntu-branches/ubuntu/trusty/libjgoodies-forms-java/trusty

« back to all changes in this revision

Viewing changes to src/main/com/jgoodies/forms/layout/RowSpec.java

  • Committer: Bazaar Package Importer
  • Author(s): Eric Lavarde
  • Date: 2006-03-23 20:54:19 UTC
  • Revision ID: james.westby@ubuntu.com-20060323205419-emo7oazp2lspvl3b
Tags: upstream-1.0.5
ImportĀ upstreamĀ versionĀ 1.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2002-2004 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
import java.util.StringTokenizer;
 
34
 
 
35
/**
 
36
 * Specifies rows in in {@link FormLayout} by their default orientation, start
 
37
 * size and resizing behavior.<p>
 
38
 * 
 
39
 * <strong>Examples:</strong><br>
 
40
 * The following examples specify a centered row with a size of 14&nbsp;dlu 
 
41
 * that won't grow.
 
42
 * <pre>
 
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");
 
49
 * </pre><p>
 
50
 * 
 
51
 * The {@link com.jgoodies.forms.factories.FormFactory} provides
 
52
 * predefined frequently used <code>RowSpec</code> instances.
 
53
 *
 
54
 * @author      Karsten Lentzsch
 
55
 * @version $Revision: 1.5 $
 
56
 * 
 
57
 * @see     com.jgoodies.forms.factories.FormFactory
 
58
 */
 
59
 
 
60
public final class RowSpec extends FormSpec {
 
61
    
 
62
    
 
63
    // Vertical Orientations ************************************************
 
64
    
 
65
    /**
 
66
     * By default put the components in the top.
 
67
     */
 
68
    public static final DefaultAlignment TOP = FormSpec.TOP_ALIGN;
 
69
 
 
70
    /**
 
71
     * By default put the components in the center.
 
72
     */
 
73
    public static final DefaultAlignment CENTER = FormSpec.CENTER_ALIGN;
 
74
 
 
75
    /**
 
76
     * By default put the components in the bottom.
 
77
     */
 
78
    public static final DefaultAlignment BOTTOM = FormSpec.BOTTOM_ALIGN;
 
79
 
 
80
    /**
 
81
     * By default fill the component into the row.
 
82
     */
 
83
    public static final DefaultAlignment FILL = FormSpec.FILL_ALIGN;
 
84
    
 
85
    /**
 
86
     * Unless overridden the default alignment for a row is CENTER.
 
87
     */
 
88
    public static final DefaultAlignment DEFAULT = CENTER;
 
89
 
 
90
 
 
91
    // Instance Creation ****************************************************
 
92
 
 
93
    /**
 
94
     * Constructs a <code>RowSpec</code> from the given default orientation,
 
95
     * size, and resize weight.
 
96
     * <p> 
 
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.
 
99
     * 
 
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
 
103
     */
 
104
    public RowSpec(DefaultAlignment defaultAlignment,
 
105
                    Size size, 
 
106
                    double resizeWeight) {
 
107
        super(defaultAlignment, size, resizeWeight);
 
108
    }
 
109
 
 
110
    /**
 
111
     * Constructs a <code>RowSpec</code> for the given size using the
 
112
     * default alignment, and no resizing.
 
113
     * 
 
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
 
117
     */
 
118
    public RowSpec(Size size) {
 
119
        super(DEFAULT, size, NO_GROW);
 
120
    }
 
121
    
 
122
    /**
 
123
     * Constructs a <code>RowSpec</code> from the specified encoded
 
124
     * description. The description will be parsed to set initial values.
 
125
     * 
 
126
     * @param encodedDescription        the encoded description
 
127
     */
 
128
        public RowSpec(String encodedDescription) {
 
129
        super(DEFAULT, encodedDescription);
 
130
        }
 
131
    
 
132
    
 
133
    // Implementing Abstract Behavior ***************************************
 
134
 
 
135
    /**
 
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.
 
139
     * 
 
140
     * @return true for horizontal, false for vertical
 
141
     */
 
142
    protected final boolean isHorizontal() { return false; }
 
143
 
 
144
 
 
145
    // Parsing and Decoding of Row Descriptions *****************************
 
146
    
 
147
    /**
 
148
     * Parses and splits encoded row specifications and returns 
 
149
     * an array of <code>RowSpec</code> objects.
 
150
     * 
 
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>
 
155
     * 
 
156
     * @see RowSpec#RowSpec(String)
 
157
     */
 
158
    public static RowSpec[] decodeSpecs(String encodedRowSpecs) {
 
159
        if (encodedRowSpecs == null) 
 
160
            throw new NullPointerException("The row description must not be null.");
 
161
        
 
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());
 
167
        }
 
168
        return rowSpecs;
 
169
    }
 
170
 
 
171
        
 
172
}
 
173