Class GridLayoutAlgorithm
java.lang.Object
org.eclipse.gef.layout.algorithms.GridLayoutAlgorithm
- All Implemented Interfaces:
ILayoutAlgorithm
- Direct Known Subclasses:
BoxLayoutAlgorithm
The
GridLayoutAlgorithm
lays out nodes in a grid.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyLayout
(LayoutContext context, boolean clean) Makes this algorithm perform layout computation and apply it to its context.protected void
calculateGrid
(Rectangle bounds) Calculates all the dimensions of grid that layout entities will be fit in.protected double[]
calculateNodeSize
(double colWidth, double rowHeight) Calculates and returns the width and height of a single node depending on thepadding
(20%), colWidth, rowHeight, andaspect ratio
.protected int[]
calculateNumberOfRowsAndCols
(int numChildren, double boundX, double boundY, double boundWidth, double boundHeight) Calculates and returns an array containing the number of columns and the number of rows.protected int[]
calculateNumberOfRowsAndCols_rectangular
(int numChildren) Calculates and returns an array containing the number of columns and the number of rows, so that there is an equal number of rows and columns.protected int[]
calculateNumberOfRowsAndCols_square
(int numChildren, double boundX, double boundY, double boundWidth, double boundHeight) Calculates and returns an array containing the number of columns and the number of rows, so that the nodes are layed out in squares.boolean
void
setAspectRatio
(double aspectRatio) Sets the preferred aspect ratio for layout entities.void
setResizing
(boolean resizing) void
setRowPadding
(int rowPadding) Sets the padding between rows in the grid
-
Constructor Details
-
GridLayoutAlgorithm
public GridLayoutAlgorithm()Default constructor.
-
-
Method Details
-
applyLayout
Description copied from interface:ILayoutAlgorithm
Makes this algorithm perform layout computation and apply it to its context.- Specified by:
applyLayout
in interfaceILayoutAlgorithm
- Parameters:
context
- TheLayoutContext
that provides all relevant information about what to layout.clean
- if true the receiver should assume that the layout context has changed significantly and recompute the whole layout even if it keeps track of changes with listeners. False can be used after dynamic layout in a context is turned back on so that layout algorithm working in background can apply accumulated changes. Static layout algorithm can ignore this call entirely if clean is false.
-
calculateGrid
Calculates all the dimensions of grid that layout entities will be fit in.- Parameters:
bounds
- ARectangle
representing the layout bounds.
-
calculateNumberOfRowsAndCols
protected int[] calculateNumberOfRowsAndCols(int numChildren, double boundX, double boundY, double boundWidth, double boundHeight) Calculates and returns an array containing the number of columns and the number of rows. If theaspect ratio
is set to1
, then thecalculateNumberOfRowsAndCols_square(int, double, double, double, double)
method is used for the computation. Otherwise, thecalculateNumberOfRowsAndCols_rectangular(int)
is used for the computation.- Parameters:
numChildren
- The number of nodes.boundX
- The horizontal offset.boundY
- The vertical offset.boundWidth
- The bounds' width.boundHeight
- The bounds' height.- Returns:
- An array containing the number of columns, and the number of rows.
-
calculateNumberOfRowsAndCols_square
protected int[] calculateNumberOfRowsAndCols_square(int numChildren, double boundX, double boundY, double boundWidth, double boundHeight) Calculates and returns an array containing the number of columns and the number of rows, so that the nodes are layed out in squares.- Parameters:
numChildren
- The number of nodes.boundX
- The horizontal offset.boundY
- The vertical offset.boundWidth
- The bounds' width.boundHeight
- The bounds' height.- Returns:
- An array containing the number of columns and the number of rows.
-
calculateNumberOfRowsAndCols_rectangular
protected int[] calculateNumberOfRowsAndCols_rectangular(int numChildren) Calculates and returns an array containing the number of columns and the number of rows, so that there is an equal number of rows and columns.- Parameters:
numChildren
- The number of nodes.- Returns:
- An array containing the number of columns and the number of rows.
-
calculateNodeSize
protected double[] calculateNodeSize(double colWidth, double rowHeight) Calculates and returns the width and height of a single node depending on thepadding
(20%), colWidth, rowHeight, andaspect ratio
.- Parameters:
colWidth
- The width of a column.rowHeight
- The height of a row.- Returns:
- An array containing the width and height of a node.
-
setRowPadding
public void setRowPadding(int rowPadding) Sets the padding between rows in the grid- Parameters:
rowPadding
- padding - should be greater than or equal to 0
-
setAspectRatio
public void setAspectRatio(double aspectRatio) Sets the preferred aspect ratio for layout entities. The default aspect ratio is 1.- Parameters:
aspectRatio
- aspect ratio - should be greater than 0
-
isResizing
public boolean isResizing()- Returns:
- true if this algorithm is set to resize elements
-
setResizing
public void setResizing(boolean resizing) - Parameters:
resizing
- true if this algorithm should resize elements (default is false)
-