Class GridLayoutAlgorithm

java.lang.Object
org.eclipse.gef.layout.algorithms.GridLayoutAlgorithm
All Implemented Interfaces:
ILayoutAlgorithm
Direct Known Subclasses:
BoxLayoutAlgorithm

public class GridLayoutAlgorithm extends Object implements ILayoutAlgorithm
The GridLayoutAlgorithm lays out nodes in a grid.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyLayout(LayoutContext context, boolean clean)
    Makes this algorithm perform layout computation and apply it to its context.
    protected void
    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(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[]
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GridLayoutAlgorithm

      public GridLayoutAlgorithm()
      Default constructor.
  • Method Details

    • applyLayout

      public void applyLayout(LayoutContext context, boolean clean)
      Description copied from interface: ILayoutAlgorithm
      Makes this algorithm perform layout computation and apply it to its context.
      Specified by:
      applyLayout in interface ILayoutAlgorithm
      Parameters:
      context - The LayoutContext 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

      protected void calculateGrid(Rectangle bounds)
      Calculates all the dimensions of grid that layout entities will be fit in.
      Parameters:
      bounds - A Rectangle 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 the 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.
      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 the padding (20%), colWidth, rowHeight, and aspect 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)