Class VFXGridSkin<T, C extends VFXCell<T>>
VFXGrid, extends MFXSkinBase and expects behaviors of type
VFXGridManager.
The layout is quite simple: there is just one node, called the 'viewport', that is the Pane resposnible for
containing and laying out the cells. Needless to say, the layout strategy is custom, and it's defined in the
layout() method.
Compared to other virtualized components' skin, this implements a rather unique feature. It allows you, by setting the
VFXGrid.alignmentProperty(), to change the x and y coordinates of the viewport node. This is especially useful
if you want the content to be centered and in combination with VFXGrid.autoArrange(int) (think about a gallery, for example).
VFXGridManager.
Read this addListeners() to check which changes are handled.
Last but not least, by design, this skin makes the component always be at least 100px tall and wide. You can change this
by overriding the DEFAULT_SIZE variable.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds listeners on the component's properties which need to produce a newVFXGridStateupon changing.protected doublecomputeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) protected doublecomputeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) voiddispose()protected VFXGridManager<T, C> protected voidlayout()Core method responsible for resizing and positioning cells in the viewport.protected voidlayoutChildren(double x, double y, double w, double h) protected voidonLayoutCompleted(boolean done) This method is crucial because it resets theVFXGrid.needsViewportLayoutProperty()to false.Methods inherited from class io.github.palexdev.mfxcore.controls.MFXSkinBase
events, getBehaviorAs, getControl, listeners, registerBehaviorMethods inherited from class javafx.scene.control.SkinBase
computeBaselineOffset, computeMaxHeight, computeMaxWidth, computePrefHeight, computePrefWidth, consumeMouseEvents, executeAccessibleAction, getChildren, getClassCssMetaData, getCssMetaData, getNode, getSkinnable, layoutInArea, layoutInArea, layoutInArea, positionInArea, positionInArea, pseudoClassStateChanged, queryAccessibleAttribute, registerChangeListener, registerInvalidationListener, registerListChangeListener, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, unregisterChangeListeners, unregisterInvalidationListeners, unregisterListChangeListeners
-
Field Details
-
viewport
-
DEFAULT_SIZE
protected double DEFAULT_SIZE
-
-
Constructor Details
-
VFXGridSkin
-
-
Method Details
-
addListeners
protected void addListeners()Adds listeners on the component's properties which need to produce a newVFXGridStateupon changing.Here's the list:
- Listener on
VFXGrid.stateProperty(), this is crucial to update the viewport's children and invokeVFXGrid.requestViewportLayout()ifVFXGridState.haveCellsChanged()istrue- Listener on
VFXGrid.needsViewportLayoutProperty(), this is crucial because invokeslayout()- Listener on
VFXGrid.helperProperty(), this is crucial because it's responsible for binding the viewport's translate properties to theVFXContainerHelper.viewportPositionProperty()By translating the viewport, we give the illusion of scrolling (virtual scrolling)- Listener on
Region.widthProperty(), will invokeVFXGridManager.onGeometryChanged()- Listener on
VFXGrid.helperProperty(), will invokeVFXGridManager.onGeometryChanged()- Listener on
VFXGrid.bufferSizeProperty(), will invokeVFXGridManager.onGeometryChanged(). Yes, it is enough to threat this change as a geometry change to avoid code duplication-Listener on
VFXGrid.vPosProperty(), will invokeVFXGridManager.onPositionChanged(Orientation)withOrientation.VERTICALas parameter-Listener on
VFXGrid.hPosProperty(), will invokeVFXGridManager.onPositionChanged(Orientation)withOrientation.HORIZONTALas parameter- Listener on
VFXGrid.columnsNumProperty(), will invokeVFXGridManager.onColumnsNumChanged()- Listener on
VFXGrid.getCellFactory(), will invokeVFXGridManager.onCellFactoryChanged()- Listener on
VFXGrid.cellSizeProperty(), will invokeVFXGridManager.onCellSizeChanged()- Listener on
VFXGrid.vSpacingProperty(), will invokeVFXGridManager.onSpacingChanged()- Listener on
VFXGrid.hSpacingProperty(), will invokeVFXGridManager.onSpacingChanged()- Listener on
VFXGrid.itemsProperty(), will invokeVFXGridManager.onItemsChanged()- Listener on
VFXGrid.alignmentProperty(), will invokeParent.requestLayout() -
layout
protected void layout()Core method responsible for resizing and positioning cells in the viewport. This method will not execute if the layout was not requested,VFXGrid.needsViewportLayoutProperty()is false, or if theVFXGrid.stateProperty()isVFXGridState.INVALID.In any case, at the end of the method,
Cells are retrieved from the current grid's state, given by theonLayoutCompleted(boolean)will be called.VFXGrid.stateProperty(). The iteration over each row and column gives us all the indexes to retrieve the cells fromVFXGridState.getCellsByIndex(). For the actual layout, however, we use two counters because the layout is 'absolute'. Meaning that the row and column indexes are irrelevant for the cell's position, we just care about which comes before/after, above/below. Make sure to also readVFXGridStateto understand how indexes are managed for theVFXGrid. In other words, it doesn't matter whether our range is [1, 5] or [4, 6] or whatever, the layout index will always start from 0 and increment towards the end of the range.The layout is performed by
VFXGridHelper.layout(int, int, VFXCell), the two aforementioned counters are passed as arguments.Little example: For a rows range of [2, 7] and columns range of [2, 7] The first cell's coordinates are [2, 2], but its layout coordinates are [0, 0] The second cell's coordinates are [2, 3], but its layout coordinates are [0, 1] ...and so on- See Also:
-
onLayoutCompleted
protected void onLayoutCompleted(boolean done) This method is crucial because it resets theVFXGrid.needsViewportLayoutProperty()to false. If you override this method or thelayout(), remember to call this!- Parameters:
done- this parameter can be useful to overriders as it gives information on whether thelayout()was executed correctly
-
computeMinWidth
-
computeMinHeight
-
layoutChildren
-
dispose
-
getBehavior
-