Example usage for javax.swing JFileChooser showSaveDialog

List of usage examples for javax.swing JFileChooser showSaveDialog

Introduction

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

Prototype

public int showSaveDialog(Component parent) throws HeadlessException 

Source Link

Document

Pops up a "Save File" file chooser dialog.

Usage

From source file:tk.tomby.tedit.actions.ExitAction.java

/**
 * DOCUMENT ME!/*from w  ww  .j a v  a 2 s. c om*/
 *
 * @param evt DOCUMENT ME!
 */
public void actionPerformed(ActionEvent evt) {
    for (IBuffer buffer : WorkspaceManager.getBufferList()) {
        if (buffer.isModified()) {
            if (log.isDebugEnabled()) {
                log.debug(buffer.getFileName() + "was modified");
            }

            int retval = JOptionPane.showConfirmDialog(WorkspaceManager.getMainFrame(),
                    ResourceManager.getProperty("main.savechanges.title"), buffer.getFileName(),
                    JOptionPane.YES_NO_CANCEL_OPTION);

            switch (retval) {
            case JOptionPane.YES_OPTION:

                if (!buffer.isNew()) {
                    buffer.save();
                } else {
                    JFileChooser chooser = new JFileChooser();

                    if (chooser
                            .showSaveDialog(WorkspaceManager.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
                        buffer.saveAs(chooser.getSelectedFile());
                    }
                }

                break;

            case JOptionPane.NO_OPTION:
                break;

            default:
                return;
            }
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("saving workspace");
    }

    WorkspaceManager.save();
    PluginManager.save();

    if (log.isDebugEnabled()) {
        log.debug("exit from application");
    }

    System.exit(0);
}

From source file:ui.UI.java

private void jButtonOutputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOutputFileActionPerformed
    JFileChooser chooser = new JFileChooser(new File("."));

    int choice = chooser.showSaveDialog(null);

    if (choice == JFileChooser.APPROVE_OPTION) {
        toddler.setOutputFile(chooser.getSelectedFile());
    }/*www. j  ava 2s  . c  o m*/
}

From source file:uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetDisplay.java

public void actionPerformed(ActionEvent ae) {

    /*   if (ae.getActionCommand().equals("plot")) {
            // ww w. jav  a2s  . co m
          drawScatterPlot();         
       }
    */
    if (ae.getActionCommand().equals("save_image")) {
        ImageSaver.saveImage(scatterPlotPanel);
    }

    else if (ae.getActionCommand().equals("swap_plot")) {

        if (storesQuantitated()) {

            plotPanel.remove(scatterPlotPanel);

            if (scatterPlotPanel instanceof GeneSetScatterPlotPanel) {
                scatterPlotPanel = new ZScoreScatterPlotPanel(fromStore, toStore, probes,
                        currentSelectedProbeList, dotSizeSlider.getValue(), zScoreLookupTable);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display standard scatterplot");
            } else if (scatterPlotPanel instanceof ZScoreScatterPlotPanel) {
                scatterPlotPanel = new GeneSetScatterPlotPanel(fromStore, toStore, startingProbeList,
                        currentSelectedProbeList, true, dotSizeSlider.getValue(), customRegressionValues,
                        simpleRegression);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display z-score plot");
            }
        }
    }

    else if (ae.getActionCommand().equals("close")) {

        /*   if(currentSelectedProbeList != null){
              currentSelectedProbeList[0].delete();
              //currentSelectedProbeList = null;
                      
           }
        */ this.dispose();

    } else if (ae.getActionCommand().equals("select_all")) {

        if (selectAllButton.isSelected()) {

            for (int i = 0; i < tableModel.selected.length; i++) {

                tableModel.selected[i] = true;

                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("deselect all");
        } else {

            for (int i = 0; i < tableModel.selected.length; i++) {

                tableModel.selected[i] = false;
                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("select all");
        }

    }

    else if (ae.getActionCommand().equals("save_selected_probelists")) {

        boolean[] selectedListsBoolean = tableModel.selected;

        if (selectedListsBoolean.length != filterResultsPVals.length) {
            System.err.println("not adding up here");
        }

        else {

            ArrayList<MappedGeneSetTTestValue> selectedListsArrayList = new ArrayList<MappedGeneSetTTestValue>();

            for (int i = 0; i < selectedListsBoolean.length; i++) {

                if (selectedListsBoolean[i] == true) {
                    selectedListsArrayList.add(filterResultsPVals[i]);
                }
            }

            MappedGeneSetTTestValue[] selectedLists = selectedListsArrayList
                    .toArray(new MappedGeneSetTTestValue[0]);

            if (selectedLists.length == 0) {

                JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No probe lists were selected",
                        "No probe lists selected", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            saveProbeLists(selectedLists);

            if (currentSelectedProbeList != null) {
                currentSelectedProbeList[0].delete();
                currentSelectedProbeList = null;
            }
        }
    }

    else if (ae.getActionCommand().equals("save_table")) {
        JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new FileFilter() {

            public String getDescription() {
                return "Text files";
            }

            public boolean accept(File f) {
                if (f.isDirectory() || f.getName().toLowerCase().endsWith(".txt")) {
                    return true;
                } else {
                    return false;
                }
            }

        });

        int result = chooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION)
            return;

        File file = chooser.getSelectedFile();
        if (!file.getPath().toLowerCase().endsWith(".txt")) {
            file = new File(file.getPath() + ".txt");
        }

        SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);

        // Check if we're stepping on anyone's toes...
        if (file.exists()) {
            int answer = JOptionPane.showOptionDialog(this,
                    file.getName() + " exists.  Do you want to overwrite the existing file?", "Overwrite file?",
                    0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" },
                    "Overwrite and Save");

            if (answer > 0) {
                return;
            }
        }

        try {
            PrintWriter p = new PrintWriter(new FileWriter(file));

            TableModel model = table.getModel();

            int rowCount = model.getRowCount();
            int colCount = model.getColumnCount();

            // Do the headers first
            StringBuffer b = new StringBuffer();
            for (int c = 1; c < colCount; c++) {
                b.append(model.getColumnName(c));
                if (c + 1 != colCount) {
                    b.append("\t");
                }
            }

            p.println(b);

            for (int r = 0; r < rowCount; r++) {
                b = new StringBuffer();
                for (int c = 1; c < colCount; c++) {
                    b.append(model.getValueAt(r, c));
                    if (c + 1 != colCount) {
                        b.append("\t");
                    }
                }
                p.println(b);

            }
            p.close();

        }

        catch (FileNotFoundException e) {
            new CrashReporter(e);
        } catch (IOException e) {
            new CrashReporter(e);
        }

    }

    else {
        throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
    }
}

From source file:uk.co.modularaudio.componentdesigner.mainframe.actions.SaveAsFileAction.java

@Override
public void actionPerformed(final ActionEvent e) {
    log.debug("SaveFileAsAction called");

    try {//  w  ww  .ja v a  2s  .  co m
        final JFileChooser saveFileChooser = new JFileChooser();
        final String rackDataModelName = fc.getRackDataModelName();
        final CDFileSaveAccessory fileSaveAccessory = new CDFileSaveAccessory(rackDataModelName);
        saveFileChooser.setAccessory(fileSaveAccessory);
        final String patchesDir = upc.getUserPreferencesMVCController().getModel().getUserPatchesModel()
                .getValue();
        saveFileChooser.setCurrentDirectory(new File(patchesDir));
        final int retVal = saveFileChooser.showSaveDialog(mainFrame);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            final File f = saveFileChooser.getSelectedFile();
            if (f != null) {
                final String rackName = fileSaveAccessory.getFileName();
                if (log.isDebugEnabled()) {
                    log.debug(
                            "Attempting to save to file as " + f.getAbsolutePath() + " with name " + rackName);
                }

                fc.saveRackToFile(f.getAbsolutePath(), rackName);
            }
        }
    } catch (final Exception ex) {
        final String msg = "Exception caught performing save file as action: " + ex.toString();
        log.error(msg, ex);
    }
}

From source file:uk.co.modularaudio.mads.subrack.ui.SubRackMadUiInstance.java

public void saveSubRack(final Component parent)
        throws DatastoreException, IOException, RecordNotFoundException, MAConstraintViolationException {
    final JFileChooser saveFileChooser = new JFileChooser();
    final CDFileSaveAccessory cdSaveFileNameAccessory = new CDFileSaveAccessory(
            rackService.getRackName(subRackDataModel));
    saveFileChooser.setAccessory(cdSaveFileNameAccessory);

    final String subRackPatchDir = userPreferencesService.getUserSubRackPatchesDir();
    saveFileChooser.setCurrentDirectory(new File(subRackPatchDir));
    final int retVal = saveFileChooser.showSaveDialog(parent);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        final File f = saveFileChooser.getSelectedFile();
        if (f != null) {
            if (log.isDebugEnabled()) {
                log.debug("Attempting to save patch to file " + f.getAbsolutePath() + " with name "
                        + cdSaveFileNameAccessory.getFileName());
            }/*from  w w w . ja v a 2  s. co m*/
            rackService.setRackName(subRackDataModel, cdSaveFileNameAccessory.getFileName());
            rackMarshallingService.saveSubRackToFile(subRackDataModel, f.getAbsolutePath());
            // Only set dirty to false after successful save
            rackService.setRackDirty(subRackDataModel, false);
        }
    }
}

From source file:updater.UpdaterGUI.java

@SuppressWarnings("resource")
public UpdaterGUI() {
    try {/* w ww. j a va 2  s . c o  m*/
        URL url1 = new URL(
                "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-version.txt");
        ReadableByteChannel obj1 = Channels.newChannel(url1.openStream());
        FileOutputStream outputstream1 = new FileOutputStream(".release-version.txt");
        outputstream1.getChannel().transferFrom(obj1, 0, Long.MAX_VALUE);
        URL url2 = new URL(
                "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-changelog.txt");
        ReadableByteChannel obj2 = Channels.newChannel(url2.openStream());
        FileOutputStream outputstream2 = new FileOutputStream(".release-changelog.txt");
        outputstream2.getChannel().transferFrom(obj2, 0, Long.MAX_VALUE);
        FileReader file = new FileReader(".release-version.txt");
        BufferedReader reader = new BufferedReader(file);
        String DownloadedString = reader.readLine();
        File file2 = new File(".release-version.txt");
        if (file2.exists() && !file2.isDirectory()) {
            file2.delete();
        }
        AvailableUpdate = Double.parseDouble(DownloadedString);
        InputStreamReader reader2 = new InputStreamReader(
                getClass().getResourceAsStream("/others/app-version.txt"));
        String tmp = IOUtils.toString(reader2);
        ApplicationVersion = Double.parseDouble(tmp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    setIconImage(Toolkit.getDefaultToolkit().getImage(UpdaterGUI.class.getResource("/graphics/Icon.png")));
    setResizable(false);
    setType(Type.UTILITY);
    setTitle("Updater");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 430, 415);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel lblApplicationVersion = new JLabel("App Version: v" + ApplicationVersion);
    lblApplicationVersion.setBounds(12, 12, 222, 15);
    contentPane.add(lblApplicationVersion);

    JLabel lblUpdateVersion = new JLabel("Update Version: v" + AvailableUpdate);
    lblUpdateVersion.setBounds(12, 30, 222, 15);
    contentPane.add(lblUpdateVersion);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(0, 51, 422, 281);
    contentPane.add(scrollPane);

    JTextArea UpdateChangelogViewer = new JTextArea();
    scrollPane.setViewportView(UpdateChangelogViewer);

    JButton btnDownload = new JButton("Download");
    btnDownload.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFrame parentFrame = new JFrame();
            JFileChooser fileChooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Zip Files", "zip");
            fileChooser.setFileFilter(filter);
            fileChooser.setDialogTitle("Save as");
            int userSelection = fileChooser.showSaveDialog(parentFrame);
            if (userSelection == JFileChooser.APPROVE_OPTION) {
                File fileToSave = fileChooser.getSelectedFile();
                try {
                    URL url = new URL("https://github.com/kvsjxd/Droid-PC-Suite/releases/download/"
                            + AvailableUpdate + "/DPCS.v" + AvailableUpdate + ".Stable.zip");
                    ReadableByteChannel obj = Channels.newChannel(url.openStream());
                    FileOutputStream outputstream = new FileOutputStream(fileToSave.getAbsolutePath() + ".zip");
                    outputstream.getChannel().transferFrom(obj, 0, Long.MAX_VALUE);
                    JOptionPane.showMessageDialog(null,
                            "Download complete!\nPlease delete this version and extract the downloaded zip\nwhich is saved at "
                                    + fileToSave.getAbsolutePath() + ".zip");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });
    btnDownload.setBounds(140, 344, 117, 25);
    contentPane.add(btnDownload);
    try {
        FileReader reader3 = new FileReader(new File(".release-changelog.txt"));
        UpdateChangelogViewer.read(reader3, "");
        File file3 = new File(".release-changelog.txt");
        if (file3.exists() && !file3.isDirectory()) {
            file3.delete();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:verdandi.ui.ProjectViewerPanel.java

private void exportProjects() {
    Preferences prefs = Preferences.userNodeForPackage(getClass());

    File exportDir = new File(prefs.get("export.dir", System.getProperty("user.home")));

    JFileChooser chooser = new JFileChooser(exportDir);
    chooser.setDialogTitle(RB.getString("projectviewer.export.filechooser.title"));
    chooser.setMultiSelectionEnabled(false);

    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        LOG.debug("User cancelled");
        return;/*from w  ww .  ja  v  a2  s  . c  o  m*/
    }

    int[] selectedProjects = projectTable.getSelectedRows();

    if (selectedProjects.length == 0) {
        LOG.debug("NO row selected");
        return;
    }

    List<CostUnit> projectsToExport = new ArrayList<CostUnit>();

    for (int i = 0; i < selectedProjects.length; i++) {
        // int selModel = projectTable.getFilters().convertRowIndexToModel(
        // selectedProjects[i]);
        int selModel = selectedProjects[i];
        CostUnit p = tableModel.getProject(selModel);
        LOG.debug("Adding project to export list: " + p);
        projectsToExport.add(p);
    }

    File exportFile = chooser.getSelectedFile();
    LOG.debug("Exporting projects to " + exportFile.getAbsolutePath());

    ObjectOutputStream listOut = null;
    try {
        listOut = new ObjectOutputStream(new FileOutputStream(exportFile));
        listOut.writeObject(projectsToExport);
    } catch (FileNotFoundException e) {
        LOG.error("", e);
    } catch (IOException e) {
        LOG.error("", e);
    } finally {
        if (listOut != null) {
            try {
                listOut.close();
            } catch (Throwable t) {
                LOG.error("Cannot close stream: ", t);
            }
        }
    }

    prefs.put("export.dir", exportFile.getParent());
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Cannot write export file preference", e);
    }

}

From source file:view.CertificatePropertiesDialog.java

private void export(X509Certificate x509c) {
    try {//from  w w w.ja v a  2  s  .com
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setDialogTitle(Bundle.getBundle().getString("title.saveAs"));
        FileNameExtensionFilter cerFilter = new FileNameExtensionFilter(
                Bundle.getBundle().getString("filter.certificateFiles") + " (*.cer)", "cer");
        fileChooser.setFileFilter(cerFilter);
        File preferedFile = new File(getCertificateCN(x509c) + ".cer");
        fileChooser.setSelectedFile(preferedFile);

        int userSelection = fileChooser.showSaveDialog(this);
        if (userSelection == JFileChooser.APPROVE_OPTION) {
            String dest = fileChooser.getSelectedFile().getAbsolutePath();
            File file = new File(dest);
            byte[] buf = x509c.getEncoded();

            FileOutputStream os = new FileOutputStream(file);
            os.write(buf);
            os.close();

            Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8"));
            wr.write(new sun.misc.BASE64Encoder().encode(buf));
            JOptionPane.showMessageDialog(this, Bundle.getBundle().getString("certSuccessfullyExported"), "",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    } catch (CertificateEncodingException ex) {
        JOptionPane.showMessageDialog(this, Bundle.getBundle().getString("certExportFailed") + "\n"
                + Bundle.getBundle().getString("certInvalidEncoding"), "", JOptionPane.ERROR_MESSAGE);
        //Logger.getLogger(CertificatePropertiesDialog.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(this, Bundle.getBundle().getString("certExportFailed") + "\n"
                + Bundle.getBundle().getString("noWritePermissions"), "", JOptionPane.ERROR_MESSAGE);
        //Logger.getLogger(CertificatePropertiesDialog.class.getName()).log(Level.SEVERE, null, ex);
        export(x509c);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this,
                Bundle.getBundle().getString("certExportFailed") + "\n"
                        + Bundle.getBundle().getString("errorCreatingOutputFile"),
                "", JOptionPane.ERROR_MESSAGE);
        //Logger.getLogger(CertificatePropertiesDialog.class.getName()).log(Level.SEVERE, null, ex);
        export(x509c);
    }
}

From source file:view.MultipleValidationDialog.java

private void writeToFile(String str) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle(Bundle.getBundle().getString("title.saveAs"));
    boolean validPath = false;
    FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter(
            Bundle.getBundle().getString("filter.textFiles") + " (*.txt)", "txt");
    fileChooser.setFileFilter(pdfFilter);
    File preferedFile = new File(Bundle.getBundle().getString("validationReport") + ".txt");
    fileChooser.setSelectedFile(preferedFile);

    while (!validPath) {
        int userSelection = fileChooser.showSaveDialog(this);
        if (userSelection == JFileChooser.CANCEL_OPTION) {
            return;
        }/*w ww .j  a  v a2s  .  co m*/
        if (userSelection == JFileChooser.APPROVE_OPTION) {
            String dest = fileChooser.getSelectedFile().getAbsolutePath();
            if (new File(dest).exists()) {
                String msg = Bundle.getBundle().getString("msg.reportFileNameAlreadyExists");
                Object[] options = { Bundle.getBundle().getString("btn.overwrite"),
                        Bundle.getBundle().getString("btn.chooseNewPath"),
                        Bundle.getBundle().getString("btn.cancel") };
                int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                if (opt == JOptionPane.YES_OPTION) {
                    validPath = true;
                } else if (opt == JOptionPane.CANCEL_OPTION) {
                    return;
                }
            } else {
                validPath = true;
            }

            if (validPath) {
                try (PrintStream out = new PrintStream(new FileOutputStream(dest))) {
                    out.print(str);
                    JOptionPane.showMessageDialog(null,
                            Bundle.getBundle().getString("msg.reportSavedSuccessfully"), "",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (FileNotFoundException ex) {
                    controller.Logger.getLogger().addEntry(ex);
                    JOptionPane.showMessageDialog(null, Bundle.getBundle().getString("msg.reportSaveFailed"),
                            "", JOptionPane.ERROR_MESSAGE);
                }
                break;
            }
        }
    }
}

From source file:view.WorkspacePanel.java

private void signDocument(Document document, boolean ocsp, boolean timestamp) {
    try {/*from   w  ww.java 2s .  c o m*/
        if (tempCCAlias.getMainCertificate().getPublicKey().equals(
                CCInstance.getInstance().loadKeyStoreAndAliases().get(0).getMainCertificate().getPublicKey())) {
            try {
                String path1 = document.getDocumentLocation();
                String path2 = null;

                if (path1.endsWith(".pdf")) {
                    path2 = path1.substring(0, path1.length() - 4).concat("(aCCinado).pdf");
                }

                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setDialogTitle(Bundle.getBundle().getString("btn.saveAs"));
                if (null != path2) {
                    boolean validPath = false;
                    FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter(
                            Bundle.getBundle().getString("filter.pdfDocuments") + " (*.pdf)", "pdf");
                    fileChooser.setFileFilter(pdfFilter);
                    File preferedFile = new File(path2);
                    fileChooser.setCurrentDirectory(preferedFile);
                    fileChooser.setSelectedFile(preferedFile);

                    while (!validPath) {
                        int userSelection = fileChooser.showSaveDialog(this);
                        if (userSelection == JFileChooser.CANCEL_OPTION) {
                            return;
                        }
                        if (userSelection == JFileChooser.APPROVE_OPTION) {
                            String dest = fileChooser.getSelectedFile().getAbsolutePath();
                            if (new File(dest).exists()) {
                                String msg = Bundle.getBundle().getString("msg.fileExists");
                                Object[] options = { Bundle.getBundle().getString("opt.replace"),
                                        Bundle.getBundle().getString("opt.chooseNewPath"),
                                        Bundle.getBundle().getString("btn.cancel") };
                                int opt = JOptionPane.showOptionDialog(null, msg, "",
                                        JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                                        options[0]);
                                if (opt == JOptionPane.YES_OPTION) {
                                    validPath = true;
                                } else if (opt == JOptionPane.CANCEL_OPTION) {
                                    return;
                                }
                            } else {
                                validPath = true;
                            }

                            signatureSettings.setOcspClient(ocsp);
                            signatureSettings.setTimestamp(timestamp);

                            if (validPath) {
                                if (!CCInstance.getInstance().signPdf(document.getDocumentLocation(), dest,
                                        signatureSettings, null)) {
                                    JOptionPane.showMessageDialog(mainWindow,
                                            Bundle.getBundle().getString("unknownErrorLog"),
                                            Bundle.getBundle().getString("label.signatureFailed"),
                                            JOptionPane.ERROR_MESSAGE);
                                    return;
                                }
                                status = Status.READY;
                                ArrayList<File> list = new ArrayList<>();
                                list.add(new File(document.getDocumentLocation()));
                                int tempPage = imagePanel.getPageNumber();
                                mainWindow.closeDocuments(list, false);
                                mainWindow.loadPdf(new File(dest), false);
                                hideRightPanel();
                                imagePanel.setPageNumber(tempPage);
                                JOptionPane.showMessageDialog(mainWindow,
                                        Bundle.getBundle().getString("label.signatureOk"), "",
                                        JOptionPane.INFORMATION_MESSAGE);
                                break;
                            }
                        }
                    }
                }
                return;
            } catch (IOException ex) {
                if (ex instanceof FileNotFoundException) {
                    JOptionPane.showMessageDialog(mainWindow,
                            Bundle.getBundle().getString("msg.keystoreFileNotFound"),
                            Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE);
                    controller.Logger.getLogger().addEntry(ex);
                } else if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("outputFileError"))) {
                    JOptionPane.showMessageDialog(mainWindow,
                            Bundle.getBundle().getString("msg.failedCreateOutputFile"),
                            Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE);
                    controller.Logger.getLogger().addEntry(ex);
                    signDocument(document, ocsp, timestamp);
                } else {
                    JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("unknownErrorLog"),
                            Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE);
                    controller.Logger.getLogger().addEntry(ex);
                }
            } catch (DocumentException | NoSuchAlgorithmException | InvalidAlgorithmParameterException
                    | HeadlessException | CertificateException | KeyStoreException ex) {
                controller.Logger.getLogger().addEntry(ex);
            } catch (SignatureFailedException ex) {
                if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("timestampFailed"))) {
                    String msg = Bundle.getBundle().getString("msg.timestampFailedNoInternet");
                    Object[] options = { Bundle.getBundle().getString("yes"),
                            Bundle.getBundle().getString("no") };
                    int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION,
                            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                    if (opt == JOptionPane.YES_OPTION) {
                        signDocument(document, false, false);
                    }
                } else {
                    controller.Logger.getLogger().addEntry(ex);
                }
            }
            return;
        } else {
            JOptionPane.showMessageDialog(mainWindow,
                    Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"),
                    WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE);
        }
    } catch (LibraryNotLoadedException | KeyStoreNotLoadedException | CertificateException | KeyStoreException
            | LibraryNotFoundException | AliasException ex) {
        controller.Logger.getLogger().addEntry(ex);
    }
    JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"),
            WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE);

}