Example usage for javax.swing JFileChooser DIRECTORIES_ONLY

List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY

Introduction

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

Prototype

int DIRECTORIES_ONLY

To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.

Click Source Link

Document

Instruction to display only directories.

Usage

From source file:org.jax.haplotype.io.SnpStreamUtil.java

/**
 * A main for snp data conversion//ww w .  j av a  2s  .  com
 * @param args
 *          dont care
 * @throws IOException
 *          if we get one
 */
public static void main(String[] args) throws IOException {
    JFileChooser inputFileChooser = new JFileChooser();
    inputFileChooser.setDialogTitle("Select CSV Chromosome Input Files");
    inputFileChooser.setMultiSelectionEnabled(true);
    inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int userSelection = inputFileChooser.showOpenDialog(null);
    if (userSelection == JFileChooser.APPROVE_OPTION) {
        JFileChooser outputDirectoryChooser = new JFileChooser();
        outputDirectoryChooser.setDialogTitle("Select an Output Directory");
        outputDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int outputUserSelection = outputDirectoryChooser.showOpenDialog(null);

        if (outputUserSelection == JFileChooser.APPROVE_OPTION) {
            File selectedOutputDirectory = outputDirectoryChooser.getSelectedFile();
            File[] selectedInputFiles = inputFileChooser.getSelectedFiles();
            for (File selectedInputFile : selectedInputFiles) {
                writeBinaryChromosomeData(new GenotypeParser(), selectedInputFile, selectedOutputDirectory);
            }
        }
    } else {
        System.out.println("user doesn't want to open the file");
    }
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Prepares to perform a download of objects from S3 by prompting the user for a directory
 * to store the files in, then performing the download.
 *
 * @throws IOException/*from w ww .  j a  v  a2s  . c  o m*/
 */
private void downloadSelectedObjects() throws IOException {
    // Prompt user to choose directory location for downloaded files (or cancel download altogether)
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Choose directory to save S3 files in");
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setSelectedFile(downloadDirectory);

    int returnVal = fileChooser.showDialog(ownerFrame, "Choose Directory");
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;
    }

    downloadDirectory = fileChooser.getSelectedFile();

    prepareForObjectsDownload();
}

From source file:org.kuali.test.creator.TestCreator.java

private void handleBackupRepository() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int result = fileChooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        final File selectedFile = fileChooser.getSelectedFile();

        new SplashDisplay(this, "Back Up", "Backing up repository...") {
            @Override/*www  .  j ava  2s .  co  m*/
            protected void runProcess() {
                try {
                    new ZipDirectory(new File(getConfiguration().getRepositoryLocation()),
                            getBackupFile(selectedFile));
                }

                catch (Exception ex) {
                    LOG.error(ex.toString(), ex);
                }
            }
        };
    }
}

From source file:org.kuali.test.ui.components.panels.FileTestPanel.java

/**
 *
 * @param e/* ww  w  .j a v a 2  s .  c  o m*/
 */
@Override
protected void handleUnprocessedActionEvent(ActionEvent e) {
    if (Constants.FILE_SEARCH_ACTION.equals(e.getActionCommand())) {
        Preferences proot = Preferences.userRoot();
        Preferences node = proot.node(Constants.PREFS_FILES_NODE);

        String lastDir = node.get(Constants.PREFS_LAST_FILE_TEST_DIR, System.getProperty("user.home"));

        JFileChooser chooser = new JFileChooser(lastDir);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return (f.isDirectory() && f.exists());
            }

            @Override
            public String getDescription() {
                return "file inquiry directory";
            }
        });

        int returnVal = chooser.showOpenDialog(getMainframe());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = chooser.getSelectedFile();
            fileDirectory.setText(f.getPath());
            node.put(Constants.PREFS_LAST_FILE_TEST_DIR, f.getPath());
        }
    } else if (Constants.FILE_EXISTS.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_DOES_NOT_EXIST).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(true);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(true);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(true);
        containingText.setEnabled(true);
    } else if (Constants.FILE_DOES_NOT_EXIST.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_EXISTS).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(false);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(false);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(false);
        containingText.setText("");
        containingText.setEnabled(false);
    } else if (Constants.FILE_CREATED_TODAY.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false);
    } else if (Constants.FILE_CREATED_YESTERDAY.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false);
    }
}

From source file:org.languagetool.gui.Tools.java

/**
 * Show a directory chooser dialog, starting with a specified directory
 * @param frame Owner frame//from  w w  w  . j  a  va  2  s .  com
 * @param initialDir The initial directory
 * @return the selected file
 * @since 3.0
 */
static File openDirectoryDialog(Frame frame, File initialDir) {
    return openFileDialog(frame, null, initialDir, JFileChooser.DIRECTORIES_ONLY);
}

From source file:org.martin.ftp.gui.GUIClient.java

private void downloadFile(FTPFile selected) throws IOException {
    fileChoos.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChoos.showOpenDialog(this);
    File directory = fileChoos.getSelectedFile();

    if (directory != null)
        linker.downloadFile(selected.getName(), directory.getPath());

}

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();//from ww  w. j  a  v  a 2  s  .c  om

                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.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.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());
    }//  ww  w .j  a  v  a  2 s  . co  m
}

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());
    }//from w  w w . j a va 2 s .com
}