Commit 555e73e0 authored by Axel Howind's avatar Axel Howind

InputControl (wip)

parent 0c5c4970
......@@ -21,10 +21,8 @@ import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableStringValue;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
......@@ -79,7 +77,7 @@ public interface InputControl<R> {
ReadOnlyStringProperty errorProperty();
class State<R> {
private final Property<R> value = new SimpleObjectProperty<>();
private final Property<R> value;
private final BooleanProperty valid = new SimpleBooleanProperty(true);
private final StringProperty error = new SimpleStringProperty("");
......@@ -92,17 +90,17 @@ public interface InputControl<R> {
return () -> frozen;
}
public State(ObservableValue<R> value) {
public State(Property<R> value) {
this(value, freeze(value));
}
public State(ObservableValue<R> value, Supplier<R> dflt) {
public State(Property<R> value, Supplier<R> dflt) {
this(value, dflt, s -> Optional.empty());
}
public State(ObservableValue<R> value, Supplier<R> dflt, Function<R,Optional<String>> validate) {
this.value.bind(value);
public State(Property<R> value, Supplier<R> dflt, Function<R,Optional<String>> validate) {
this.value = value;
this.value.addListener( (v,o,n) -> updateValidState(n) );
this.dflt = Objects.requireNonNull(dflt);
this.validate = Objects.requireNonNull(validate);
......@@ -143,7 +141,7 @@ public interface InputControl<R> {
public static SimpleInputControl<TextField, String> stringInput(Supplier<String> dflt, Function<String, Optional<String>> validate) {
TextField control = new TextField();
ObservableStringValue value = control.textProperty();
StringProperty value = control.textProperty();
SimpleInputControl<TextField, String> inputControl = new SimpleInputControl<>(control, value, dflt, validate);
return inputControl;
}
......
......@@ -15,9 +15,6 @@ import com.dua3.fx.util.FxUtil;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.geometry.Dimension2D;
import javafx.geometry.Insets;
......
......@@ -2,12 +2,11 @@ package com.dua3.fx.util.controls;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.logging.Logger;
import com.dua3.fx.util.StringValueConverter;
import com.dua3.utility.options.Option;
import com.dua3.utility.options.Option.ChoiceOption;
import com.dua3.utility.options.Option.StringOption;
......@@ -15,22 +14,13 @@ import com.dua3.utility.options.Option.Value;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import com.dua3.fx.util.StringValueConverter;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
public class OptionsPane extends GridPane implements InputControl<OptionValues>{
......@@ -42,7 +32,7 @@ public class OptionsPane extends GridPane implements InputControl<OptionValues>{
private Supplier<OptionSet> options;
private Supplier<OptionValues> dflt;
private ObservableValue<OptionValues> value = new SimpleObjectProperty<>();
private Property<OptionValues> value = new SimpleObjectProperty<>();
private LinkedHashMap<Option<?>, InputControl<?>> items = new LinkedHashMap<>();
......
package com.dua3.fx.util.controls;
import com.dua3.fx.util.FxUtil;
import javafx.event.ActionEvent;
import javafx.geometry.Dimension2D;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import java.util.*;
import java.util.function.Supplier;
import java.util.logging.Logger;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
public class PromptPane extends InputDialogPane<String> {
/** Logger */
......
......@@ -4,11 +4,10 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.logging.Logger;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.RadioButton;
......@@ -35,6 +34,7 @@ public class RadioPane<T> extends VBox implements InputControl<T> {
* @param currentValue
* the current value
*/
@SuppressWarnings("unchecked")
public RadioPane(Collection<T> items, T currentValue) {
this.group = new ToggleGroup();
......@@ -49,12 +49,13 @@ public class RadioPane<T> extends VBox implements InputControl<T> {
}
// update state when selected toggle changes
@SuppressWarnings("unchecked")
ObservableValue<T> valueBinding = Bindings.createObjectBinding( () -> {
Toggle selectedToggle = group.getSelectedToggle();
return selectedToggle != null ? (T) selectedToggle.getUserData() : null;
}, group.selectedToggleProperty());
this.state = new State<>(valueBinding);
Property<T> property = new SimpleObjectProperty<>();
group.selectedToggleProperty().addListener( (v,o,n) -> {
Toggle toggle = group.getSelectedToggle();
property.setValue(toggle != null ? (T) toggle.getUserData() : null);
});
this.state = new State<>(property);
// update toggle, when state changes
state.valueProperty().addListener( (v,o,n) -> {
......
......@@ -8,7 +8,6 @@ import java.util.function.Supplier;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Control;
class SimpleInputControl<C extends Control,R> implements InputControl<R> {
......@@ -17,7 +16,7 @@ class SimpleInputControl<C extends Control,R> implements InputControl<R> {
private final State<R> state;
private final Supplier<R> dflt;
protected SimpleInputControl(C control, ObservableValue<R> value, Supplier<R> dflt, Function<R,Optional<String>> validate) {
protected SimpleInputControl(C control, Property<R> value, Supplier<R> dflt, Function<R,Optional<String>> validate) {
this.control = Objects.requireNonNull(control);
this.state = new State<>(value);
this.dflt = dflt;
......
......@@ -13,7 +13,6 @@ import com.dua3.fx.util.controls.AbstractDialogPaneBuilder.ResultHandler;
import com.dua3.utility.data.Pair;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.BooleanExpression;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
......@@ -22,7 +21,6 @@ import javafx.event.Event;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
public class WizardDialog extends Dialog<Map<String,Object>> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment