Class GridRow<T,C extends GridCell<T>>
GridState.
The major issue in managing VirtualGrid is that we are dealing with a 2D data structure, and a type of cell
GridCell, that works on both linear indexes and coordinated. All of this makes the algorithms a lot more complex
and easy to screw up.
GridRow's goal is to simplify this mess by having one specific task: managing the columns for one specific row
of items. So, in the end with GridRow we have to manage a 1D structure which is the map containing the cells
representing the columns of a single row.
GridRows contain information such as:
- the row's index
- the range of columns for the row
- the actual cells that will be displayed in the viewport, kept in a map as: columnIndex -> Cell
- a map containing the horizontal positions of the cells, so that in some cases these can be reused avoiding
a part of the layoutCells(double, boolean) computation
- the vertical position at which the row (every cell) will be positioned
-
Constructor Summary
ConstructorsConstructorDescriptionGridRow(VirtualGrid<T, C> grid, int index, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) -
Method Summary
Modifier and TypeMethodDescriptionbooleanprotected voidclear()CallsCell.dispose()on all the cells in the map, then clears the map, leading to an emptyGridRow.getCells()io.github.palexdev.mfxcore.base.beans.range.IntegerRangeintgetIndex()Converts the cells map to a new map with a different key -> value mapping.doubleinit()InitializesGridRowby creating the needed amount of cells given by thegetColumns()range.booleanvoidlayoutCells(double position, boolean adjustColumns) This core method is called byGridState.layoutRows()and it's responsible for laying out all the cells in theGridRow.of(VirtualGrid<T, C> virtualGrid, int index, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) protected voidonColumnAdd(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for correctly updating theGridRowwhen aGridChangeType.ADD_COLUMNchange occurs in the grid's data structure.protected voidonColumnRemove(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for correctly updating theGridRowwhen aGridChangeType.REMOVE_COLUMNchange occurs in the grid's data structure.protected voidonDiagReplace(T item) CallsonReplace(int, Object), since it is a diagonal replacement the column index is the same as the row's index.protected voidonInit(io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for supplying of removing cells according to the new given columns range.protected voidThis is responsible for updating theGridRowwhen the row has been replaced.protected voidThis is responsible for updating only the cell at the given column index (if present in the map) with the given item.protected voidonRowAdd(int newIndex) CallspartialUpdate(int).protected voidonRowRemove(int newIndex) CallspartialUpdate(int).protected voidonScroll(io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for updating theGridRowwhen the viewport scrolls horizontally.protected voidsetReusablePositions(boolean reusablePositions) protected voidsetVisible(boolean visible) Responsible for showing/hiding the cells of this row.intsize()inttoLinear(int row, int column) Converts the given coordinates to a linear index usingGridUtils.subToInd(int, int, int).protected voidupdateIndex(int index) This is responsible for updating the cells when the row's index must change to the given one.
-
Constructor Details
-
GridRow
public GridRow(VirtualGrid<T, C> grid, int index, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns)
-
-
Method Details
-
of
public static <T,C extends GridCell<T>> GridRow<T,C> of(VirtualGrid<T, C> virtualGrid, int index, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) -
init
InitializesGridRowby creating the needed amount of cells given by thegetColumns()range.If the row has already been initialized before all the cells are disposed, cleared and re-created.
-
onInit
protected void onInit(io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for supplying of removing cells according to the new given columns range.This is used by
GridManager.init(). If the given range is equal to the current one no operation is done. -
updateIndex
protected void updateIndex(int index) This is responsible for updating the cells when the row's index must change to the given one. All cells are fully updated (both index and item). -
onScroll
protected void onScroll(io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for updating theGridRowwhen the viewport scrolls horizontally. -
onReplace
protected void onReplace()This is responsible for updating theGridRowwhen the row has been replaced. All the cells keep their indexes but their item must be updated. -
onReplace
This is responsible for updating only the cell at the given column index (if present in the map) with the given item. -
onDiagReplace
CallsonReplace(int, Object), since it is a diagonal replacement the column index is the same as the row's index. -
onRowAdd
protected void onRowAdd(int newIndex) CallspartialUpdate(int). -
onRowRemove
protected void onRowRemove(int newIndex) CallspartialUpdate(int). -
onColumnAdd
protected void onColumnAdd(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for correctly updating theGridRowwhen aGridChangeType.ADD_COLUMNchange occurs in the grid's data structure. The algorithm is very similar to the one used forGridChangeType.ADD_ROW, described hereGridState.change(ObservableGrid.Change). -
onColumnRemove
protected void onColumnRemove(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns) This is responsible for correctly updating theGridRowwhen aGridChangeType.REMOVE_COLUMNchange occurs in the grid's data structure. The algorithm is very similar to the one used forGridChangeType.REMOVE_ROW, described hereGridState.change(ObservableGrid.Change). -
layoutCells
public void layoutCells(double position, boolean adjustColumns) This core method is called byGridState.layoutRows()and it's responsible for laying out all the cells in theGridRow. Two information are required, the vertical position of the row in the viewport and whether we are in an exceptional case as described hereGridState.layoutRows(). The horizontal positions for each column/cell are computed or reused if possible.Then from the last cell and position, cells are laid out using
GridHelper.layout(Node, double, double). -
clear
protected void clear()CallsCell.dispose()on all the cells in the map, then clears the map, leading to an emptyGridRow. -
size
public int size()- Returns:
- the number of cells/columns in the
GridRow
-
toLinear
public int toLinear(int row, int column) Converts the given coordinates to a linear index usingGridUtils.subToInd(int, int, int). -
getVirtualGrid
- Returns:
- the
VirtualGridinstance associated to this row
-
getIndex
public int getIndex()- Returns:
- this row's index
-
getColumns
public io.github.palexdev.mfxcore.base.beans.range.IntegerRange getColumns()- Returns:
- the range of columns represented by this row
-
getCells
- Returns:
- the cells map
-
getCellsUnmodifiable
- Returns:
- the cells map as an unmodifiable map
-
getLinearCells
Converts the cells map to a new map with a different key -> value mapping.Instead of using the column index as the key, this map converts each index to a linear index using
toLinear(int, int). -
getPositions
- Returns:
- the cells' positions set
-
getPositionsUnmodifiable
- Returns:
- the cells' positions set as an unmodifiable set
-
getPosition
public double getPosition()- Returns:
- the vertical position at which the row should be positioned in the viewport
-
canReusePositions
public boolean canReusePositions()- Returns:
- whether the already computed positions for the cells can be reused by
layoutCells(double, boolean)
-
setReusablePositions
protected void setReusablePositions(boolean reusablePositions) -
isVisible
public boolean isVisible()- Returns:
- whether the cells of this row are visible in the viewport
-
setVisible
protected void setVisible(boolean visible) Responsible for showing/hiding the cells of this row. Cells are visible by default but various implementations of the Grid may decide to hide rows under certain conditions.
-