Commit e1a38679 authored by Axel Howind's avatar Axel Howind

InputBuilder.addNode() for custom nodes

parent 6fe9c34f
Pipeline #55445078 failed with stages
in 17 minutes and 19 seconds
......@@ -2,6 +2,7 @@ package com.dua3.fx.util.controls;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import javafx.scene.Node;
import javafx.stage.FileChooser;
import java.io.File;
......@@ -49,7 +50,33 @@ public interface InputBuilder<B extends InputBuilder<B>> {
* {@code this}
*/
<T> B add(String id, Class<T> type, Supplier<T> dflt, InputControl<T> control);
/**
* Add labeled input control.
*
* @param id
* the node's ID
* @param label
* the label text
* @param node
* the node
* @return
* {@code this}
*/
B addNode(String id, String label, Node node);
/**
* Add unlabeled input control.
*
* @param id
* the node's ID
* @param node
* the node
* @return
* {@code this}
*/
B addNode(String id, Node node);
/**
* Set number of columns for layout (default is 1).
* @param columns
......@@ -263,4 +290,5 @@ public interface InputBuilder<B extends InputBuilder<B>> {
* {@code this}
*/
B chooseFile(String id, String label, Supplier<File> dflt, FileDialogMode mode, FileChooser.ExtensionFilter fiilter);
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ package com.dua3.fx.util.controls;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import javafx.beans.binding.Bindings;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.stage.FileChooser;
......@@ -68,6 +69,18 @@ implements InputBuilder<InputDialogBuilder> {
return this;
}
@Override
public InputDialogBuilder addNode(String id, String label, Node node) {
pb.addNode(id, label, node);
return this;
}
@Override
public InputDialogBuilder addNode(String id, Node node) {
pb.addNode(id, node);
return this;
}
@Override
public InputDialogBuilder columns(int columns) {
pb.columns(columns);
......
......@@ -18,6 +18,8 @@ import com.dua3.fx.util.controls.InputGrid.Meta;
import com.dua3.utility.lang.LangUtil;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import javafx.beans.property.*;
import javafx.scene.Node;
import javafx.stage.FileChooser;
import java.io.File;
......@@ -67,7 +69,59 @@ implements InputBuilder<InputGridBuilder> {
LangUtil.check(prev == null, "Input with id '" + id + "' already defined");
return this;
}
static class ControlWrapper implements InputControl<Void> {
private final Node node;
private final Property<Void> value = new SimpleObjectProperty<>(null);
private final BooleanProperty valid = new SimpleBooleanProperty(true);
private final ReadOnlyStringProperty error = new SimpleStringProperty("");
ControlWrapper(Node node) {
this.node = Objects.requireNonNull(node);
}
@Override
public Node node() {
return node;
}
@Override
public void reset() { /* nop */ }
@Override
public Property<Void> valueProperty() {
return value;
}
@Override
public ReadOnlyBooleanProperty validProperty() {
return valid;
}
@Override
public ReadOnlyStringProperty errorProperty() {
return error;
}
}
@Override
public InputGridBuilder addNode(String id, String label, Node node) {
Meta<Void> meta = new Meta<Void>(id, label, Void.class, null, new ControlWrapper(node));
Meta<?> prev = data.put(id, meta);
LangUtil.check(prev == null, "Input with id '" + id + "' already defined");
return this;
}
@Override
public InputGridBuilder addNode(String id, Node node) {
Meta<Void> meta = new Meta<Void>(id, "", Void.class, null, new ControlWrapper(node));
Meta<?> prev = data.put(id, meta);
LangUtil.check(prev == null, "Input with id '" + id + "' already defined");
return this;
}
/* (non-Javadoc)
* @see com.dua3.fx.util.controls.InputBuilder#columns(int)
*/
......
......@@ -17,6 +17,7 @@ package com.dua3.fx.util.controls;
import com.dua3.utility.data.Pair;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import javafx.scene.Node;
import javafx.scene.control.ButtonType;
import javafx.stage.FileChooser;
......@@ -56,6 +57,18 @@ implements InputBuilder<InputPaneBuilder> {
return this;
}
@Override
public InputPaneBuilder addNode(String id, String label, Node node) {
pb.addNode(id, label, node);
return this;
}
@Override
public InputPaneBuilder addNode(String id, Node node) {
pb.addNode(id, node);
return this;
}
@Override
public InputPaneBuilder columns(int columns) {
pb.columns(columns);
......
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