Class GridLayout

All Implemented Interfaces:
LayoutManager

public class GridLayout extends AbstractHintLayout
Lays out children into a Grid arrangement in which overall aligment and spacing can be configured, as well as specific 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:
  • Field Details

    • 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 Map<IFigure,Object> constraints
      The layout contraints
  • Constructor Details

    • 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 Details