Package org.eclipse.draw2d
Class GridLayout
java.lang.Object
org.eclipse.draw2d.AbstractLayout
org.eclipse.draw2d.AbstractHintLayout
org.eclipse.draw2d.GridLayout
- All Implemented Interfaces:
LayoutManager
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 Summary
FieldsModifier and TypeFieldDescriptionThe layout contraintsint
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 specifies whether all columns in the layout will be forced to have the same width.int
marginHeight specifies the number of pixels of vertical margin that will be placed along the top and bottom edges of the layout.int
marginWidth specifies the number of pixels of horizontal margin that will be placed along the left and right edges of the layout.int
numColumns specifies the number of cell columns in the layout.int
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
ConstructorsConstructorDescriptionDefault ConstructorGridLayout
(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
Modifier and TypeMethodDescriptionprotected 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) getConstraint
(IFigure child) Returns the constraint for the given figure.void
Lays out the given figure.void
setConstraint
(IFigure figure, Object newConstraint) Sets the layout constraint of the given figure.Methods inherited from class org.eclipse.draw2d.AbstractHintLayout
calculateMinimumSize, getMinimumSize, getPreferredSize, invalidate, isSensitiveHorizontally, isSensitiveVertically
Methods inherited from class org.eclipse.draw2d.AbstractLayout
calculatePreferredSize, getBorderPreferredSize, getMinimumSize, getPreferredSize, invalidate, isObservingVisibility, remove, setObserveVisibility
-
Field Details
-
numColumns
public int numColumnsnumColumns specifies the number of cell columns in the layout. The default value is 1. -
makeColumnsEqualWidth
public boolean makeColumnsEqualWidthmakeColumnsEqualWidth specifies whether all columns in the layout will be forced to have the same width. The default value is false. -
marginWidth
public int marginWidthmarginWidth 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 marginHeightmarginHeight 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 horizontalSpacinghorizontalSpacing 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 verticalSpacingverticalSpacing 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
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 gridmakeColumnsEqualWidth
- whether or not the columns will have equal width
-
-
Method Details
-
getChildSize
- Parameters:
child
-wHint
-hHint
-- Returns:
- the child size.
-
calculatePreferredSize
Description copied from class:AbstractLayout
Calculates the preferred size of the given figure, using width and height hints.- Specified by:
calculatePreferredSize
in classAbstractLayout
- Parameters:
container
- The figurewHint
- The width hinthHint
- The height hint- Returns:
- The preferred size
-
layout
Description copied from interface:LayoutManager
Lays out the given figure.- Parameters:
container
- The figure
-
getConstraint
Description copied from class:AbstractLayout
Returns the constraint for the given figure.- Specified by:
getConstraint
in interfaceLayoutManager
- Overrides:
getConstraint
in classAbstractLayout
- Parameters:
child
- The figure- Returns:
- The constraint
-
setConstraint
Sets the layout constraint of the given figure. The constraints can only be of typeGridData
.- Specified by:
setConstraint
in interfaceLayoutManager
- Overrides:
setConstraint
in classAbstractLayout
- Parameters:
figure
- the childnewConstraint
- the child's new constraint- See Also:
-