Example usage for javax.swing JFileChooser setFileSelectionMode

List of usage examples for javax.swing JFileChooser setFileSelectionMode

Introduction

In this page you can find the example usage for javax.swing JFileChooser setFileSelectionMode.

Prototype

@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY",
        "JFileChooser.DIRECTORIES_ONLY",
        "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.")
public void setFileSelectionMode(int mode) 

Source Link

Document

Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories.

Usage

From source file:org.mbs3.juniuploader.gui.pnlWoWDirectories.java

private void btnAddDirectoryActionPerformed(ActionEvent evt) {
    if (evt.getSource() == this.btnAddDirectory) {
        boolean failed = false;
        boolean mac = Util.isMac();
        if (mac) {
            java.awt.Frame f = jUniUploader.inst;
            FileDialog fd = new FileDialog(f, "Select a World of Warcraft Directory", FileDialog.LOAD);
            try {
                fd.show();/*www  .j  a v  a 2 s. c  o m*/

                String fileName = fd.getFile();
                String rootDir = fd.getDirectory();
                String completePath = (rootDir == null ? "" : rootDir) + (fileName == null ? "" : fileName);
                log.debug("Adding OS X style " + completePath);
                if (completePath != null) {
                    File file = new File(completePath);
                    if (file != null && file.exists() && file.isDirectory()) {
                        WDirectory wd = new WDirectory(file);
                        frmMain.wowDirectories.addElement(wd);
                    }

                }

            } catch (Exception ex) {
                failed = true;
                log.warn("Failed trying to display a FileDialog, falling back to JFileChooser", ex);
            }

        }
        if (!mac || failed) {
            JFileChooser fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = fc.showOpenDialog(this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                if (file != null && file.exists() && file.isDirectory()) {
                    WDirectory wd = new WDirectory(file);
                    frmMain.wowDirectories.addElement(wd);
                }

            } else {
                log.trace("Open command cancelled by user.");
            }

        }
    }
}

From source file:org.neo4j.desktop.ui.BrowseForDatabaseActionListener.java

private File fileSelection() {
    File selectedFile = null;//w  w w. ja  va  2  s .  c o m

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(DIRECTORIES_ONLY);
    fileChooser.setCurrentDirectory(new File(directoryDisplay.getText()));
    fileChooser.setDialogTitle("Select database");
    fileChooser.setDialogType(CUSTOM_DIALOG);

    int choice = fileChooser.showOpenDialog(frame);

    if (choice == APPROVE_OPTION) {
        selectedFile = fileChooser.getSelectedFile();
    }

    return selectedFile;
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private void pickFolder() {
    JFileChooser fileChooser = new JFileChooser(new File(folderField.getText()));
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = fileChooser.showDialog(frame, "Select folder");
    if (returnVal == JFileChooser.APPROVE_OPTION)
        folderField.setText(fileChooser.getSelectedFile().getAbsolutePath());
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private void pickScanReportFile() {
    JFileChooser fileChooser = new JFileChooser(new File(folderField.getText()));
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int returnVal = fileChooser.showDialog(frame, "Select scan report file");
    if (returnVal == JFileChooser.APPROVE_OPTION)
        scanReportFileField.setText(fileChooser.getSelectedFile().getAbsolutePath());
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private void pickTables() {
    DbSettings sourceDbSettings = getSourceDbSettings();
    if (sourceDbSettings != null) {
        if (sourceDbSettings.dataType == DbSettings.CSVFILES) {
            JFileChooser fileChooser = new JFileChooser(new File(folderField.getText()));
            fileChooser.setMultiSelectionEnabled(true);
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Delimited text files", "csv", "txt");
            fileChooser.setFileFilter(filter);

            int returnVal = fileChooser.showDialog(frame, "Select tables");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                for (File table : fileChooser.getSelectedFiles()) {
                    String tableName = DirectoryUtilities.getRelativePath(new File(folderField.getText()),
                            table);//from  w  w  w. j av a 2 s.  co m
                    if (!tables.contains(tableName))
                        tables.add(tableName);
                    tableList.setListData(tables);
                }

            }
        } else if (sourceDbSettings.dataType == DbSettings.DATABASE) {
            RichConnection connection = new RichConnection(sourceDbSettings.server, sourceDbSettings.domain,
                    sourceDbSettings.user, sourceDbSettings.password, sourceDbSettings.dbType);
            String tableNames = StringUtilities.join(connection.getTableNames(sourceDbSettings.database), "\t");
            if (tableNames.length() == 0) {
                JOptionPane.showMessageDialog(frame, "No tables found in database " + sourceDbSettings.database,
                        "Error fetching table names", JOptionPane.ERROR_MESSAGE);
            } else {
                DBTableSelectionDialog selectionDialog = new DBTableSelectionDialog(frame, true, tableNames);
                if (selectionDialog.getAnswer()) {
                    for (Object item : selectionDialog.getSelectedItems()) {
                        if (!tables.contains(item))
                            tables.add((String) item);
                        tableList.setListData(tables);
                    }
                }
            }
            connection.close();
        }
    }
}

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

private void settingsFolderChooseButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_settingsFolderChooseButtonActionPerformed
    JFileChooser settingsFolderChooser = new JFileChooser();
    settingsFolderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = settingsFolderChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = settingsFolderChooser.getSelectedFile();
        settingsFolderTextField.setText(file.getAbsolutePath());
    }/*from  w  w  w.  j  a v  a  2s  .com*/
}

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

