Commit c483b162 authored by Axel Howind's avatar Axel Howind

add extension filter parameter

parent c2b2b712
Pipeline #54004284 failed with stages
in 24 minutes and 52 seconds
......@@ -8,6 +8,7 @@ import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import java.util.List;
......@@ -66,7 +67,7 @@ public class DialogSample extends Application {
i -> i >= 4 && i <= 7 ? Optional.empty() : Optional.of(i + " is not between 4 and 7"))
.comboBox("list", "choose one", () -> "Maybe", String.class, List.of("Yes", "No", "Maybe"))
.checkBox("bool", "Yes or No:", () -> false, "yes")
.chooseFile("file", "File", () -> null, InputBuilder.FileDialogMode.OPEN)
.chooseFile("file", "File", () -> null, InputBuilder.FileDialogMode.OPEN, new FileChooser.ExtensionFilter("all files", "*"))
.showAndWait();
}));
......
......@@ -7,6 +7,7 @@ import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import java.io.File;
import java.nio.file.Files;
......@@ -19,6 +20,7 @@ public class FileInput extends HBox implements InputControl<File> {
private final ObjectProperty<File> value = new SimpleObjectProperty<>();
private final InputBuilder.FileDialogMode mode;
private final FileChooser.ExtensionFilter filter;
private final Supplier<File> dflt;
private final TextField tfFilename;
......@@ -27,8 +29,9 @@ public class FileInput extends HBox implements InputControl<File> {
private final StringProperty error = new SimpleStringProperty("");
private final BooleanProperty valid = new SimpleBooleanProperty(true);
public FileInput(InputBuilder.FileDialogMode mode, Supplier<File> dflt) {
this.mode = mode;
public FileInput(InputBuilder.FileDialogMode mode, Supplier<File> dflt, FileChooser.ExtensionFilter filter) {
this.mode = Objects.requireNonNull(mode);
this.filter = Objects.requireNonNull(filter);
this.dflt = Objects.requireNonNull(dflt);
this.tfFilename = new TextField();
......@@ -46,11 +49,13 @@ public class FileInput extends HBox implements InputControl<File> {
if (mode== InputBuilder.FileDialogMode.OPEN) {
Dialogs.chooseFile()
.initialDir(initialDir)
.filter(filter)
.showOpenDialog(null)
.ifPresent(f -> value.setValue(f));
} else {
Dialogs.chooseFile()
.initialDir(initialDir)
.filter(filter)
.showSaveDialog(null)
.ifPresent(f -> value.setValue(f));
}
......
......@@ -2,6 +2,7 @@ package com.dua3.fx.util.controls;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import javafx.stage.FileChooser;
import java.io.File;
import java.util.Collection;
......@@ -261,5 +262,5 @@ public interface InputBuilder<B extends InputBuilder<B>> {
* @return
* {@code this}
*/
B chooseFile(String id, String label, Supplier<File> dflt, FileDialogMode mode);
B chooseFile(String id, String label, Supplier<File> dflt, FileDialogMode mode, FileChooser.ExtensionFilter fiilter);
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ import com.dua3.utility.options.OptionValues;
import javafx.beans.binding.Bindings;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.stage.FileChooser;
import java.io.File;
import java.util.Collection;
......@@ -122,8 +123,8 @@ implements InputBuilder<InputDialogBuilder> {
}
@Override
public InputDialogBuilder chooseFile(String id, String label, Supplier<File> dflt, FileDialogMode mode) {
pb.chooseFile(id, label, dflt, mode);
public InputDialogBuilder chooseFile(String id, String label, Supplier<File> dflt, FileDialogMode mode, FileChooser.ExtensionFilter filter) {
pb.chooseFile(id, label, dflt, mode, filter);
return this;
}
}
......@@ -20,6 +20,7 @@ import com.dua3.utility.lang.LangUtil;
import com.dua3.utility.options.OptionSet;
import com.dua3.utility.options.OptionValues;
import javafx.scene.control.ButtonType;
import javafx.stage.FileChooser;
import java.io.File;
import java.util.*;
......@@ -138,8 +139,8 @@ implements InputBuilder<InputPaneBuilder> {
}
@Override
public InputPaneBuilder chooseFile(String id, String label, Supplier<File> dflt, FileDialogMode mode) {
return add(id, label, File.class, dflt, new FileInput(mode, dflt));
public InputPaneBuilder chooseFile(String id, String label, Supplier<File> dflt, FileDialogMode mode, FileChooser.ExtensionFilter filter) {
return add(id, label, File.class, dflt, new FileInput(mode, dflt, filter));
}
// TODO: add date and time inputs
......
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