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/ListCellFactory.java

35 lines
899 B
Java

package envoy.client.ui.listcell;
import java.util.function.Function;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.util.Callback;
/**
* Provides a creation mechanism for generic list cells given a list view and a conversion function.
*
* @author Kai S. K. Engelbart
* @param <T> the type of object to display
* @param <U> the type of node displayed
* @since Envoy Client v0.1-beta
*/
public final class ListCellFactory<T, U extends Node>
implements Callback<ListView<T>, ListCell<T>> {
private final Function<? super T, U> renderer;
/**
* @param renderer a function converting the type to display into a node
* @since Envoy Client v0.1-beta
*/
public ListCellFactory(Function<? super T, U> renderer) {
this.renderer = renderer;
}
@Override
public ListCell<T> call(ListView<T> listView) {
return new GenericListCell<>(listView, renderer);
}
}