use of javax.swing.JFileChooser.DIRECTORIES_ONLY in project briefcase by opendatakit.
the class FileChooser method buildFileDialog.
static FileDialog buildFileDialog(Container parent, Optional<File> initialLocation, JFileChooser fileChooser) {
System.setProperty("apple.awt.fileDialogForDirectories", fileChooser.getFileSelectionMode() == DIRECTORIES_ONLY ? "true" : "false");
Window windowAncestor = SwingUtilities.getWindowAncestor(parent);
FileDialog fileDialog = windowAncestor instanceof Frame ? new FileDialog((Frame) windowAncestor, fileChooser.getDialogTitle()) : new FileDialog((Dialog) windowAncestor, fileChooser.getDialogTitle());
if (fileChooser.getFileSelectionMode() == DIRECTORIES_ONLY)
fileDialog.setFilenameFilter((dir, name) -> new File(dir, name).isDirectory());
initialLocation.ifPresent(file -> fileDialog.setFile(file.getAbsolutePath()));
return fileDialog;
}
Aggregations