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.pdfsam.plugin.setviewer.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  va2  s  .  c om*/
    }
    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 www  .ja  v a  2  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();
    }

}

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

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

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

        args.add(UnpackParsedCommand.COMMAND_UNPACK);

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

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

public void actionPerformed(ActionEvent e) {
    if (!panel.getComposerPanel().hasValidElements()) {
        JOptionPane.showMessageDialog(panel,
                GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                        "Please select a pdf document or undelete some pages"),
                GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Warning"),
                JOptionPane.WARNING_MESSAGE);
        return;//from  w ww . j a  v a2s  . c o  m
    }
    if (StringUtils.isEmpty(panel.getDestinationFileText().getText())) {
        DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.FILE_DESTINATION);
        return;
    }
    // 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;
        }
    }

    LinkedList<String> args = new LinkedList<String>();
    try {
        args.addAll(panel.getComposerPanel().getValidConsoleParameters());

        // rotation
        String rotation = panel.getComposerPanel().getRotatedElementsString();
        if (rotation != null && rotation.length() > 0) {
            args.add("-" + ConcatParsedCommand.R_ARG);
            args.add(rotation);
        }
        String destination = "";
        // if no extension given
        ensurePdfExtensionOnTextField(panel.getDestinationFileText());
        File destinationDir = new File(panel.getDestinationFileText().getText());
        File parent = destinationDir.getParentFile();
        if (!(parent != null && parent.exists())) {
            String suggestedDir = null;
            if (Configuration.getInstance().getDefaultWorkingDirectory() != null
                    && Configuration.getInstance().getDefaultWorkingDirectory().length() > 0) {
                suggestedDir = new File(Configuration.getInstance().getDefaultWorkingDirectory(),
                        destinationDir.getName()).getAbsolutePath();
            }
            if (suggestedDir != null) {
                int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
                if (JOptionPane.YES_OPTION == chosenOpt) {
                    panel.getDestinationFileText().setText(suggestedDir);
                } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                    return;
                }

            }
        }
        destination = panel.getDestinationFileText().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);

        if (panel.getOverwriteCheckbox().isSelected())
            args.add("-" + ConcatParsedCommand.OVERWRITE_ARG);
        if (panel.getOutputCompressedCheck().isSelected())
            args.add("-" + ConcatParsedCommand.COMPRESSED_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.vpagereorder.listeners.RunButtonActionListener.java

public void actionPerformed(ActionEvent e) {

    File inputFile = panel.getSelectionPanel().getSelectedPdfDocument();
    if (inputFile == null || !panel.getSelectionPanel().hasValidElements()) {
        JOptionPane.showMessageDialog(panel,
                GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                        "Please select a pdf document or undelete some page"),
                GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Warning"),
                JOptionPane.WARNING_MESSAGE);
        return;//from   w  w w . j a va  2s .c o m
    }
    if (!panel.getSameAsSourceRadio().isSelected()
            && StringUtils.isEmpty(panel.getDestinationFileText().getText())) {
        DialogUtility.showWarningNoDestinationSelected(panel, DialogUtility.FILE_DESTINATION);
        return;
    }
    // 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;
        }
    }

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

        args.addAll(panel.getSelectionPanel().getValidConsoleParameters());

        // rotation
        String rotation = panel.getSelectionPanel().getRotatedElementsString();
        if (rotation != null && rotation.length() > 0) {
            args.add("-" + ConcatParsedCommand.R_ARG);
            args.add(rotation);
        }

        String destination = "";
        // check radio for output options
        if (panel.getSameAsSourceRadio().isSelected()) {
            if (inputFile != null) {
                destination = inputFile.getAbsolutePath();
            }
        } else {
            // if no extension given
            ensurePdfExtensionOnTextField(panel.getDestinationFileText());
            File destinationDir = new File(panel.getDestinationFileText().getText());
            File parent = destinationDir.getParentFile();
            if (!(parent != null && parent.exists())) {
                String suggestedDir = null;
                if (Configuration.getInstance().getDefaultWorkingDirectory() != null
                        && Configuration.getInstance().getDefaultWorkingDirectory().length() > 0) {
                    suggestedDir = new File(Configuration.getInstance().getDefaultWorkingDirectory(),
                            destinationDir.getName()).getAbsolutePath();
                } else {
                    suggestedDir = new File(inputFile.getParent(), destinationDir.getName()).getAbsolutePath();
                }
                if (suggestedDir != null) {
                    int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir);
                    if (JOptionPane.YES_OPTION == chosenOpt) {
                        panel.getDestinationFileText().setText(suggestedDir);
                    } else if (JOptionPane.CANCEL_OPTION == chosenOpt) {
                        return;
                    }

                }
            }
            destination = panel.getDestinationFileText().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);

        if (panel.getOverwriteCheckbox().isSelected())
            args.add("-" + ConcatParsedCommand.OVERWRITE_ARG);
        if (panel.getOutputCompressedCheck().isSelected())
            args.add("-" + ConcatParsedCommand.COMPRESSED_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.pentaho.reporting.designer.core.actions.report.SaveReportUtilities.java

/**
 * Validates that the extension of the filename is prpt, and prompts the user if it is not.
 *
 * @param proposedFile the target file to validate
 * @param parent       the parent component in case we need to display a dialog
 * @return the filename based on the validation and optional prompting, or <code>null</code> if the user decided to
 * cancel the operaion/*from   w  ww .  j  av  a  2 s  .com*/
 */
public static File validateFileExtension(final File proposedFile, final Component parent) {
    if (proposedFile == null) {
        return null;
    }

    // See if we need to change the file extension
    final String s = proposedFile.getName();
    if (s.endsWith(DEFAULT_EXTENSION) || s.endsWith(".prpti")) {
        return proposedFile;
    }

    final String extension = IOUtils.getInstance().getFileExtension(s);
    if ("".equals(extension)) {
        final File parentFile = proposedFile.getParentFile();
        if (parentFile == null) {
            return new File(IOUtils.getInstance().stripFileExtension(s) + DEFAULT_EXTENSION);
        } else {
            return new File(parentFile, IOUtils.getInstance().stripFileExtension(s) + DEFAULT_EXTENSION);
        }
    }

    logger.debug("The selected filename does not have the standard extension - " + // NON-NLS
            "prompting the user to see if they want to change the extension");// NON-NLS
    final int result = JOptionPane.showConfirmDialog(parent,
            ActionMessages.getString("SaveReportUtilities.VerifyFileExtension.Message",
                    proposedFile.getAbsolutePath()),
            ActionMessages.getString("SaveReportUtilities.VerifyFileExtension.Title"),
            JOptionPane.YES_NO_CANCEL_OPTION);
    if (result == JOptionPane.CANCEL_OPTION) {
        return null;
    }
    if (result == JOptionPane.NO_OPTION) {
        return proposedFile;
    }

    final File validatedFile = new File(proposedFile.getParent(),
            IOUtils.getInstance().stripFileExtension(s) + DEFAULT_EXTENSION);
    logger.debug("User has selected YES - the filename has been changed to [" + validatedFile.getName() + "]");// NON-NLS
    return validatedFile;
}

From source file:org.pentaho.reporting.designer.core.editor.styles.styleeditor.StyleDefinitionUtilities.java

/**
 * Validates that the extension of the filename is prpt, and prompts the user if it is not.
 *
 * @param proposedFile the target file to validate
 * @param parent       the parent component in case we need to display a dialog
 * @return the filename based on the validation and optional prompting, or <code>null</code> if the user decided to
 * cancel the operaion/*w  ww  .  j  a va 2 s. c om*/
 */
public static File validateFileExtension(final File proposedFile, final Component parent) {
    if (proposedFile == null) {
        return null;
    }

    // See if we need to change the file extension
    final String s = proposedFile.getName();
    if (s.endsWith(DEFAULT_EXTENSION)) {
        return proposedFile;
    }

    final String extension = IOUtils.getInstance().getFileExtension(s);
    if ("".equals(extension)) {
        final File parentFile = proposedFile.getParentFile();
        if (parentFile == null) {
            return new File(IOUtils.getInstance().stripFileExtension(s) + DEFAULT_EXTENSION);
        } else {
            return new File(parentFile, IOUtils.getInstance().stripFileExtension(s) + DEFAULT_EXTENSION);
        }
    }

    logger.debug("The selected filename does not have the standard extension - " + // NON-NLS
            "prompting the user to see if they want to change the extension");// NON-NLS
    final int result = JOptionPane.showConfirmDialog(parent,
            Messages.getString("StyleDefinitionUtilities.VerifyFileExtension.Message",
                    proposedFile.getAbsolutePath()),
            Messages.getString("StyleDefinitionUtilities.VerifyFileExtension.Title"),
            JOptionPane.YES_NO_CANCEL_OPTION);
    if (result == JOptionPane.CANCEL_OPTION) {
        return null;
    }
    if (result == JOptionPane.NO_OPTION) {
        return proposedFile;
    }

    final File validatedFile = new File(proposedFile.getParent(),
            IOUtils.getInstance().stripFileExtension(s) + DEFAULT_EXTENSION);
    logger.debug("User has selected YES - the filename has been changed to [" + validatedFile.getName() + "]");// NON-NLS
    return validatedFile;
}

From source file:org.rimudb.editor.RimuDBEditor.java

/**
 * DataObjectEditor/* w w w  .  j  a v a 2  s  . c  om*/
 */
public RimuDBEditor() {
    super(TITLE);

    log.debug(System.getProperties());
    logMemory();

    // Create a preferences object
    preferences = new RimuDBPreferences(this.getClass().getName());

    // Use the system l&f
    try {
        String plaf = UIManager.getSystemLookAndFeelClassName();
        UIManager.setLookAndFeel(plaf);
    } catch (Exception e) {
    }

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            if (getDescriptorEditor().hasChanged()) {
                log.debug("windowClosing() Save changes to table descriptor?");
                int option = JOptionPane.showConfirmDialog(RimuDBEditor.this,
                        "Save changes to Table Descriptor?", "RimuDB Editor", JOptionPane.YES_NO_CANCEL_OPTION);
                // Cancel the close operation
                if (option == JOptionPane.CANCEL_OPTION) {
                    // setVisible(true);
                    return;
                }
                // Save the file
                if (option == JOptionPane.YES_OPTION) {
                    log.debug("windowClosing() saving data");
                    getDescriptorFileContoller().save();
                }
            }
            log.debug("System.exit(0)");
            System.exit(0);
        }
    });

    setIconImage(loadIcon("/images/rimudb_logo.gif").getImage());

    descriptorFileController = new DescriptorFileController(this);

    setJMenuBar(buildJMenuBar());
    JToolBar toolbar = createToolbar();

    editor = new DescriptorEditor(this);

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(toolbar, BorderLayout.NORTH);
    panel.add(new JSeparator());
    panel.add(editor, BorderLayout.CENTER);

    setContentPane(panel);

    pack();

    editor.requestPackageFocus();

    // Center in the screen
    setLocationRelativeTo(null);

    startDriverCheck();
}

From source file:org.roche.antibody.services.graphsynchronizer.GraphSynchronizer.java

/**
 * Syncs the changes back to the antibody and returns whether changes should be submitted (and the macromolecule
 * editor cleared)/*ww w  .  j av a2  s .  c om*/
 * 
 * @param helmCode
 * @return true when macromolecule editor should be cleared and the antibody synced back to abEditor. False when sync
 *         should be cancelled for further edit.
 * @throws FileNotFoundException
 */
public boolean syncBackToAntibody(String helmCode) throws FileNotFoundException {
    Map<HELMElement, Sequence> helmToSequence = new HashMap<HELMElement, Sequence>();
    HELMCode code = HelmNotationService.getInstance().toHELMCode(helmCode);
    List<HELMElement> handledElements = new ArrayList<HELMElement>();
    deletedConnectionCount = 0;
    createdConnectionCount = 0;

    // do not change anything, when molecule did not change
    try {
        if (ComplexNotationParser.getCanonicalNotation(helmSentToEditor)
                .equals(ComplexNotationParser.getCanonicalNotation(helmCode))) {
            return true;
        }
    } catch (Exception e) {
        LOG.error(e.getMessage());
    }

    int validationOption = validate(code);
    if (validationOption == JOptionPane.YES_OPTION) {
        removeBlocker(code);
        deleteOldSequencesAndConnections();
        handleActiveDomain(code, helmToSequence, handledElements);
        handleNewSequences(code, helmToSequence, handledElements);
        handleNewConnections(code, helmToSequence);

        // align non-domain Sequences, after they were created and connected
        AbstractGraphService.alignNonDomainSequences(abEditor.getAbstractGraph(), ab,
                (NodeMap) abEditor.getAbstractGraph().getDataProvider(GivenLayersLayerer.LAYER_ID_KEY));
        abEditor.updateLayoutHints();
        abEditor.updateGraphLayout();
    } else {
        //
        if (validationOption == JOptionPane.CANCEL_OPTION) {
            return false;
        } else if (validationOption == JOptionPane.NO_OPTION) {
            return true;
        }
    }

    try {
        DomainAnnotationAction.annotateDomain(AntibodyEditorAccess.getInstance().getAntibodyEditorPane(),
                activeDomain);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    // Show the user an appropriate message when the connection count
    // changed.
    int connectionCountChange = deletedConnectionCount - createdConnectionCount;
    if (connectionCountChange > 0) {
        String message = String.format("%d %s removed, because automated reconfiguration is not possible.",
                connectionCountChange, connectionCountChange > 1 ? "connections" : "connection");
        JOptionPane.showMessageDialog(this.abEditor, message, "Connection count changed",
                JOptionPane.INFORMATION_MESSAGE);
    } else if (connectionCountChange < 0) {
        String message = String.format("%d %s additional connections added.", -connectionCountChange,
                connectionCountChange < -1 ? "connections" : "connection");
        JOptionPane.showMessageDialog(this.abEditor, message, "Connection count changed",
                JOptionPane.INFORMATION_MESSAGE);
    }

    return true;
}

From source file:org.roche.antibody.services.graphsynchronizer.GraphSynchronizer.java

/**
 * Validates in order to decide, if we can sync our model back or not!
 * //from   ww  w .  ja v  a 2 s  .  c o m
 * @param code
 * @return JOptionPane.YES_NO_CANCEL_OPTION
 */
private int validate(HELMCode code) {
    int blockersInCode = 0;
    boolean activeDomainDetected = false;
    boolean activeDomainChanged = false;

    String domainChangesMsg = "";

    for (HELMElement elem : code.getAllElements()) {
        if (blocksToRemove.contains(elem.getSequenceRepresentation())) {
            blockersInCode++;
        }
        if (elem instanceof HELMPeptide) {
            HELMPeptide pep = (HELMPeptide) elem;
            if (pep.getSimpleSequence().startsWith(activeDomain.getSequence())
                    || pep.getSimpleSequence().endsWith(activeDomain.getSequence())) {
                activeDomainDetected = true;
            } else {
                domainChangesMsg = checkForSequenceChanges(activeDomain.getSequence(), pep.getSimpleSequence());
                activeDomainChanged = true;
            }
        }
    }
    if (blockersInCode != blockerCount) {
        JOptionPane.showMessageDialog(me.getFrame(), "Blockers were mainpulated! Model cannot be sync back!",
                "Sync Error", JOptionPane.ERROR_MESSAGE);
        return JOptionPane.CANCEL_OPTION;

    } else if (!activeDomainDetected && activeDomainChanged) {
        FontUIResource defaultFont = (FontUIResource) UIManager.get("OptionPane.messageFont");
        UIManager.put("OptionPane.messageFont", new FontUIResource("Courier New", FontUIResource.PLAIN, 13));
        int isConfirmed = JOptionPane.showConfirmDialog(me.getFrame(), domainChangesMsg, "Sequence has changed",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        UIManager.put("OptionPane.messageFont", defaultFont);

        return isConfirmed;

    }
    return JOptionPane.YES_OPTION;
}