From 00512f5554090cfc878936deb9156712400a44df Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Thu, 27 Jun 2024 23:46:47 +0200 Subject: [PATCH 1/2] Add FileWidget.FILE_AND_DIRECTORY_STYLE --- pom.xml | 5 +++++ src/main/java/org/scijava/ui/UserInterface.java | 2 ++ src/main/java/org/scijava/widget/FileWidget.java | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/pom.xml b/pom.xml index 468e5842d..f1b9aec33 100644 --- a/pom.xml +++ b/pom.xml @@ -134,6 +134,11 @@ https://imagej.net/people/jaywarrick jaywarrick + + Christian Tischer + https://imagej.net/people/tischi + tischi + diff --git a/src/main/java/org/scijava/ui/UserInterface.java b/src/main/java/org/scijava/ui/UserInterface.java index 54dbfb767..938a5663a 100644 --- a/src/main/java/org/scijava/ui/UserInterface.java +++ b/src/main/java/org/scijava/ui/UserInterface.java @@ -163,6 +163,7 @@ default File chooseFile(final File file, final String style) { // TODO use a utility class for style handling, e.g. StyleUtils.isStyle(style, ...) if (style == null) title = "Choose a file"; else if (style.toLowerCase().contains(FileWidget.DIRECTORY_STYLE)) title = "Choose a directory"; + else if (style.toLowerCase().contains(FileWidget.FILE_AND_DIRECTORY_STYLE )) title = "Choose a file or directory"; else if (style.toLowerCase().contains(FileWidget.OPEN_STYLE)) title = "Open"; else if (style.toLowerCase().contains(FileWidget.SAVE_STYLE)) title = "Save"; else title = "Choose a file"; @@ -180,6 +181,7 @@ default File chooseFile(final File file, final String style) { *
  • {@link FileWidget#OPEN_STYLE}
  • *
  • {@link FileWidget#SAVE_STYLE}
  • *
  • {@link FileWidget#DIRECTORY_STYLE}
  • + *
  • {@link FileWidget#FILE_AND_DIRECTORY_STYLE}
  • * * @return The {@link File} chosen by the user, or null if prompt is not * available diff --git a/src/main/java/org/scijava/widget/FileWidget.java b/src/main/java/org/scijava/widget/FileWidget.java index a4322554d..e72d41c37 100644 --- a/src/main/java/org/scijava/widget/FileWidget.java +++ b/src/main/java/org/scijava/widget/FileWidget.java @@ -59,4 +59,11 @@ public interface FileWidget extends InputWidget { */ String DIRECTORY_STYLE = "directory"; + /** + * Widget style for directory chooser dialogs. + * + * @see org.scijava.plugin.Parameter#style() + */ + String FILE_AND_DIRECTORY_STYLE = "both"; + } From 79a92d832f773bbefe0c8f44da840017b36e5ebb Mon Sep 17 00:00:00 2001 From: Jan Eglinger Date: Mon, 1 Jul 2024 11:20:31 +0200 Subject: [PATCH 2/2] Use WidgetStyle.isStyle for style logic --- src/main/java/org/scijava/ui/UserInterface.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/scijava/ui/UserInterface.java b/src/main/java/org/scijava/ui/UserInterface.java index 938a5663a..f4c6d0c70 100644 --- a/src/main/java/org/scijava/ui/UserInterface.java +++ b/src/main/java/org/scijava/ui/UserInterface.java @@ -41,6 +41,7 @@ import org.scijava.ui.console.ConsolePane; import org.scijava.ui.viewer.DisplayWindow; import org.scijava.widget.FileWidget; +import org.scijava.widget.WidgetStyle; /** * An end-user SciJava application user interface. @@ -160,12 +161,11 @@ DialogPrompt dialogPrompt(String message, String title, default File chooseFile(final File file, final String style) { final String title; // style can be a string with multiple comma-separated keywords - // TODO use a utility class for style handling, e.g. StyleUtils.isStyle(style, ...) if (style == null) title = "Choose a file"; - else if (style.toLowerCase().contains(FileWidget.DIRECTORY_STYLE)) title = "Choose a directory"; - else if (style.toLowerCase().contains(FileWidget.FILE_AND_DIRECTORY_STYLE )) title = "Choose a file or directory"; - else if (style.toLowerCase().contains(FileWidget.OPEN_STYLE)) title = "Open"; - else if (style.toLowerCase().contains(FileWidget.SAVE_STYLE)) title = "Save"; + else if (WidgetStyle.isStyle(style, FileWidget.DIRECTORY_STYLE)) title = "Choose a directory"; + else if (WidgetStyle.isStyle(style, FileWidget.FILE_AND_DIRECTORY_STYLE)) title = "Choose a file or directory"; + else if (WidgetStyle.isStyle(style, FileWidget.OPEN_STYLE)) title = "Open"; + else if (WidgetStyle.isStyle(style, FileWidget.SAVE_STYLE)) title = "Save"; else title = "Choose a file"; return chooseFile(title, file, style);