1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.wizards.dialogfields;
13 //import org.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.GridData;
15 //import org.eclipse.swt.layout.GridLayout;
16 //import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
19 public class LayoutUtil {
22 * Calculates the number of columns needed by field editors
24 public static int getNumberOfColumns(DialogField[] editors) {
26 for (int i = 0; i < editors.length; i++) {
27 nCulumns = Math.max(editors[i].getNumberOfControls(), nCulumns);
33 * Creates a composite and fills in the given editors.
36 * Defines if the label of all fields should be on top of the
39 // public static void doDefaultLayout(Composite parent, DialogField[] editors,
40 // boolean labelOnTop) {
41 // doDefaultLayout(parent, editors, labelOnTop, 0, 0, 0, 0);
45 * Creates a composite and fills in the given editors.
48 * Defines if the label of all fields should be on top of the
51 * The minimal width of the composite
53 * The minimal height of the composite
55 // public static void doDefaultLayout(Composite parent, DialogField[] editors,
56 // boolean labelOnTop, int minWidth, int minHeight) {
57 // doDefaultLayout(parent, editors, labelOnTop, minWidth, minHeight, 0, 0);
61 * Creates a composite and fills in the given editors.
64 * Defines if the label of all fields should be on top of the
67 * The minimal width of the composite
69 * The minimal height of the composite
71 * The margin width to be used by the composite
73 * The margin height to be used by the composite
76 // public static void doDefaultLayout(Composite parent, DialogField[] editors,
77 // boolean labelOnTop, int minWidth, int minHeight, int marginWidth,
78 // int marginHeight) {
79 // int nCulumns = getNumberOfColumns(editors);
80 // Control[][] controls = new Control[editors.length][];
81 // for (int i = 0; i < editors.length; i++) {
82 // controls[i] = editors[i].doFillIntoGrid(parent, nCulumns);
86 // modifyLabelSpans(controls, nCulumns);
88 // GridLayout layout = new GridLayout();
89 // if (marginWidth != SWT.DEFAULT) {
90 // layout.marginWidth = marginWidth;
92 // if (marginHeight != SWT.DEFAULT) {
93 // layout.marginHeight = marginHeight;
95 // layout.numColumns = nCulumns;
96 // parent.setLayout(layout);
99 // private static void modifyLabelSpans(Control[][] controls, int nCulumns) {
100 // for (int i = 0; i < controls.length; i++) {
101 // setHorizontalSpan(controls[i][0], nCulumns);
106 * Sets the span of a control. Assumes that GridData is used.
108 public static void setHorizontalSpan(Control control, int span) {
109 Object ld = control.getLayoutData();
110 if (ld instanceof GridData) {
111 ((GridData) ld).horizontalSpan = span;
112 } else if (span != 1) {
113 GridData gd = new GridData();
114 gd.horizontalSpan = span;
115 control.setLayoutData(gd);
120 * Sets the width hint of a control. Assumes that GridData is used.
122 public static void setWidthHint(Control control, int widthHint) {
123 Object ld = control.getLayoutData();
124 if (ld instanceof GridData) {
125 ((GridData) ld).widthHint = widthHint;
130 * Sets the heigthHint hint of a control. Assumes that GridData is used.
132 // public static void setHeigthHint(Control control, int heigthHint) {
133 // Object ld = control.getLayoutData();
134 // if (ld instanceof GridData) {
135 // ((GridData) ld).heightHint = heigthHint;
140 * Sets the horizontal indent of a control. Assumes that GridData is used.
142 // public static void setHorizontalIndent(Control control, int horizontalIndent) {
143 // Object ld = control.getLayoutData();
144 // if (ld instanceof GridData) {
145 // ((GridData) ld).horizontalIndent = horizontalIndent;
150 * Sets the horizontal indent of a control. Assumes that GridData is used.
152 public static void setHorizontalGrabbing(Control control) {
153 Object ld = control.getLayoutData();
154 if (ld instanceof GridData) {
155 ((GridData) ld).grabExcessHorizontalSpace = true;