Example usage for javax.swing JOptionPane CANCEL_OPTION

List of usage examples for javax.swing JOptionPane CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

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

Click Source Link

Document

Return value from class method if CANCEL is chosen.

Usage

From source file:org.parosproxy.paros.extension.beanshell.BeanShellConsoleDialog.java

private JButton getBtnLoad() {
    if (btnLoad == null) {
        btnLoad = new JButton();
        btnLoad.setText("Load...");

        btnLoad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                if (getBeanShellPanel().isSaved() == false) {
                    int confirm = view.showConfirmDialog("Script is not saved, discard?");
                    if (confirm == JOptionPane.CANCEL_OPTION)
                        return;
                }/*from   w ww. java 2s  . c  om*/
                JFileChooser fc = new JFileChooser(scriptsDir);
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int result = fc.showOpenDialog(getBeanShellPanel());

                if (result == JFileChooser.APPROVE_OPTION) {
                    try {
                        String temp = loadScript(fc.getSelectedFile());
                        getBeanShellPanel().getTxtEditor().setText(temp);
                        getBeanShellPanel().setSaved(true);
                        currentScriptFile = fc.getSelectedFile();
                    } catch (IOException ee) {
                        ee.printStackTrace();
                    }

                }
            }
        });
    }
    return btnLoad;
}

From source file:org.parosproxy.paros.extension.history.PopupMenuExportMessage.java

/**
 * This method initializes this/*www.ja  v  a2 s. co  m*/
 * 
 * @return void
 */
private void initialize() {
    this.setText("Export Messages to File...");

    this.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent e) {

            JList listLog = extension.getLogPanel().getListLog();
            Object[] obj = listLog.getSelectedValues();
            if (obj.length == 0) {
                extension.getView()
                        .showWarningDialog("Select HTTP messages in History panel before export to file.");
                return;
            }

            File file = getOutputFile();
            if (file == null) {
                return;
            }

            boolean isAppend = true;
            if (file.exists()) {
                int rc = extension.getView()
                        .showYesNoCancelDialog("File exists.  Yes = overwrite, No = append?");
                if (rc == JOptionPane.CANCEL_OPTION) {
                    return;
                } else if (rc == JOptionPane.YES_OPTION) {
                    isAppend = false;
                }
            }

            BufferedWriter fw = null;
            try {
                fw = new BufferedWriter(new FileWriter(file, isAppend));
                for (int i = 0; i < obj.length; i++) {
                    HistoryReference ref = (HistoryReference) obj[i];
                    exportHistory(ref, fw);
                }

            } catch (Exception e1) {
                extension.getView().showWarningDialog("Error saving file to " + file.getAbsolutePath() + ".");
                // ZAP: Log exceptions
                log.warn(e1.getMessage(), e1);
            } finally {
                try {
                    fw.close();
                } catch (Exception e2) {
                    // ZAP: Log exceptions
                    log.warn(e2.getMessage(), e2);
                }
            }
        }
    });

}

From source file:org.parosproxy.paros.extension.history.PopupMenuExportResponse.java

/**
 * This method initializes this/*from   w w w .ja  v  a  2 s. co  m*/
 * 
 * @return void
 */
private void initialize() {
    this.setText("Export Response to File...");

    this.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent e) {

            JList listLog = extension.getLogPanel().getListLog();
            Object[] obj = listLog.getSelectedValues();
            if (obj.length == 0) {
                extension.getView()
                        .showWarningDialog("Select HTTP message in History panel before export to file.");
                return;
            }

            if (obj.length > 1) {
                extension.getView().showWarningDialog("Only one response can be exported at a time.");
                return;
            }

            HistoryReference ref = (HistoryReference) obj[0];
            HttpMessage msg = null;
            try {
                msg = ref.getHttpMessage();
            } catch (Exception e1) {
                extension.getView().showWarningDialog("Error reading response.");
                return;
            }

            if (msg.getResponseHeader().isEmpty() || msg.getResponseBody().length() == 0) {
                extension.getView().showWarningDialog("Empty body.  File not created.");
                return;
            }

            File file = getOutputFile(msg);
            if (file == null) {
                return;
            }

            boolean isAppend = true;
            if (file.exists()) {
                int rc = extension.getView()
                        .showYesNoCancelDialog("File exists.  Yes = overwrite, No = append?");
                if (rc == JOptionPane.CANCEL_OPTION) {
                    return;
                } else if (rc == JOptionPane.YES_OPTION) {
                    isAppend = false;
                }
            }

            BufferedOutputStream bos = null;
            try {
                bos = new BufferedOutputStream(new FileOutputStream(file, isAppend));
                for (int i = 0; i < obj.length; i++) {
                    exportHistory(msg, bos);
                }

            } catch (Exception e1) {
                extension.getView().showWarningDialog("Error saving file to " + file.getAbsolutePath() + ".");
                // ZAP: Log exceptions
                log.warn(e1.getMessage(), e1);
            } finally {
                try {
                    bos.close();
                } catch (Exception e2) {
                    // ZAP: Log exceptions
                    log.warn(e2.getMessage(), e2);
                }
            }
        }
    });

}

