1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.gui.layout;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20
21 /**
22 * <p>
23 * The concrete percent layout implementation.
24 * </p>
25 * <p>
26 * This class implements a basic percent layout as it is described in the
27 * documentation of the base class: a table-like layout with a set of properties
28 * for each column and row. Please refer to this documentation for a more
29 * complete description of all supported features.
30 * </p>
31 * <p>
32 * Heart of this class is the implementation of the <code>initCells()</code>
33 * method. This implementation expects that all components added to the layout
34 * have been associated with valid constraints of type {@link PercentData}. It
35 * will then initialize all cells of the layout correctly.
36 * </p>
37 *
38 * @author Oliver Heger
39 * @version $Id: PercentLayout.java 205 2012-01-29 18:29:57Z oheger $
40 */
41 public class PercentLayout extends PercentLayoutBase implements Serializable
42 {
43 /**
44 * The serial version UID.
45 */
46 private static final long serialVersionUID = 20090730L;
47
48 /**
49 * Creates a new instance of <code>PercentLayout</code> and sets the
50 * layout's dimensions. The constraints for the cells are set to default
51 * values.
52 *
53 * @param cols the number of columns
54 * @param rows the number of rows
55 */
56 public PercentLayout(int cols, int rows)
57 {
58 super(cols, rows);
59 }
60
61 /**
62 * Creates a new instance of <code>PercentLayout</code> and initializes it
63 * from the specified collections with {@link CellConstraints} objects.
64 *
65 * @param colConstr a collection with column constraints
66 * @param rowConstr a collection with row constraints
67 */
68 public PercentLayout(Collection<? extends CellConstraints> colConstr,
69 Collection<? extends CellConstraints> rowConstr)
70 {
71 super(colConstr, rowConstr);
72 }
73
74 /**
75 * Creates a new instance of <code>PercentLayout</code> and initializes it
76 * from the given string with specifications for the column and row
77 * constraints. These strings must contain valid specifications of cell
78 * constraints as defined in the documentation of {@link CellConstraints}.
79 * As separators between two cell definitions the following characters can
80 * be used: " ,;".
81 *
82 * @param colConstr a string defining column constraints
83 * @param rowConstr a string defining row constraints
84 */
85 public PercentLayout(String colConstr, String rowConstr)
86 {
87 super(colConstr, rowConstr);
88 }
89
90 /**
91 * Performs initialization of this layout. Information about the dimensions
92 * and the column and row constraints has already been set directly through
93 * the constructors and the appropriate setter methods. The task of this
94 * method is to initialize the cell array with information about the
95 * contained components. Those are fetched from the passed in platform
96 * adapter.
97 *
98 * @param adapter the platform adapter
99 */
100 @Override
101 protected void initCells(PercentLayoutPlatformAdapter adapter)
102 {
103 clearCells();
104 for (int i = 0; i < adapter.getComponentCount(); i++)
105 {
106 initCell(adapter.getComponent(i), adapter.getConstraints(i));
107 }
108 }
109 }