com.ibm.commons.swt
Class SWTLayoutUtils

java.lang.Object
  extended by com.ibm.commons.swt.SWTLayoutUtils

public class SWTLayoutUtils
extends java.lang.Object

Utilities for laying out SWT controls and composites.


Field Summary
static int COMPUTED_EXTRA_WIDTH
          The default amount of width a computed field takes up more than a normal field.
static int CONTROL_BIG_WHINT
          The width hint for an extra-large control
static int CONTROL_INDENT_AMT
          The amount of pixels (10px) to indent a control from the text field.
static int CONTROL_SMALL_WHINT
          The default width hint for an extra-small control
static int CONTROL_WHINT
          The default width hint for a control (a large text, or combo box, for instance).
static int EXTRA_INDENT_AMT
          The amount of pixels (20px) to indent something when it should be indented below a radio or other label.
static int H_SPACING
          The amount of space (10px) between child columns horizontally.
static int PARENT_H_MARGIN
          The amount of pixels (14px) to use for the horizontal margin of the entire composite.
static int PARENT_H_SPACING
          The amount of space between parent columns.
static int PARENT_V_MARGIN
          The amount of pixels (14px) to use for the vertical margin of the entire composite.
static int TEXT_COLS
          The default amount of columns for a computed text field.
static int TEXT_WIDTH_HINT
          The default width for a value (100, 300) pixels text field.
static int UNITS_COMBO_WIDTH_HINT
          The default width for a units (pixels, auto, percent) combo.
static int V_SPACING
          The amount of space (7px) between child cells vertically.
 
Constructor Summary
SWTLayoutUtils()
           
 
Method Summary
static void alignControls(java.util.List<org.eclipse.swt.widgets.Control> controls)
          Aligns controls who are to appear in the same column across multiple composites.
static void alignControlsWithIndent(java.util.List<org.eclipse.swt.widgets.Control> controls)
          Aligns controls who are to appear in the same column across multiple composites.
static org.eclipse.swt.layout.FillLayout createFillLayoutDefaultMarginDefaultSpacing(boolean verticalLayout)
          Creates a FillLayout layout object.
static org.eclipse.swt.layout.FillLayout createFillLayoutNoMargin(boolean verticalLayout)
          Creates a FillLayout layout object.
static org.eclipse.swt.layout.FillLayout createFillLayoutNoMarginNoSpacing(boolean verticalLayout)
          Creates a FillLayout layout object.
static org.eclipse.swt.layout.GridData createGDControlIndent()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridData createGDExtraIndent()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridData createGDFill()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridData createGDFillHorizontal()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridData createGDFillHorizontalNoGrab()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridData createGDFillNoGrab()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridData createGDFillVertical()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridData createGDFillVerticalNoGrab()
          Creates a new GridData object.
static org.eclipse.swt.layout.GridLayout createLayoutDefaultSpacing(int numColumns)
          Creates a new GridLayout layout object.
static org.eclipse.swt.layout.GridLayout createLayoutNoHeight(int numColumns)
          Creates a new GridLayout layout object.
static org.eclipse.swt.layout.GridLayout createLayoutNoMarginDefaultSpacing(int numColumns)
          Creates a new GridLayout layout object.
static org.eclipse.swt.layout.GridLayout createLayoutNoMarginNoSpacing(int numColumns)
          Creates a new GridLayout layout object.
static org.eclipse.swt.layout.GridLayout createLayoutNoWidth(int numColumns)
          Creates a new GridLayout layout object.
static org.eclipse.swt.layout.GridLayout createLayoutTopMarginVerticalSpacing(int numColumns)
          Creates a new GridLayout layout object.
static org.eclipse.swt.widgets.Text createTextForWrappingInADialog(org.eclipse.swt.widgets.Composite parent, int style)
          Creates a specialized SWT text widget that is intended to never demand space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARENT_H_SPACING

public static final int PARENT_H_SPACING
The amount of space between parent columns.

See Also:
Constant Field Values

TEXT_COLS

public static final int TEXT_COLS
The default amount of columns for a computed text field.

See Also:
Constant Field Values

TEXT_WIDTH_HINT

public static final int TEXT_WIDTH_HINT
The default width for a value (100, 300) pixels text field.

See Also:
Constant Field Values

UNITS_COMBO_WIDTH_HINT

public static final int UNITS_COMBO_WIDTH_HINT
The default width for a units (pixels, auto, percent) combo.

See Also:
Constant Field Values

COMPUTED_EXTRA_WIDTH

public static final int COMPUTED_EXTRA_WIDTH
The default amount of width a computed field takes up more than a normal field.

See Also:
Constant Field Values

CONTROL_BIG_WHINT

public static final int CONTROL_BIG_WHINT
The width hint for an extra-large control

See Also:
Constant Field Values

CONTROL_SMALL_WHINT

public static final int CONTROL_SMALL_WHINT
The default width hint for an extra-small control

See Also:
Constant Field Values

CONTROL_WHINT

public static final int CONTROL_WHINT
The default width hint for a control (a large text, or combo box, for instance).

See Also:
Constant Field Values

CONTROL_INDENT_AMT

public static final int CONTROL_INDENT_AMT
The amount of pixels (10px) to indent a control from the text field.

See Also:
Constant Field Values

EXTRA_INDENT_AMT

public static final int EXTRA_INDENT_AMT
The amount of pixels (20px) to indent something when it should be indented below a radio or other label.

See Also:
Constant Field Values

V_SPACING

public static final int V_SPACING
The amount of space (7px) between child cells vertically.

See Also:
Constant Field Values

H_SPACING

public static final int H_SPACING
The amount of space (10px) between child columns horizontally.

See Also:
Constant Field Values

PARENT_V_MARGIN

public static final int PARENT_V_MARGIN
The amount of pixels (14px) to use for the vertical margin of the entire composite.

See Also:
Constant Field Values

PARENT_H_MARGIN

public static final int PARENT_H_MARGIN
The amount of pixels (14px) to use for the horizontal margin of the entire composite.

See Also:
Constant Field Values
Constructor Detail

SWTLayoutUtils

public SWTLayoutUtils()
Method Detail

createGDFill

public static org.eclipse.swt.layout.GridData createGDFill()
Creates a new GridData object. The object is set to fill vertical and horizontal areas and to also 'grab' excess horizontal and vertical spaces. The minimum height and width are defaults (SWT.DEFAULT)

Returns:
GridData
See Also:
GridData

createGDFillNoGrab

public static org.eclipse.swt.layout.GridData createGDFillNoGrab()
Creates a new GridData object. The object is set to fill vertical and horizontal areas but to not 'grab' excess horizontal and vertical spaces. The minimum height and width are defaults (SWT.DEFAULT)

Returns:
GridData
See Also:
GridData

createGDControlIndent

public static org.eclipse.swt.layout.GridData createGDControlIndent()
Creates a new GridData object. The GridData object is set to use all default values except for the horizontalIndent.
horizontalIndent is set to be the value of SWTLayoutUtils.CONTROL_INDENT_AMT. This GridData would typically be used when laying out a label and input control. This GridData would be used for the input control, it creates a 'natural' spacing between the controls.

Returns:
GridData
See Also:
GridData

createGDExtraIndent

public static org.eclipse.swt.layout.GridData createGDExtraIndent()
Creates a new GridData object. The GridData object is set to use all default values except for the horizontalIndent.
horizontalIndent is set to be the value of SWTLayoutUtils.EXTRA_INDENT_AMT. This GridData would typically be used where a control needs to be indented a significant amount for extra emphasis.

Returns:
GridData
See Also:
GridData

createGDFillHorizontal

public static org.eclipse.swt.layout.GridData createGDFillHorizontal()
Creates a new GridData object. The GridData object is set to FILL the horizontal area, and also to 'grab' excess horizontal space. It is set to align vertically at the BEGINNING and not 'grab' excess vertical space.

Returns:
GridData
See Also:
GridData

