Skip to content

Commit 4dddf65

Browse files
authored
Merge pull request #84 from tischi/fix-issue-83
Enable FileWidget.FILE_AND_DIRECTORY_STYLE
2 parents f0f6a67 + d013819 commit 4dddf65

4 files changed

Lines changed: 73 additions & 6 deletions

File tree

‎pom.xml‎

Lines changed: 5 additions & 0 deletions
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>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public File chooseFile(final Component owner, final File file,
159159
final JFileChooser chooser = new JFileChooser(file);
160160
if (FileWidget.DIRECTORY_STYLE.equals(style)) {
161161
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
162+
} else if (FileWidget.FILE_AND_DIRECTORY_STYLE.equals(style)) {
163+
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
162164
}
163165
final int rval;
164166
if (FileWidget.SAVE_STYLE.equals(style)) {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ public void actionPerformed(final ActionEvent e) {
132132
final String style;
133133
if (model.isStyle(FileWidget.DIRECTORY_STYLE)) {
134134
style = FileWidget.DIRECTORY_STYLE;
135-
}
136-
else if (model.isStyle(FileWidget.SAVE_STYLE)) {
135+
} else if (model.isStyle(FileWidget.FILE_AND_DIRECTORY_STYLE)) {
136+
style = FileWidget.FILE_AND_DIRECTORY_STYLE;
137+
} else if (model.isStyle(FileWidget.SAVE_STYLE)) {
137138
style = FileWidget.SAVE_STYLE;
138-
}
139-
else {
139+
} else {
140140
style = FileWidget.OPEN_STYLE;
141141
}
142142
file = chooseFile(file, style);
@@ -185,8 +185,9 @@ public void doRefresh() {
185185
* <ul>
186186
* <li>{@link FileWidget#OPEN_STYLE}</li>
187187
* <li>{@link FileWidget#SAVE_STYLE}</li>
188-
* <li>{@link FileListWidget#FILES_ONLY}</li>
189188
* <li>{@link FileWidget#DIRECTORY_STYLE}</li>
189+
* <li>{@link FileWidget#FILE_AND_DIRECTORY_STYLE}</li>
190+
* <li>{@link FileListWidget#FILES_ONLY}</li>
190191
* <li>{@link FileListWidget#DIRECTORIES_ONLY}</li>
191192
* <li>{@link FileListWidget#FILES_AND_DIRECTORIES}</li>
192193
* </ul>
@@ -204,7 +205,7 @@ public static FileFilter createFileFilter(final String widgetStyle) {
204205
FileWidget.DIRECTORY_STYLE, FileListWidget.DIRECTORIES_ONLY
205206
);
206207
final List<String> filesAndDirsStyles = Arrays.asList(
207-
FileListWidget.FILES_AND_DIRECTORIES
208+
FileWidget.FILE_AND_DIRECTORY_STYLE, FileListWidget.FILES_AND_DIRECTORIES
208209
);
209210

210211
final List<String> exts = new ArrayList<>();
Lines changed: 59 additions & 0 deletions
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 - 2026 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)