From source file:org.pdfsam.plugin.coverfooter.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent e) {

    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;//from ww  w  .  java  2s  .c o m
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (ArrayUtils.isEmpty(items)) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC);
        return;
    }

    LinkedList<String> args = new LinkedList<String>();
    LinkedList<String> args1 = new LinkedList<String>();
    LinkedList<String> argsFooter = new LinkedList<String>();
    // validation and permission check are demanded
    try {
        if (panel.getOutputCompressedCheck().isSelected()) {
            args.add("-" + ConcatParsedCommand.COMPRESSED_ARG);
        }
        if (panel.getMergeTypeCheck().isSelected()) {
            args.add("-" + ConcatParsedCommand.COPYFIELDS_ARG);
        }

        args.add("-" + ConcatParsedCommand.PDFVERSION_ARG);
        args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId());

        PdfSelectionTableItem[] coveritems = panel.getCoverSelectionPanel().getTableRows();
        PdfSelectionTableItem[] footeritems = panel.getFooterSelectionPanel().getTableRows();
        String coverSelectionString = "";
        // manage cover
        if ((coveritems == null || coveritems.length != 1)
                && (footeritems == null || footeritems.length != 1)) {
            JOptionPane.showMessageDialog(panel,
                    GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                            "Select at least one cover or one footer"),
                    GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Warning"),
                    JOptionPane.WARNING_MESSAGE);
        } else {

            // overwrite confirmation
            if (panel.getOverwriteCheckbox().isSelected()
                    && Configuration.getInstance().isAskOverwriteConfirmation()) {
                int dialogRet = DialogUtility.askForOverwriteConfirmation(panel);
                if (JOptionPane.NO_OPTION == dialogRet) {
                    panel.getOverwriteCheckbox().setSelected(false);
                } else if (JOptionPane.CANCEL_OPTION == dialogRet) {
                    return;
                }
            }
            if (panel.getOverwriteCheckbox().isSelected()) {
                args.add("-" + ConcatParsedCommand.OVERWRITE_ARG);
            }

            if ((coveritems != null && coveritems.length == 1)) {
                PdfSelectionTableItem coveritem = coveritems[0];
                String coverSelection = (coveritem.getPageSelection() != null
                        && coveritem.getPageSelection().length() > 0) ? coveritem.getPageSelection()
                                : CoverFooterMainGUI.ALL_STRING;
                if (coverSelection.trim().length() > 0 && coverSelection.indexOf(",") != 0) {
                    String[] selectionsArray = coverSelection.split(",");
                    for (int j = 0; j < selectionsArray.length; j++) {
                        String tmpString = selectionsArray[j].trim();
                        if ((tmpString != null) && (!tmpString.equals(""))) {
                            args.add("-" + ConcatParsedCommand.F_ARG);
                            String f = coveritem.getInputFile().getAbsolutePath();
                            if ((coveritem.getPassword()) != null && (coveritem.getPassword()).length() > 0) {
                                log.debug(GettextResource.gettext(
                                        Configuration.getInstance().getI18nResourceBundle(),
                                        "Found a password for input file."));
                                f += ":" + coveritem.getPassword();
                            }
                            args.add(f);
                            coverSelectionString += (tmpString.matches("[\\d]+"))
                                    ? tmpString + "-" + tmpString + ":"
                                    : tmpString + ":";
                        }
                    }

                } else {
                    args.add("-" + ConcatParsedCommand.F_ARG);
                    String f = coveritem.getInputFile().getAbsolutePath();
                    if ((coveritem.getPassword()) != null && (coveritem.getPassword()).length() > 0) {
                        log.debug(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                                "Found a password for input file."));
                        f += ":" + coveritem.getPassword();
                    }
                    args.add(f);
                    coverSelectionString += (coverSelection.matches("[\\d]+"))
                            ? coverSelection + "-" + coverSelection + ":"
                            : coverSelection + ":";
                }
            }
            String footerSelectionString = "";
            // manage footer
            if ((footeritems != null && footeritems.length == 1)) {
                PdfSelectionTableItem footeritem = footeritems[0];
                String footerSelection = (footeritem.getPageSelection() != null
                        && footeritem.getPageSelection().length() > 0) ? footeritem.getPageSelection()
                                : CoverFooterMainGUI.ALL_STRING;
                if (footerSelection.trim().length() > 0 && footerSelection.indexOf(",") != 0) {
                    String[] selectionsArray = footerSelection.split(",");
                    for (int j = 0; j < selectionsArray.length; j++) {
                        String tmpString = selectionsArray[j].trim();
                        if ((tmpString != null) && (!tmpString.equals(""))) {
                            argsFooter.add("-" + ConcatParsedCommand.F_ARG);
                            String footerItem = footeritem.getInputFile().getAbsolutePath();
                            if ((footeritem.getPassword()) != null && (footeritem.getPassword()).length() > 0) {
                                log.debug(GettextResource.gettext(
                                        Configuration.getInstance().getI18nResourceBundle(),
                                        "Found a password for input file."));
                                footerItem += ":" + footeritem.getPassword();
                            }
                            argsFooter.add(footerItem);
                            footerSelectionString += (tmpString.matches("[\\d]+"))
                                    ? tmpString + "-" + tmpString + ":"
                                    : tmpString + ":";
                        }
                    }

                } else {
                    argsFooter.add("-" + ConcatParsedCommand.F_ARG);
                    String footerItem = footeritem.getInputFile().getAbsolutePath();
                    if ((footeritem.getPassword()) != null && (footeritem.getPassword()).length() > 0) {
                        log.debug(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                                "Found a password for input file."));
                        footerItem += ":" + footeritem.getPassword();
                    }
                    argsFooter.add(footerItem);
                    footerSelectionString += (footerSelection.matches("[\\d]+"))
                            ? footerSelection + "-" + footerSelection + ":"
                            : footerSelection + ":";
                }
            }
            // selection page
            PdfSelectionTableItem item = null;
            for (int i = 0; i < items.length; i++) {
                String pageSelectionString = coverSelectionString;
                try {
                    args1.clear();
                    args1.addAll(args);

                    item = items[i];
                    String pageSelection = (item.getPageSelection() != null
                            && item.getPageSelection().length() > 0) ? item.getPageSelection()
                                    : CoverFooterMainGUI.ALL_STRING;
                    if (pageSelection.trim().length() > 0 && pageSelection.indexOf(",") != 0) {
                        String[] selectionsArray = pageSelection.split(",");
                        for (int j = 0; j < selectionsArray.length; j++) {
                            String tmpString = selectionsArray[j].trim();
                            if ((tmpString != null) && (!tmpString.equals(""))) {
                                args1.add("-" + ConcatParsedCommand.F_ARG);
                                String f = item.getInputFile().getAbsolutePath();
                                if ((item.getPassword()) != null && (item.getPassword()).length() > 0) {
                                    log.debug(GettextResource.gettext(
                                            Configuration.getInstance().getI18nResourceBundle(),
                                            "Found a password for input file."));
                                    f += ":" + item.getPassword();
                                }
                                args1.add(f);
                                pageSelectionString += (tmpString.matches("[\\d]+"))
                                        ? tmpString + "-" + tmpString + ":"
                                        : tmpString + ":";
                            }
                        }

                    } else {
                        args1.add("-" + ConcatParsedCommand.F_ARG);
                        String f = item.getInputFile().getAbsolutePath();
                        if ((item.getPassword()) != null && (item.getPassword()).length() > 0) {
                            log.debug(
                                    GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                                            "Found a password for input file."));
                            f += ":" + item.getPassword();
                        }
                        args1.add(f);
                        pageSelectionString += (pageSelection.matches("[\\d]+"))
                                ? pageSelection + "-" + pageSelection + ":"
                                : pageSelection + ":";
                    }

                    args1.addAll(argsFooter);
                    args1.add("-" + ConcatParsedCommand.U_ARG);
                    args1.add(pageSelectionString + footerSelectionString);

                    // manage output destination option
                    args1.add("-" + ConcatParsedCommand.O_ARG);
                    if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) {
                        String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]);
                        int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
                        if (JOptionPane.YES_OPTION == chosenOpt) {
                            panel.getDestinationTextField().setText(suggestedDir);
                        } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                            return;
                        }
                    }
                    if (panel.getDestinationTextField().getText().length() > 0) {
                        args1.add(panel.getDestinationTextField().getText() + File.separator
                                + item.getInputFile().getName());
                    }

                    args1.add(AbstractParsedCommand.COMMAND_CONCAT);

                    WorkExecutor.getInstance().execute(new WorkThread(args1.toArray(new String[args1.size()])));
                } catch (Exception ex) {
                    log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                            "Error: "), ex);
                }
            }
        }
    } catch (Exception ex) {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
        SoundPlayer.getInstance().playErrorSound();
    }

}