createGDFillVertical

public static org.eclipse.swt.layout.GridData createGDFillVertical()
Creates a new GridData object. The GridData object is set to FILL the vertical area, and also to 'grab' excess vertical space. It is set to align horizontally at the BEGINNING and not 'grab' excess horizontal space.

Returns:
GridData
See Also:
GridData

createGDFillHorizontalNoGrab

public static org.eclipse.swt.layout.GridData createGDFillHorizontalNoGrab()
Creates a new GridData object. The GridData object is set to FILL the horizontal area, but not to 'grab' excess horizontal space. It is set to align vertically at the BEGINNING and not 'grab' excess vertical space.

Returns:
GridData
See Also:
GridData

createGDFillVerticalNoGrab

public static org.eclipse.swt.layout.GridData createGDFillVerticalNoGrab()
Creates a new GridData object. The GridData object is set to FILL the vertical area, but not to 'grab' excess vertical space. It is set to align horizontally at the BEGINNING and not 'grab' excess horizontal space.

Returns:
GridData
See Also:
GridData

createLayoutDefaultSpacing

public static org.eclipse.swt.layout.GridLayout createLayoutDefaultSpacing(int numColumns)
Creates a new GridLayout layout object. The GridLayout will layout the composite to have the number of columns requested.
The horizontal and vertical spacing are set to com.ibm.commons.swt.SWTLayoutUtils.H_SPACING and com.ibm.commons.swt.SWTLayoutUtils.V_SPACING respectively. All other margins and spacings are the GridLayout detaults. The columns are NOT of equal width.

Parameters:
numColumns - - int
Returns:
GridLayout
See Also:
GridLayout

createLayoutNoHeight

public static org.eclipse.swt.layout.GridLayout createLayoutNoHeight(int numColumns)
Creates a new GridLayout layout object. The GridLayout will layout the composite to have the number of columns requested.
The layout will not take up any extra vertical height other than that requested by the child controls. Both the verticalSpacing and marginHeight properties are set to zero (0).

Parameters:
numColumns - - int
Returns:
GridLayout
See Also:
GridLayout

createLayoutNoMarginDefaultSpacing

public static org.eclipse.swt.layout.GridLayout createLayoutNoMarginDefaultSpacing(int numColumns)
Creates a new GridLayout layout object. The GridLayout will layout the composite to have the number of columns requested.
The horizontal and vertical spacing are set to com.ibm.commons.swt.SWTLayoutUtils.H_SPACING and com.ibm.commons.swt.SWTLayoutUtils.V_SPACING respectively. The marginHeight and marginWidth properties are both zero. All other margins and spacings are the GridLayout detaults. The columns are NOT of equal width.

Parameters:
numColumns - - int
Returns:
GridLayout
See Also:
GridLayout

createLayoutNoMarginNoSpacing

public static org.eclipse.swt.layout.GridLayout createLayoutNoMarginNoSpacing(int numColumns)
Creates a new GridLayout layout object. The GridLayout will layout the composite to have the number of columns requested.
The horizontal and vertical spacing are set to zero (0). The marginHeight and marginWidth properties are both zero. All other margins and spacings are the GridLayout detaults. The columns are NOT of equal width.

Parameters:
numColumns - - int
Returns:
GridLayout
See Also:
GridLayout

createLayoutTopMarginVerticalSpacing

public static org.eclipse.swt.layout.GridLayout createLayoutTopMarginVerticalSpacing(int numColumns)
Creates a new GridLayout layout object. The GridLayout will layout the composite to have the number of columns requested.
The horizontal spacing is set to zero (0). The marginHeight and marginWidth properties are both zero. The topMargin property is set to 5px. All other margins and spacings are the GridLayout detaults. The columns are NOT of equal width.

Parameters:
numColumns - - int
Returns:
GridLayout
See Also:
GridLayout

createLayoutNoWidth

public static org.eclipse.swt.layout.GridLayout createLayoutNoWidth(int numColumns)
Creates a new GridLayout layout object. The GridLayout will layout the composite to have the number of columns requested.
The layout will not take up any extra horizontal width other than that requested by the child controls. Both the horizontalSpacing and marginWidth properties are set to zero (0).

