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.jab.docsearch.DocSearch.java

private void doOpen() {
    JFileChooser fdo = new JFileChooser();
    fdo.setCurrentDirectory(new File(defaultSaveFolder));
    int fileGotten = fdo.showDialog(this, I18n.getString("button.open"));
    if (fileGotten == JFileChooser.APPROVE_OPTION) {
        File file = fdo.getSelectedFile();
        String fileName = file.toString();
        // get document stream and save it
        if (!fileName.startsWith("http")) {
            setPage(fileString + fileName);
        } else {/*from   w w w. ja v  a2  s  .  c  o m*/
            setPage(fileName);
        }
    }
    // end if approved
}

From source file:org.jab.docsearch.DocSearch.java

private void doSave() {
    setStatus(I18n.getString("tooltip.save"));

    // defaultSaveFolder
    JFileChooser fds = new JFileChooser();
    fds.setDialogTitle(I18n.getString("windowtitle.save"));

    String saveName;//ww w  .j  a  v  a2  s .c  om
    if (curPage.equals("results")) {
        saveName = "results.htm";
    } else if (curPage.equals("home")) {
        saveName = "home.htm";
    } else {
        saveName = Utils.getNameOnly(curPage);
    }
    saveName = FileUtils.addFolder(defaultSaveFolder, saveName);
    fds.setCurrentDirectory(new File(defaultSaveFolder));
    fds.setSelectedFile(new File(saveName));

    int fileGotten = fds.showDialog(this, I18n.getString("button.save"));
    if (fileGotten == JFileChooser.APPROVE_OPTION) {
        File saveFile = fds.getSelectedFile();
        setStatus(I18n.getString("button.save") + saveFile);

        // get document stream and save it
        String saveText = editorPane.getText();
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(new FileWriter(saveFile));
            pw.print(saveText);
        } catch (IOException ioe) {
            logger.fatal("doSave() failed with IOException", ioe);
            showMessage(dsErrSaFi, "\n" + saveFile);
        } finally {
            IOUtils.closeQuietly(pw);
        }
    }
}

From source file:org.jab.docsearch.DocSearch.java

private void getSeachLogReport() {
    JFileChooser fdo = new JFileChooser();
    fdo.setCurrentDirectory(new File(fEnv.getWorkingDirectory()));
    int fileGotten = fdo.showDialog(this, I18n.getString("select"));
    if (fileGotten == JFileChooser.APPROVE_OPTION) {
        File file = fdo.getSelectedFile();
        try {//from   w  w  w. j av  a2 s .c  o  m
            LogAnalysis.doLogAnalysis(this, file.toString());
        } catch (IOException ioe) {
            logger.fatal("getSeachLogReport() failed", ioe);
            setStatus(I18n.getString("error_status_log_report") + ioe.toString());
        }
    }
}

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 w w  .  ja va  2s .  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.kse.gui.actions.ImportCaReplyFromFileAction.java

private File chooseCaFile() {
    JFileChooser chooser = FileChooserFactory.getCaReplyFileChooser();
    chooser.setCurrentDirectory(CurrentDirectory.get());
    chooser.setDialogTitle(res.getString("ImportCaReplyFromFileAction.ImportCaReply.Title"));
    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(frame, res.getString("ImportCaReplyFromFileAction.ImportCaReply.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File openFile = chooser.getSelectedFile();
        CurrentDirectory.updateForFile(openFile);
        return openFile;
    }//  ww w  .ja v a  2 s.  c  o  m

    return null;
}

From source file:org.kse.gui.crypto.DUpgradeCryptoStrength.java

private void browsePolicyPressed() {
    JFileChooser chooser = FileChooserFactory.getZipFileChooser();

    chooser.setCurrentDirectory(CurrentDirectory.get());

    chooser.setDialogTitle(res.getString("DUpgradeCryptoStrength.Title.ChoosePolicyZip.Title"));

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this,
            res.getString("DUpgradeCryptoStrength.Title.PolicyZipChooser.button"));
    if (rtnValue == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();

        if (!chosenFile.isFile()) {
            JOptionPane.showMessageDialog(DUpgradeCryptoStrength.this,
                    res.getString("DUpgradeCryptoStrength.NotPolicyZip.message"),
                    res.getString("DUpgradeCryptoStrength.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }/*from w ww .  j  a va  2  s  .  com*/

        processPolicyZipFile(chosenFile);
    }
}

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

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

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

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

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

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this,
            res.getString("DImportKeyPairOpenSsl.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.DImportKeyPairOpenSsl.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  ww  w . j a  va 2s  .com*/
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

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

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this,
            res.getString("DImportKeyPairOpenSsl.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.importexport.DImportKeyPairPkcs8.java

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

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

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

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

    chooser.setMultiSelectionEnabled(false);

    int rtnValue = chooser.showDialog(this, res.getString("DImportKeyPairPkcs8.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.DImportKeyPairPkcs8.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 {/*  w w w. java  2s .  c  o  m*/
        chooser.setCurrentDirectory(CurrentDirectory.get());
    }

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

    chooser.setMultiSelectionEnabled(false);

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