diff --git a/pom.xml b/pom.xml
index 091e663..d28d7c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,11 @@
https://imagej.net/people/NicoKiaru
NicoKiaru
+
+ Christian Tischer
+ https://imagej.net/people/tischi
+ tischi
+
@@ -126,6 +131,7 @@
org.scijava
scijava-common
+ 2.99.0-SNAPSHOT
org.scijava
diff --git a/src/main/java/org/scijava/ui/swing/AbstractSwingUI.java b/src/main/java/org/scijava/ui/swing/AbstractSwingUI.java
index 45b98fe..c638ae0 100644
--- a/src/main/java/org/scijava/ui/swing/AbstractSwingUI.java
+++ b/src/main/java/org/scijava/ui/swing/AbstractSwingUI.java
@@ -145,6 +145,8 @@ public File chooseFile(final File file, final String style) {
final JFileChooser chooser = new JFileChooser(file);
if (FileWidget.DIRECTORY_STYLE.equals(style)) {
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ } else if (FileWidget.FILE_AND_DIRECTORY_STYLE.equals(style)) {
+ chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
}
final int rval;
if (FileWidget.SAVE_STYLE.equals(style)) {
diff --git a/src/main/java/org/scijava/ui/swing/widget/SwingFileWidget.java b/src/main/java/org/scijava/ui/swing/widget/SwingFileWidget.java
index f669e39..2d88173 100644
--- a/src/main/java/org/scijava/ui/swing/widget/SwingFileWidget.java
+++ b/src/main/java/org/scijava/ui/swing/widget/SwingFileWidget.java
@@ -127,11 +127,11 @@ public void actionPerformed(final ActionEvent e) {
final String style;
if (model.isStyle(FileWidget.DIRECTORY_STYLE)) {
style = FileWidget.DIRECTORY_STYLE;
- }
- else if (model.isStyle(FileWidget.SAVE_STYLE)) {
+ } else if (model.isStyle(FileWidget.FILE_AND_DIRECTORY_STYLE)) {
+ style = FileWidget.FILE_AND_DIRECTORY_STYLE;
+ } else if (model.isStyle(FileWidget.SAVE_STYLE)) {
style = FileWidget.SAVE_STYLE;
- }
- else {
+ } else {
style = FileWidget.OPEN_STYLE;
}
file = uiService.chooseFile(file, style);
@@ -180,8 +180,9 @@ public void doRefresh() {
*
* - {@link FileWidget#OPEN_STYLE}
* - {@link FileWidget#SAVE_STYLE}
- * - {@link FileListWidget#FILES_ONLY}
* - {@link FileWidget#DIRECTORY_STYLE}
+ * - {@link FileWidget#FILE_AND_DIRECTORY_STYLE}
+ * - {@link FileListWidget#FILES_ONLY}
* - {@link FileListWidget#DIRECTORIES_ONLY}
* - {@link FileListWidget#FILES_AND_DIRECTORIES}
*
@@ -199,7 +200,7 @@ public static FileFilter createFileFilter(final String widgetStyle) {
FileWidget.DIRECTORY_STYLE, FileListWidget.DIRECTORIES_ONLY
);
final List filesAndDirsStyles = Arrays.asList(
- FileListWidget.FILES_AND_DIRECTORIES
+ FileWidget.FILE_AND_DIRECTORY_STYLE, FileListWidget.FILES_AND_DIRECTORIES
);
final List exts = new ArrayList<>();
diff --git a/src/test/java/org/scijava/ui/swing/command/FileAndDirectoryChooserCommandDemo.java b/src/test/java/org/scijava/ui/swing/command/FileAndDirectoryChooserCommandDemo.java
new file mode 100644
index 0000000..214fe09
--- /dev/null
+++ b/src/test/java/org/scijava/ui/swing/command/FileAndDirectoryChooserCommandDemo.java
@@ -0,0 +1,59 @@
+/*-
+ * #%L
+ * SciJava UI components for Java Swing.
+ * %%
+ * Copyright (C) 2010 - 2023 SciJava developers.
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package org.scijava.ui.swing.command;
+
+import org.scijava.Context;
+import org.scijava.command.Command;
+import org.scijava.command.CommandService;
+import org.scijava.command.InteractiveCommand;
+import org.scijava.plugin.Parameter;
+import org.scijava.plugin.Plugin;
+import org.scijava.ui.UIService;
+
+import java.io.File;
+
+@Plugin(type = Command.class, menuPath = "Test>File and Directory Chooser Command")
+public class FileAndDirectoryChooserCommandDemo implements Command {
+
+ @Parameter (style = "both")
+ File file;
+
+ @Override
+ public void run() {
+ System.out.println("You chose: " + file.toString());
+ }
+
+ public static void main(String... args) throws Exception {
+
+ Context context = new Context();
+ context.service(UIService.class).showUI();
+ context.service(CommandService.class).run( FileAndDirectoryChooserCommandDemo.class, true);
+
+ }
+}