Class AreaGrid


  • public class AreaGrid
    extends Object
    A grid of areas in an abstract parent rectangle. The grid is used as the default area topology.
    Author:
    burgetr
    • Field Detail

      • GRID_THRESHOLD

        public static final int GRID_THRESHOLD
        The maximal difference between two lengths that are considered a "being the same"
        See Also:
        Constant Field Values
    • Constructor Detail

      • AreaGrid

        public AreaGrid​(DefaultArea area,
                        AreaTopology targetTopology)
        Constructs a grid of all the child areas of the given parent area.
        Parameters:
        area - the parent area whose children will be laid out in the grid
        targetTopology - the area topology where the computed grid positions will be set
      • AreaGrid

        public AreaGrid​(Rectangular position,
                        Collection<ContentRect> areas,
                        AreaTopology targetTopology)
        Constructs a grid from the list of areas.
        Parameters:
        position - Absolute position of the grid area
        areas - the areas to be laid out in the grid.
        targetTopology - the area topology where the computed grid positions will be set
    • Method Detail

      • getAbsolutePosition

        public Rectangular getAbsolutePosition()
        Obtains the absolute position where the grid is placed within the page.
        Returns:
      • getCols

        public int[] getCols()
        Returns:
        Returns the cols.
      • getHeight

        public int getHeight()
        Returns:
        Returns the height.
      • getRows

        public int[] getRows()
        Returns:
        Returns the rows.
      • getWidth

        public int getWidth()
        Returns:
        Returns the width.
      • getMinIndent

        public int getMinIndent()
      • getMaxIndent

        public int getMaxIndent()
      • getCellBoundsRelative

        public Rectangular getCellBoundsRelative​(int x,
                                                 int y)
        Computes the coordinates of the specified grid cell relatively to the area top left corner.
        Parameters:
        x - the column index of the cell
        y - the row index of the cell
        Returns:
        the coordinates of the given cell in pixels
      • getCellBoundsAbsolute

        public Rectangular getCellBoundsAbsolute​(int x,
                                                 int y)
        Computes the absolute coordinates of the specified grid cell.
        Parameters:
        x - the column index of the cell
        y - the row index of the cell
        Returns:
        the coordinates of the given cell in pixels
      • getAreaBoundsAbsolute

        public Rectangular getAreaBoundsAbsolute​(int x1,
                                                 int y1,
                                                 int x2,
                                                 int y2)
        Computes the absolute coordinates of the specified area in the grid.
        Parameters:
        x1 - the column index of the top left cell of the area.
        y1 - the row index of the top left cell of the area.
        x2 - the column index of the bottom right cell of the area.
        y2 - the row index of the bottom right cell of the area.
        Returns:
        the absolute coordinates of the given area in pixels.
      • getAreaBoundsAbsolute

        public Rectangular getAreaBoundsAbsolute​(Rectangular area)
        Computes the absolute coordinates of the specified area in the grid.
        Parameters:
        area - The area coordinates in the grid.
        Returns:
        the absolute coordinates of the given area in pixels.
      • findCellX

        public int findCellX​(int x)
        Finds a grid cell that contains the specified point
        Parameters:
        x - the x coordinate of the specified point
        Returns:
        the X offset of the grid cell that contains the specified absolute x coordinate or -1 when there is no such cell
      • findCellY

        public int findCellY​(int y)
        Finds a grid cell that contains the specified point
        Parameters:
        y - the y coordinate of the specified point
        Returns:
        the Y offset of the grid cell that contains the specified absolute y coordinate or -1 when there is no such cell