Skip to content

Commit

Permalink
Implement FileWidget.FILES_AND_DIRECTORIES
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 27, 2024
1 parent 2770bbf commit 822fb74
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<url>https://imagej.net/people/NicoKiaru</url>
<properties><id>NicoKiaru</id></properties>
</contributor>
<contributor>
<name>Christian Tischer</name>
<url>https://imagej.net/people/tischi</url>
<properties><id>tischi</id></properties>
</contributor>
</contributors>

<mailingLists>
Expand Down Expand Up @@ -126,6 +131,7 @@
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-common</artifactId>
<version>2.99.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/scijava/ui/swing/AbstractSwingUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.FILES_AND_DIRECTORIES.equals(style)) {
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
}
final int rval;
if (FileWidget.SAVE_STYLE.equals(style)) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/scijava/ui/swing/widget/SwingFileWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.FILES_AND_DIRECTORIES)) {
style = FileWidget.FILES_AND_DIRECTORIES;
} else if (model.isStyle(FileWidget.SAVE_STYLE)) {
style = FileWidget.SAVE_STYLE;
}
else {
} else {
style = FileWidget.OPEN_STYLE;
}
file = uiService.chooseFile(file, style);
Expand Down Expand Up @@ -199,7 +199,7 @@ public static FileFilter createFileFilter(final String widgetStyle) {
FileWidget.DIRECTORY_STYLE, FileListWidget.DIRECTORIES_ONLY
);
final List<String> filesAndDirsStyles = Arrays.asList(
FileListWidget.FILES_AND_DIRECTORIES
FileWidget.FILES_AND_DIRECTORIES, FileListWidget.FILES_AND_DIRECTORIES
);

final List<String> exts = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
}

0 comments on commit 822fb74

Please sign in to comment.