35 lines
899 B
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);
|
|
}
|
|
}
|