Package cz.vutbr.fit.layout.impl
Class AreaGrid
- java.lang.Object
-
- cz.vutbr.fit.layout.impl.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 Summary
Fields Modifier and Type Field Description static int
GRID_THRESHOLD
The maximal difference between two lengths that are considered a "being the same"
-
Constructor Summary
Constructors Constructor Description AreaGrid(DefaultArea area, AreaTopology targetTopology)
Constructs a grid of all the child areas of the given parent area.AreaGrid(Rectangular position, Collection<ContentRect> areas, AreaTopology targetTopology)
Constructs a grid from the list of areas.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
findCellX(int x)
Finds a grid cell that contains the specified pointint
findCellY(int y)
Finds a grid cell that contains the specified pointRectangular
getAbsolutePosition()
Obtains the absolute position where the grid is placed within the page.Rectangular
getAreaBoundsAbsolute(int x1, int y1, int x2, int y2)
Computes the absolute coordinates of the specified area in the grid.Rectangular
getAreaBoundsAbsolute(Rectangular area)
Computes the absolute coordinates of the specified area in the grid.Rectangular
getCellBoundsAbsolute(int x, int y)
Computes the absolute coordinates of the specified grid cell.Rectangular
getCellBoundsRelative(int x, int y)
Computes the coordinates of the specified grid cell relatively to the area top left corner.int
getColOfs(int col)
Finds the offset of the specified column from the grid origin.int[]
getCols()
int
getHeight()
int
getMaxIndent()
int
getMinIndent()
int
getRowOfs(int row)
Finds the offset of the specified row from the grid origin.int[]
getRows()
int
getWidth()
String
toString()
-
-
-
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 gridtargetTopology
- 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 areaareas
- 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()
-
getColOfs
public int getColOfs(int col) throws ArrayIndexOutOfBoundsException
Finds the offset of the specified column from the grid origin.- Parameters:
col
- the column index- Returns:
- the offset in pixels. Column 0 has always the offset 0.
- Throws:
ArrayIndexOutOfBoundsException
-
getRowOfs
public int getRowOfs(int row) throws ArrayIndexOutOfBoundsException
Finds the offset of the specified row from the grid origin.- Parameters:
row
- the row index- Returns:
- the offset in pixels. Row 0 has always the offset 0.
- Throws:
ArrayIndexOutOfBoundsException
-
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 celly
- 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 celly
- 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
-
-