Skip to content
Snippets Groups Projects
Commit ff7611b7 authored by cramakri's avatar cramakri
Browse files

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
...@@ -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");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment