Class TableHelper.FixedTableHelper

java.lang.Object
io.github.palexdev.virtualizedfx.table.TableHelper.AbstractHelper
io.github.palexdev.virtualizedfx.table.TableHelper.FixedTableHelper
All Implemented Interfaces:
TableHelper
Direct Known Subclasses:
PaginatedHelper.FixedPaginatedTableHelper, TableHelper.VariableTableHelper
Enclosing interface:
TableHelper

public static class TableHelper.FixedTableHelper extends TableHelper.AbstractHelper
Concrete implementation of TableHelper.AbstractHelper made to work specifically with ColumnsLayoutMode.FIXED.

As you can guess, this is the most efficient and fast helper since many computations are simplified by the fact that we know exactly the size of any column at any time.

To be honest, this mode and helper has been developed for those who have tabular data with a lot and I mean a lot of columns... or maybe you just find fixed columns more attractive?
  • Field Details

  • Constructor Details

    • FixedTableHelper

      public FixedTableHelper(VirtualTable<?> table)
  • Method Details

    • firstRow

      public int firstRow()
      Returns:
      the first visible row index
    • lastRow

      public int lastRow()
      Returns:
      the last visible row index
    • firstColumn

      public int firstColumn()
      Returns:
      the first visible column index
    • lastColumn

      public int lastColumn()
      Returns:
      the last visible column index
    • maxRows

      public int maxRows()
      Returns:
      the number of rows the viewport can display at any time
    • maxColumns

      public int maxColumns()
      Returns:
      the number of columns the viewport can display at any time
    • rowsRange

      public io.github.palexdev.mfxcore.base.beans.range.IntegerRange rowsRange()

      Note that the result given by maxRows() to compute the index of the first row, is clamped so that it will never be greater then the number of items in the data structure.

      Returns:
      the range of visible rows
    • columnsRange

      public io.github.palexdev.mfxcore.base.beans.range.IntegerRange columnsRange()

      Note that the result given by maxColumns() to compute the index of the first column, is clamped so that it will never be greater then the number of columns in the table.

      Returns:
      the range of visible columns
    • maxVScroll

      public double maxVScroll()

      The value is given by:

      Returns:
      the maximum amount of pixels the viewport can scroll vertically
    • maxHScroll

      public double maxHScroll()

      The value is given by:

      Returns:
      the maximum amount of pixels the viewport can scroll horizontally
    • computeEstimatedSize

      public io.github.palexdev.mfxcore.base.beans.Size computeEstimatedSize()
      Returns:
      the total virtual size of the viewport
    • xPosBinding

      public DoubleBinding xPosBinding()
      This binding holds the horizontal position of the viewport.

      This is the direction along the estimated breath. However, the implementation makes it so that the position of the viewport is virtual. This binding which depends on both VirtualTable.positionProperty() and VirtualTable.columnSizeProperty() will always return a value that is greater or equal to 0 and lesser than the columns width. (the value is made negative as this is how scrolling works)

      This is the formula: -table.getHPos() % table.getColumnSize().getWidth().

      Think about this. We have columns of width 64. and we scroll 15px on each gesture. When we reach 60px, we can still see the column for 4px, but once we scroll again it makes no sense to go to 75px because the first column won't be visible anymore, so we go back at 11px. Now the other column will be visible for 53px.

      Long story short, scrolling is just an illusion, the viewport just scroll by a little to give this illusion and when needed the columns are just repositioned. This is important because the estimated length could, in theory, reach very high values, so we don't want the viewport to scroll by thousands of pixels.

    • yPosBinding

      public DoubleBinding yPosBinding()
      This binding holds the vertical position of the viewport.

      This is the direction along the estimated length. However, the implementation makes it so that the position of the viewport is virtual. This binding which depends on both VirtualTable.positionProperty() and VirtualTable.cellHeightProperty() will always return a value that is greater or equal to 0 and lesser than the cell height. (the value is made negative as this is how scrolling works)

      This is the formula: -table.getVPos() % table.getCellHeight().

      Think about this. We have cells of width 64. and we scroll 15px on each gesture. When we reach 60px, we can still see the cell for 4px, but once we scroll again it makes no sense to go to 75px because the first cell won't be visible anymore, so we go back at 11px. Now the other cell will be visible for 53px.

      Long story short, scrolling is just an illusion, the viewport just scroll by a little to give this illusion and when needed the cells are just repositioned. This is important because the estimated length could, in theory, reach very high values, so we don't want the viewport to scroll by thousands of pixels.

    • scrollToRow

      public void scrollToRow(int index)
      Description copied from interface: TableHelper
      Scrolls the viewport to the given row index.
    • scrollToColumn

      public void scrollToColumn(int index)
      Description copied from interface: TableHelper
      Scrolls the viewport to the given column index.
    • scrollBy

      public void scrollBy(double pixels, Orientation orientation)
      Description copied from interface: TableHelper
      Scrolls the viewport by the given amount of pixels. The direction is determined by the "orientation" parameter.
    • scrollTo

      public void scrollTo(double pixel, Orientation orientation)
      Description copied from interface: TableHelper
      Scrolls the viewport to the given pixel value. The direction is determined by the "orientation" parameter.
    • autosizeColumn

      public void autosizeColumn(TableColumn<?,? extends TableCell<?>> column)
      Description copied from interface: TableHelper
      Attempts at auto-sizing the given column to fit its content.
      Throws:
      UnsupportedOperationException - ColumnsLayoutMode.FIXED doesn't allow columns to be resized.
    • autosizeColumns

      public void autosizeColumns()
      Description copied from interface: TableHelper
      Attempts at auto-sizing all the columns.
      Throws:
      UnsupportedOperationException - ColumnsLayoutMode.FIXED doesn't allow columns to be resized.
    • computePositions

      public Map<Orientation,List<Double>> computePositions(TableState<?> state, boolean forceXComputation, boolean forceYComputation)
      Given a certain state, computes the positions of each column/row/cell as a map. The key is an Orientation value to differentiate between the vertical and horizontal positions.

      Most of the time this computation is not needed and the old positions can be reused, but if for whatever reason the computation is believed to be necessary then it's possible to force it by setting the desired parameter flags as true.

      X Positions Computation

      The horizontal positions are computed by using a DoubleStream.iterate(double, DoubleUnaryOperator) with columnsNum * columnsW as the seed and x -> x - columnW as the operator. The stream is also limited, DoubleStream.limit(long), to the number of columns we need, the results are collected in a list and put in the positions map with Orientation.HORIZONTAL as the key.

      Horizontal positions are not computed unless at least one of these conditions is true:

      - forceXComputation flag is true

      - the positions have not been computed before

      - the number of positions previously computed is not equal to the number of columns we need

      Y Positions Computation

      The vertical positions are computed by using a DoubleStream.iterate(double, DoubleUnaryOperator) with rowsNum * cellHeight as the seed and x -> x - cellHeight as the operator. The stream is also limited, DoubleStream.limit(long), to the number of rows we need, the results are stored in a list and put in the positions map with Orientation.VERTICAL as the key.

      Vertical positions are not computed unless at least one of these conditions is true:

      - forceYComputation flag is true

      - the positions have not been computed before

      - the number of positions previously computed is not equal to the number of rows we need

      forceXComputation - forces the computation of the HORIZONTAL positions even if not needed
      forceYComputation - forces the computation of the VERTICAL positions even if not needed
    • layout

      public void layout()
      Entirely responsible for laying out columns/rows/cells.

      The layout makes use of the current table' state, VirtualTable.stateProperty(), and the positions computed by computePositions(TableState, boolean, boolean), this is invoked without forcing the re-computation.

      Exits immediately if the state is TableState.EMPTY, if TableHelper.AbstractHelper.invalidatedPos() returns true, or if VirtualTable.needsViewportLayoutProperty() is false.

      Before proceeding with layout retrieves the following parameters:

      - the columns width

      - the columns height

      - the columns range

      - the X positions

      - the X offset with TableHelper.AbstractHelper.horizontalOffset()

      - the cells height

      - the Y positions

      - the Y offset with TableHelper.AbstractHelper.verticalOffset()

      Columns are laid out from left to right, relocated at the extracted X position (+ the X offset) and at Y 0; and resized with the previously gathered sizes. The last column is an exception because if not all the space of the table was occupied by laying out the previous columns than it width will be set to the entire remaining space.

      Rows are laid out from top to bottom, relocated at the previously computed X offset and at the extracted Y position (+ the Y offset); and resized with the previously gathered height. The width is given by the maximum between the table width and the row size (given by the number of cells in the row multiplied by the columns width)

      For each row in the loop it also lays out the their cells. Each cell is relocated at the extracted X position and at Y 0; and resized to the previously gathered cell height. The width is the same of the corresponding column.
    • dispose

      public void dispose()
      Description copied from interface: TableHelper
      Disposes bindings/listeners that are not required anymore.
      Specified by:
      dispose in interface TableHelper
      Overrides:
      dispose in class TableHelper.AbstractHelper