From source file:org.pdfsam.plugin.decrypt.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent e) {
    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;/*from   ww w  .j  av  a  2s.c o m*/
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (ArrayUtils.isEmpty(items)) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC);
        return;
    }

    final LinkedList<String> args = new LinkedList<String>();
    try {

        // overwrite confirmation
        if (panel.getOverwriteCheckbox().isSelected()
                && Configuration.getInstance().isAskOverwriteConfirmation()) {
            int dialogRet = DialogUtility.askForOverwriteConfirmation(panel);
            if (JOptionPane.NO_OPTION == dialogRet) {
                panel.getOverwriteCheckbox().setSelected(false);
            } else if (JOptionPane.CANCEL_OPTION == dialogRet) {
                return;
            }
        }

        args.addAll(getInputFilesArguments(items));

        args.add("-" + DecryptParsedCommand.O_ARG);
        if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) {
            String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]);
            int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getDestinationTextField().setText(suggestedDir);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }
        args.add(panel.getDestinationTextField().getText());

        if (panel.getOverwriteCheckbox().isSelected()) {
            args.add("-" + DecryptParsedCommand.OVERWRITE_ARG);
        }
        if (panel.getOutputCompressedCheck().isSelected()) {
            args.add("-" + DecryptParsedCommand.COMPRESSED_ARG);
        }

        args.add("-" + EncryptParsedCommand.P_ARG);
        args.add(panel.getOutPrefixTextField().getText());
        args.add("-" + DecryptParsedCommand.PDFVERSION_ARG);
        args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId());

        args.add(AbstractParsedCommand.COMMAND_DECRYPT);

        String[] myStringArray = args.toArray(new String[args.size()]);
        WorkExecutor.getInstance().execute(new WorkThread(myStringArray));

    } catch (Exception ex) {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
        SoundPlayer.getInstance().playErrorSound();
    }

}

From source file:org.pdfsam.plugin.docinfo.listeners.RunButtonActionListener.java

@Override
public void actionPerformed(ActionEvent e) {
    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;//w w w.jav a  2 s .  c o  m
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (items == null || items.length != 1) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.ONE_DOC);
        return;
    }
    if (StringUtils.isEmpty(panel.getDestinationTextField().getText())
            && !panel.getSameAsSourceRadio().isSelected()) {
        DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.FILE_DESTINATION);
        return;
    }
    LinkedList<String> args = new LinkedList<String>();
    try {
        PdfSelectionTableItem item = null;
        item = items[0];
        String destination = "";

        if (panel.getSameAsSourceRadio().isSelected()) {
            destination = item.getInputFile().getAbsolutePath();
        } else {
            // overwrite confirmation
            if (panel.getOverwriteCheckbox().isSelected()
                    && Configuration.getInstance().isAskOverwriteConfirmation()) {
                int dialogRet = DialogUtility.askForOverwriteConfirmation(panel);
                if (JOptionPane.NO_OPTION == dialogRet) {
                    panel.getOverwriteCheckbox().setSelected(false);
                } else if (JOptionPane.CANCEL_OPTION == dialogRet) {
                    return;
                }
            }

            ensurePdfExtensionOnTextField(panel.getDestinationTextField());
            destination = panel.getDestinationTextField().getText();
            File destinationDir = new File(destination);
            File parent = destinationDir.getParentFile();
            if (!(parent != null && parent.exists())) {
                String suggestedDir = getSuggestedOutputFile(items[items.length - 1], destinationDir.getName());
                int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
                if (JOptionPane.YES_OPTION == chosenOpt) {
                    destination = suggestedDir;
                } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                    return;
                }
            }
        }
        panel.getDestinationTextField().setText(destination);

        // check if the file already exists and the user didn't select to overwrite
        File destFile = (destination != null) ? new File(destination) : null;
        if (destFile != null && destFile.exists() && !panel.getOverwriteCheckbox().isSelected()) {
            int chosenOpt = DialogUtility.askForOverwriteOutputFileDialog(panel, destFile.getName());
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getOverwriteCheckbox().setSelected(true);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }

        args.add("-" + DocumentInfoParsedCommand.O_ARG);
        args.add(destination);

        args.add("-" + DocumentInfoParsedCommand.TITLE_ARG);
        args.add(panel.getTitleTextField().getText());

        args.add("-" + DocumentInfoParsedCommand.AUTHOR_ARG);
        args.add(panel.getAuthorTextField().getText());

        args.add("-" + DocumentInfoParsedCommand.SUBJECT_ARG);
        args.add(panel.getSubjectTextField().getText());

        args.add("-" + DocumentInfoParsedCommand.KEYWORDS_ARG);
        args.add(panel.getKeywordsTextField().getText());

        if (panel.getOverwriteCheckbox().isSelected())
            args.add("-" + DocumentInfoParsedCommand.OVERWRITE_ARG);
        if (panel.getOutputCompressedCheck().isSelected())
            args.add("-" + DocumentInfoParsedCommand.COMPRESSED_ARG);

        args.add("-" + SplitParsedCommand.PDFVERSION_ARG);
        if (JPdfVersionCombo.SAME_AS_SOURCE
                .equals(((StringItem) panel.getVersionCombo().getSelectedItem()).getId())) {
            StringItem minItem = panel.getVersionCombo().getMinItem();
            String currentPdfVersion = Character.toString(item.getPdfVersion());
            if (minItem != null) {
                if (Integer.parseInt(currentPdfVersion) < Integer.parseInt(minItem.getId())) {
                    if (JOptionPane.YES_OPTION != DialogUtility.askForPdfVersionConfilct(panel,
                            minItem.getDescription())) {
                        return;
                    }
                }
            }
            args.add(currentPdfVersion);
        } else {
            args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId());
        }

        args.add("-" + DocumentInfoParsedCommand.F_ARG);
        String f = item.getInputFile().getAbsolutePath();
        if ((item.getPassword()) != null && (item.getPassword()).length() > 0) {
            log.debug(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                    "Found a password for input file."));
            f += ":" + item.getPassword();
        }
        args.add(f);

        args.add(AbstractParsedCommand.COMMAND_SETDOCINFO);

        String[] myStringArray = args.toArray(new String[args.size()]);
        WorkExecutor.getInstance().execute(new WorkThread(myStringArray));
    } catch (Exception ex) {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
        SoundPlayer.getInstance().playErrorSound();
    }
}

From source file:org.pdfsam.plugin.encrypt.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent e) {

    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;//  w ww .  j a  va 2 s . c o m
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (ArrayUtils.isEmpty(items)) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC);
        return;
    }
    LinkedList<String> args = new LinkedList<String>();
    // validation and permission check are demanded to the CmdParser object
    try {
        // overwrite confirmation
        if (panel.getOverwriteCheckbox().isSelected()
                && Configuration.getInstance().isAskOverwriteConfirmation()) {
            int dialogRet = DialogUtility.askForOverwriteConfirmation(panel);
            if (JOptionPane.NO_OPTION == dialogRet) {
                panel.getOverwriteCheckbox().setSelected(false);
            } else if (JOptionPane.CANCEL_OPTION == dialogRet) {
                return;
            }
        }

        args.addAll(getEncPermissions(panel.getPermissionsCheck(), panel.getAllowAllCheck()));
        args.addAll(getInputFilesArguments(items));

        args.add("-" + EncryptParsedCommand.P_ARG);
        args.add(panel.getOutPrefixTextField().getText());
        args.add("-" + EncryptParsedCommand.APWD_ARG);
        args.add(panel.getOwnerPwdField().getText());
        args.add("-" + EncryptParsedCommand.UPWD_ARG);
        args.add(panel.getUserPwdField().getText());
        // check if is needed page option
        args.add("-" + EncryptParsedCommand.ETYPE_ARG);
        args.add(EncryptionUtility.getEncAlgorithm((String) panel.getEncryptType().getSelectedItem()));
        args.add("-" + EncryptParsedCommand.O_ARG);

        if (StringUtils.isEmpty(panel.getDestFolderText().getText())) {
            String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]);
            int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getDestFolderText().setText(suggestedDir);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }
        args.add(panel.getDestFolderText().getText());

        if (panel.getOverwriteCheckbox().isSelected()) {
            args.add("-" + EncryptParsedCommand.OVERWRITE_ARG);
        }
        if (panel.getOutputCompressedCheck().isSelected()) {
            args.add("-" + EncryptParsedCommand.COMPRESSED_ARG);
        }

        args.add("-" + EncryptParsedCommand.PDFVERSION_ARG);
        args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId());

        args.add(AbstractParsedCommand.COMMAND_ENCRYPT);

        final String[] myStringArray = (String[]) args.toArray(new String[args.size()]);
        WorkExecutor.getInstance().execute(new WorkThread(myStringArray));

    } catch (Exception ex) {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
        SoundPlayer.getInstance().playErrorSound();
    }
}

From source file:org.pdfsam.plugin.merge.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent arg0) {
    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;//from  ww w  .  j  ava 2s .  c  o m
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (ArrayUtils.isEmpty(items)) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC);
        return;
    }
    if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) {
        DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.FILE_DESTINATION);
        return;
    }
    LinkedList<String> args = new LinkedList<String>();
    try {
        // overwrite confirmation
        if (panel.getOverwriteCheckbox().isSelected()
                && Configuration.getInstance().isAskOverwriteConfirmation()) {
            int dialogRet = DialogUtility.askForOverwriteConfirmation(panel);
            if (JOptionPane.NO_OPTION == dialogRet) {
                panel.getOverwriteCheckbox().setSelected(false);
            } else if (JOptionPane.CANCEL_OPTION == dialogRet) {
                return;
            }
        }

        // if no extension given
        ensurePdfExtensionOnTextField(panel.getDestinationTextField());

        File destinationDir = new File(panel.getDestinationTextField().getText());
        File parent = destinationDir.getParentFile();
        // only filename no dir
        if (!(parent != null && parent.exists())) {
            String suggestedDir = getSuggestedOutputFile(items[items.length - 1], destinationDir.getName());
            int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getDestinationTextField().setText(suggestedDir);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }

        String destination = panel.getDestinationTextField().getText();

        // check if the file already exists and the user didn't select to overwrite
        File destFile = (destination != null) ? new File(destination) : null;
        if (destFile != null && destFile.exists() && !panel.getOverwriteCheckbox().isSelected()) {
            int chosenOpt = DialogUtility.askForOverwriteOutputFileDialog(panel, destFile.getName());
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getOverwriteCheckbox().setSelected(true);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }

        args.add("-" + ConcatParsedCommand.O_ARG);
        args.add(destination);

        StringBuilder psStringBuilder = new StringBuilder();
        for (PdfSelectionTableItem item : items) {
            String pageSelection = (!StringUtils.isEmpty(item.getPageSelection())) ? item.getPageSelection()
                    : MergeMainGUI.ALL_STRING;
            String[] selections = StringUtils.split(pageSelection, ",");
            if (!ValidationUtility.isValidPageSelectionsArray(selections)) {
                DialogUtility.errorValidatingBounds(panel, pageSelection);
                return;
            } else {
                args.add("-" + ConcatParsedCommand.F_ARG);
                String f = item.getInputFile().getAbsolutePath();
                if (!StringUtils.isEmpty(item.getPassword())) {
                    log.debug(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                            "Found a password for input file."));
                    f += ":" + item.getPassword();
                }
                args.add(f);
                psStringBuilder.append(pageSelection).append(":");
            }
        }

        args.add("-" + ConcatParsedCommand.U_ARG);
        args.add(psStringBuilder.toString());

        if (panel.getOverwriteCheckbox().isSelected())
            args.add("-" + ConcatParsedCommand.OVERWRITE_ARG);
        if (panel.getOutputCompressedCheck().isSelected())
            args.add("-" + ConcatParsedCommand.COMPRESSED_ARG);
        if (panel.getMergeTypeCheck().isSelected())
            args.add("-" + ConcatParsedCommand.COPYFIELDS_ARG);

        args.add("-" + ConcatParsedCommand.PDFVERSION_ARG);
        args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId());

        args.add(AbstractParsedCommand.COMMAND_CONCAT);

        String[] myStringArray = args.toArray(new String[args.size()]);
        WorkExecutor.getInstance().execute(new WorkThread(myStringArray));

    } catch (Exception ex) {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
        SoundPlayer.getInstance().playErrorSound();
    }
}

From source file:org.pdfsam.plugin.mix.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent arg0) {
    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;// w  w w.j a va 2  s .c  om
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (items == null || items.length != 2) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.TWO_DOC);
        return;
    }
    if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) {
        DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.FILE_DESTINATION);
        return;
    }
    LinkedList<String> args = new LinkedList<String>();
    try {
        // overwrite confirmation
        if (panel.getOverwriteCheckbox().isSelected()
                && Configuration.getInstance().isAskOverwriteConfirmation()) {
            int dialogRet = DialogUtility.askForOverwriteConfirmation(panel);
            if (JOptionPane.NO_OPTION == dialogRet) {
                panel.getOverwriteCheckbox().setSelected(false);
            } else if (JOptionPane.CANCEL_OPTION == dialogRet) {
                return;
            }
        }

        args.addAll(getInputFilesArguments(items));

        String destination = "";
        // if no extension given
        ensurePdfExtensionOnTextField(panel.getDestinationTextField());
        File destinationDir = new File(panel.getDestinationTextField().getText());
        File parent = destinationDir.getParentFile();
        if (!(parent != null && parent.exists())) {
            String suggestedDir = getSuggestedOutputFile(items[items.length - 1], destinationDir.getName());
            int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getDestinationTextField().setText(suggestedDir);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }

        destination = panel.getDestinationTextField().getText();

        // check if the file already exists and the user didn't select to overwrite
        File destFile = (destination != null) ? new File(destination) : null;
        if (destFile != null && destFile.exists() && !panel.getOverwriteCheckbox().isSelected()) {
            int chosenOpt = DialogUtility.askForOverwriteOutputFileDialog(panel, destFile.getName());
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getOverwriteCheckbox().setSelected(true);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }
        args.add("-" + MixParsedCommand.O_ARG);
        args.add(destination);

        String step = panel.getStepTextField().getText();
        if (StringUtils.isNotEmpty(step)) {
            args.add("-" + MixParsedCommand.STEP_ARG);
            args.add(step);
        }

        String secondStep = panel.getSecondStepTextField().getText();
        if (StringUtils.isNotEmpty(secondStep)) {
            args.add("-" + MixParsedCommand.SECOND_STEP_ARG);
            args.add(secondStep);
        }

        if (panel.getOverwriteCheckbox().isSelected())
            args.add("-" + MixParsedCommand.OVERWRITE_ARG);
        if (panel.getOutputCompressedCheck().isSelected())
            args.add("-" + MixParsedCommand.COMPRESSED_ARG);
        if (panel.getReverseFirstCheckbox().isSelected())
            args.add("-" + MixParsedCommand.REVERSE_FIRST_ARG);
        if (panel.getReverseSecondCheckbox().isSelected())
            args.add("-" + MixParsedCommand.REVERSE_SECOND_ARG);

        args.add("-" + MixParsedCommand.PDFVERSION_ARG);
        args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId());

        args.add(MixParsedCommand.COMMAND_MIX);
        String[] myStringArray = args.toArray(new String[args.size()]);
        WorkExecutor.getInstance().execute(new WorkThread(myStringArray));

    } catch (Exception ex) {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
        SoundPlayer.getInstance().playErrorSound();
    }

}

From source file:org.pdfsam.plugin.rotate.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent e) {
    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;//from   w ww.  ja  v  a  2 s  . com
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (ArrayUtils.isEmpty(items)) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC);
        return;
    }
    LinkedList<String> args = new LinkedList<String>();
    try {

        // overwrite confirmation
        if (panel.getOverwriteCheckbox().isSelected()
                && Configuration.getInstance().isAskOverwriteConfirmation()) {
            int dialogRet = DialogUtility.askForOverwriteConfirmation(panel);
            if (JOptionPane.NO_OPTION == dialogRet) {
                panel.getOverwriteCheckbox().setSelected(false);
            } else if (JOptionPane.CANCEL_OPTION == dialogRet) {
                return;
            }
        }

        args.addAll(getInputFilesArguments(items));

        args.add("-" + RotateParsedCommand.O_ARG);

        if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) {
            String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]);
            int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
            if (JOptionPane.YES_OPTION == chosenOpt) {
                panel.getDestinationTextField().setText(suggestedDir);
            } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                return;
            }
        }
        args.add(panel.getDestinationTextField().getText());

        if (panel.getOverwriteCheckbox().isSelected()) {
            args.add("-" + RotateParsedCommand.OVERWRITE_ARG);
        }
        if (panel.getOutputCompressedCheck().isSelected()) {
            args.add("-" + RotateParsedCommand.COMPRESSED_ARG);
        }

        args.add("-" + RotateParsedCommand.R_ARG);
        args.add(((StringItem) panel.getRotationPagesBox().getSelectedItem()).getId() + ":"
                + panel.getRotationBox().getSelectedItem());

        args.add("-" + RotateParsedCommand.P_ARG);
        args.add(panel.getOutPrefixTextField().getText());
        args.add("-" + RotateParsedCommand.PDFVERSION_ARG);
        args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId());

        args.add(AbstractParsedCommand.COMMAND_ROTATE);

        String[] myStringArray = args.toArray(new String[args.size()]);
        WorkExecutor.getInstance().execute(new WorkThread(myStringArray));

    } catch (Exception ex) {
        log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
        SoundPlayer.getInstance().playErrorSound();
    }

}