Parameters:
numColumns - - int
Returns:
GridLayout
See Also:
GridLayout

createTextForWrappingInADialog

public static org.eclipse.swt.widgets.Text createTextForWrappingInADialog(org.eclipse.swt.widgets.Composite parent,
                                                                          int style)
Creates a specialized SWT text widget that is intended to never demand space. On the other hand, it should have a GridData with the SWT.FILL for widthHint and grabExcessHorizontalSpace to true. The text will simply resize to the appropriate size of the dialog, and wrap it's text accordingly. The usual SWT text widget, if given the SWT.FILL and such constraints, will demand space before deciding to WRAP. This is usually averted by setting a width hint on the text, however, this method allows the user to not have to worry about doing so, and that this text will resize itself to the maximum size of any other element in the dialog. One other note about this control is it will need its grid cell created large enough by some other control because it won't be able to create its own space.


createFillLayoutNoMarginNoSpacing

public static org.eclipse.swt.layout.FillLayout createFillLayoutNoMarginNoSpacing(boolean verticalLayout)
Creates a FillLayout layout object. The layout will lay controls out vertically or horizontally depending on the parameter provided. The resulting layout will not have any margin width or margin height, nor will it have any spacing between laid out controls.

Parameters:
verticalLayout - - boolean true if the controls are to be laid out vertically
Returns:
FillLayout
See Also:
FillLayout

createFillLayoutNoMargin

public static org.eclipse.swt.layout.FillLayout createFillLayoutNoMargin(boolean verticalLayout)
Creates a FillLayout layout object. The layout will lay controls out vertically or horizontally depending on the parameter provided. The resulting layout will not have any margin width or margin height. Depending on whether the layout lays controls out vertically or horizontally, the spacing between controls will be com.ibm.commons.swt.SWTLayoutUtils.V_SPACING or com.ibm.commons.swt.SWTLayoutUtils.H_SPACING.

Parameters:
verticalLayout - - boolean true if the controls are to be laid out vertically
Returns:
FillLayout
See Also:
FillLayout

createFillLayoutDefaultMarginDefaultSpacing

public static org.eclipse.swt.layout.FillLayout createFillLayoutDefaultMarginDefaultSpacing(boolean verticalLayout)
Creates a FillLayout layout object. The layout will lay controls out vertically or horizontally depending on the parameter provided. The resulting layout will not have default margin width and height as per the standard behavior of FillLayout. Depending on whether the layout lays controls out vertically or horizontally, the spacing between controls will be com.ibm.commons.swt.SWTLayoutUtils.V_SPACING or com.ibm.commons.swt.SWTLayoutUtils.H_SPACING.

Parameters:
verticalLayout - - boolean true if the controls are to be laid out vertically
Returns:
FillLayout
See Also:
FillLayout

alignControls

public static void alignControls(java.util.List<org.eclipse.swt.widgets.Control> controls)
Aligns controls who are to appear in the same column across multiple composites. This utility method is especially useful if labels need to be aligned in a column, but the labels reside in different parents, meaning the controls will be laid out by different layout managers. This utility method will compute the 'natural' size of each control. Once the widest control's width is determined that width is set as the widthHint on all of the controls in the list.

Parameters:
controls - - java.util.List A list of controls that need to be aligned

alignControlsWithIndent

public static void alignControlsWithIndent(java.util.List<org.eclipse.swt.widgets.Control> controls)
Aligns controls who are to appear in the same column across multiple composites. This utility method is especially useful if labels need to be aligned in a column, but the labels reside in different parents, meaning the controls will be laid out by different layout managers. This method takes the indent settings of each control into account before calculating the final width. This utility method will compute the 'natural' size of each control, plus the horizontal indent (if one is set). Once the widest control's width is determined that width is set as the widthHint on all of the controls in the list.

Parameters:
controls - - java.util.List A list of controls that need to be aligned