io.github.palexdev.virtualizedfx.cells.Cell Maven / Gradle / Ivy
Show all versions of virtualizedfx Show documentation
package io.github.palexdev.virtualizedfx.cells;
import javafx.scene.Node;
/**
* Public, base API for all cells used by any virtualized container. All cells need these three main capabilities:
* - A way to convert themselves to a {@link Node}, can be implemented in various ways see {@link #toNode()}
*
- A way to keep track of its index
*
- A way to keep track of the displayed item
*
* Aside from these core functionalities, the API also offers other hooks:
* - Virtualized containers that make use of a cache (to avoid creating new cells every time one is needed) should
* make use of {@link #onCache()} and {@link #onDeCache()}. Implementations can track cache/de-cache operations by overriding
* these methods
*
- When cells are not needed anymore, {@link #dispose()} should be called (automatically handled by the framework
* don't worry). Here implementations can specify operations to do before the cell is GCd.
*
* @param the type of item to display
*/
public interface Cell {
/**
* Converts the cell to a {@link Node}.
*
* Implementations can follow the following examples:
*
* {@code
* // Example 1
* public class SimpleCell extends Label implements Cell {
* ...
* ...
*
* @Override
* public Node toNode() {
* return this;
* }
* }
*
* // Example 2
* public class SimpleCell implements Cell {
* private final Label label = ...;
* ...
* ...
*
* @Override
* public Node toNode() {
* return label;
* }
* }
*
*/
Node toNode();
/**
* 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 {@link CellBase} and read how this is handled.
*/
void updateIndex(int index);
/**
* 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 {@link CellBase} and read how this is handled.
*/
void updateItem(T item);
/**
* Virtualized containers that make use of a cache to store unneeded cells that may be required again in a second time
* should call this when adding the cell to the cache.
*
* Users can intercept/hook to this operation by overriding this method.
*/
default void onCache() {}
/**
* Virtualized containers that make use of a cache to store unneeded cells that may be required again in a second time
* should call this when removing the cell from the cache.
*
* Users can intercept/hook to this operation by overriding this method.
*/
default void onDeCache() {}
/**
* Automatically called by the framework when the cell is not needed anymore. The use can override this to perform
* some operations before the cell is GCd.
*/
default void dispose() {}
}