This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/client/src/main/java/envoy/client/ui/listcell/AbstractListCell.java

49 lines
1.3 KiB
Java

package envoy.client.ui.listcell;
import javafx.scene.*;
import javafx.scene.control.*;
/**
* Provides a convenience frame for list cell creation.
*
* @author Kai S. K. Engelbart
* @param <T> the type of element displayed by the list cell
* @param <U> the type of node as which the list element will be displayed
* @since Envoy Client v0.1-beta
*/
public abstract class AbstractListCell<T, U extends Node> extends ListCell<T> {
protected ListView<? extends T> listView;
/**
* @param listView the list view inside of which the cell will be displayed
* @since Envoy Client v0.1-beta
*/
public AbstractListCell(ListView<? extends T> listView) {
this.listView = listView;
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
getStyleClass().add("list-element");
}
@Override
protected final void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (!(empty || item == null)) {
setCursor(Cursor.HAND);
setGraphic(renderItem(item));
} else {
setGraphic(null);
setCursor(Cursor.DEFAULT);
}
}
/**
* Converts a list item to a node. This can have side effects on the list cell.
*
* @param item the item to render
* @return a node representing the item
* @since Envoy Client v0.1-beta
*/
protected abstract U renderItem(T item);
}