Class TableHelper.FixedTableHelper
- All Implemented Interfaces:
TableHelper
- Direct Known Subclasses:
PaginatedHelper.FixedPaginatedTableHelper
,TableHelper.VariableTableHelper
- Enclosing interface:
- TableHelper
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?-
Property Summary
Properties inherited from class io.github.palexdev.virtualizedfx.table.TableHelper.AbstractHelper
estimatedSize
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.palexdev.virtualizedfx.table.TableHelper
TableHelper.AbstractHelper, TableHelper.FixedTableHelper, TableHelper.VariableTableHelper
-
Field Summary
FieldsFields inherited from class io.github.palexdev.virtualizedfx.table.TableHelper.AbstractHelper
estimatedSize, heightListener, manager, positionListener, table, widthListener, xPosBinding, yPosBinding
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
autosizeColumn
(TableColumn<?, ? extends TableCell<?>> column) Attempts at auto-sizing the given column to fit its content.void
Attempts at auto-sizing all the columns.io.github.palexdev.mfxcore.base.beans.range.IntegerRange
io.github.palexdev.mfxcore.base.beans.Size
computePositions
(TableState<?> state, boolean forceXComputation, boolean forceYComputation) Given a certain state, computes the positions of each column/row/cell as a map.void
dispose()
Disposes bindings/listeners that are not required anymore.int
int
firstRow()
int
int
lastRow()
void
layout()
Entirely responsible for laying out columns/rows/cells.int
double
int
maxRows()
double
io.github.palexdev.mfxcore.base.beans.range.IntegerRange
void
scrollBy
(double pixels, Orientation orientation) Scrolls the viewport by the given amount of pixels.void
scrollTo
(double pixel, Orientation orientation) Scrolls the viewport to the given pixel value.void
scrollToColumn
(int index) Scrolls the viewport to the given column index.void
scrollToRow
(int index) Scrolls the viewport to the given row index.This binding holds the horizontal position of the viewport.This binding holds the vertical position of the viewport.Methods inherited from class io.github.palexdev.virtualizedfx.table.TableHelper.AbstractHelper
estimatedSizeProperty, getViewportHeight, horizontalOffset, invalidatedPos, onHeightChanged, onPositionChanged, onWidthChanged, verticalOffset
-
Field Details
-
positions
-
-
Constructor Details
-
FixedTableHelper
-
-
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
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()
andVirtualTable.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
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()
andVirtualTable.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
Description copied from interface:TableHelper
Scrolls the viewport by the given amount of pixels. The direction is determined by the "orientation" parameter. -
scrollTo
Description copied from interface:TableHelper
Scrolls the viewport to the given pixel value. The direction is determined by the "orientation" parameter. -
autosizeColumn
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 anOrientation
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 ComputationThe horizontal positions are computed by using a
DoubleStream.iterate(double, DoubleUnaryOperator)
withcolumnsNum * columnsW
as the seed andx -> 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 withOrientation.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 ComputationThe vertical positions are computed by using a
DoubleStream.iterate(double, DoubleUnaryOperator)
withrowsNum * cellHeight
as the seed andx -> 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 withOrientation.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 neededforceYComputation
- 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 bycomputePositions(TableState, boolean, boolean)
, this is invoked without forcing the re-computation.Exits immediately if the state is
Before proceeding with layout retrieves the following parameters:TableState.EMPTY
, ifTableHelper.AbstractHelper.invalidatedPos()
returns true, or ifVirtualTable.needsViewportLayoutProperty()
is false.- 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
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.TableHelper.AbstractHelper.verticalOffset()
-
dispose
public void dispose()Description copied from interface:TableHelper
Disposes bindings/listeners that are not required anymore.- Specified by:
dispose
in interfaceTableHelper
- Overrides:
dispose
in classTableHelper.AbstractHelper
-