Das Composite Control implementiert die Schnittstelle
IControl
und bietet ein
IComposite
als Content Pane zum Hinzufügen
von Controls.
Die Klasse CompositeControl
ist wie folgt
implementiert:
1 public class CompositeControl extends ControlWrapper implements IControl { 2 3 public CompositeControl(final IContainer parent) { 4 this(parent, BPF.composite(), null); 5 } 6 7 public CompositeControl( 8 final IContainer parent, 9 final int index) { 10 11 this(parent, index, BPF.composite(), null); 12 } 13 14 public CompositeControl( 15 final IContainer parent, 16 final ICompositeDescriptor descriptor) { 17 18 this(parent, descriptor, null); 19 } 20 21 public CompositeControl( 22 final IContainer parent, 23 final int index, 24 final ICompositeDescriptor descriptor) { 25 26 this(parent, index, descriptor, null); 27 } 28 29 public CompositeControl( 30 final IContainer parent, 31 final Object layoutConstraints) { 32 33 this(parent, BPF.composite(), layoutConstraints); 34 } 35 36 public CompositeControl( 37 final IContainer parent, 38 final int index, 39 final Object layoutConstraints) { 40 41 this(parent, index, BPF.composite(), layoutConstraints); 42 } 43 44 public CompositeControl( 45 final IContainer parent, 46 final ICompositeDescriptor descriptor, 47 final Object layoutConstraints) { 48 49 super(Assert.getParamNotNull(parent, "parent").add( 50 descriptor, 51 layoutConstraints)); 52 } 53 54 public CompositeControl( 55 final IContainer parent, 56 final int index, 57 final ICompositeDescriptor descriptor, 58 final Object layoutConstraints) { 59 60 super(Assert.getParamNotNull(parent, "parent").add( 61 index, 62 descriptor, 63 layoutConstraints)); 64 } 65 66 protected IComposite getComposite() { 67 return (IComposite) super.getWidget(); 68 } 69 70 }
Das
BaseCompositeControlSnipped
demonstriert die Verwendung der Klasse
Dialog
:
1 public final class BaseCompositeControlSnipped implements IApplication { 2 3 @Override 4 public void start(final IApplicationLifecycle lifecycle) { 5 6 final IFrame frame = new MyFrame(); 7 8 frame.addWindowListener(new WindowAdapter() { 9 @Override 10 public void windowClosed() { 11 lifecycle.finish(); 12 } 13 }); 14 15 frame.setVisible(true); 16 } 17 18 private final class MyFrame extends Frame { 19 20 public MyFrame() { 21 super("Base composite control snipped"); 22 23 setMinPackSize(new Dimension(300, 0)); 24 25 setLayout(FillLayout.get()); 26 27 final MyControl control = new MyControl(this, "growx, growy"); 28 control.setText1("Hello"); 29 control.setText2("World"); 30 } 31 32 } 33 34 private final class MyControl extends CompositeControl { 35 36 private final IInputField<String> field1; 37 private final IInputField<String> field2; 38 39 public MyControl(final IContainer parent, final Object layoutConstraints) { 40 super(parent, layoutConstraints); 41 42 final IComposite composite = getComposite(); 43 44 composite.setLayout(new MigLayoutDescriptor("wrap", "[][grow]", "[][]")); 45 46 composite.add(BPF.textLabel("Label 1")); 47 field1 = composite.add(BPF.inputFieldString(), "growx"); 48 49 composite.add(BPF.textLabel("Label 2")); 50 field2 = composite.add(BPF.inputFieldString(), "growx"); 51 } 52 53 public void setText1(final String text) { 54 field1.setValue(text); 55 } 56 57 public void setText2(final String text) { 58 field2.setValue(text); 59 } 60 61 } 62 }