Eclipse Draw2d 3.3

## org.eclipse.draw2d
Class GridLayout

    java.lang.Object
      org.eclipse.draw2d.AbstractLayout
          org.eclipse.draw2d.GridLayout

All Implemented Interfaces:
  LayoutManager

    public class GridLayout

extends AbstractLayout

Lays out children into a Grid arrangement in which overall aligment and spacing can be configured, as well as specfic layout requirements for the each individual member of the GridLayout. This layout is a Draw2D port of the swt GridLayout. `GridLayout` has a number of configuration fields, and the Figures it lays out can have an associated layout data object, called `GridData` (similar to the swt GridData object). The power of `GridLayout` lies in the ability to configure `GridData` for each Figure in the layout.

The following code creates a container Figure managed by a `GridLayout` with 2 columns, containing 3 RectangleFigure shapes, the last of which has been given further layout instructions. Note that it is the `GridLayout` method `setConstraint` that binds the child `Figure` to its layout `GridData` object.

     Figure container = new Figure();
     GridLayout gridLayout = new GridLayout();
     gridLayout.numColumns = 2;
     container.setLayout(gridLayout);

     Shape rect;
     rect = new RectangleFigure();
     container.add(rect);

     rect = new RectangleFigure();
     container.add(rect);

     rect = new RectangleFigure();
     GridData gridData = new GridData();
     gridData.widthHint = 150;
     layout.setConstraint(rect, gridData);

     container.add(rect);

The `numColumns` field is the most important field in a `GridLayout`. Widgets are laid out in columns from left to right, and a new row is created when `numColumns`+ 1 figures are added to the `Figure`parent container.``

See Also:
  `GridData`

Field Summary
`protected java.util.Map` `constraints` The layout contraints
`int` `horizontalSpacing` horizontalSpacing specifies the number of pixels between the right edge of one cell and the left edge of its neighbouring cell to the right.
`boolean` `makeColumnsEqualWidth` makeColumnsEqualWidth specifies whether all columns in the layout will be forced to have the same width.
`int` `marginHeight` marginHeight specifies the number of pixels of vertical margin that will be placed along the top and bottom edges of the layout.
`int` `marginWidth` marginWidth specifies the number of pixels of horizontal margin that will be placed along the left and right edges of the layout.
`int` `numColumns` numColumns specifies the number of cell columns in the layout.
`int` `verticalSpacing` verticalSpacing specifies the number of pixels between the bottom edge of one cell and the top edge of its neighbouring cell underneath.

Fields inherited from class org.eclipse.draw2d.AbstractLayout
`isObservingVisibility, preferredSize`

Constructor Summary
`GridLayout()` Default Constructor
`GridLayout(int numColumns, boolean makeColumnsEqualWidth)` Constructs a new instance of this class given the number of columns, and whether or not the columns should be forced to have the same width.

Method Summary
`protected Dimension` `calculatePreferredSize(IFigure container, int wHint, int hHint)` Calculates the preferred size of the given figure, using width and height hints.
`protected Dimension` `getChildSize(IFigure child, int wHint, int hHint)`
`java.lang.Object` `getConstraint(IFigure child)` Returns the constraint for the given figure.
`void` `layout(IFigure container)` Lays out the given figure.
`void` `setConstraint(IFigure figure, java.lang.Object newConstraint)` Sets the layout constraint of the given figure.

Methods inherited from class org.eclipse.draw2d.AbstractLayout
`calculatePreferredSize, getBorderPreferredSize, getMinimumSize, getMinimumSize, getPreferredSize, getPreferredSize, invalidate, invalidate, isObservingVisibility, remove, setObserveVisibility`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### numColumns

    public int numColumns

  numColumns specifies the number of cell columns in the layout. The default value is 1.

### makeColumnsEqualWidth

    public boolean makeColumnsEqualWidth

  makeColumnsEqualWidth specifies whether all columns in the layout will be forced to have the same width. The default value is false.

### marginWidth

    public int marginWidth

  marginWidth specifies the number of pixels of horizontal margin that will be placed along the left and right edges of the layout. The default value is 5.

### marginHeight

    public int marginHeight

  marginHeight specifies the number of pixels of vertical margin that will be placed along the top and bottom edges of the layout. The default value is 5.

### horizontalSpacing

    public int horizontalSpacing

  horizontalSpacing specifies the number of pixels between the right edge of one cell and the left edge of its neighbouring cell to the right. The default value is 5.

### verticalSpacing

    public int verticalSpacing

  verticalSpacing specifies the number of pixels between the bottom edge of one cell and the top edge of its neighbouring cell underneath. The default value is 5.

### constraints

    protected java.util.Map constraints

  The layout contraints

Constructor Detail

### GridLayout

    public GridLayout()

  Default Constructor

### GridLayout

    public GridLayout(int numColumns,
                      boolean makeColumnsEqualWidth)

  Constructs a new instance of this class given the number of columns, and whether or not the columns should be forced to have the same width.

  Parameters:
    `numColumns` - the number of columns in the grid
    `makeColumnsEqualWidth` - whether or not the columns will have equal width

Method Detail

### getChildSize

    protected Dimension getChildSize(IFigure child,
                                     int wHint,
                                     int hHint)

  Parameters:
    `child` -
    `wHint` -
    `hHint` -
  Returns:
    the child size.

### calculatePreferredSize

    protected Dimension calculatePreferredSize(IFigure container,
                                               int wHint,
                                               int hHint)

  Description copied from class: `AbstractLayout`
  Calculates the preferred size of the given figure, using width and height hints.

  Specified by:
    `calculatePreferredSize` in class `AbstractLayout`
  Parameters:
    `container` - The figure
    `wHint` - The width hint
    `hHint` - The height hint
  Returns:
    The preferred size

### layout

    public void layout(IFigure container)

  Description copied from interface: `LayoutManager`
  Lays out the given figure.

  Parameters:
    `container` - The figure

### getConstraint

    public java.lang.Object getConstraint(IFigure child)

  Description copied from class: `AbstractLayout`
  Returns the constraint for the given figure.

  Specified by:
    `getConstraint` in interface `LayoutManager`
  Overrides:
    `getConstraint` in class `AbstractLayout`
  Parameters:
    `child` - The figure
  Returns:
    The constraint

### setConstraint

    public void setConstraint(IFigure figure,
                              java.lang.Object newConstraint)

  Sets the layout constraint of the given figure. The constraints can only be of type `GridData`.

  Specified by:
    `setConstraint` in interface `LayoutManager`
  Overrides:
    `setConstraint` in class `AbstractLayout`
  Parameters:
    `figure` - the child
    `newConstraint` - the child's new constraint
  See Also:
    `LayoutManager.setConstraint(IFigure, Object)`

Eclipse Draw2d 3.3

Copyright (c) IBM Corp. and others 2000, 2007. All Rights Reserved.