public class GridLayoutAlgorithm extends java.lang.Object implements ILayoutAlgorithm
GridLayoutAlgorithm
lays out nodes in a grid.Constructor and Description |
---|
GridLayoutAlgorithm()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
applyLayout(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
the
padding (20%), colWidth,
rowHeight, and aspect ratio . |
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.
|
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.
|
LayoutContext |
getLayoutContext()
Returns the previously set
LayoutContext . |
boolean |
isResizing() |
void |
setAspectRatio(double aspectRatio)
Sets the preferred aspect ratio for layout entities.
|
void |
setLayoutContext(LayoutContext context)
Sets the layout context for this algorithm.
|
void |
setResizing(boolean resizing) |
void |
setRowPadding(int rowPadding)
Sets the padding between rows in the grid
|
public void setLayoutContext(LayoutContext context)
ILayoutAlgorithm
setLayoutContext
in interface ILayoutAlgorithm
context
- a new layout context or null if this algorithm should not
perform any layoutpublic void applyLayout(boolean clean)
ILayoutAlgorithm
applyLayout
in interface ILayoutAlgorithm
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.protected void calculateGrid(Rectangle bounds)
bounds
- A Rectangle
representing the layout bounds.protected int[] calculateNumberOfRowsAndCols(int numChildren, double boundX, double boundY, double boundWidth, double boundHeight)
aspect ratio
is
set to 1
, then the
calculateNumberOfRowsAndCols_square(int, double, double, double, double)
method is used for the computation. Otherwise, the
calculateNumberOfRowsAndCols_rectangular(int)
is used for the
computation.numChildren
- The number of nodes.boundX
- The horizontal offset.boundY
- The vertical offset.boundWidth
- The bounds' width.boundHeight
- The bounds' height.protected int[] calculateNumberOfRowsAndCols_square(int numChildren, double boundX, double boundY, double boundWidth, double boundHeight)
numChildren
- The number of nodes.boundX
- The horizontal offset.boundY
- The vertical offset.boundWidth
- The bounds' width.boundHeight
- The bounds' height.protected int[] calculateNumberOfRowsAndCols_rectangular(int numChildren)
numChildren
- The number of nodes.protected double[] calculateNodeSize(double colWidth, double rowHeight)
padding
(20%), colWidth,
rowHeight, and aspect ratio
.colWidth
- The width of a column.rowHeight
- The height of a row.public void setRowPadding(int rowPadding)
rowPadding
- padding - should be greater than or equal to 0public void setAspectRatio(double aspectRatio)
aspectRatio
- aspect ratio - should be greater than 0public boolean isResizing()
public void setResizing(boolean resizing)
resizing
- true if this algorithm should resize elements (default is
false)public LayoutContext getLayoutContext()
ILayoutAlgorithm
LayoutContext
.getLayoutContext
in interface ILayoutAlgorithm
LayoutContext
Copyright (c) 2014 itemis AG and others. All rights reserved.