01: package org.osbl.client.wings.form.layouter;
02:
03: import org.wings.*;
04: import org.osbl.client.wings.form.ComponentProvider;
05:
06: import java.util.*;
07: import java.util.List;
08: import java.awt.*;
09:
10: /**
11: * Arranges Columns.
12: */
13: public class Division implements Instruction {
14: public String titleCode;
15: public double weight = 0d;
16: public List<Column> columns;
17:
18: /**
19: * Construct a structural description of a Division.
20: * @param columns the columns arrange in the division
21: */
22: public Division(Column... columns) {
23: this .columns = new ArrayList<Column>(Arrays.asList(columns));
24: }
25:
26: /**
27: * Construct a structural description of a Division.
28: * @param titleCode the division title
29: * @param columns the columns arrange in the division
30: */
31: public Division(String titleCode, Column... columns) {
32: this .titleCode = titleCode;
33: this .columns = new ArrayList<Column>(Arrays.asList(columns));
34: }
35:
36: /**
37: * Construct a structural description of a Division.
38: * @param titleCode the division title
39: * @param weight how much of the available vertical space should the division span
40: * @param columns the columns arrange in the division
41: */
42: public Division(String titleCode, double weight, Column... columns) {
43: this .titleCode = titleCode;
44: this .weight = weight;
45: this .columns = new ArrayList<Column>(Arrays.asList(columns));
46: }
47:
48: /**
49: * Construct a structural description of a Division.
50: * @param weight how much of the available vertical space should the division span
51: * @param columns the columns arrange in the division
52: */
53: public Division(double weight, Column... columns) {
54: this .weight = weight;
55: this .columns = new ArrayList<Column>(Arrays.asList(columns));
56: }
57:
58: public void build(ComponentProvider componentProvider,
59: SContainer container) {
60: //container.setBackground(Color.green);
61: GridBagConstraints columnConstraints = new GridBagConstraints();
62: columnConstraints.fill = GridBagConstraints.BOTH;
63: columnConstraints.anchor = GridBagConstraints.NORTH;
64: columnConstraints.weighty = 1d;
65:
66: for (int c = 0; c < columns.size(); c++) {
67: Column column = columns.get(c);
68: SPanel columnPanel = new SPanel(new SGridBagLayout());
69: columnPanel
70: .setPreferredSize(column.weight != 0d ? SDimension.FULLAREA
71: : SDimension.FULLHEIGHT);
72: columnPanel.setVerticalAlignment(SConstants.TOP_ALIGN);
73: column.build(componentProvider, columnPanel);
74:
75: columnConstraints.gridwidth = c == columns.size() - 1 ? GridBagConstraints.REMAINDER
76: : 1;
77: columnConstraints.weightx = column.weight != 0d ? column.weight
78: : 1d;
79: columnConstraints.insets = new Insets(10, c > 1 ? 20 : 10,
80: 10, c < columns.size() - 1 ? 20 : 10);
81: container.add(columnPanel, columnConstraints);
82: }
83: }
84:
85: public void follow(Builder builder) {
86: for (Column column : columns)
87: builder.build(column);
88: }
89: }
|