Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

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

Prototype

int NO_OPTION

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

Click Source Link

Document

Return value from class method if NO is chosen.

Usage

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

protected int showFilterPlusDialog() {
    HistoryFilterPlusDialog dialog = getFilterPlusDialog();
    dialog.setModal(true);/*from  w w w  .  ja v  a  2  s .c  o  m*/
    try {
        dialog.setAllTags(getModel().getDb().getTableTag().getAllTags());
    } catch (DatabaseException e) {
        logger.error(e.getMessage(), e);
    }

    int exit = dialog.showDialog();
    int result = 0; // cancel, state unchanged
    HistoryFilter historyFilter = dialog.getFilter();
    if (exit == JOptionPane.OK_OPTION) {
        searchHistory(historyFilter);
        logPanel.setFilterStatus(historyFilter);
        result = 1; // applied

    } else if (exit == JOptionPane.NO_OPTION) {
        searchHistory(historyFilter);
        logPanel.setFilterStatus(historyFilter);
        result = -1; // reset
    }

    return result;
}

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   w  w  w.  ja 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>();
    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;//www .  j av  a  2 s .  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;//from w  w  w  .  j  av a  2 s .  c om
    }
    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 ava 2s . 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>();
    // 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;/*  w w  w. ja  v  a  2  s . 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 ava2  s  . c o m*/
    }
    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   www .  j  a v a  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>();
    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();
    }

}

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

public void actionPerformed(ActionEvent arg0) {
    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;/*from   w  w  w .ja v  a2s.  co 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(getInputFilesArguments(items));

        args.add("-" + SetViewerParsedCommand.P_ARG);
        args.add(panel.getOutPrefixTextField().getText());

        args.add("-" + SetViewerParsedCommand.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());

        args.add("-" + SetViewerParsedCommand.L_ARG);
        args.add(((StringItem) panel.getViewerLayout().getSelectedItem()).getId());

        args.add("-" + SetViewerParsedCommand.M_ARG);
        args.add(((StringItem) panel.getViewerOpenMode().getSelectedItem()).getId());

        if (panel.getNonFullScreenMode().isEnabled()) {
            args.add("-" + SetViewerParsedCommand.NFSM_ARG);
            args.add(((StringItem) panel.getNonFullScreenMode().getSelectedItem()).getId());
        }

        if (((StringItem) panel.getDirectionCombo().getSelectedItem()).getId().length() > 0) {
            args.add("-" + SetViewerParsedCommand.DIRECTION_ARG);
            args.add(((StringItem) panel.getDirectionCombo().getSelectedItem()).getId());
        }

        if (panel.getHideMenuBar().isSelected()) {
            args.add("-" + SetViewerParsedCommand.HIDEMENU_ARG);
        }
        if (panel.getHideToolBar().isSelected()) {
            args.add("-" + SetViewerParsedCommand.HIDETOOLBAR_ARG);
        }
        if (panel.getHideUIElements().isSelected()) {
            args.add("-" + SetViewerParsedCommand.HIDEWINDOWUI_ARG);
        }
        if (panel.getResizeToFit().isSelected()) {
            args.add("-" + SetViewerParsedCommand.FITWINDOW_ARG);
        }
        if (panel.getCenterScreen().isSelected()) {
            args.add("-" + SetViewerParsedCommand.CENTERWINDOW_ARG);
        }
        if (panel.getDisplayTitle().isSelected()) {
            args.add("-" + SetViewerParsedCommand.DOCTITLE_ARG);
        }
        if (panel.getNoPageScaling().isSelected()) {
            args.add("-" + SetViewerParsedCommand.NOPRINTSCALING_ARG);
        }
        if (panel.getOverwriteCheckbox().isSelected()) {
            args.add("-" + SetViewerParsedCommand.OVERWRITE_ARG);
        }
        if (panel.getOutputCompressedCheck().isSelected()) {
            args.add("-" + SetViewerParsedCommand.COMPRESSED_ARG);
        }

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

        args.add(SetViewerParsedCommand.COMMAND_SETVIEWER);

        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.split.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent e) {

    if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) {
        DialogUtility.showWarningAddingDocument(panel);
        return;/*from w ww .j  a  va2  s . co m*/
    }
    if (!panel.getSameAsSourceRadio().isSelected()
            && StringUtils.isEmpty(panel.getDestinationFolderText().getText())) {
        DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.DIRECTORY_DESTINATION);
        return;
    }
    PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows();
    if (items == null || items.length != 1) {
        DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.ONE_DOC);
        return;
    }
    LinkedList<String> args = new LinkedList<String>();
    try {
        PdfSelectionTableItem item = null;
        // 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;
            }
        }

        item = items[0];
        args.add("-" + SplitParsedCommand.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("-" + SplitParsedCommand.P_ARG);
        args.add(panel.getOutPrefixText().getText());
        args.add("-" + SplitParsedCommand.S_ARG);
        String splitType = panel.getSplitType();
        args.add(splitType);
        // check if is needed page option
        if (splitType.equals(SplitParsedCommand.S_SPLIT)) {
            args.add("-" + SplitParsedCommand.N_ARG);
            args.add(panel.getThisPageTextField().getText());
        } else if (splitType.equals(SplitParsedCommand.S_NSPLIT)) {
            args.add("-" + SplitParsedCommand.N_ARG);
            args.add(panel.getnPagesTextField().getText());
        } else if (splitType.equals(SplitParsedCommand.S_SIZE)) {
            args.add("-" + SplitParsedCommand.B_ARG);
            if (panel.getSplitSizeCombo().isSelectedItem() && panel.getSplitSizeCombo().isValidSelectedItem()) {
                args.add(Long.toString(panel.getSplitSizeCombo().getSelectedBytes()));
            } else {
                throw new Exception(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                        "Invalid split size"));
            }
        } else if (splitType.equals(SplitParsedCommand.S_BLEVEL)) {
            args.add("-" + SplitParsedCommand.BL_ARG);
            args.add((String) panel.getbLevelCombo().getSelectedItem());
        }

        args.add("-" + SplitParsedCommand.O_ARG);
        // check radio for output options
        if (panel.getSameAsSourceRadio().isSelected()) {
            if (item != null) {
                args.add(item.getInputFile().getParent());
            }
        } else {
            if (StringUtils.isEmpty(panel.getDestinationFolderText().getText())) {
                String suggestedDir = getSuggestedDestinationDirectory(item);
                int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
                if (JOptionPane.YES_OPTION == chosenOpt) {
                    panel.getDestinationFolderText().setText(suggestedDir);
                } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                    return;
                }

            }
            args.add(panel.getDestinationFolderText().getText());
        }
        if (panel.getOverwriteCheckbox().isSelected())
            args.add("-" + SplitParsedCommand.OVERWRITE_ARG);
        if (panel.getOutputCompressedCheck().isSelected())
            args.add("-" + SplitParsedCommand.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(AbstractParsedCommand.COMMAND_SPLIT);

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

}