Top Description Inners Fields Constructors Methods
org.fxmisc.flowless

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

extends Region
implements Virtualized
Class Inheritance
All Implemented Interfaces
org.fxmisc.flowless.Virtualized
Type Parameters
<T>
the model content that the cell's node renders
<C>
the Cell that can render the model with a javafx.scene.Node.
Imports
java.util.ArrayList, .Collections, .List, .Optional, java.util.function.Function, javafx.beans.property.ObjectProperty, javafx.collections.ObservableList, javafx.css.CssMetaData, .StyleConverter, .Styleable, .StyleableObjectProperty, .StyleableProperty, javafx.geometry.Bounds, .Orientation, .Point2D, javafx.scene.input.ScrollEvent, javafx.scene.layout.Region, javafx.scene.shape.Rectangle, org.reactfx.collection.MemoizationList, org.reactfx.util.Lists, org.reactfx.value.Val, .Var

A VirtualFlow is a memory-efficient viewport that only renders enough of its content to completely fill up the viewport through its Navigator. Based on the viewport's Gravity, it sequentially lays out the javafx.scene.Nodes of the Cells until the viewport is completely filled up or it has no additional cell's nodes to render.

Since this viewport does not fully render all of its content, the scroll values are estimates based on the nodes that are currently displayed in the viewport. If every node that could be rendered is the same width or same height, then the corresponding scroll values (e.g., scrollX or totalX) are accurate

Note

the VirtualFlow does not have scroll bars by default. These can be added by wrapping this object in a VirtualizedScrollPane.

Since the viewport can be used to lay out its content horizontally or vertically, it uses two orientation-agnostic terms to refer to its width and height: "breadth" and "length," respectively. The viewport always lays out its cell's javafx.scene.Nodes from "top-to-bottom" or from "bottom-to-top" (these terms should be understood in reference to the viewport's orientation and Gravity). Thus, its length ("height") is independent as the viewport's bounds are dependent upon its parent's bounds whereas its breadth ("width") is dependent upon its length.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
VirtualFlow.Gravity

Determines how the cells in the viewport should be laid out and where any extra unused space should exist if there are not enough cells to completely fill up the viewport

Field Summary

Modifier and TypeField and Description
private final Var<Double>
private final Var<Double>
private final CellListManager<T, C>
private final CellPositioner<T, C>
private final StyleableObjectProperty<VirtualFlow.Gravity>
private static final CssMetaData<VirtualFlow<T, C extends Cell<T, ?>>, VirtualFlow.Gravity>
private final ObservableList<T>
private final Var<Double>
private final OrientationHelper
private final SizeTracker
private static final List<CssMetaData<? extends Styleable, ?>>
Inherited from javafx.scene.layout.Region:
USE_COMPUTED_SIZEUSE_PREF_SIZE

Constructor Summary

AccessConstructor and Description
private
VirtualFlow(ObservableList<T> items, Function<? super T, ? extends C> cellFactory, OrientationHelper orientation, VirtualFlow.Gravity gravity)

Method Summary

Modifier and TypeMethod and Description
public Var<Double>
public Bounds
cellToViewport(C cell, Bounds bounds)

public Point2D
cellToViewport(C cell, Point2D point)

public Point2D
cellToViewport(C cell, double x, double y)

private double
protected final double
computePrefHeight(double width)

Overrides javafx.scene.layout.Region.computePrefHeight.

Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy.

private double
computePrefLength(double breadth)

protected final double
computePrefWidth(double height)

Overrides javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height.

public static <T, C extends Cell<T, ?>> VirtualFlow<T, C>
createHorizontal(ObservableList<T> items, Function<? super T, ? extends C> cellFactory)

Creates a viewport that lays out content horizontally from left to right

public static <T, C extends Cell<T, ?>> VirtualFlow<T, C>
createHorizontal(ObservableList<T> items, Function<? super T, ? extends C> cellFactory, VirtualFlow.Gravity gravity)

Creates a viewport that lays out content horizontally

public static <T, C extends Cell<T, ?>> VirtualFlow<T, C>
createVertical(ObservableList<T> items, Function<? super T, ? extends C> cellFactory)

Creates a viewport that lays out content vertically from top to bottom

public static <T, C extends Cell<T, ?>> VirtualFlow<T, C>
createVertical(ObservableList<T> items, Function<? super T, ? extends C> cellFactory, VirtualFlow.Gravity gravity)

Creates a viewport that lays out content vertically from top to bottom

public void
public Var<Double>
public Var<Double>
public C

Returns:

Cell for the given item. The cell will be valid only until the next layout pass. It should therefore not be stored. It is intended to be used for measurement purposes only.
getCell
(int itemIndex)

If the item is out of view, instantiates a new cell for the item.

public Optional<C>
getCellIfVisible(int itemIndex)

This method calls layout() as a side-effect to insure that the VirtualFlow is up-to-date in light of any changes

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

Hides javafx.scene.layout.Region.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public final Orientation
getContentBias()

Overrides javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes.

public List<CssMetaData<? extends Styleable, ?>>
getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

public int

Returns:

The index of the first visible cell
getFirstVisibleIndex
()

Get the index of the first visible cell (at the time of the last layout).

public VirtualFlow.Gravity
public int

Returns:

The index of the last visible cell
getLastVisibleIndex
()

Get the index of the last visible cell (at the time of the last layout).

public ObjectProperty<VirtualFlow.Gravity>
gravityProperty()

The gravity of the virtual flow.

public VirtualFlowHit<C>

Returns:

hit info containing the cell that was hit and coordinates relative to the cell. If the hit was before the cells (i.e. above a vertical flow content or left of a horizontal flow content), returns a hit before cells containing offset from the top left corner of the content. If the hit was after the cells (i.e. below a vertical flow content or right of a horizontal flow content), returns a hit after cells containing offset from the top right corner of the content of a horizontal flow or bottom left corner of the content of a vertical flow.
hit
(double
x offset from the left edge of the viewport
x
,
double
y offset from the top edge of the viewport
y
)

Hits this virtual flow at the given coordinates.

private void
jumpToAbsolutePosition(double pixels)

protected void
layoutChildren()

Overrides javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent.

public Var<Double>
pack-priv void
scrollBreadth(double deltaBreadth)

pack-priv void
scrollLength(double deltaLength)

public void
scrollXBy(double
positive value scrolls right, negative value scrolls left
deltaX
)

Implements org.fxmisc.flowless.Virtualized.scrollXBy.

Scroll the content horizontally by the given amount.

public void
scrollXToPixel(double
- the pixel position to which to scroll
pixel
)

Implements org.fxmisc.flowless.Virtualized.scrollXToPixel.

Scroll the content horizontally to the pixel

public void
scrollYBy(double
positive value scrolls down, negative value scrolls up
deltaY
)

Implements org.fxmisc.flowless.Virtualized.scrollYBy.

Scroll the content vertically by the given amount.

public void
scrollYToPixel(double
- the pixel position to which to scroll
pixel
)

Implements org.fxmisc.flowless.Virtualized.scrollYToPixel.

Scroll the content vertically to the pixel

pack-priv void
setBreadthOffset(double pixels)

public void
pack-priv void
setLengthOffset(double pixels)

public void
show(double
See OrientationHelper and its implementations for explanation on what the offset means based on which implementation is used.
viewportOffset
)

Forces the viewport to acts as though it scrolled from 0 to viewportOffset)

Note

the viewport makes an educated guess as to which cell is actually at viewportOffset if the viewport's entire content was completely rendered.

public void
show(int itemIdx)

Forces the viewport to show the given item by "scrolling" to it

public void
show(int itemIndex, Bounds region)

Forces the viewport to show the given item by "scrolling" to it and then further "scrolling," so that the region is visible, in one layout call (e.g., this method does not "scroll" twice).

public void
showAsFirst(int itemIdx)

Forces the viewport to show the given item as the first visible item as determined by its Gravity.

public void
showAsLast(int itemIdx)

Forces the viewport to show the given item as the last visible item as determined by its Gravity.

public void
showAtOffset(int itemIdx, double
the offset value as determined by the viewport's OrientationHelper.
offset
)

Forces the viewport to show the given item by "scrolling" to it and then further "scrolling" by offset in one layout call (e.g., this method does not "scroll" twice)

private void
showBreadthRegion(double fromX, double toX)

public Val<Double>
public Val<Double>
public Val<Double>
public Val<Double>
public ObservableList<C>
visibleCells()

This method calls layout() as a side-effect to insure that the VirtualFlow is up-to-date in light of any changes

Inherited from javafx.scene.layout.Region:
backgroundPropertyborderPropertycacheShapePropertycenterShapePropertycomputeMaxHeightcomputeMaxWidthcomputeMinHeightcomputeMinWidthgetBackgroundgetBordergetHeightgetInsetsgetMaxHeightgetMaxWidthgetMinHeightgetMinWidthgetOpaqueInsetsgetPaddinggetPrefHeightgetPrefWidthgetShapegetUserAgentStylesheetgetWidthheightPropertyinsetsPropertyisCacheShapeisCenterShapeisResizableisScaleShapeisSnapToPixellayoutInArealayoutInArealayoutInArealayoutInAreamaxHeightmaxHeightPropertymaxWidthmaxWidthPropertyminHeightminHeightPropertyminWidthminWidthPropertyopaqueInsetsPropertypaddingPropertypositionInAreapositionInAreaprefHeightprefHeightPropertyprefWidthprefWidthPropertyresizescaleShapePropertysetBackgroundsetBordersetCacheShapesetCenterShapesetHeightsetMaxHeightsetMaxSizesetMaxWidthsetMinHeightsetMinSizesetMinWidthsetOpaqueInsetssetPaddingsetPrefHeightsetPrefSizesetPrefWidthsetScaleShapesetShapesetSnapToPixelsetWidthshapePropertysnappedBottomInsetsnappedLeftInsetsnappedRightInsetsnappedTopInsetsnapPositionsnapPositionXsnapPositionYsnapSizesnapSizeXsnapSizeYsnapSpacesnapSpaceXsnapSpaceYsnapToPixelPropertywidthProperty

Field Detail

breadthOffsetback to summary
private final Var<Double> breadthOffset
breadthOffset0back to summary
private final Var<Double> breadthOffset0
cellListManagerback to summary
private final CellListManager<T, C> cellListManager
cellPositionerback to summary
private final CellPositioner<T, C> cellPositioner
gravityback to summary
private final StyleableObjectProperty<VirtualFlow.Gravity> gravity
GRAVITYback to summary
private static final CssMetaData<VirtualFlow<T, C extends Cell<T, ?>>, VirtualFlow.Gravity> GRAVITY
Annotations
@SuppressWarnings:unchecked
itemsback to summary
private final ObservableList<T> items
lengthOffsetEstimateback to summary
private final Var<Double> lengthOffsetEstimate
orientationback to summary
private final OrientationHelper orientation
sizeTrackerback to summary
private final SizeTracker sizeTracker
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

VirtualFlowback to summary
private VirtualFlow(ObservableList<T> items, Function<? super T, ? extends C> cellFactory, OrientationHelper orientation, VirtualFlow.Gravity gravity)

Method Detail

breadthOffsetPropertyback to summary
public Var<Double> breadthOffsetProperty()
cellToViewportback to summary
public Bounds cellToViewport(C cell, Bounds bounds)
cellToViewportback to summary
public Point2D cellToViewport(C cell, Point2D point)
cellToViewportback to summary
public Point2D cellToViewport(C cell, double x, double y)
computePrefBreadthback to summary
private double computePrefBreadth()
computePrefHeightback to summary
protected final double computePrefHeight(double width)

Overrides javafx.scene.layout.Region.computePrefHeight.

Doc from javafx.scene.layout.Region.computePrefHeight.

Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.

Annotations
@Override
computePrefLengthback to summary
private double computePrefLength(double breadth)
computePrefWidthback to summary
protected final double computePrefWidth(double height)

Overrides javafx.scene.layout.Region.computePrefWidth.

Doc from javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a VERTICAL content bias, then the height parameter can be ignored.

Annotations
@Override
createHorizontalback to summary
public static <T, C extends Cell<T, ?>> VirtualFlow<T, C> createHorizontal(ObservableList<T> items, Function<? super T, ? extends C> cellFactory)

Creates a viewport that lays out content horizontally from left to right

createHorizontalback to summary
public static <T, C extends Cell<T, ?>> VirtualFlow<T, C> createHorizontal(ObservableList<T> items, Function<? super T, ? extends C> cellFactory, VirtualFlow.Gravity gravity)

Creates a viewport that lays out content horizontally

createVerticalback to summary
public static <T, C extends Cell<T, ?>> VirtualFlow<T, C> createVertical(ObservableList<T> items, Function<? super T, ? extends C> cellFactory)

Creates a viewport that lays out content vertically from top to bottom

createVerticalback to summary
public static <T, C extends Cell<T, ?>> VirtualFlow<T, C> createVertical(ObservableList<T> items, Function<? super T, ? extends C> cellFactory, VirtualFlow.Gravity gravity)

