Class VirtualFlow<T,C extends Cell<T>>

Type Parameters:
T - the type of objects to represent
C - the type of Cell to use
All Implemented Interfaces:
Styleable, EventTarget, Skinnable
Direct Known Subclasses:
PaginatedVirtualFlow

public class VirtualFlow<T,C extends Cell<T>> extends Control
Basic implementation of a virtual flow for virtualized list controls.

Extends Control, has its own skin implementation VirtualFlowSkin and its own cell system, Cell.

These are all its features:

- The items list is managed automatically (permutations, insertions, removals, updates)

- The function used to generate the cells, also called "cellFactory", can be changed anytime even at runtime

- The control also manages the size of all the cells through the cellSizeProperty()

- You can set the position (scroll) through the properties or a series of public methods

- It can lay out the cell from the TOP to the BOTTOM or from the LEFT to the RIGHT according to the set orientation, orientationProperty(), you can swap the orientation at anytime

- It even allows you to specify the OrientationHelper through the orientationHelperFactoryProperty()

- It is possible to retrieve the currently shown/built cells as a map in which each cell has the item's index as its key. Just keep in mind that if you want to observe for changes in the cells it is best to observe for changes on the stateProperty() since the virtual flow rarely builds new cells and reuses the one already available

It is possible to observe for changes o the estimated length and max breadth through estimatedLengthProperty() and maxBreadthProperty()

It is possible to programmatically tell the viewport to update its layout with requestViewportLayout()

Before proceeding with reading the methods documentations note that this new implementation uses the concepts of length and breadth, simply put:

Orientation.VERTICAL: length -> height, breadth -> width

