Class GridRow<T,C extends GridCell<T>>

java.lang.Object
io.github.palexdev.virtualizedfx.grid.GridRow<T,C>

public class GridRow<T,C extends GridCell<T>> extends Object
This is a helper class to support 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

    Constructors
    Constructor
    Description
    GridRow(VirtualGrid<T,C> grid, int index, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    protected void
    Calls Cell.dispose() on all the cells in the map, then clears the map, leading to an empty GridRow.
    protected Map<Integer,C>
     
     
    io.github.palexdev.mfxcore.base.beans.range.IntegerRange
     
    int
     
    Converts the cells map to a new map with a different key -> value mapping.
    double
     
    protected Set<Double>
     
     
     
    Initializes GridRow by creating the needed amount of cells given by the getColumns() range.
    boolean
     
    void
    layoutCells(double position, boolean adjustColumns)
    This core method is called by GridState.layoutRows() and it's responsible for laying out all the cells in the GridRow.
    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)
     
    protected void
    onColumnAdd(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns)
    This is responsible for correctly updating the GridRow when a GridChangeType.ADD_COLUMN change occurs in the grid's data structure.
    protected void
    onColumnRemove(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns)
    This is responsible for correctly updating the GridRow when a GridChangeType.REMOVE_COLUMN change occurs in the grid's data structure.
    protected void
    Calls onReplace(int, Object), since it is a diagonal replacement the column index is the same as the row's index.
    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.
    protected void
    This is responsible for updating the GridRow when the row has been replaced.
    protected void
    onReplace(int column, T item)
    This is responsible for updating only the cell at the given column index (if present in the map) with the given item.
    protected void
    onRowAdd(int newIndex)
    Calls partialUpdate(int).
    protected void
    onRowRemove(int newIndex)
    Calls partialUpdate(int).
    protected void
    onScroll(io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns)
    This is responsible for updating the GridRow when the viewport scrolls horizontally.
    protected void
    setReusablePositions(boolean reusablePositions)
     
    protected void
    setVisible(boolean visible)
    Responsible for showing/hiding the cells of this row.
    int
     
    int
    toLinear(int row, int column)
    Converts the given coordinates to a linear index using GridUtils.subToInd(int, int, int).
    protected void
    updateIndex(int index)
    This is responsible for updating the cells when the row's index must change to the given one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public GridRow<T,C> init()
      Initializes GridRow by creating the needed amount of cells given by the getColumns() 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 the GridRow when the viewport scrolls horizontally.
    • onReplace

      protected void onReplace()
      This is responsible for updating the GridRow when the row has been replaced. All the cells keep their indexes but their item must be updated.
    • onReplace

      protected void onReplace(int column, T item)
      This is responsible for updating only the cell at the given column index (if present in the map) with the given item.
    • onDiagReplace

      protected void onDiagReplace(T item)
      Calls onReplace(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)
      Calls partialUpdate(int).
    • onRowRemove

      protected void onRowRemove(int newIndex)
      Calls partialUpdate(int).
    • onColumnAdd

      protected void onColumnAdd(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns)
      This is responsible for correctly updating the GridRow when a GridChangeType.ADD_COLUMN change occurs in the grid's data structure.

      The algorithm is very similar to the one used for GridChangeType.ADD_ROW, described here GridState.change(ObservableGrid.Change).
    • onColumnRemove

      protected void onColumnRemove(int column, io.github.palexdev.mfxcore.base.beans.range.IntegerRange columns)
      This is responsible for correctly updating the GridRow when a GridChangeType.REMOVE_COLUMN change occurs in the grid's data structure.

      The algorithm is very similar to the one used for GridChangeType.REMOVE_ROW, described here GridState.change(ObservableGrid.Change).
    • layoutCells

      public void layoutCells(double position, boolean adjustColumns)
      This core method is called by GridState.layoutRows() and it's responsible for laying out all the cells in the GridRow. Two information are required, the vertical position of the row in the viewport and whether we are in an exceptional case as described here GridState.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()
      Calls Cell.dispose() on all the cells in the map, then clears the map, leading to an empty GridRow.
    • 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 using GridUtils.subToInd(int, int, int).
    • getVirtualGrid

      public VirtualGrid<T,C> getVirtualGrid()
      Returns:
      the VirtualGrid instance 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

      protected Map<Integer,C> getCells()
      Returns:
      the cells map
    • getCellsUnmodifiable

      public Map<Integer,C> getCellsUnmodifiable()
      Returns:
      the cells map as an unmodifiable map
    • getLinearCells

      public Map<Integer,C> 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

      protected Set<Double> getPositions()
      Returns:
      the cells' positions set
    • getPositionsUnmodifiable

      public Set<Double> 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.