Creates a viewport that lays out content vertically from top to bottom

disposeback to summary
public void dispose()
estimatedScrollXPropertyback to summary
public Var<Double> estimatedScrollXProperty()

Implements org.fxmisc.flowless.Virtualized.estimatedScrollXProperty.

Annotations
@Override
estimatedScrollYPropertyback to summary
public Var<Double> estimatedScrollYProperty()

Implements org.fxmisc.flowless.Virtualized.estimatedScrollYProperty.

Annotations
@Override
getCellback to summary
public C getCell(int itemIndex)

If the item is out of view, instantiates a new cell for the item. The returned cell will be properly sized, but not properly positioned relative to the cells in the viewport, unless it is itself in the viewport.

Returns:C

Cell for the given item. The cell will be valid only until the next layout pass. It should therefore not be stored. It is intended to be used for measurement purposes only.

getCellIfVisibleback to summary
public Optional<C> getCellIfVisible(int itemIndex)

This method calls layout() as a side-effect to insure that the VirtualFlow is up-to-date in light of any changes

getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.layout.Region.getClassCssMetaData.

Doc from javafx.scene.layout.Region.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

getContentBiasback to summary
public final Orientation getContentBias()

Overrides javafx.scene.Node.getContentBias.

Doc from javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes. If the node type has no bias, returns null. If the node is resizable and it's height depends on its width, returns HORIZONTAL, else if its width depends on its height, returns VERTICAL.

Resizable subclasses should override this method to return an appropriate value.

Annotations
@Override
getCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

Doc from javafx.scene.layout.Region.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

Annotations
@Override
getFirstVisibleIndexback to summary
public int getFirstVisibleIndex()

Get the index of the first visible cell (at the time of the last layout).

Returns:int

The index of the first visible cell

getGravityback to summary
public VirtualFlow.Gravity getGravity()
getLastVisibleIndexback to summary
public int getLastVisibleIndex()

Get the index of the last visible cell (at the time of the last layout).

Returns:int

The index of the last visible cell

gravityPropertyback to summary
public ObjectProperty<VirtualFlow.Gravity> gravityProperty()

The gravity of the virtual flow. When there are not enough cells to fill the full height (vertical virtual flow) or width (horizontal virtual flow), the cells are placed either at the front (vertical: top, horizontal: left), or rear (vertical: bottom, horizontal: right) of the virtual flow, depending on the value of the gravity property. The gravity can also be styled in CSS, using the "-flowless-gravity" property, for example:

.virtual-flow { -flowless-gravity: rear; }
hitback to summary
public VirtualFlowHit<C> hit(double x, double y)

Hits this virtual flow at the given coordinates.

Parameters
x:double

x offset from the left edge of the viewport

y:double

y offset from the top edge of the viewport

Returns:VirtualFlowHit<C>

hit info containing the cell that was hit and coordinates relative to the cell. If the hit was before the cells (i.e. above a vertical flow content or left of a horizontal flow content), returns a hit before cells containing offset from the top left corner of the content. If the hit was after the cells (i.e. below a vertical flow content or right of a horizontal flow content), returns a hit after cells containing offset from the top right corner of the content of a horizontal flow or bottom left corner of the content of a vertical flow.

jumpToAbsolutePositionback to summary
private void jumpToAbsolutePosition(double pixels)
layoutChildrenback to summary
protected void layoutChildren()

Overrides javafx.scene.Parent.layoutChildren.

Doc from javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent. By default it will only set the size of managed, resizable content to their preferred sizes and does not do any node positioning.

Subclasses should override this function to layout content as needed.

Annotations
@Override
lengthOffsetEstimatePropertyback to summary
public Var<Double> lengthOffsetEstimateProperty()
scrollBreadthback to summary
pack-priv void scrollBreadth(double deltaBreadth)
scrollLengthback to summary
pack-priv void scrollLength(double deltaLength)
scrollXByback to summary
public void scrollXBy(double deltaX)

Implements org.fxmisc.flowless.Virtualized.scrollXBy.

Scroll the content horizontally by the given amount.

Parameters
deltaX:double

positive value scrolls right, negative value scrolls left

Annotations
@Override
scrollXToPixelback to summary
public void scrollXToPixel(double pixel)

Implements org.fxmisc.flowless.Virtualized.scrollXToPixel.

Scroll the content horizontally to the pixel

Parameters
pixel:double

- the pixel position to which to scroll

