public class GridLayout extends AbstractHintLayout
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.
GridData
Modifier and Type | Field and Description |
---|---|
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.
|
isObservingVisibility, preferredSize
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
calculateMinimumSize, getMinimumSize, getPreferredSize, invalidate, isSensitiveHorizontally, isSensitiveVertically
calculatePreferredSize, getBorderPreferredSize, getMinimumSize, getPreferredSize, invalidate, isObservingVisibility, remove, setObserveVisibility
public int numColumns
public boolean makeColumnsEqualWidth
public int marginWidth
public int marginHeight
public int horizontalSpacing
public int verticalSpacing
protected java.util.Map constraints
public GridLayout()
public GridLayout(int numColumns, boolean makeColumnsEqualWidth)
numColumns
- the number of columns in the gridmakeColumnsEqualWidth
- whether or not the columns will have equal widthprotected Dimension getChildSize(IFigure child, int wHint, int hHint)
child
- wHint
- hHint
- protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint)
AbstractLayout
calculatePreferredSize
in class AbstractLayout
container
- The figurewHint
- The width hinthHint
- The height hintpublic void layout(IFigure container)
LayoutManager
container
- The figurepublic java.lang.Object getConstraint(IFigure child)
AbstractLayout
getConstraint
in interface LayoutManager
getConstraint
in class AbstractLayout
child
- The figurepublic void setConstraint(IFigure figure, java.lang.Object newConstraint)
GridData
.setConstraint
in interface LayoutManager
setConstraint
in class AbstractLayout
figure
- the childnewConstraint
- the child's new constraintLayoutManager.setConstraint(IFigure, Object)
Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.