KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Specifies rows in in {@link FormLayout} by their default orientation, start
35  * size and resizing behavior.
36  * <p>
37  * <b>Examples:</b><br>
38  * The following examples specify a centered row with a size of 14&nbsp;dlu
39  * that won't grow.
40  * <pre>
41  * new RowSpec(Sizes.dluX(14));
42  * new RowSpec(RowSpec.CENTER, Sizes.dluX(14), 0.0);
43  * new RowSpec(rowSpec.CENTER, Sizes.dluX(14), RowSpec.NO_GROW);
44  * new RowSpec("14dlu");
45  * new RowSpec("14dlu:0");
46  * new RowSpec("center:14dlu:0");
47  * </pre>
48  * <p>
49  * The {@link com.jgoodies.forms.factories.FormFactory} provides
50  * predefined frequently used <code>RowSpec</code> instances.
51  *
52  * @author Karsten Lentzsch
53  * @version $Revision: 1.2 $
54  * @see com.jgoodies.forms.factories.FormFactory
55  */

56
57 public class RowSpec extends FormSpec {
58     
59     
60     // Vertical Orientations ************************************************
61

62     /**
63      * By default put the components in the top.
64      */

65     public static final DefaultAlignment TOP = FormSpec.TOP_ALIGN;
66
67     /**
68      * By default put the components in the center.
69      */

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

75     public static final DefaultAlignment BOTTOM = FormSpec.BOTTOM_ALIGN;
76
77     /**
78      * By default fill the component into the row.
79      */

80     public static final DefaultAlignment FILL = FormSpec.FILL_ALIGN;
81     
82     /**
83      * Unless overridden the default alignment for a row is CENTER.
84      */

85     public static final DefaultAlignment DEFAULT = CENTER;
86
87
88     // Instance Creation ****************************************************
89

90     /**
91      * Constructs a <code>RowSpec</code> from the given default orientation,
92      * size, and resize weight.
93      * <p>
94      * The resize weight must be a non-negative double; you can use
95      * <code>NO_FILL</code> as a convenience value for no resize.
96      *
97      * @param defaultAlignment the row's default alignment
98      * @param size the row's size as value with unit
99      * @param resizeWeight the row's resize weight
100      */

101     public RowSpec(DefaultAlignment defaultAlignment,
102                     Size size,
103                     double resizeWeight) {
104         super(defaultAlignment, size, resizeWeight);
105     }
106
107     /**
108      * Constructs a <code>RowSpec</code> for the given size using the
109      * default alignment, and no resizing.
110      *
111      * @param size constant size, component size, or bounded size
112      * @throws IllegalArgumentException if the pixel size is invalid or the
113      * resize weight is negative
114      */

115     public RowSpec(Size size) {
116         super(DEFAULT, size, NO_GROW);
117     }
118     
119     /**
120      * Constructs a <code>RowSpec</code> from the specified encoded
121      * description. The description will be parsed to set initial values.
122      *
123      * @param encodedDescription the encoded description
124      */

125     public RowSpec(String JavaDoc encodedDescription) {
126         super(DEFAULT, encodedDescription);
127     }
128     
129     
130     /**
131      * Creates and answers an unmodifyable version of this
132      * <code>RowSpec</code>.
133      *
134      * @return an unmodifyable version of this <code>RowSpec</code>
135      */

136     public RowSpec asUnmodifyable() {
137         return new UnmodifyableRowSpec(this);
138     }
139     
140
141     // Implementing Abstract Behavior ***************************************
142

143     /**
144      * Returns if this is a horizontal specification (vs. vertical).
145      * Used to distinct between horizontal and vertical dialog units,
146      * which have different conversion factors.
147      *
148      * @return true for horizontal, false for vertical
149      */

150     protected final boolean isHorizontal() { return false; }
151
152
153     // An Unmodifyable Version of RowSpec ***********************************
154

155     private static final class UnmodifyableRowSpec extends RowSpec {
156         
157         private UnmodifyableRowSpec(RowSpec rowSpec) {
158             super(rowSpec.getDefaultAlignment(),
159                    rowSpec.getSize(),
160                    rowSpec.getResizeWeight());
161         }
162
163         /**
164          * @throws UnsupportedOperationException always
165          */

166         public void setDefaultAlignment(DefaultAlignment newDefaultAlignment) {
167             throw new UnsupportedOperationException JavaDoc();
168         }
169
170         /**
171          * @throws UnsupportedOperationException always
172          */

173         public void setSize(Size size) {
174             throw new UnsupportedOperationException JavaDoc();
175         }
176         
177         /**
178          * @throws UnsupportedOperationException always
179          */

180         public void setResizeWeight(double weight) {
181             throw new UnsupportedOperationException JavaDoc();
182         }
183         
184         /**
185          * Returns this <code>RowSpec</code>; it already is unmodifyable.
186          *
187          * @return this <code>RowSpec</code>
188          */

189         public RowSpec asUnmodifyable() {
190             return this;
191         }
192     
193     }
194     
195     
196         
197 }
198
199
Popular Tags