Annotations
@Override
scrollYByback to summary
public void scrollYBy(double deltaY)

Implements org.fxmisc.flowless.Virtualized.scrollYBy.

Scroll the content vertically by the given amount.

Parameters
deltaY:double

positive value scrolls down, negative value scrolls up

Annotations
@Override
scrollYToPixelback to summary
public void scrollYToPixel(double pixel)

Implements org.fxmisc.flowless.Virtualized.scrollYToPixel.

Scroll the content vertically to the pixel

Parameters
pixel:double

- the pixel position to which to scroll

Annotations
@Override
setBreadthOffsetback to summary
pack-priv void setBreadthOffset(double pixels)
setGravityback to summary
public void setGravity(VirtualFlow.Gravity gravity)
setLengthOffsetback to summary
pack-priv void setLengthOffset(double pixels)
showback to summary
public void show(double viewportOffset)

Forces the viewport to acts as though it scrolled from 0 to viewportOffset)

Note

the viewport makes an educated guess as to which cell is actually at viewportOffset if the viewport's entire content was completely rendered.

Parameters
viewportOffset:double

See OrientationHelper and its implementations for explanation on what the offset means based on which implementation is used.

showback to summary
public void show(int itemIdx)

Forces the viewport to show the given item by "scrolling" to it

showback to summary
public void show(int itemIndex, Bounds region)

Forces the viewport to show the given item by "scrolling" to it and then further "scrolling," so that the region is visible, in one layout call (e.g., this method does not "scroll" twice).

showAsFirstback to summary
public void showAsFirst(int itemIdx)

Forces the viewport to show the given item as the first visible item as determined by its Gravity.

showAsLastback to summary
public void showAsLast(int itemIdx)

Forces the viewport to show the given item as the last visible item as determined by its Gravity.

showAtOffsetback to summary
public void showAtOffset(int itemIdx, double offset)

Forces the viewport to show the given item by "scrolling" to it and then further "scrolling" by offset in one layout call (e.g., this method does not "scroll" twice)

Parameters
offset:double

the offset value as determined by the viewport's OrientationHelper.

showBreadthRegionback to summary
private void showBreadthRegion(double fromX, double toX)
totalBreadthEstimatePropertyback to summary
public Val<Double> totalBreadthEstimateProperty()
totalHeightEstimatePropertyback to summary
public Val<Double> totalHeightEstimateProperty()

Implements org.fxmisc.flowless.Virtualized.totalHeightEstimateProperty.

Annotations
@Override
totalLengthEstimatePropertyback to summary
public Val<Double> totalLengthEstimateProperty()
totalWidthEstimatePropertyback to summary
public Val<Double> totalWidthEstimateProperty()

Implements org.fxmisc.flowless.Virtualized.totalWidthEstimateProperty.

Annotations
@Override
visibleCellsback to summary
public ObservableList<C> visibleCells()

This method calls layout() as a side-effect to insure that the VirtualFlow is up-to-date in light of any changes

org.fxmisc.flowless back to summary

public final Enum VirtualFlow.Gravity

extends Enum<VirtualFlow.Gravity>
Class Inheritance

Determines how the cells in the viewport should be laid out and where any extra unused space should exist if there are not enough cells to completely fill up the viewport

Field Summary

Modifier and TypeField and Description
public static final VirtualFlow.Gravity
FRONT

If using a vertical viewport, lays out the content from top-to-bottom.

public static final VirtualFlow.Gravity
REAR

If using a vertical viewport, lays out the content from bottom-to-top.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static VirtualFlow.Gravity
public static VirtualFlow.Gravity[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FRONTback to summary
public static final VirtualFlow.Gravity FRONT

If using a vertical viewport, lays out the content from top-to-bottom. The first visible item will appear at the top and the last visible item (or unused space) towards the bottom.

If using a horizontal viewport, lays out the content from left-to-right. The first visible item will appear at the left and the last visible item (or unused space) towards the right.

REARback to summary
public static final VirtualFlow.Gravity REAR

If using a vertical viewport, lays out the content from bottom-to-top. The first visible item will appear at the bottom and the last visible item (or unused space) towards the top.

If using a horizontal viewport, lays out the content from right-to-left. The first visible item will appear at the right and the last visible item (or unused space) towards the left.

Constructor Detail

Gravityback to summary
private Gravity()

Method Detail

valueOfback to summary
public static VirtualFlow.Gravity valueOf(String name)
valuesback to summary
public static VirtualFlow.Gravity[] values()