Orientation.HORIZONTAL: length -> width, breadth -> height

  • Property Details

  • Constructor Details

  • Method Details

    • requestViewportLayout

      public void requestViewportLayout()
      Basically a setter for needsViewportLayoutProperty(). This sets the property to true causing the virtual flow skin to catch the change through a listener which then orders the viewport container to re-compute the layout.
    • cellSizeChanged

      protected void cellSizeChanged()
    • scrollBy

      public void scrollBy(double pixels)
      Tells the current orientationHelperProperty() to scroll by the given amount of pixels.

      Unsupported by PaginatedVirtualFlow

    • scrollToPixel

      public void scrollToPixel(double pixel)
      Tells the current orientationHelperProperty() to scroll to the given pixel.

      Unsupported by PaginatedVirtualFlow

    • scrollToIndex

      public void scrollToIndex(int index)
      Tells the current orientationHelperProperty() to scroll to the given cell index.
    • scrollToFirst

      public void scrollToFirst()
      Tells the current orientationHelperProperty() to scroll to the first cell.
    • scrollToLast

      public void scrollToLast()
      Tells the current orientationHelperProperty() to scroll to the last cell.
    • getEstimatedLength

      public double getEstimatedLength()
      Gets the value of the estimatedLength property.
      Property description:
      Specifies the total length of all the cells.
      Returns:
      the value of the estimatedLength property
      See Also:
    • estimatedLengthProperty

      public ReadOnlyDoubleProperty estimatedLengthProperty()
      Specifies the total length of all the cells.
      Returns:
      the estimatedLength property
      See Also:
    • getMaxBreadth

      public double getMaxBreadth()
      Gets the value of the maxBreadth property.
      Property description:
      Specifies the max breadth among the currently visible cells.
      Returns:
      the value of the maxBreadth property
      See Also:
    • maxBreadthProperty

      public ReadOnlyDoubleProperty maxBreadthProperty()
      Specifies the max breadth among the currently visible cells.
      Returns:
      the maxBreadth property
      See Also:
    • getState

      public FlowState<T,C> getState()
      Gets the value of the state property.
      Property description:
      Specifies the current FlowState which describes the state of the viewport. This property is useful to listen to any change happening in the viewport.
      Returns:
      the value of the state property
      See Also:
    • stateProperty

      public ReadOnlyObjectProperty<FlowState<T,C>> stateProperty()
      Specifies the current FlowState which describes the state of the viewport. This property is useful to listen to any change happening in the viewport.
      Returns:
      the state property
      See Also:
    • getLastRange

      public io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer> getLastRange()
      Gets the value of the lastRange property.
      Property description:
      Specifies the last range of displayed items by the viewport as an IntegerRange.
      Returns:
      the value of the lastRange property
      See Also:
    • lastRangeProperty

      public ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> lastRangeProperty()
      Specifies the last range of displayed items by the viewport as an IntegerRange.
      Returns:
      the lastRange property
      See Also:
    • getIndexedCells

      public Map<Integer,C> getIndexedCells()
      Delegate method for FlowState.getCells().
    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class Control
    • getControlCssMetaData

      protected List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Overrides:
      getControlCssMetaData in class Control
    • isFitToBreadth

      public boolean isFitToBreadth()
      Gets the value of the fitToBreadth property.
      Property description:
      Specifies whether cells should be resized to be the same size of the viewport in the opposite direction of the current orientationProperty().

      It is also possible to set this property via CSS with the "-fx-fit-to-breadth" property.

      Returns:
      the value of the fitToBreadth property
      See Also:
    • fitToBreadthProperty

      public io.github.palexdev.mfxcore.base.properties.styleable.StyleableBooleanProperty fitToBreadthProperty()
      Specifies whether cells should be resized to be the same size of the viewport in the opposite direction of the current orientationProperty().

      It is also possible to set this property via CSS with the "-fx-fit-to-breadth" property.

      Returns:
      the fitToBreadth property
      See Also:
    • setFitToBreadth

      public void setFitToBreadth(boolean fitToBreadth)
      Sets the value of the fitToBreadth property.
      Property description:
      Specifies whether cells should be resized to be the same size of the viewport in the opposite direction of the current orientationProperty().

      It is also possible to set this property via CSS with the "-fx-fit-to-breadth" property.

      Parameters:
      fitToBreadth - the value for the fitToBreadth property
      See Also:
    • getCellSize

      public double getCellSize()
      Gets the value of the cellSize property.
      Property description:
      Specifies the cells' size:

      - Orientation.VERTICAL: size -> height

      - Orientation.HORIZONTAL: size -> width

      It is also possible to set this property via CSS with the "-fx-cell-size" property.

      Returns:
      the value of the cellSize property
      See Also:
    • cellSizeProperty

      public io.github.palexdev.mfxcore.base.properties.styleable.StyleableDoubleProperty cellSizeProperty()
      Specifies the cells' size:

      - Orientation.VERTICAL: size -> height

      - Orientation.HORIZONTAL: size -> width

      It is also possible to set this property via CSS with the "-fx-cell-size" property.

      Returns:
      the cellSize property
      See Also:
    • setCellSize

      public void setCellSize(double cellSize)
      Sets the value of the cellSize property.
      Property description:
      Specifies the cells' size:

      - Orientation.VERTICAL: size -> height

      - Orientation.HORIZONTAL: size -> width

      It is also possible to set this property via CSS with the "-fx-cell-size" property.

      Parameters:
      cellSize - the value for the cellSize property
      See Also:
    • getOrientation

      public Orientation getOrientation()
      Gets the value of the orientation property.
      Property description:
      Specifies the orientation of the virtual flow.

      It is also possible to set this property via CSS with the "-fx-orientation" property.

      Returns:
      the value of the orientation property
      See Also:
    • orientationProperty

      public io.github.palexdev.mfxcore.base.properties.styleable.StyleableObjectProperty<Orientation> orientationProperty()
      Specifies the orientation of the virtual flow.

      It is also possible to set this property via CSS with the "-fx-orientation" property.

      Returns:
      the orientation property
      See Also:
    • setOrientation

      public void setOrientation(Orientation orientation)
      Sets the value of the orientation property.
      Property description:
      Specifies the orientation of the virtual flow.

      It is also possible to set this property via CSS with the "-fx-orientation" property.

      Parameters:
      orientation - the value for the orientation property
      See Also:
    • getClipBorderRadius

      public double getClipBorderRadius()
      Gets the value of the clipBorderRadius property.
      Property description:
      Used by the viewport's clip to set its border radius. This is useful when you want to make a rounded virtual flow, this prevents the content from going outside the view.

      This is mostly useful if not using the flow with VirtualScrollPane, this is the same as VirtualScrollPane.clipBorderRadiusProperty().

      Side note: the clip is a Rectangle, now for some fucking reason the rectangle's arcWidth and arcHeight values used to make it round do not act like the border-radius or background-radius properties, instead their value is usually 2 / 2.5 times the latter. So for a border radius of 5 you want this value to be at least 10/13.

      It is also possible to set this property via CSS with the "-fx-clip-border-radius" property.

      Returns:
      the value of the clipBorderRadius property
      See Also:
    • clipBorderRadiusProperty

      public io.github.palexdev.mfxcore.base.properties.styleable.StyleableDoubleProperty clipBorderRadiusProperty()
      Used by the viewport's clip to set its border radius. This is useful when you want to make a rounded virtual flow, this prevents the content from going outside the view.

      This is mostly useful if not using the flow with VirtualScrollPane, this is the same as VirtualScrollPane.clipBorderRadiusProperty().

      Side note: the clip is a Rectangle, now for some fucking reason the rectangle's arcWidth and arcHeight values used to make it round do not act like the border-radius or background-radius properties, instead their value is usually 2 / 2.5 times the latter. So for a border radius of 5 you want this value to be at least 10/13.

      It is also possible to set this property via CSS with the "-fx-clip-border-radius" property.

      Returns:
      the clipBorderRadius property
      See Also:
    • setClipBorderRadius

      public void setClipBorderRadius(double clipBorderRadius)
      Sets the value of the clipBorderRadius property.
      Property description:
      Used by the viewport's clip to set its border radius. This is useful when you want to make a rounded virtual flow, this prevents the content from going outside the view.

      This is mostly useful if not using the flow with VirtualScrollPane, this is the same as VirtualScrollPane.clipBorderRadiusProperty().

      Side note: the clip is a Rectangle, now for some fucking reason the rectangle's arcWidth and arcHeight values used to make it round do not act like the border-radius or background-radius properties, instead their value is usually 2 / 2.5 times the latter. So for a border radius of 5 you want this value to be at least 10/13.

      It is also possible to set this property via CSS with the "-fx-clip-border-radius" property.

      Parameters:
      clipBorderRadius - the value for the clipBorderRadius property
      See Also:
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
    • getViewportManager

      protected ViewportManager<T,C> getViewportManager()
    • getItems

      public ObservableList<T> getItems()
      Gets the value of the items property.
      Property description:
      Specifies the ObservableList used to store the items.

      This is an ObjectProperty so that it can also be bound to other properties.

      Returns:
      the value of the items property
      See Also:
    • itemsProperty

      public ObjectProperty<ObservableList<T>> itemsProperty()
      Specifies the ObservableList used to store the items.

      This is an ObjectProperty so that it can also be bound to other properties.

      Returns:
      the items property
      See Also:
    • setItems

      public void setItems(ObservableList<T> items)
      Sets the value of the items property.
      Property description:
      Specifies the ObservableList used to store the items.

      This is an ObjectProperty so that it can also be bound to other properties.

      Parameters:
      items - the value for the items property
      See Also:
    • getCellFactory

      public Function<T,C> getCellFactory()
      Gets the value of the cellFactory property.
      Property description:
      Specifies the function used to build the cells.
      Returns:
      the value of the cellFactory property
      See Also:
    • cellFactoryProperty

      public io.github.palexdev.mfxcore.base.properties.functional.FunctionProperty<T,C> cellFactoryProperty()
      Specifies the function used to build the cells.
      Returns:
      the cellFactory property
      See Also:
    • setCellFactory

      public void setCellFactory(Function<T,C> cellFactory)
      Sets the value of the cellFactory property.
      Property description:
      Specifies the function used to build the cells.
      Parameters:
      cellFactory - the value for the cellFactory property
      See Also:
    • getVPos

      public double getVPos()
      Gets the value of the vPos property.
      Property description:
      Specifies the vertical position in the viewport.
      Returns:
      the value of the vPos property
      See Also:
    • vPosProperty

      public DoubleProperty vPosProperty()
      Specifies the vertical position in the viewport.
      Returns:
      the vPos property
      See Also:
    • setVPos

      public void setVPos(double vPos)
      Sets the value of the vPos property.
      Property description:
      Specifies the vertical position in the viewport.
      Parameters:
      vPos - the value for the vPos property
      See Also:
    • getHPos

      public double getHPos()
      Gets the value of the hPos property.
      Property description:
      Specifies the horizontal position in the viewport.
      Returns:
      the value of the hPos property
      See Also:
    • hPosProperty

      public DoubleProperty hPosProperty()
      Specifies the horizontal position in the viewport.
      Returns:
      the hPos property
      See Also:
    • setHPos

      public void setHPos(double hPos)
      Sets the value of the hPos property.
      Property description:
      Specifies the horizontal position in the viewport.
      Parameters:
      hPos - the value for the hPos property
      See Also:
    • getOrientationHelper

      public OrientationHelper getOrientationHelper()
      Gets the value of the orientationHelper property.
      Property description:
      The current built helper for the current orientationProperty(), see OrientationHelper.
      Returns:
      the value of the orientationHelper property
      See Also:
    • orientationHelperProperty

      public ReadOnlyObjectProperty<OrientationHelper> orientationHelperProperty()
      The current built helper for the current orientationProperty(), see OrientationHelper.
      Returns:
      the orientationHelper property
      See Also:
    • setOrientationHelper

      protected void setOrientationHelper(OrientationHelper orientationHelper)
      Sets the value of the orientationHelper property.
      Property description:
      The current built helper for the current orientationProperty(), see OrientationHelper.
      Parameters:
      orientationHelper - the value for the orientationHelper property
      See Also:
    • getOrientationHelperFactory

      public Function<Orientation,OrientationHelper> getOrientationHelperFactory()
      Gets the value of the orientationHelperFactory property.
      Property description:
      To allow more customization on how the cells are laid out, the virtual flow allows you to specify a function used to build a OrientationHelper which is responsible for some core actions about cells and layout. This way you could implement your own helper and set it through this factory since the orientationHelperProperty() is intended to be read-only.
      Returns:
      the value of the orientationHelperFactory property
      See Also:
    • orientationHelperFactoryProperty

      public io.github.palexdev.mfxcore.base.properties.functional.FunctionProperty<Orientation,OrientationHelper> orientationHelperFactoryProperty()
      To allow more customization on how the cells are laid out, the virtual flow allows you to specify a function used to build a OrientationHelper which is responsible for some core actions about cells and layout. This way you could implement your own helper and set it through this factory since the orientationHelperProperty() is intended to be read-only.
      Returns:
      the orientationHelperFactory property
      See Also:
    • setOrientationHelperFactory

      public void setOrientationHelperFactory(Function<Orientation,OrientationHelper> orientationHelperFactory)
      Sets the value of the orientationHelperFactory property.
      Property description:
      To allow more customization on how the cells are laid out, the virtual flow allows you to specify a function used to build a OrientationHelper which is responsible for some core actions about cells and layout. This way you could implement your own helper and set it through this factory since the orientationHelperProperty() is intended to be read-only.
      Parameters:
      orientationHelperFactory - the value for the orientationHelperFactory property
      See Also:
    • isNeedsViewportLayout

      public boolean isNeedsViewportLayout()
      Gets the value of the needsViewportLayout property.
      Property description:
      Specifies whether the viewport needs to compute the layout of its content.

      Since this is read-only, layout requests must be sent by using requestViewportLayout().

      Returns:
      the value of the needsViewportLayout property
      See Also:
    • needsViewportLayoutProperty

      public ReadOnlyBooleanProperty needsViewportLayoutProperty()
      Specifies whether the viewport needs to compute the layout of its content.

      Since this is read-only, layout requests must be sent by using requestViewportLayout().

      Returns:
      the needsViewportLayout property
      See Also:
    • setNeedsViewportLayout

      protected void setNeedsViewportLayout(boolean needsViewportLayout)
      Sets the value of the needsViewportLayout property.
      Property description:
      Specifies whether the viewport needs to compute the layout of its content.

      Since this is read-only, layout requests must be sent by using requestViewportLayout().

      Parameters:
      needsViewportLayout - the value for the needsViewportLayout property
      See Also: