Class VFXCellBase<T>

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
io.github.palexdev.mfxcore.controls.MFXControl
io.github.palexdev.virtualizedfx.cells.VFXCellBase<T>
All Implemented Interfaces:
io.github.palexdev.mfxcore.behavior.WithBehavior, io.github.palexdev.mfxcore.controls.MFXSkinnable, io.github.palexdev.mfxcore.controls.MFXStyleable, VFXCell<T>, javafx.css.Styleable, javafx.event.EventTarget, javafx.scene.control.Skinnable
Direct Known Subclasses:
VFXSimpleCell, VFXSimpleTableCell

public abstract class VFXCellBase<T> extends io.github.palexdev.mfxcore.controls.MFXControl implements VFXCell<T>
The basic and typical implementation of a cell in JavaFX is a cell with just two properties: one to keep track of the cell's index and the other to keep track of the displayed item.

This abstract class is a good starting point to implement concrete, usable cells.

Unusually, this enforces the structuring of cells as specified by the MVC pattern. In fact, this extends MFXControl, expects behaviors of type CellBaseBehavior and doesn't come with a default skin.

The idea is to make the skin implementation responsible for how data is represented (a String, a Node, processing, etc.). A downside of such approach is that for some reason, users are a bit reluctant in making or customizing skins, however, I can assure you it's no big deal at all. Also, never forget that VirtualizedFX containers do not enforce the usage of VFXCellBase or any of its implementations, if you are more comfortable using a simpler cell system you are free do it.

The default style class is 'cell-base'.

A word on performance As also stated in the javadocs of updateIndex(int) and updateItem(Object), to simplify the internal management of cells, there is no 100% guarantee that updates are called with a different index/item from what the cell currently has. For this reason, here's how you should implement the 'rendering' operations:

You probably want to execute some operations when the index or item change by listening to the respective properties, indexProperty() and itemProperty(). This means that your operations will run only and only if the property fires an invalidation/change event. In this base class the updateIndex(int) and updateItem(Object) methods are implemented naively, because we work on generic items, we don't know the model, which means that they update the respective properties without any check.

- For the indexProperty() it's tricky: the JVM caches Integers between -128 and 127, which means that the '==' operator only works in that range; for larger datasets, you may want to override the updateIndex(int) method to actually check for equality.

For the itemProperty() it's the same concept. If you know the model, you may want to perform some equality check in the updateItem(Object) method to avoid useless updates. For example, if in your dataset there are two Person objects with the same attributes but different references you may want to update the property (so that the reference is correct) but not perform any operation that strictly depends on the attributes (if a label displays the attributes, there's no need to re-compute the text)

See Also:
  • Property Summary

    Properties
    Type
    Property
    Description
    io.github.palexdev.mfxcore.base.properties.styleable.StyleableObjectProperty<javafx.geometry.Pos>
    Specifies the alignment of the displayed data.
    javafx.beans.property.ObjectProperty<javafx.scene.Node>
    Allows adding a Node to the cell.
    javafx.beans.property.IntegerProperty
    Specifies the cell's index.
    javafx.beans.property.ObjectProperty<T>
    Specifies the cell's item.

    Properties inherited from class io.github.palexdev.mfxcore.controls.MFXControl

    behaviorFactory, skinFactory

    Properties inherited from class javafx.scene.control.Control

    contextMenu, skin, tooltip

    Properties inherited from class javafx.scene.layout.Region

    background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width

    Properties inherited from class javafx.scene.Parent

    needsLayout

    Properties inherited from class javafx.scene.Node

    accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible

    Properties inherited from interface javafx.scene.control.Skinnable

    skin
  • Field Summary

    Fields inherited from class javafx.scene.layout.Region

    USE_COMPUTED_SIZE, USE_PREF_SIZE

    Fields inherited from class javafx.scene.Node

    BASELINE_OFFSET_SAME_AS_HEIGHT
  • Constructor Summary

    Constructors
    Constructor
    Description
    VFXCellBase(T item)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    io.github.palexdev.mfxcore.base.properties.styleable.StyleableObjectProperty<javafx.geometry.Pos>
    Specifies the alignment of the displayed data.
    protected VFXContext<T>
     
    Supplier<io.github.palexdev.mfxcore.behavior.MFXBehavior<? extends javafx.scene.Node>>
     
     
    void
    Automatically called by the framework when the cell is not needed anymore.
    javafx.geometry.Pos
    Gets the value of the alignment property.
    static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>>
     
    protected List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>>
     
    javafx.scene.Node
    Gets the value of the graphic property.
    int
    Gets the value of the index property.
    Gets the value of the item property.
    javafx.beans.property.ObjectProperty<javafx.scene.Node>
    Allows adding a Node to the cell.
    javafx.beans.property.IntegerProperty
    Specifies the cell's index.
    javafx.beans.property.ObjectProperty<T>
    Specifies the cell's item.
    void
    Called when a cell is created and associated with a VFXContainer.
    void
    setAlignment(javafx.geometry.Pos alignment)
    Sets the value of the alignment property.
    void
    setGraphic(javafx.scene.Node graphic)
    Sets the value of the graphic property.
    void
    setIndex(int index)
    Sets the value of the index property.
    void
    setItem(T item)
    Sets the value of the item property.
    javafx.scene.Node
    Converts the cell to a Node.
    void
    updateIndex(int index)
    Automatically called by the framework when the cell needs to update its index.
    void
    updateItem(T item)
    Automatically called by the framework when the cell needs to update its item.

    Methods inherited from class io.github.palexdev.mfxcore.controls.MFXControl

    behaviorFactoryProperty, buildSkin, createDefaultSkin, getBehavior, preloadSkin, skinFactoryProperty

    Methods inherited from class javafx.scene.control.Control

    computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getContextMenu, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty

    Methods inherited from class javafx.scene.layout.Region

    backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty

    Methods inherited from class javafx.scene.Parent

    getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds

    Methods inherited from class javafx.scene.Node

    accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, requestFocusTraversal, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface io.github.palexdev.mfxcore.controls.MFXSkinnable

    defaultSkinFactory, getSkinFactory, setDefaultSkinFactory, setSkinFactory

    Methods inherited from interface io.github.palexdev.mfxcore.controls.MFXStyleable

    setDefaultStyleClasses

    Methods inherited from interface javafx.scene.control.Skinnable

    getSkin, setSkin, skinProperty

    Methods inherited from interface javafx.css.Styleable

    getCssMetaData, getId, getPseudoClassStates, getStyle, getStyleableNode, getStyleableParent, getStyleClass, getTypeSelector

    Methods inherited from interface VFXCell

    afterLayout, beforeLayout, onCache, onDeCache

    Methods inherited from interface io.github.palexdev.mfxcore.behavior.WithBehavior

    getBehaviorFactory, setBehaviorFactory, setDefaultBehaviorFactory
  • Property Details

    • alignment

      public io.github.palexdev.mfxcore.base.properties.styleable.StyleableObjectProperty<javafx.geometry.Pos> alignmentProperty
      Specifies the alignment of the displayed data. How this is used depends on the skin implementation.

      This is settable via CSS with the "-fx-alignment" property.

      See Also:
    • index

      public javafx.beans.property.IntegerProperty indexProperty
      Specifies the cell's index.
      See Also:
    • item

      public javafx.beans.property.ObjectProperty<T> itemProperty
      Specifies the cell's item.
      See Also:
    • graphic

      public javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty
      Allows adding a Node to the cell. To be precise, how this property is used depends on the skin implementation.
      See Also:
  • Constructor Details

    • VFXCellBase

      public VFXCellBase(T item)
  • Method Details

    • defaultStyleClasses

      public List<String> defaultStyleClasses()
      Specified by:
      defaultStyleClasses in interface io.github.palexdev.mfxcore.controls.MFXStyleable
    • defaultBehaviorFactory

      public Supplier<io.github.palexdev.mfxcore.behavior.MFXBehavior<? extends javafx.scene.Node>> defaultBehaviorFactory()
      Specified by:
      defaultBehaviorFactory in interface io.github.palexdev.mfxcore.behavior.WithBehavior
    • toNode

      public javafx.scene.Node toNode()
      Description copied from interface: VFXCell
      Converts the cell to a Node.

      Implementations can check these examples:

      
      // Example 1
      public class SimpleCell<T> extends Label implements VFXCell<T> {
          ...
          ...
      
          @Override
          public Node toNode() {
              return this;
          }
      }
      
      // Example 2
      public class SimpleCell<T> implements VFXCell<T> {
          private final Label label = ...;
          ...
          ...
      
          @Override
          public Node toNode() {
              return label;
          }
      }
      
      
      Specified by:
      toNode in interface VFXCell<T>
    • updateItem

      public void updateItem(T item)
      Automatically called by the framework when the cell needs to update its item.

      Note though, that there is no 100% guarantee the new given item is different from the current one. If you have some operations happen when the item changes, for performance reasons, I recommend you to first ensure the new item really is different.

      See VFXCellBase and read how this is handled.

      Updates the itemProperty().
      Specified by:
      updateItem in interface VFXCell<T>
    • updateIndex

      public void updateIndex(int index)
      Automatically called by the framework when the cell needs to update its index.

      Note though, that there is no 100% guarantee the new given index is different from the current one. If you have some operations happen when the index changes, for performance reasons, I recommend you to first ensure the new index really is different.

      See VFXCellBase and read how this is handled.

      Updates the indexProperty().
      Specified by:
      updateIndex in interface VFXCell<T>
    • onCreated

      public void onCreated(VFXContext<T> context)
      Called when a cell is created and associated with a VFXContainer. This method provides the cell with a reference to its container, along with additional services that the cell may use to extend its functionalities.

      It's up to the implementation to decide how to use it.

      Note: This method should only be called by the container that created this cell. Calling it with a different or incorrect container instance may lead to inconsistent behavior or errors.

      The implementation stores the context and prevents overwrites once the instance is set (not null anymore).
      Specified by:
      onCreated in interface VFXCell<T>
      See Also:
    • dispose

      public void dispose()
      Description copied from interface: VFXCell
      Automatically called by the framework when the cell is not needed anymore. The user can override this to perform some operations before the cell is GCd.
      Specified by:
      dispose in interface VFXCell<T>
    • getAlignment

      public javafx.geometry.Pos getAlignment()
      Gets the value of the alignment property.
      Property description:
      Specifies the alignment of the displayed data. How this is used depends on the skin implementation.

      This is settable via CSS with the "-fx-alignment" property.

      Returns:
      the value of the alignment property
      See Also:
    • alignmentProperty

      public io.github.palexdev.mfxcore.base.properties.styleable.StyleableObjectProperty<javafx.geometry.Pos> alignmentProperty()
      Specifies the alignment of the displayed data. How this is used depends on the skin implementation.

      This is settable via CSS with the "-fx-alignment" property.

      Returns:
      the alignment property
      See Also:
    • setAlignment

      public void setAlignment(javafx.geometry.Pos alignment)
      Sets the value of the alignment property.
      Property description:
      Specifies the alignment of the displayed data. How this is used depends on the skin implementation.

      This is settable via CSS with the "-fx-alignment" property.

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

      public static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> getClassCssMetaData()
    • getControlCssMetaData

      protected List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> getControlCssMetaData()
      Overrides:
      getControlCssMetaData in class javafx.scene.control.Control
    • context

      protected VFXContext<T> context()
      See Also:
    • getIndex

      public int getIndex()
      Gets the value of the index property.
      Property description:
      Specifies the cell's index.
      Returns:
      the value of the index property
      See Also:
    • indexProperty

      public javafx.beans.property.IntegerProperty indexProperty()
      Specifies the cell's index.
      Returns:
      the index property
      See Also:
    • setIndex

      public void setIndex(int index)
      Sets the value of the index property.
      Property description:
      Specifies the cell's index.
      Parameters:
      index - the value for the index property
      See Also:
    • getItem

      public T getItem()
      Gets the value of the item property.
      Property description:
      Specifies the cell's item.
      Returns:
      the value of the item property
      See Also:
    • itemProperty

      public javafx.beans.property.ObjectProperty<T> itemProperty()
      Specifies the cell's item.
      Returns:
      the item property
      See Also:
    • setItem

      public void setItem(T item)
      Sets the value of the item property.
      Property description:
      Specifies the cell's item.
      Parameters:
      item - the value for the item property
      See Also:
    • getGraphic

      public javafx.scene.Node getGraphic()
      Gets the value of the graphic property.
      Property description:
      Allows adding a Node to the cell. To be precise, how this property is used depends on the skin implementation.
      Returns:
      the value of the graphic property
      See Also:
    • graphicProperty

      public javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty()
      Allows adding a Node to the cell. To be precise, how this property is used depends on the skin implementation.
      Returns:
      the graphic property
      See Also:
    • setGraphic

      public void setGraphic(javafx.scene.Node graphic)
      Sets the value of the graphic property.
      Property description:
      Allows adding a Node to the cell. To be precise, how this property is used depends on the skin implementation.
      Parameters:
      graphic - the value for the graphic property
      See Also: