Example usage for javax.swing JFileChooser showDialog

List of usage examples for javax.swing JFileChooser showDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public int showDialog(Component parent, String approveButtonText) throws HeadlessException 

Source Link

Document

Pops a custom file chooser dialog with a custom approve button.

Usage

From source file:org.kse.gui.dialogs.importexport.DImportKeyPairPvk.java

private void privateKeyBrowsePressed() {
    JFileChooser chooser = FileChooserFactory.getPvkFileChooser();

    File currentFile = new File(jtfPrivateKeyPath.getText());

    if ((currentFile.getParentFile() != null) && (currentFile.getParentFile().exists())) {
        chooser.setCurrentDirectory(currentFile.getParentFile());
    } else {/*from  www .  ja  v a  2 s . c om*/
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

    chooser.setDialogTitle(res.getString("DImportKeyPairPvk.ChoosePrivateKey.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this, res.getString("DImportKeyPairPvk.PrivateKeyFileChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);
        jtfPrivateKeyPath.setText(chosenFile.toString());
        jtfPrivateKeyPath.setCaretPosition(0);
    }
}

From source file:org.kse.gui.dialogs.importexport.DImportKeyPairPvk.java

private void certificateBrowsePressed() {
    JFileChooser chooser = FileChooserFactory.getCertFileChooser();

    File currentFile = new File(jtfCertificatePath.getText());

    if ((currentFile.getParentFile() != null) && (currentFile.getParentFile().exists())) {
        chooser.setCurrentDirectory(currentFile.getParentFile());
    } else {//from   w ww.  j  a va2s  .  co m
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

    chooser.setDialogTitle(res.getString("DImportKeyPairPvk.ChooseCertificate.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this, res.getString("DImportKeyPairPvk.CertificateFileChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);
        jtfCertificatePath.setText(chosenFile.toString());
        jtfCertificatePath.setCaretPosition(0);
    }
}

From source file:org.kse.gui.dialogs.sign.DSignJar.java

private void inputJarBrowsePressed() {
    JFileChooser chooser = FileChooserFactory.getArchiveFileChooser();

    File currentFile = new File(jtfInputJar.getText().trim());

    if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) {
        chooser.setCurrentDirectory(currentFile.getParentFile());
        chooser.setSelectedFile(currentFile);
    } else {/*from  ww w.j av  a 2s  . c  o m*/
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

    chooser.setDialogTitle(res.getString("DSignJar.ChooseInputJar.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this, res.getString("DSignJar.InputJarChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);
        jtfInputJar.setText(chosenFile.toString());
        jtfInputJar.setCaretPosition(0);
        populateOutputJarFileName(chosenFile);
    }
}

From source file:org.kse.gui.dialogs.sign.DSignJar.java

private void outputJarBrowsePressed() {
    JFileChooser chooser = FileChooserFactory.getArchiveFileChooser();

    File currentFile = new File(jtfOutputJar.getText());

    if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) {
        chooser.setCurrentDirectory(currentFile.getParentFile());
        chooser.setSelectedFile(currentFile);
    } else {//w  ww.  jav  a  2  s.  co m
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

    chooser.setDialogTitle(res.getString("DSignJar.ChooseOutputJar.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this)
            : chooser.showDialog(this, res.getString("DSignJar.OutputJarChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);
        jtfOutputJar.setText(chosenFile.toString());
        jtfOutputJar.setCaretPosition(0);
    }
}

From source file:org.kse.gui.dialogs.sign.DSignMidlet.java

private void inputJadBrowsePressed() {
    JFileChooser chooser = FileChooserFactory.getJadFileChooser();

    File currentFile = new File(jtfInputJad.getText());

    if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) {
        chooser.setCurrentDirectory(currentFile.getParentFile());
        chooser.setSelectedFile(currentFile);
    } else {//from w  ww . j av a 2  s . com
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

    chooser.setDialogTitle(res.getString("DSignMidlet.ChooseInputJad.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this, res.getString("DSignMidlet.InputJadChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);
        jtfInputJad.setText(chosenFile.toString());
        jtfInputJad.setCaretPosition(0);
        populateOutputJadFileName(chosenFile);
    }
}

From source file:org.kse.gui.dialogs.sign.DSignMidlet.java

private void outputJadBrowsePressed() {
    JFileChooser chooser = FileChooserFactory.getJadFileChooser();

    File currentFile = new File(jtfOutputJad.getText());

    if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) {
        chooser.setCurrentDirectory(currentFile.getParentFile());
        chooser.setSelectedFile(currentFile);
    } else {/*from w  w w.j  a v  a 2s . c o  m*/
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

    chooser.setDialogTitle(res.getString("DSignMidlet.ChooseOutputJad.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this)
            : chooser.showDialog(this, res.getString("DSignMidlet.OutputJadChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);
        jtfOutputJad.setText(chosenFile.toString());
        jtfOutputJad.setCaretPosition(0);
    }
}

From source file:org.kse.gui.dialogs.sign.DSignMidlet.java

private void jarBrowsePressed() {
    JFileChooser chooser = FileChooserFactory.getArchiveFileChooser();

    File currentFile = new File(jtfJar.getText());

    if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) {
        chooser.setCurrentDirectory(currentFile.getParentFile());
    } else {//from  www  .  j a va  2 s  .com
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

    chooser.setDialogTitle(res.getString("DSignMidlet.ChooseJar.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this, res.getString("DSignMidlet.JarChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(chosenFile);
        jtfJar.setText(chosenFile.toString());
        jtfJar.setCaretPosition(0);
    }
}

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  a  v a2 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();
        }
    }
}