01: package org.osbl.client.wings.form.layouter;
02:
03: import org.osbl.client.wings.form.ComponentProvider;
04: import org.wings.*;
05:
06: import java.awt.*;
07:
08: /**
09: * Place multiple editor components, all obtained from the ComponentProvider in one line.
10: */
11: public class Editors extends Line {
12: static private GridBagConstraints editorsConstraints = new GridBagConstraints();
13: static {
14: editorsConstraints = new GridBagConstraints();
15: editorsConstraints.fill = GridBagConstraints.HORIZONTAL;
16: editorsConstraints.anchor = GridBagConstraints.NORTH;
17: editorsConstraints.gridwidth = GridBagConstraints.REMAINDER;
18: editorsConstraints.insets = LINE_INSETS;
19: editorsConstraints.weightx = 1d;
20: }
21: private static final Insets EDITOR_INSETS = new Insets(0, 5, 0, 0);
22: private static final Insets NO_INSETS = new Insets(0, 0, 0, 0);
23:
24: public Editor[] editors;
25:
26: /**
27: * Construct a label and editors component placement description.
28: * @param editors the editors to be arranged in the line
29: */
30: public Editors(Editor... editors) {
31: this .editors = editors;
32: }
33:
34: /**
35: * Construct a label and editors component placement description.
36: * @param weight how much of the available vertical space should the line span
37: * @param editors the editors to be arranged in the line
38: */
39: public Editors(double weight, Editor[] editors) {
40: super (weight);
41: this .editors = editors;
42: }
43:
44: public void build(ComponentProvider componentProvider,
45: SContainer container) {
46: SPanel editorsPanel = new SPanel();
47: editorsPanel.putClientProperty("instruction", this );
48: editorsPanel.setLayout(new SGridBagLayout());
49:
50: for (int i = 0; i < editors.length; i++) {
51: Editor editor = editors[i];
52: editor.editorConstraints.insets = i > 0 ? EDITOR_INSETS
53: : NO_INSETS;
54: editor.editorConstraints.weightx = 1d;
55: editor.editorConstraints.gridwidth = 1;
56: editor.build(componentProvider, editorsPanel);
57: editor.editorConstraints.gridwidth = GridBagConstraints.REMAINDER;
58: }
59: editorsPanel
60: .setPreferredSize(weight != 0d ? SDimension.FULLAREA
61: : SDimension.FULLWIDTH);
62: editorsConstraints.weighty = weight;
63: container.add(editorsPanel, editorsConstraints);
64: }
65: }
|