Package com.itextpdf.layout.renderer
Class Grid
- java.lang.Object
-
- com.itextpdf.layout.renderer.Grid
-
class Grid extends java.lang.ObjectThis class represents a grid of elements. Complex elements (which span over few cells of a grid) are stored as duplicates. For example if element with width = 2, height = 3 added to a grid, grid will store it as 6 elements each having width = height = 1.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classGrid.BuilderThis class is used to properly initialize starting values for grid.private static classGrid.CellPlacementHelperThis class is used to place cells on grid.private static classGrid.ColumnCellComparatorThis comparator sorts cells so ones with both fixed row and column positions would go first, then cells with fixed column and then all other cells.private static classGrid.CssGridCell(package private) static classGrid.GridOrderprivate static classGrid.RowCellComparatorThis comparator sorts cells so ones with both fixed row and column positions would go first, then cells with fixed row and then all other cells.
-
Field Summary
Fields Modifier and Type Field Description private intcolumnOffsetColumn start offset, it is not zero only if there are cells with negative indexes.private java.util.List<GridCell>itemsWithoutPlaceprivate introwOffsetRow start offset, it is not zero only if there are cells with negative indexes.private GridCell[][]rowsCells container.private java.util.List<java.util.Collection<GridCell>>uniqueCellsUnique grid cells cached values.
-
Constructor Summary
Constructors Constructor Description Grid(int initialRowsCount, int initialColumnsCount, int columnOffset, int rowOffset)Creates new grid instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddCell(GridCell cell)Add cell in the grid, checking that it would fit and initializing it bottom left corner (x, y).(package private) intcollapseNullLines(Grid.GridOrder order, int minSize)Deletes all null rows/columns depending on the given values.private intdetermineNullLinesStart(Grid.GridOrder order)(package private) intgetColumnOffset()get column start offset or grid "zero column" position.(package private) intgetNumberOfColumns()Gets the current number of rows of grid.(package private) intgetNumberOfRows()Gets the current number of rows of grid.(package private) intgetRowOffset()get row start offset or grid "zero row" position.(package private) GridCell[][]getRows()Get internal matrix of cells.(package private) java.util.Collection<GridCell>getUniqueGridCells(Grid.GridOrder iterationOrder)Get all unique cells in the grid.(package private) voidresize(int height, int width)Resize grid if needed, so it would have given number of rows/columns.
-
-
-
Field Detail
-
rows
private GridCell[][] rows
Cells container.
-
rowOffset
private int rowOffset
Row start offset, it is not zero only if there are cells with negative indexes. Such cells should not be covered by templates, so the offset represents row from which template values should be considered.
-
columnOffset
private int columnOffset
Column start offset, it is not zero only if there are cells with negative indexes. Such cells should not be covered by templates, so the offset represents column from which template values should be considered.
-
uniqueCells
private final java.util.List<java.util.Collection<GridCell>> uniqueCells
Unique grid cells cached values. first value of array contains unique cells in order from left to right and the second value contains cells in order from top to bottom.
-
itemsWithoutPlace
private final java.util.List<GridCell> itemsWithoutPlace
-
-
Constructor Detail
-
Grid
Grid(int initialRowsCount, int initialColumnsCount, int columnOffset, int rowOffset)Creates new grid instance.- Parameters:
initialRowsCount- initial number of row for the gridinitialColumnsCount- initial number of columns for the gridcolumnOffset- actual start(zero) position of columns, from where template should be appliedrowOffset- actual start(zero) position of rows, from where template should be applied
-
-
Method Detail
-
getRows
final GridCell[][] getRows()
Get internal matrix of cells.- Returns:
- matrix of cells.
-
getNumberOfRows
final int getNumberOfRows()
Gets the current number of rows of grid.- Returns:
- the number of rows
-
getNumberOfColumns
final int getNumberOfColumns()
Gets the current number of rows of grid.- Returns:
- the number of columns
-
getRowOffset
int getRowOffset()
get row start offset or grid "zero row" position.- Returns:
- row start offset if there are negative indexes, 0 otherwise
-
getColumnOffset
int getColumnOffset()
get column start offset or grid "zero column" position.- Returns:
- column start offset if there are negative indexes, 0 otherwise
-
getUniqueGridCells
java.util.Collection<GridCell> getUniqueGridCells(Grid.GridOrder iterationOrder)
Get all unique cells in the grid. Internally big cells (height * width > 1) are stored in multiple quantities For example, cell with height = 2 and width = 2 will have 4 instances on a grid (width * height) to simplify internal grid processing. This method counts such cells as one and returns a list of unique cells. The result is cached since grid can't be changed after creation.- Parameters:
iterationOrder- if {GridOrder.ROW} the order of cells is from left to right, top to bottom if {GridOrder.COLUMN} the order of cells is from top to bottom, left to right- Returns:
- collection of unique grid cells.
-
resize
final void resize(int height, int width)Resize grid if needed, so it would have given number of rows/columns.- Parameters:
height- new grid heightwidth- new grid width
-
collapseNullLines
int collapseNullLines(Grid.GridOrder order, int minSize)
Deletes all null rows/columns depending on the given values. If resulting grid size is less than provided minSize than some null lines will be preserved.- Parameters:
order- which null lines to remove -Grid.GridOrder.ROWto remove rowsGrid.GridOrder.COLUMNto remove columnsminSize- minimal size of the resulting grid- Returns:
- the number of left lines in given order
-
addCell
private void addCell(GridCell cell)
Add cell in the grid, checking that it would fit and initializing it bottom left corner (x, y).- Parameters:
cell- cell to and in the grid
-
determineNullLinesStart
private int determineNullLinesStart(Grid.GridOrder order)
-
-