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.awt.*;
07:
08: /**
09: * Place an editor component along with a label, both obtained from the ComponentProvider in one line.
10: */
11: public class LabelAndEditor extends Line {
12: static private GridBagConstraints labelConstraints = new GridBagConstraints();
13: static {
14: labelConstraints = new GridBagConstraints();
15: labelConstraints.fill = GridBagConstraints.HORIZONTAL;
16: labelConstraints.anchor = GridBagConstraints.NORTH;
17: labelConstraints.insets = LINE_INSETS;
18: labelConstraints.weightx = 0d;
19: }
20: static private GridBagConstraints editorConstraints = new GridBagConstraints();
21: static {
22: editorConstraints = new GridBagConstraints();
23: editorConstraints.fill = GridBagConstraints.HORIZONTAL;
24: editorConstraints.anchor = GridBagConstraints.NORTH;
25: editorConstraints.gridwidth = GridBagConstraints.REMAINDER;
26: editorConstraints.insets = LINE_INSETS;
27: editorConstraints.weightx = 1d;
28: }
29:
30: public String bean;
31: public String property;
32:
33: protected LabelAndEditor() {
34: }
35:
36: protected LabelAndEditor(double weight) {
37: super (weight);
38: }
39:
40: /**
41: * Construct a label and editor component placement description.
42: * @param bean the bean, whose property is getting editable (typically BeanMeta)
43: * @param property the property, which is getting editable (typically PropertyMeta)
44: */
45: public LabelAndEditor(String bean, String property) {
46: this .bean = bean;
47: this .property = property;
48: }
49:
50: /**
51: * Construct a label and editor component placement description.
52: * @param weight how much of the available vertical space should the line span
53: * @param bean the bean, whose property is getting editable (typically BeanMeta)
54: * @param property the property, which is getting editable (typically PropertyMeta)
55: */
56: public LabelAndEditor(double weight, String bean, String property) {
57: super (weight);
58: this .bean = bean;
59: this .property = property;
60: }
61:
62: public void build(ComponentProvider componentProvider,
63: SContainer container) {
64: SLabel propertyLabel = label(componentProvider);
65: propertyLabel.setPreferredSize(LABEL_SIZE);
66: container.add(propertyLabel, labelConstraints);
67:
68: SComponent propertyComponent = component(componentProvider);
69: propertyComponent.putClientProperty("instruction", this );
70: if (propertyComponent.getPreferredSize() == null)
71: propertyComponent.setPreferredSize(SDimension.FULLWIDTH);
72:
73: editorConstraints.weighty = weight;
74: container.add(propertyComponent, editorConstraints);
75: }
76:
77: protected SLabel label(ComponentProvider componentProvider) {
78: return componentProvider.getLabel(bean, property);
79: }
80:
81: protected SComponent component(ComponentProvider componentProvider) {
82: return componentProvider.getEditorComponent(bean, property);
83: }
84: }
|