Skip to content

Commit 822fb74

Browse files
committed
Implement FileWidget.FILES_AND_DIRECTORIES
1 parent 2770bbf commit 822fb74

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
<url>https://imagej.net/people/NicoKiaru</url>
7575
<properties><id>NicoKiaru</id></properties>
7676
</contributor>
77+
<contributor>
78+
<name>Christian Tischer</name>
79+
<url>https://imagej.net/people/tischi</url>
80+
<properties><id>tischi</id></properties>
81+
</contributor>
7782
</contributors>
7883

7984
<mailingLists>
@@ -126,6 +131,7 @@
126131
<dependency>
127132
<groupId>org.scijava</groupId>
128133
<artifactId>scijava-common</artifactId>
134+
<version>2.99.0-SNAPSHOT</version>
129135
</dependency>
130136
<dependency>
131137
<groupId>org.scijava</groupId>

src/main/java/org/scijava/ui/swing/AbstractSwingUI.java

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public File chooseFile(final File file, final String style) {
145145
final JFileChooser chooser = new JFileChooser(file);
146146
if (FileWidget.DIRECTORY_STYLE.equals(style)) {
147147
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
148+
} else if (FileWidget.FILES_AND_DIRECTORIES.equals(style)) {
149+
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
148150
}
149151
final int rval;
150152
if (FileWidget.SAVE_STYLE.equals(style)) {

src/main/java/org/scijava/ui/swing/widget/SwingFileWidget.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ public void actionPerformed(final ActionEvent e) {
127127
final String style;
128128
if (model.isStyle(FileWidget.DIRECTORY_STYLE)) {
129129
style = FileWidget.DIRECTORY_STYLE;
130-
}
131-
else if (model.isStyle(FileWidget.SAVE_STYLE)) {
130+
} else if (model.isStyle(FileWidget.FILES_AND_DIRECTORIES)) {
131+
style = FileWidget.FILES_AND_DIRECTORIES;
132+
} else if (model.isStyle(FileWidget.SAVE_STYLE)) {
132133
style = FileWidget.SAVE_STYLE;
133-
}
134-
else {
134+
} else {
135135
style = FileWidget.OPEN_STYLE;
136136
}
137137
file = uiService.chooseFile(file, style);
@@ -199,7 +199,7 @@ public static FileFilter createFileFilter(final String widgetStyle) {
199199
FileWidget.DIRECTORY_STYLE, FileListWidget.DIRECTORIES_ONLY
200200
);
201201
final List<String> filesAndDirsStyles = Arrays.asList(
202-
FileListWidget.FILES_AND_DIRECTORIES
202+
FileWidget.FILES_AND_DIRECTORIES, FileListWidget.FILES_AND_DIRECTORIES
203203
);
204204

205205
final List<String> exts = new ArrayList<>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*-
2+
* #%L
3+
* SciJava UI components for Java Swing.
4+
* %%
5+
* Copyright (C) 2010 - 2023 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package org.scijava.ui.swing.command;
30+
31+
import org.scijava.Context;
32+
import org.scijava.command.Command;
33+
import org.scijava.command.CommandService;
34+
import org.scijava.command.InteractiveCommand;
35+
import org.scijava.plugin.Parameter;
36+
import org.scijava.plugin.Plugin;
37+
import org.scijava.ui.UIService;
38+
39+
import java.io.File;
40+
41+
@Plugin(type = Command.class, menuPath = "Test>File and Directory Chooser Command")
42+
public class FileAndDirectoryChooserCommandDemo implements Command {
43+
44+
@Parameter (style = "both")
45+
File file;
46+
47+
@Override
48+
public void run() {
49+
System.out.println("You chose: " + file.toString());
50+
}
51+
52+
public static void main(String... args) throws Exception {
53+
54+
Context context = new Context();
55+
context.service(UIService.class).showUI();
56+
context.service(CommandService.class).run( FileAndDirectoryChooserCommandDemo.class, true);
57+
58+
}
59+
}

0 commit comments

Comments
 (0)