private void panboxFolderChooseButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_panboxFolderChooseButtonActionPerformed
    JFileChooser panboxFolderChooser = new JFileChooser();
    panboxFolderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = panboxFolderChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = panboxFolderChooser.getSelectedFile();
        panboxFolderTextField.setText(file.getAbsolutePath());
    }//w  ww . j a v  a 2 s .  co  m
}

From source file:org.panbox.desktop.common.gui.RestoreRevisionDialog.java

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser(PANBOX_DIR + "/" + shareName);
    fileChooser.setFileView(new FileView() {
        @Override/*from w  ww  .  j av  a 2s.com*/
        public Boolean isTraversable(File f) {
            try {
                return f.isDirectory()
                        && FilenameUtils.directoryContains(PANBOX_DIR.getAbsolutePath(), f.getAbsolutePath());
            } catch (IOException e) {
                logger.error("Error determining folder parent status!");
                return true;
            }
        }
    });
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int ret = fileChooser.showOpenDialog(this);
    if (ret == JFileChooser.APPROVE_OPTION && fileChooser.getSelectedFile().getParentFile().getAbsolutePath()
            .startsWith(PANBOX_DIR.getAbsolutePath())) {
        String path = getCSPSupportedPath(fileChooser.getSelectedFile().getPath());
        fileTextField.setText(path);
        fillRevisionsForFileName(path);
    }
}

From source file:org.panbox.desktop.common.vfs.backend.dropbox.DropboxClientIntegration.java

@Override
public File getCurrentSyncDir() throws IOException {
    Settings settings = Settings.getInstance();
    File f = new File(settings.getDropboxSynchronizationDir());
    if (!f.exists() || !f.isDirectory()) {
        // FIXME: this should be handled in a dedicated pane for
        // CSP-specific settings
        int res = JOptionPane.showConfirmDialog(null,
                bundle.getString("DropboxClientIntegration.configureDropboxDir"),
                bundle.getString("DropboxClientIntegration.syncDirLookup"), JOptionPane.YES_NO_OPTION);
        if (res == JOptionPane.YES_OPTION) {
            f = readSyncDirFromMetadata();
            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle(bundle.getString("DropboxClientIntegration.syncDir"));
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setSelectedFile(f);/*from  w ww .j a v  a  2s .c o  m*/
            int ret = chooser.showOpenDialog(null);
            if (ret == JFileChooser.APPROVE_OPTION) {
                f = chooser.getSelectedFile();
                if (f.exists() && f.isDirectory()) {
                    settings.setDropboxSynchronizationDir(f.getAbsolutePath());
                    settings.flush();
                    return f;
                }
            }
        }
    } else {
        return f;
    }
    return null;
}

From source file:org.parosproxy.paros.extension.beanshell.BeanShellConsoleDialog.java

private JButton getBtnLoad() {
    if (btnLoad == null) {
        btnLoad = new JButton();
        btnLoad.setText("Load...");

        btnLoad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                if (getBeanShellPanel().isSaved() == false) {
                    int confirm = view.showConfirmDialog("Script is not saved, discard?");
                    if (confirm == JOptionPane.CANCEL_OPTION)
                        return;
                }/*from w  w w. ja v  a2  s .  c o  m*/
                JFileChooser fc = new JFileChooser(scriptsDir);
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int result = fc.showOpenDialog(getBeanShellPanel());

                if (result == JFileChooser.APPROVE_OPTION) {
                    try {
                        String temp = loadScript(fc.getSelectedFile());
                        getBeanShellPanel().getTxtEditor().setText(temp);
                        getBeanShellPanel().setSaved(true);
                        currentScriptFile = fc.getSelectedFile();
                    } catch (IOException ee) {
                        ee.printStackTrace();
                    }

                }
            }
        });
    }
    return btnLoad;
}