de.rpgframework.jfx.SelectionControllerNode Maven / Gradle / Ivy
package de.rpgframework.jfx;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.List;
import java.util.function.BiFunction;
import de.rpgframework.genericrpg.chargen.ComplexDataItemController;
import de.rpgframework.genericrpg.data.DataItem;
import de.rpgframework.genericrpg.data.DataItemValue;
import de.rpgframework.genericrpg.data.Decision;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Control;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.Skin;
import javafx.util.Callback;
/**
* @author prelle
*
*/
public class SelectionControllerNode> extends Control {
private final static Logger logger = RPGFrameworkJavaFX.logger;
private static final String DEFAULT_STYLE_CLASS = "selection-control";
private ObjectProperty> control;
private ObjectProperty> availableProperty = new SimpleObjectProperty>(FXCollections.observableArrayList());
private ObjectProperty> selectedProperty = new SimpleObjectProperty>(FXCollections.observableArrayList());
private ObjectProperty, ListCell>> availableCellFactoryProperty;
private ObjectProperty, ListCell>> selectedCellFactoryProperty;
private ObjectProperty, Decision[]>> optionCallbackProperty;
private BooleanProperty showHeadingsProperty;
private StringProperty availableHeadingProperty;
private StringProperty selectedHeadingProperty;
private StringProperty availablePlaceholderProperty;
private StringProperty selectedPlaceholderProperty;
private ObjectProperty showHelpForProperty;
private StringProperty availableStyleProperty;
private StringProperty selectedStyleProperty;
//-------------------------------------------------------------------
public SelectionControllerNode(ComplexDataItemController control) {
if (control==null)
throw new NullPointerException("Controller may not be null");
this.control = new SimpleObjectProperty>(control);
availableCellFactoryProperty = new SimpleObjectProperty<>();
selectedCellFactoryProperty = new SimpleObjectProperty<>();
optionCallbackProperty = new SimpleObjectProperty<>();
showHeadingsProperty = new SimpleBooleanProperty(true);
availableHeadingProperty = new SimpleStringProperty(RPGFrameworkJFXConstants.UI.getString("label.available"));
selectedHeadingProperty = new SimpleStringProperty(RPGFrameworkJFXConstants.UI.getString("label.selected"));
availablePlaceholderProperty = new SimpleStringProperty();
selectedPlaceholderProperty = new SimpleStringProperty();
showHelpForProperty = new SimpleObjectProperty<>();
availableStyleProperty = new SimpleStringProperty();
selectedStyleProperty = new SimpleStringProperty();
getStyleClass().setAll(DEFAULT_STYLE_CLASS);
this.control.addListener( (ov,o,n) -> refresh());
refresh();
}
//-------------------------------------------------------------------
/**
* @see javafx.scene.control.Control#createDefaultSkin()
*/
@Override
public Skin> createDefaultSkin() {
return new SelectionControlTwoColumnSkin<>(this);
}
//-------------------------------------------------------------------
public ObjectProperty> getControllerProperty() { return control;}
public ComplexDataItemController getController() { return control.get();}
public void setController(ComplexDataItemController value) { control.set(value); }
//-------------------------------------------------------------------
public void refresh() {
logger.log(Level.INFO, "SelectionControllerNode.refresh: "+control.get().getSelected());
try {
availableProperty.get().setAll(control.get().getAvailable());
selectedProperty.get().setAll(control.get().getSelected());
logger.log(Level.DEBUG, "SelectionControllerNode.refresh2: "+selectedProperty.get());
} finally {
logger.log(Level.DEBUG, "SelectionControllerNode.refresh: done");
}
}
//-------------------------------------------------------------------
public ObjectProperty> availableProperty() { return availableProperty; }
public ObservableList getAvailable() { return availableProperty.get(); }
// public void setAvailable(ObservableList value) { availableProperty.setValue(value); }
//-------------------------------------------------------------------
public ObjectProperty> selectedProperty() { return selectedProperty; }
public ObservableList getSelected() { return selectedProperty.get(); }
// public void setSelected(ObservableList value) { selectedProperty.setValue(value); }
//-------------------------------------------------------------------
public ObjectProperty, Decision[]>> optionCallbackProperty() { return optionCallbackProperty; }
public BiFunction, Decision[]> getOptionCallback() { return optionCallbackProperty.get(); }
public void setOptionCallback(BiFunction, Decision[]> value) { optionCallbackProperty.setValue(value); }
//-------------------------------------------------------------------
public ObjectProperty, ListCell>> availableCellFactoryProperty() { return availableCellFactoryProperty; }
public Callback, ListCell> getAvailableCellFactory() { return availableCellFactoryProperty.get(); }
public void setAvailableCellFactory(Callback, ListCell> value) { availableCellFactoryProperty.setValue(value); }
//-------------------------------------------------------------------
public ObjectProperty, ListCell>> selectedCellFactoryProperty() { return selectedCellFactoryProperty; }
public Callback, ListCell> getSelectedCellFactory() { return selectedCellFactoryProperty.get(); }
public void setSelectedCellFactory(Callback, ListCell> value) { selectedCellFactoryProperty.setValue(value); }
//-------------------------------------------------------------------
public BooleanProperty showHeadingsProperty() { return showHeadingsProperty; }
public boolean getShowHeadings() { return showHeadingsProperty.get(); }
public void setShowHeadings(boolean value) { showHeadingsProperty.set(value); }
//-------------------------------------------------------------------
public StringProperty availableHeadingProperty() { return availableHeadingProperty; }
public String getAvailableHeading() { return availableHeadingProperty.get(); }
public void setAvailableHeading(String value) { availableHeadingProperty.set(value); }
//-------------------------------------------------------------------
public StringProperty selectedHeadingProperty() { return selectedHeadingProperty; }
public String getSelectedHeading() { return selectedHeadingProperty.get(); }
public void setSelectedHeading(String value) { selectedHeadingProperty.set(value); }
//-------------------------------------------------------------------
public StringProperty availablePlaceholderProperty() { return availablePlaceholderProperty; }
public String getAvailablePlaceholder() { return availablePlaceholderProperty.get(); }
public void setAvailablePlaceholder(String value) { availablePlaceholderProperty.set(value); }
//-------------------------------------------------------------------
public StringProperty selectedPlaceholderProperty() { return selectedPlaceholderProperty; }
public String getSelectedPlaceholder() { return selectedPlaceholderProperty.get(); }
public void setSelectedPlaceholder(String value) { selectedPlaceholderProperty.set(value); }
//-------------------------------------------------------------------
public ObjectProperty showHelpForProperty() { return showHelpForProperty; }
public T getShowHelpFor() { return showHelpForProperty.get(); }
public void setShowHelpFor(T value) { showHelpForProperty.setValue(value); }
//-------------------------------------------------------------------
public StringProperty availableStyleProperty() { return availableStyleProperty; }
public String getAvailableStyle() { return availableStyleProperty.get(); }
public void setAvailableStyle(String value) { availableStyleProperty.set(value); }
//-------------------------------------------------------------------
public StringProperty selectedStyleProperty() { return selectedStyleProperty; }
public String getSelectedStyle() { return selectedStyleProperty.get(); }
public void setSelectedStyle(String value) { selectedStyleProperty.set(value); }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy