Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable FileWidget.FILE_AND_DIRECTORY_STYLE #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.FILE_AND_DIRECTORY_STYLE.equals(style)) {
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
}
final int rval;
if (FileWidget.SAVE_STYLE.equals(style)) {
Expand Down
13 changes: 7 additions & 6 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.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);
Expand Down Expand Up @@ -180,8 +180,9 @@ public void doRefresh() {
* <ul>
* <li>{@link FileWidget#OPEN_STYLE}</li>
* <li>{@link FileWidget#SAVE_STYLE}</li>
* <li>{@link FileListWidget#FILES_ONLY}</li>
* <li>{@link FileWidget#DIRECTORY_STYLE}</li>
* <li>{@link FileWidget#FILE_AND_DIRECTORY_STYLE}</li>
* <li>{@link FileListWidget#FILES_ONLY}</li>
* <li>{@link FileListWidget#DIRECTORIES_ONLY}</li>
* <li>{@link FileListWidget#FILES_AND_DIRECTORIES}</li>
* </ul>
Expand All @@ -199,7 +200,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.FILE_AND_DIRECTORY_STYLE, 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);

}
}
Loading