import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class FormLayoutDemo {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		FormLayoutDemo fld = new FormLayoutDemo();
		fld.runDemo(myDisplay);
	}

	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display);
		shell.setSize(500, 400);
		shell.setText("Form Layout Demo");
		shell.setLayout(new FormLayout());

		//Fill Layout panel
		Composite fillComp = new Composite(shell, SWT.BORDER);
		fillComp.setLayout(new FillLayout(SWT.VERTICAL));
		Label label0 = new Label(fillComp, SWT.NONE);
		label0.setText("Instructions:");
		Label label1 = new Label(fillComp, SWT.NONE);
		label1.setText("1. Fill in your name");
		Label label2 = new Label(fillComp, SWT.NONE);
		label2.setText("2. Fill in your age");
		Label label3 = new Label(fillComp, SWT.NONE);
		label3.setText("3. Fill in your gender");
		Label label4 = new Label(fillComp, SWT.NONE);
		label4.setText("4. Check the box for employment");
		Label label5 = new Label(fillComp, SWT.NONE);
		label5.setText("5. Click on OK");

		FormData formFill = new FormData();
		formFill.top = new FormAttachment(0, 10);
		formFill.left = new FormAttachment(0, 10);
		formFill.bottom = new FormAttachment(75, 0);
		formFill.right = new FormAttachment(40,0);
		fillComp.setLayoutData(formFill);

		//Row Layout panel
		Composite rowComp = new Composite(shell, SWT.NONE);
		RowLayout rowLayout = new RowLayout();
		rowLayout.pack = false;
		rowComp.setLayout(rowLayout);

		Button b1 = new Button(rowComp, SWT.PUSH);
		b1.setText("Address");
		Button b2 = new Button(rowComp, SWT.PUSH);
		b2.setText("Phone Numbers");
		Button b3 = new Button(rowComp, SWT.PUSH);
		b3.setText("Credit Cards");
		Button b4 = new Button(rowComp, SWT.PUSH);
		b4.setText("Organizations");
		Button b5 = new Button(rowComp, SWT.PUSH);
		b5.setText("Cancel");
		Button b6 = new Button(rowComp, SWT.PUSH);
		b6.setText("OK");

		FormData formRow = new FormData();
		formRow.top = new FormAttachment(fillComp, 10);
		formRow.left = new FormAttachment(0, 10);
		formRow.bottom = new FormAttachment(100, -10);
		formRow.right = new FormAttachment(100, -10);
		rowComp.setLayoutData(formRow);

		//Grid Layout panel
		Composite gridComp = new Composite(shell, SWT.NONE);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		gridComp.setLayout(gridLayout);

		Label label11 = new Label(gridComp, SWT.NONE);
		label11.setText("Name:");
		Text text1 = new Text(gridComp, SWT.BORDER);
		Label label12 = new Label(gridComp, SWT.NONE);
		label12.setText("Age:");
		Text text2 = new Text(gridComp, SWT.BORDER);
		Label label13 = new Label(gridComp, SWT.NONE);
		label13.setText("Gender:");
		Text text3 = new Text(gridComp, SWT.BORDER);
		Button button = new Button(gridComp, SWT.CHECK);
		button.setText("Have you been employed in the past six months?");

		GridData data = new GridData();
		data.widthHint = 60;
		label11.setLayoutData(data);
		data = new GridData();
		data.widthHint = 60;
		label12.setLayoutData(data);
		data = new GridData();
		data.widthHint = 60;
		label13.setLayoutData(data);

		GridData data2 = new GridData(GridData.FILL_HORIZONTAL);
		text1.setLayoutData(data2);
		data2 = new GridData(GridData.FILL_HORIZONTAL);
		text2.setLayoutData(data2);
		data2 = new GridData(GridData.FILL_HORIZONTAL);
		text3.setLayoutData(data2);

		GridData data3 = new GridData();
		data3.horizontalSpan = 2;
		button.setLayoutData(data3);
		
		FormData formGrid = new FormData();
		formGrid.top = new FormAttachment(0,10);
		formGrid.left = new FormAttachment(fillComp,10);
		formGrid.right = new FormAttachment(100,-10);
		formGrid.bottom = new FormAttachment(fillComp,10, SWT.BOTTOM);
		gridComp.setLayoutData(formGrid);

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		if (internalCall) display.dispose();
	}
}
