Search in sources :

Example 1 with DIRECTORIES_ONLY

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;
}
Also used : Window(java.awt.Window) OPEN_DIALOG(javax.swing.JFileChooser.OPEN_DIALOG) Frame(java.awt.Frame) Predicate(java.util.function.Predicate) Window(java.awt.Window) FindDirectoryStructure.isUnix(org.opendatakit.briefcase.util.FindDirectoryStructure.isUnix) FileFilter(javax.swing.filechooser.FileFilter) FILES_ONLY(javax.swing.JFileChooser.FILES_ONLY) File(java.io.File) FindDirectoryStructure.isWindows(org.opendatakit.briefcase.util.FindDirectoryStructure.isWindows) SwingUtilities(javax.swing.SwingUtilities) FileDialog(java.awt.FileDialog) Optional(java.util.Optional) Container(java.awt.Container) JFileChooser(javax.swing.JFileChooser) DIRECTORIES_ONLY(javax.swing.JFileChooser.DIRECTORIES_ONLY) Dialog(java.awt.Dialog) Frame(java.awt.Frame) FileDialog(java.awt.FileDialog) Dialog(java.awt.Dialog) FileDialog(java.awt.FileDialog) File(java.io.File)

Aggregations

Container (java.awt.Container)1 Dialog (java.awt.Dialog)1 FileDialog (java.awt.FileDialog)1 Frame (java.awt.Frame)1 Window (java.awt.Window)1 File (java.io.File)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 JFileChooser (javax.swing.JFileChooser)1 DIRECTORIES_ONLY (javax.swing.JFileChooser.DIRECTORIES_ONLY)1 FILES_ONLY (javax.swing.JFileChooser.FILES_ONLY)1 OPEN_DIALOG (javax.swing.JFileChooser.OPEN_DIALOG)1 SwingUtilities (javax.swing.SwingUtilities)1 FileFilter (javax.swing.filechooser.FileFilter)1 FindDirectoryStructure.isUnix (org.opendatakit.briefcase.util.FindDirectoryStructure.isUnix)1 FindDirectoryStructure.isWindows (org.opendatakit.briefcase.util.FindDirectoryStructure.isWindows)1