01: package fr.aliacom.form.swt.maker;
02:
03: import org.eclipse.swt.SWT;
04: import org.eclipse.swt.graphics.Point;
05: import org.eclipse.swt.layout.GridLayout;
06: import org.eclipse.swt.layout.RowData;
07: import org.eclipse.swt.layout.RowLayout;
08: import org.eclipse.swt.widgets.Composite;
09: import org.eclipse.swt.widgets.Control;
10: import org.w3c.dom.Element;
11:
12: import fr.aliacom.form.common.FormLoader;
13: import fr.aliacom.form.common.IFormComponent;
14: import fr.aliacom.form.swt.BuilderFactory;
15: import fr.aliacom.form.swt.SWTBuilder;
16: import fr.aliacom.form.swt.ui.SWTComposite;
17:
18: /**
19: * @author tom
20: *
21: * (C) 2001, 2002 Thomas Cataldo
22: */
23: public final class BoxBuilder extends SWTBuilder {
24:
25: /**
26: * @see fr.aliacom.form.swt.SWTBuilder#build(Element, IFormComponent, FormLoader, BuilderFactory)
27: */
28: public IFormComponent build(Element elem, IFormComponent parent,
29: FormLoader loader, BuilderFactory factory) {
30: String axis = elem.getAttribute("axis");
31: IFormComponent ret;
32: if (axis.equals("X_AXIS")) {
33: ret = buildHBox(parent);
34: } else {
35: ret = buildVBox(parent);
36: }
37: buildChildren(elem, ret, loader, factory);
38:
39: if (axis.equals("X_AXIS")) {
40: Composite c = (Composite) ret.getNativeWidget();
41: Control[] ctrls = c.getChildren();
42: for (int i = 0, n = ctrls.length; i < n; i++) {
43: Point p = ctrls[i].getSize();
44: if (p.x > 1) {
45: RowData data = new RowData(p);
46: ctrls[i].setLayoutData(data);
47: }
48: }
49: }
50:
51: return ret;
52: }
53:
54: private IFormComponent buildHBox(IFormComponent parent) {
55: Composite ret = new Composite((Composite) parent
56: .getNativeWidget(), SWT.NONE);
57: RowLayout layout = new RowLayout();
58: layout.marginLeft = 0;
59: layout.marginRight = 0;
60: layout.marginTop = 0;
61: layout.marginBottom = 0;
62: ret.setLayout(layout);
63:
64: return new SWTComposite(ret);
65: }
66:
67: private IFormComponent buildVBox(IFormComponent parent) {
68: Composite ret = new Composite((Composite) parent
69: .getNativeWidget(), SWT.NONE);
70: GridLayout layout = new GridLayout();
71: layout.numColumns = 1;
72: layout.makeColumnsEqualWidth = false;
73: ret.setLayout(layout);
74:
75: return new SWTComposite(ret);
76: }
77:
78: }
|