Example usage for javax.swing JOptionPane DEFAULT_OPTION

List of usage examples for javax.swing JOptionPane DEFAULT_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane DEFAULT_OPTION.

Prototype

int DEFAULT_OPTION

To view the source code for javax.swing JOptionPane DEFAULT_OPTION.

Click Source Link

Document

Type meaning Look and Feel should not supply any options -- only use the options from the JOptionPane.

Usage

From source file:view.MainWindow.java

private void refreshOpenedDocumentsList() {
    int tempCount = dmtn.getChildCount();
    lblOpenedDocuments.setText("0 " + Bundle.getBundle().getString("tn.documentsLoaded"));
    dmtn = new DefaultMutableTreeNode(null);
    int num = 0;/*from ww  w . j  a v  a  2  s . co m*/
    if (!files.isEmpty()) {
        File last = null;
        for (File file : files) {
            dmtn.insert(new DefaultMutableTreeNode(file), 0);
            num++;
            if (files.size() == num) {
                last = file;
            }
        }

        if (null == openedFile) {
            ctrl.openDocument(last.getAbsolutePath());
            workspacePanel.setDocument(ctrl.getDocument());
            openedFile = last;

            int opened = dmtn.getChildCount();
            if (opened == 1) {
                lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":");
                dmtn.setUserObject(null);
            } else {
                lblOpenedDocuments
                        .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":");
                dmtn.setUserObject(null);
            }

            TreeModel tm = new DefaultTreeModel(dmtn);
            jtOpenedDocuments.setModel(tm);
            jtOpenedDocuments.setSelectionRow(0);
            jtOpenedDocuments.scrollRowToVisible(0);
        } else if (tempCount != dmtn.getChildCount()) {
            String msg = Bundle.getBundle().getString("msg.openNewOrKeepCurrent2");
            Object[] options = { Bundle.getBundle().getString("yes"),
                    Bundle.getBundle().getString("opt.justAdd") };
            int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (opt == JOptionPane.YES_OPTION) {
                ctrl.openDocument(last.getAbsolutePath());
                workspacePanel.setDocument(ctrl.getDocument());
                openedFile = last;
                int opened = dmtn.getChildCount();
                if (opened == 1) {
                    lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":");
                    dmtn.setUserObject(null);
                } else {
                    lblOpenedDocuments
                            .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":");
                    dmtn.setUserObject(null);
                }
                TreeModel tm = new DefaultTreeModel(dmtn);
                jtOpenedDocuments.setModel(tm);
                jtOpenedDocuments.setSelectionRow(0);
                jtOpenedDocuments.scrollRowToVisible(0);
            } else {
                int opened = dmtn.getChildCount();
                if (opened == 1) {
                    lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":");
                    dmtn.setUserObject(null);
                } else {
                    lblOpenedDocuments
                            .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":");
                    dmtn.setUserObject(null);
                }
                TreeModel tm = new DefaultTreeModel(dmtn);
                jtOpenedDocuments.setModel(tm);
                jtOpenedDocuments.setSelectionRow(num);
                jtOpenedDocuments.scrollRowToVisible(num);
            }
        }

    }
}

From source file:view.MultipleSignDialog.java

/**
 * Creates new form MultipleSignStatusDialog
 *
 * @param parent/*  www.j av  a 2 s .c  o m*/
 * @param modal
 * @param alFiles
 * @param settings
 * @param dest
 */
public MultipleSignDialog(java.awt.Frame parent, boolean modal, final ArrayList<File> alFiles,
        final CCSignatureSettings settings, final String dest) {
    super(parent, modal);
    initComponents();

    updateText();

    jProgressBar1.setMinimum(0);
    jProgressBar1.setMaximum(alFiles.size());
    jProgressBar1.setString(Bundle.getBundle().getString("pb.signed") + ": 0 "
            + Bundle.getBundle().getString("of") + alFiles.size());

    final DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
    final SignatureListener sl = new SignatureListener() {

        @Override
        public void onSignatureComplete(String filename, boolean valid, String message) {
            dtm.addRow(new Object[] { filename,
                    (valid ? Bundle.getBundle().getString("label.signatureOk")
                            : Bundle.getBundle().getString("label.signatureFailed"))
                            + (message.isEmpty() ? "" : " - " + message) });
        }
    };

    Runnable r = new Runnable() {
        @Override
        public void run() {
            int numSigned = 0;
            btnClose.setEnabled(false);
            for (File file : alFiles) {
                String destinationPath = "";
                boolean validPath = false;
                if (dest == null) {
                    if (file.getName().endsWith(".pdf")) {
                        destinationPath = file.getAbsolutePath()
                                .substring(0, file.getAbsolutePath().length() - 4).concat("(aCCinado).pdf");
                        if (new File(destinationPath).exists()) {
                            int num = 1;
                            while (!validPath) {
                                destinationPath = file.getAbsolutePath()
                                        .substring(0, file.getAbsolutePath().length() - 4)
                                        .concat("(aCCinado" + num + ").pdf");
                                if (new File(destinationPath).exists()) {
                                    destinationPath = file.getAbsolutePath()
                                            .substring(0, file.getAbsolutePath().length() - 4)
                                            .concat("(aCCinado).pdf");
                                    num++;
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    if (file.getName().endsWith(".pdf")) {
                        destinationPath = dest + File.separator + file.getName()
                                .substring(0, file.getName().length() - 4).concat("(aCCinado).pdf");
                        if (new File(destinationPath).exists()) {
                            int num = 1;
                            while (!validPath) {
                                destinationPath = dest + File.separator
                                        + file.getName().substring(0, file.getName().length() - 4)
                                                .concat("(aCCinado" + num + ").pdf");
                                if (new File(destinationPath).exists()) {
                                    destinationPath = dest + File.separator + file.getName()
                                            .substring(0, file.getName().length() - 4).concat("(aCCinado).pdf");
                                    num++;
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                }

                try {
                    // Aplicar
                    if (CCInstance.getInstance().signPdf(file.getAbsolutePath(), destinationPath, settings,
                            sl)) {
                        signedDocsList.add(new File(destinationPath));
                        numSigned++;
                        jProgressBar1.setValue(numSigned);
                        jProgressBar1.setString(Bundle.getBundle().getString("pb.signed") + ": " + numSigned
                                + " " + Bundle.getBundle().getString("of") + " " + alFiles.size());

                    } else {
                        //JOptionPane.showMessageDialog(this, "Erro desconhecido: ver log", "Assinatura falhou", JOptionPane.ERROR_MESSAGE);
                    }
                } catch (CertificateException | IOException | DocumentException | KeyStoreException
                        | NoSuchAlgorithmException | InvalidAlgorithmParameterException ex) {
                    Logger.getLogger(MultipleSignDialog.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SignatureFailedException ex) {
                    if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("userCanceled"))) {
                        String msg = Bundle.getBundle().getString("msg.cancelSigning");
                        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) {
                            jProgressBar1.setValue(jProgressBar1.getMaximum());
                            jProgressBar1.setString(Bundle.getBundle().getString("pb.canceled"));
                            break;
                        }
                    }
                }
            }
            btnClose.setEnabled(true);
        }
    };
    Thread t = new Thread(r);
    t.start();
}

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;
        }//from   www .  j a  v a2 s  .  c  o 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

public void setDocument(Document document) {
    if (null == document) {
        this.document = null;
        topToolbar.setVisible(false);/*from  w  w w . j  a  va  2 s.  c  om*/
        bottomToolbar.setVisible(false);
        imagePanel.clear();
        status = Status.READY;
        btnPageBackward.setEnabled(false);
        btnPageForward.setEnabled(false);
        lblTip.setVisible(true);
        removeTempSignature();
        hideRightPanel();
    } else {
        if (status.equals(Status.SIGNING)) {
            String msg = Bundle.getBundle().getString("msg.signatureStillNotAppliedOpenOther");

            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.NO_OPTION) {
                return;
            }
        }
        lblTip.setVisible(false);
        this.document = document;
        imagePanel.setDocumentAndComponents(mainWindow, jsImagePanel, document, btnPageBackward,
                btnPageForward);

    }
    jSplitPane1.setDividerSize(0);
}

From source file:view.WorkspacePanel.java

@Override
public void onSignatureClick(SignatureValidation sv) {
    if (status != Status.SIGNING) {
        jtValidation.clearSelection();/*ww w  . java  2  s. c  o  m*/
        if (!rightPanel.isVisible()) {
            cl.show(this.rightPanel, String.valueOf(CardEnum.VALIDATE_PANEL));
            rightPanel.setVisible(true);
            jSplitPane1.setDividerSize(5);
            jSplitPane1.setDividerLocation(0.6);
        } else if (this.status == Status.SIGNING) {
            String msg = "";
            Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") };
            int opt = JOptionPane.showOptionDialog(null, msg,
                    Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1"),
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (opt == JOptionPane.YES_OPTION) {
                removeTempSignature();
                cl.show(this.rightPanel, String.valueOf(CardEnum.VALIDATE_PANEL));
            } else {
                return;
            }
        }

        for (int i = 0; i < jtValidation.getRowCount(); i++) {
            TreePath tp = jtValidation.getPathForRow(i);
            DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) tp.getLastPathComponent();
            if (dmtn.getUserObject() instanceof SignatureValidation) {
                SignatureValidation sVal = (SignatureValidation) dmtn.getUserObject();
                if (sv.equals(sVal)) {
                    jtValidation.setSelectionRow(i);
                    jtValidation.expandRow(i);
                }
            }
        }

        status = Status.READY;
    }
}

From source file:view.WorkspacePanel.java

private void btnValidateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnValidateActionPerformed
    if (mainWindow.getOpenedFiles().size() > 1) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem m = null;//from ww  w.j  a  v a  2  s .c  om
        ActionListener validateOne = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (!rightPanel.isVisible()) {
                    changeCard(CardEnum.VALIDATE_PANEL, true);
                    startValidationThread();
                } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) {
                    String msg = Bundle.getBundle().getString("yes");
                    Object[] options = { Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1"),
                            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) {
                        status = Status.READY;
                        changeCard(CardEnum.VALIDATE_PANEL, true);
                        startValidationThread();
                    }
                }
            }
        };
        ActionListener validateAll = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MultipleValidationDialog mvd = new MultipleValidationDialog(mainWindow, true,
                        mainWindow.getOpenedFiles());
                mvd.setLocationRelativeTo(null);
                mvd.setVisible(true);
            }
        };
        int numSigs = CCInstance.getInstance().getNumberOfSignatures(document.getDocumentLocation());
        if (numSigs == 0) {
            m = new JMenuItem(Bundle.getBundle().getString("notSigned"));
            m.addActionListener(validateOne);
            m.setEnabled(false);
            popup.add(m);
        } else {
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateOnlyThis"));
            m.addActionListener(validateOne);
            popup.add(m);
        }

        if (mainWindow.getSelectedOpenedFiles().size() > 1
                && mainWindow.getSelectedOpenedFiles().size() < mainWindow.getOpenedFiles().size()) {
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAllSelected"));
            m.addActionListener(validateAll);
            popup.add(m);
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll"));
            m.addActionListener(validateAll);
            popup.add(m);
        } else {
            m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll"));
            m.addActionListener(validateAll);
            popup.add(m);
        }

        popup.setLightWeightPopupEnabled(true);
        popup.show(btnValidate, 0, btnValidate.getHeight());

    } else if (!rightPanel.isVisible()) {
        changeCard(CardEnum.VALIDATE_PANEL, true);
        startValidationThread();
    } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) {
        String msg = Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1");
        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) {
            status = Status.READY;
            changeCard(CardEnum.VALIDATE_PANEL, true);
            startValidationThread();
        } else {
            return;
        }
    }
    removeTempSignature();
}

From source file:view.WorkspacePanel.java

private void signDocument(Document document, boolean ocsp, boolean timestamp) {
    try {/*from  w ww  .j a va  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);

}

From source file:view.WorkspacePanel.java

public void signBatch(CCSignatureSettings settings) {
    ArrayList<File> toSignList = mainWindow.getOpenedFiles();
    try {//from  w w w .ja  va2s .com
        if (tempCCAlias.getMainCertificate().getPublicKey().equals(
                CCInstance.getInstance().loadKeyStoreAndAliases().get(0).getMainCertificate().getPublicKey())) {
            String dest = null;
            Object[] options = { Bundle.getBundle().getString("opt.saveInOriginalFolder"),
                    Bundle.getBundle().getString("msg.choosePath"),
                    Bundle.getBundle().getString("btn.cancel") };
            int i = JOptionPane.showOptionDialog(null, Bundle.getBundle().getString("msg.chooseSignedPath"), "",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (i == 1) {
                JFileChooser chooser = new JFileChooser();
                chooser.setCurrentDirectory(new java.io.File("."));
                chooser.setDialogTitle(Bundle.getBundle().getString("btn.choosePath"));
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setAcceptAllFileFilterUsed(false);

                if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                    dest = chooser.getSelectedFile().getAbsolutePath();
                } else {
                    return;
                }
            } else if (i == 2) {
                return;
            }

            MultipleSignDialog msd = new MultipleSignDialog(mainWindow, true, toSignList, settings, dest);
            msd.setLocationRelativeTo(null);
            msd.setVisible(true);

            ArrayList<File> signedDocsList = msd.getSignedDocsList();
            if (!signedDocsList.isEmpty()) {
                removeTempSignature();
                clearSignatureFields();
                hideRightPanel();
                status = Status.READY;
                mainWindow.closeDocuments(mainWindow.getOpenedFiles(), false);

                for (File f : signedDocsList) {
                    mainWindow.loadPdf(f, false);
                }
            }

            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);
}

From source file:view.WorkspacePanel.java

private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
    String msg = Bundle.getBundle().getString("msg.cancelSignature");
    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) {
        // Cancelar Assinatura
        if (null != exec) {
            if (!exec.isShutdown()) {
                exec.shutdown();//  w w w . j  av a2 s.  c  o  m
                exec = null;
                //signatureOptionsPanel.setVisible(false);
            }
        }
        removeTempSignature();
        hideRightPanel();
        status = Status.READY;
    }
}

From source file:view.WorkspacePanel.java

private void btnApplySignatureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnApplySignatureActionPerformed
    if (tempCCAlias != null) {
        signatureSettings.setPageNumber(imagePanel.getPageNumber());
        signatureSettings.setCcAlias(tempCCAlias);
        signatureSettings.setReason(tfReason.getText());
        signatureSettings.setLocation(tfLocation.getText());
        if (jRadioButton1.isSelected()) {
            signatureSettings.setCertificationLevel(PdfSignatureAppearance.NOT_CERTIFIED);
        } else if (jRadioButton2.isSelected()) {
            signatureSettings.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
        } else if (jRadioButton3.isSelected()) {
            signatureSettings.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_FORM_FILLING);
        } else if (jRadioButton4.isSelected()) {
            signatureSettings// ww w .ja  va2  s.c om
                    .setCertificationLevel(PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS);
        }
        signatureSettings.setOcspClient(true);
        if (cbTimestamp.isSelected()) {
            signatureSettings.setTimestamp(true);
            if (tfTimestamp.getText().isEmpty()) {
                JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.timestampEmpty"),
                        "", JOptionPane.ERROR_MESSAGE);
                return;
            } else {
                signatureSettings.setTimestampServer(tfTimestamp.getText());
            }
        } else {
            signatureSettings.setTimestamp(false);
            cbTimestamp.setSelected(false);
            tfTimestamp.setVisible(false);
        }
        signatureSettings.setVisibleSignature(cbVisibleSignature.isSelected());

        if (cbVisibleSignature.isSelected()) {
            Point p = tempSignature.getScaledPositionOnDocument();
            Dimension d = tempSignature.getScaledSizeOnDocument();
            float p1 = (float) p.getX();
            float p3 = (float) d.getWidth() + p1;
            float p2 = (float) ((document.getPageDimension(imagePanel.getPageNumber(), 0).getHeight())
                    - (p.getY() + d.getHeight()));
            float p4 = (float) d.getHeight() + p2;

            signatureSettings.setVisibleSignature(true);
            if (tempSignature.getImageLocation() != null) {
                signatureSettings.getAppearance().setImageLocation(tempSignature.getImageLocation());
            }
            Rectangle rect = new Rectangle(p1, p2, p3, p4);
            signatureSettings.setSignaturePositionOnDocument(rect);
            signatureSettings.setText(tfText.getText());
        } else {
            signatureSettings.setVisibleSignature(false);
        }
        if (mainWindow.getOpenedFiles().size() > 1) {
            Object[] options = { Bundle.getBundle().getString("menuItem.allDocuments"),
                    Bundle.getBundle().getString("menuItem.onlyThis"),
                    Bundle.getBundle().getString("btn.cancel") };
            int i = JOptionPane.showOptionDialog(null,
                    Bundle.getBundle().getString("msg.multipleDocumentsOpened"),
                    Bundle.getBundle().getString("msg.multipleDocumentsOpenedTitle"),
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (i == 0) {
                signBatch(signatureSettings);
            } else if (i == 1) {
                signDocument(document, true, true);
            }
        } else {
            signDocument(document, true, true);
        }
    } else {
        JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("noSmartcardFound"),
                WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE);
        changeCard(CardEnum.SIGN_PANEL, false);
    }
}