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

java.lang.Object
javafx.scene.control.SkinBase<VirtualGrid<T,C>>
io.github.palexdev.virtualizedfx.grid.VirtualGridSkin<T,C>
All Implemented Interfaces:
Skin<VirtualGrid<T,C>>
Direct Known Subclasses:
PaginatedVirtualGridSkin

public class VirtualGridSkin<T,C extends GridCell<T>> extends SkinBase<VirtualGrid<T,C>>
Default skin implementation for VirtualGrid.

There is only one component which is the viewport. This is responsible for containing the currently visible cells and scrolling "a little" to give the illusion of real scrolling, more info here: GridHelper.xPosBinding(), GridHelper.yPosBinding(), GridState.layoutRows().

There are two approaches for the layout:

1) It can be managed manually and request it only when you think it's needed, this is the most performant

2) It can be left to the viewport, this is the most accurate. The performance difference should be negligible though. This skin uses this approach.

The viewport is also clipped to avoid content leaking out of it.

The actual positioning and resizing of the cells is done by GridHelper.layout(Node, double, double) though, this allows the user to create custom implementations of the interface and set is as the grid's helper through VirtualGrid.gridHelperSupplierProperty().

The position of the viewport is controlled through its translateX and translateY properties, two bindings are created by the GridHelper to update the positions when needed (linked above).
  • Field Details

  • Constructor Details

    • VirtualGridSkin

      public VirtualGridSkin(VirtualGrid<T,C> grid)
  • Method Details

    • onItemsChanged

      protected void onItemsChanged(io.github.palexdev.mfxcore.collections.ObservableGrid.Change<T> change)
      The default implementation is responsible for telling the GridManager to process the occurred ObservableGrid.Change and produce eventually a new state.

      This also ensures after the change that the viewport's estimated size is correct by calling GridHelper.computeEstimatedSize().

    • onGridChanged

      protected void onGridChanged(io.github.palexdev.mfxcore.collections.ObservableGrid<T> oldValue, io.github.palexdev.mfxcore.collections.ObservableGrid<T> newValue)
      Tells the grid's components what to do when the items data structure changes. By default, this causes the removal of the itemsChanged listener from the old structure, which is then added to the new one. The estimated size is also recomputed and the viewport reset.
    • onFactoryChanged

      protected void onFactoryChanged(Function<T,C> newValue)
      The default implementation is responsible for resetting the viewport, GridManager.reset(), when the function used to build the cells has been changed.

      Also makes sure to reset the last range properties of GridManager.
      Throws:
      IllegalStateException - if the new function is null
    • onStateChanged

      protected void onStateChanged(GridState<T,C> oldValue, GridState<T,C> newValue)
      The default implementation is responsible for updating the viewport's children when the state changes. The new state though must have the GridState.haveCellsChanged() flag set to true for this to happen. The nodes are collected through GridState.getNodes().
    • onHelperChanged

      protected void onHelperChanged(GridHelper newValue)
      The default implementation is responsible for re-binding the viewport's translateX and translateY properties to the bindings created by the new GridHelper.
      Throws:
      IllegalStateException - if the new helper is null
    • onLayoutRequest

      protected void onLayoutRequest(boolean newValue)
      The default implementation is responsible for calling Parent.requestLayout() on the viewport when the VirtualGrid.needsViewportLayoutProperty() has been set to true.
    • computeMinWidth

      protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computeMinWidth in class SkinBase<VirtualGrid<T,C extends GridCell<T>>>
    • computeMinHeight

      protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computeMinHeight in class SkinBase<VirtualGrid<T,C extends GridCell<T>>>
    • computeMaxWidth

      protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computeMaxWidth in class SkinBase<VirtualGrid<T,C extends GridCell<T>>>
    • computeMaxHeight

      protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)
      Overrides:
      computeMaxHeight in class SkinBase<VirtualGrid<T,C extends GridCell<T>>>
    • dispose

      public void dispose()
      Specified by:
      dispose in interface Skin<T>
      Overrides:
      dispose in class SkinBase<VirtualGrid<T,C extends GridCell<T>>>