Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
ff7611b7
Commit
ff7611b7
authored
14 years ago
by
cramakri
Browse files
Options
Downloads
Patches
Plain Diff
LMS-2102 Expand the options available in the file chooser utils.
SVN: 20265
parent
5f063ac4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/source/java/ch/systemsx/cisd/common/gui/FileChooserUtils.java
+31
-0
31 additions, 0 deletions
...ce/java/ch/systemsx/cisd/common/gui/FileChooserUtils.java
with
31 additions
and
0 deletions
common/source/java/ch/systemsx/cisd/common/gui/FileChooserUtils.java
+
31
−
0
View file @
ff7611b7
...
@@ -85,6 +85,37 @@ public class FileChooserUtils
...
@@ -85,6 +85,37 @@ public class FileChooserUtils
}
}
/**
* Let the user choose a file or directory. Start the selection process in
* <var>initialDirectoryOrNull</var> (defaulted to the home directory if it is null). The
* windows will be shown relative to <var>parentFrame</var>.
*
* @return The new file or directory if the user approved the selection or <code>null</code> if
* the user cancelled the selection.
*/
public
static
File
tryChooseFileOrDirectory
(
Frame
parentFrame
,
File
initialDirectoryOrNull
)
{
// We can't use the awt file chooser to select files *or* directories (it only allows
// selection of one or the other).
File
initialDirectory
=
(
initialDirectoryOrNull
!=
null
)
?
initialDirectoryOrNull
:
new
File
(
System
.
getProperty
(
"user.home"
));
final
JFileChooser
fileChooser
=
new
JFileChooser
(
initialDirectory
);
fileChooser
.
setFileSelectionMode
(
JFileChooser
.
FILES_AND_DIRECTORIES
);
fileChooser
.
setDialogTitle
(
"Select a directory or file"
);
final
int
returnVal
=
fileChooser
.
showOpenDialog
(
parentFrame
);
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
return
fileChooser
.
getSelectedFile
();
}
else
{
return
null
;
}
}
private
static
String
getTitle
(
boolean
chooseDirectories
)
private
static
String
getTitle
(
boolean
chooseDirectories
)
{
{
return
"Select a "
+
(
chooseDirectories
?
"Directory"
:
"File"
);
return
"Select a "
+
(
chooseDirectories
?
"Directory"
:
"File"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment