Commit a5c8472d authored by Axel Howind's avatar Axel Howind

options() (in progress)

parent db5c0e62
......@@ -8,6 +8,8 @@ import java.util.function.Function;
import java.util.function.IntFunction;
import com.dua3.fx.util.controls.InputDialogPane.InputControl;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
public interface InputBuilder<B extends InputBuilder<B>> {
......@@ -15,16 +17,22 @@ public interface InputBuilder<B extends InputBuilder<B>> {
B columns(int columns);
B text(String id, String label, String dflt);
default B text(String id, String label, String dflt) {
return text(id, label, dflt, s -> Optional.empty());
}
B text(String id, String label, String dflt, Function<String, Optional<String>> validate);
B integer(String id, String label, Integer dflt);
default B integer(String id, String label, Integer dflt) {
return integer(id, label, dflt, i -> Optional.empty());
}
B integer(String id, String label, Integer dflt, IntFunction<Optional<String>> validate);
B decimal(String id, String label, Double dflt);
default B decimal(String id, String label, Double dflt) {
return decimal(id, label, dflt, d -> Optional.empty());
}
B decimal(String id, String label, Double dflt, DoubleFunction<Optional<String>> validate);
B checkBox(String id, String label, boolean dflt, String text);
......@@ -43,4 +51,6 @@ public interface InputBuilder<B extends InputBuilder<B>> {
return radioList(id, label, dflt, cls, Arrays.asList(items));
}
B options(String id, String label, OptionValues dflt, Class<OptionValues> cls, OptionSet options);
}
\ No newline at end of file
......@@ -22,6 +22,8 @@ import java.util.function.Function;
import java.util.function.IntFunction;
import com.dua3.fx.util.controls.InputDialogPane.InputControl;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
/**
* Builder for Alert Dialogs.
......@@ -50,12 +52,6 @@ implements InputBuilder<InputDialogBuilder> {
return this;
}
@Override
public InputDialogBuilder text(String id, String label, String dflt) {
pb.text(id, label, dflt);
return this;
}
@Override
public InputDialogBuilder text(String id, String label, String dflt, Function<String,Optional<String>> validate) {
pb.text(id, label, dflt, validate);
......@@ -63,23 +59,11 @@ implements InputBuilder<InputDialogBuilder> {
}
@Override
public InputDialogBuilder integer(String id, String label, Integer dflt) {
pb.integer(id, label, dflt);
return this;
}
@Override
public InputDialogBuilder integer(String id, String label, Integer dflt, IntFunction<Optional<String>> validate) {
pb.integer(id, label, dflt, validate);
return this;
}
@Override
public InputDialogBuilder decimal(String id, String label, Double dflt) {
pb.decimal(id, label, dflt);
return this;
}
@Override
public InputDialogBuilder decimal(String id, String label, Double dflt, DoubleFunction<Optional<String>> validate) {
pb.decimal(id, label, dflt, validate);
......@@ -103,7 +87,14 @@ implements InputBuilder<InputDialogBuilder> {
pb.radioList(id, label, dflt, cls, items);
return this;
}
@Override
public InputDialogBuilder options(String id, String label, OptionValues dflt, Class<OptionValues> cls,
OptionSet options) {
pb.options(id, label, dflt, cls, options);
return this;
}
@Override
public InputDialog build() {
InputDialog dlg = super.build();
......@@ -112,4 +103,5 @@ implements InputBuilder<InputDialogBuilder> {
return dlg;
}
}
......@@ -26,6 +26,8 @@ import java.util.function.IntFunction;
import com.dua3.fx.util.controls.InputDialogPane.InputControl;
import com.dua3.fx.util.controls.InputDialogPane.Meta;
import com.dua3.utility.lang.LangUtil;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import javafx.collections.FXCollections;
import javafx.scene.Node;
......@@ -72,14 +74,6 @@ implements InputBuilder<InputDialogPaneBuilder> {
return this;
}
/* (non-Javadoc)
* @see com.dua3.fx.util.controls.InputBuilder#text(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public InputDialogPaneBuilder text(String id, String label, String dflt) {
return text(id, label, dflt, s -> Optional.empty());
}
/* (non-Javadoc)
* @see com.dua3.fx.util.controls.InputBuilder#text(java.lang.String, java.lang.String, java.lang.String, java.util.function.Function)
*/
......@@ -111,14 +105,6 @@ implements InputBuilder<InputDialogPaneBuilder> {
});
}
/* (non-Javadoc)
* @see com.dua3.fx.util.controls.InputBuilder#integer(java.lang.String, java.lang.String, java.lang.Integer)
*/
@Override
public InputDialogPaneBuilder integer(String id, String label, Integer dflt) {
return integer(id, label, dflt, i -> Optional.empty());
}
/* (non-Javadoc)
* @see com.dua3.fx.util.controls.InputBuilder#integer(java.lang.String, java.lang.String, java.lang.Integer, java.util.function.Function)
*/
......@@ -156,14 +142,6 @@ implements InputBuilder<InputDialogPaneBuilder> {
});
}
/* (non-Javadoc)
* @see com.dua3.fx.util.controls.InputBuilder#decimal(java.lang.String, java.lang.String, java.lang.Double)
*/
@Override
public InputDialogPaneBuilder decimal(String id, String label, Double dflt) {
return decimal(id, label, dflt, d -> Optional.empty());
}
/* (non-Javadoc)
* @see com.dua3.fx.util.controls.InputBuilder#decimal(java.lang.String, java.lang.String, java.lang.Double, java.util.function.Function)
*/
......@@ -283,6 +261,11 @@ implements InputBuilder<InputDialogPaneBuilder> {
public <T> InputDialogPaneBuilder radioList(String id, String label, T dflt, Class<T> cls, Collection<T> items) {
return add(id, label, cls, dflt, new RadioPane<>(items, null));
}
@Override
public InputDialogPaneBuilder options(String id, String label, OptionValues dflt, Class<OptionValues> cls, OptionSet options) {
return null;
}
// TODO: add date and time inputs
......
......@@ -29,7 +29,7 @@ import javafx.scene.control.DialogPane;
*/
public class OptionsDialog extends Dialog<OptionValues> {
private OptionPane optionPane;
private OptionsPane optionPane;
public OptionsDialog() {
// buttons
......@@ -56,7 +56,7 @@ public class OptionsDialog extends Dialog<OptionValues> {
*/
public void setOptions(OptionSet optionSet, OptionValues currentValues) {
LangUtil.check(optionPane==null, "setOptions() already called!");
this.optionPane = new OptionPane(optionSet, currentValues);
this.optionPane = new OptionsPane(optionSet, currentValues);
getDialogPane().setContent(optionPane);
}
......
......@@ -20,10 +20,10 @@ import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
public class OptionPane extends GridPane {
public class OptionsPane extends GridPane {
/** Logger */
protected static final Logger LOG = Logger.getLogger(OptionPane.class.getSimpleName());
protected static final Logger LOG = Logger.getLogger(OptionsPane.class.getSimpleName());
private final OptionSet options;
private final OptionValues currentValues;
......@@ -32,13 +32,13 @@ public class OptionPane extends GridPane {
private static final Insets INSETS = new Insets(2);
/**
* Create new OptionPane.
* Create new OptionsPane.
* @param optionSet
* the available options
* @param currentValues
* the current values
*/
public OptionPane(OptionSet optionSet, OptionValues currentValues) {
public OptionsPane(OptionSet optionSet, OptionValues currentValues) {
this.options = Objects.requireNonNull(optionSet);
this.currentValues = new OptionValues(currentValues);
this.newValues = new OptionValues(currentValues);
......@@ -73,7 +73,7 @@ public class OptionPane extends GridPane {
}
/**
* Get the options for this OptionPane.
* Get the options for this OptionsPane.
* @return
* the options
*/
......
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