1- The layout is wrong when runninng in SWT Designer while when it runs in the main, it looks just right.
2- I want to be able to create all the embedded buttons using the form toolkit. Must I go through all the composite children and "adapt" them one by one? Or is there a way to tell SWT Designer to use a toolkit? If so, where does it get it?
3- How can I embed this complex composite into another composite? This is the part I am not getting right in SWT Designer. Do I have to manually add it to the source of the other composite?
I included the code that shows these issues. Maybe this will help identify a bug for #1.
Is #2 a limitation?
Thanks, and I am truly impressed with this plugin.
- Code: Select all
package example.forms.swtdesigner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
public class TestWinds extends Composite {
public TestWinds(Composite parent, int style) {
super(parent, style);
FormLayout layout = new FormLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
this.setLayout(layout);
int checkStyle = SWT.RADIO;
Button bn = new Button(this, checkStyle);
Button bne = new Button(this, checkStyle);
Button be = new Button(this, checkStyle);
Button bse = new Button(this, checkStyle);
Button bs = new Button(this, checkStyle);
Button bsw = new Button(this, checkStyle);
Button bw = new Button(this, checkStyle);
Button bnw = new Button(this, checkStyle);
Label ln = new Label(this, SWT.NONE);
ln.setText("N");
Label le = new Label(this, SWT.NONE);
le.setText("E");
Label lw = new Label(this, SWT.NONE);
lw.setText("W");
Label ls = new Label(this, SWT.NONE);
ls.setText("S");
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(50, 100, -5);
ln.setLayoutData(data);
// n
data = new FormData();
data.top = new FormAttachment(ln, 0, SWT.BOTTOM);
data.left = new FormAttachment(ln, 0, SWT.CENTER);
bn.setLayoutData(data);
// ne
data = new FormData();
data.top = new FormAttachment(bn, -6, SWT.BOTTOM);
data.left = new FormAttachment(bn, 5, SWT.RIGHT);
bne.setLayoutData(data);
// nw
data = new FormData();
data.top = new FormAttachment(bne, 0, SWT.TOP);
data.right = new FormAttachment(bn, -5, SWT.LEFT);
bnw.setLayoutData(data);
// e
data = new FormData();
data.top = new FormAttachment(bne, 2, SWT.BOTTOM);
data.left = new FormAttachment(bne, -2, SWT.RIGHT);
be.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(be, 0, SWT.CENTER);
data.left = new FormAttachment(be, 5, SWT.RIGHT);
le.setLayoutData(data);
// w
data = new FormData();
data.top = new FormAttachment(be, 0, SWT.TOP);
data.right = new FormAttachment(bnw, 2, SWT.LEFT);
bw.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(bw, 0, SWT.CENTER);
data.right = new FormAttachment(bw, -3, SWT.LEFT);
lw.setLayoutData(data);
// se
data = new FormData();
data.top = new FormAttachment(be, 2, SWT.BOTTOM);
data.right = new FormAttachment(bne, 0, SWT.RIGHT);
bse.setLayoutData(data);
// sw
data = new FormData();
data.top = new FormAttachment(bse, 0, SWT.TOP);
data.left = new FormAttachment(bnw, 0, SWT.LEFT);
bsw.setLayoutData(data);
// s
data = new FormData();
data.top = new FormAttachment(bse, -4, SWT.BOTTOM);
data.left = new FormAttachment(bn, 0, SWT.LEFT);
bs.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(bs, 0, SWT.BOTTOM);
data.left = new FormAttachment(bs, 0, SWT.CENTER);
ls.setLayoutData(data);
//
}
public void dispose() {
super.dispose();
}
protected void checkSubclass() {
}
public static void main(String[] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setSize(640, 480);
shell.setLayout (new FillLayout ());
boolean useForm = false;
if (useForm){
FormToolkit toolkit = new FormToolkit(shell.getDisplay());
ScrolledForm form = toolkit.createScrolledForm(shell);
form.getBody().setLayout(new FillLayout());
form.setText("WindSelectorControl2");
TestWinds control = new TestWinds(form.getBody(), SWT.NONE);
toolkit.adapt(control);
} else {
new TestWinds(shell, SWT.NONE);
}
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}