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.sleeksnap.ScreenSnapper.java

/**
 * Prompt the user for a configuration reset
 *///w w w  .  jav  a2  s. c om
public void promptConfigurationReset() {
    final int option = JOptionPane.showConfirmDialog(null, Language.getString("settingsCorrupted"),
            Language.getString("errorLoadingSettings"), JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    if (option == JOptionPane.YES_OPTION) {
        try {
            loadSettings(true);
        } catch (final Exception e) {
            logger.log(Level.SEVERE, "Unable to load default settings!", e);
        }
    } else if (option == JOptionPane.NO_OPTION) {
        // If no, let them set the configuration themselves..
        openSettings();
    } else if (option == JOptionPane.CANCEL_OPTION) {
        // Exit, they don't want anything to do with it.
        System.exit(0);
    }
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

/**
 * Handles clicking the "New Rule" button.
 *
 * @param evt The event which caused this call.
 *//*from  ww w .j a  v  a  2 s  .c  om*/
private void bnNewRuleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnNewRuleActionPerformed
    if (hasRuleChanged()) {
        // if rule has changed without saving
        if (JOptionPane.showConfirmDialog(this,
                NbBundle.getMessage(FileExporterSettingsPanel.class,
                        "FileExporterSettingsPanel.UnsavedChangesLost"),
                NbBundle.getMessage(FileExporterSettingsPanel.class,
                        "FileExporterSettingsPanel.ChangesWillBeLost"),
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.CANCEL_OPTION) {
            // they were not quite ready to navigate away yet, so clear the selection
            treeSelectionModel.clearSelection();
            return;
        }
    }
    clearRuleEditor();
    localRule = makeRuleFromUserInput();
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

private void trRuleListValueChanged(javax.swing.event.TreeSelectionEvent evt) {
    int selectionCount = treeSelectionModel.getSelectionCount();
    lsAttributeList.removeAll();/*from ww  w .j  ava2s . com*/
    attributeListModel.removeAllElements();

    if (selectionCount > 0) {
        if (hasRuleChanged()) {
            // and the rule has changed without saving
            if (JOptionPane.showConfirmDialog(this,
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.UnsavedChangesLost"),
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.ChangesWillBeLost"),
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                // they were not quite ready to navigate away yet, so clear the selection
                trRuleList.clearSelection();
                return;
            }
        }

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) trRuleList.getLastSelectedPathComponent();
        if (node == null) { // Nothing is selected
            return;
        }

        Item nodeInfo = (Item) node.getUserObject();
        bnDeleteRule.setEnabled(nodeInfo.getItemType() == ItemType.RULE);

        if (nodeInfo.getItemType() == ItemType.RULE_SET) {
            tbRuleName.setText(null);
            clearSizeCondition();
            clearMIMECondition();
            clearArtifactCondition();
            localRule = makeRuleFromUserInput();
            return;
        }

        String selectedRuleName = nodeInfo.getRuleName();
        Rule rule = exportRuleSet.getRules().get(selectedRuleName);
        if (rule != null) {
            // Read values for this rule and display them in the UI
            tbRuleName.setText(rule.getName());
            FileMIMETypeCondition fileMIMETypeCondition = rule.getFileMIMETypeCondition();
            if (fileMIMETypeCondition != null) {
                // if there is a MIME type condition
                cbMimeType.setSelected(true);
                comboBoxMimeTypeComparison.setSelectedItem(fileMIMETypeCondition.getRelationalOp().getSymbol());
                comboBoxMimeValue.setSelectedItem(fileMIMETypeCondition.getMIMEType());
            } else { // Clear the selection
                clearMIMECondition();
            }

            List<FileSizeCondition> fileSizeCondition = rule.getFileSizeConditions();
            if (fileSizeCondition != null && !fileSizeCondition.isEmpty()) {
                // if there is a file size condition                            
                FileSizeCondition condition = fileSizeCondition.get(0);
                cbFileSize.setSelected(true);
                spFileSizeValue.setValue(condition.getSize());
                comboBoxFileSizeUnits.setSelectedItem(condition.getUnit().toString());
                comboBoxFileSizeComparison.setSelectedItem(condition.getRelationalOperator().getSymbol());
            } else {
                // Clear the selection
                clearSizeCondition();
            }

            ArtifactCondition artifactConditionToPopulateWith = null;
            List<ArtifactCondition> artifactConditions = rule.getArtifactConditions();
            if (nodeInfo.getItemType() != ItemType.ARTIFACT_CLAUSE) {
                // if there are any attribute clauses, populate the first one, otherwise clear artifact editor
                if (artifactConditions.isEmpty()) {
                    clearArtifactCondition();
                } else {
                    artifactConditionToPopulateWith = artifactConditions.get(0);
                }
            } else { // an artifact clause is selected. populate it.
                for (ArtifactCondition artifact : artifactConditions) {
                    if (artifact.getTreeDisplayName().compareTo(nodeInfo.getName()) == 0) {
                        artifactConditionToPopulateWith = artifact;
                        break;
                    }
                }
            }
            if (artifactConditionToPopulateWith != null) {
                for (ArtifactCondition artifact : artifactConditions) {
                    attributeListModel.addElement(artifact.getTreeDisplayName());
                }
                // Don't let listSelectionListener respond
                lsAttributeList.removeListSelectionListener(listSelectionListener);
                lsAttributeList.setSelectedValue(artifactConditionToPopulateWith.getTreeDisplayName(), true);
                populateArtifactEditor(artifactConditionToPopulateWith);
                setDeleteAttributeButton();
                lsAttributeList.addListSelectionListener(listSelectionListener);
            }
        }
        localRule = makeRuleFromUserInput();
    } else {
        bnDeleteRule.setEnabled(false);
    }
}

From source file:org.sleuthkit.autopsy.modules.hashdatabase.HashDbCreateDatabaseDialog.java

private void initFileChooser() {
    fileChooser = new JFileChooser() {
        @Override/*from   www  .  j a va2  s .c  om*/
        public void approveSelection() {
            File selectedFile = getSelectedFile();
            if (!FilenameUtils.getExtension(selectedFile.getName())
                    .equalsIgnoreCase(HashDbManager.getHashDatabaseFileExtension())) {
                if (JOptionPane.showConfirmDialog(this,
                        NbBundle.getMessage(this.getClass(),
                                "HashDbCreateDatabaseDialog.hashDbMustHaveFileExtensionMsg",
                                HashDbManager.getHashDatabaseFileExtension()),
                        NbBundle.getMessage(this.getClass(), "HashDbCreateDatabaseDialog.fileNameErr"),
                        JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
                    cancelSelection();
                }
                return;
            }
            if (selectedFile.exists()) {
                if (JOptionPane.showConfirmDialog(this,
                        NbBundle.getMessage(this.getClass(),
                                "HashDbCreateDatabaseDialog.fileNameAlreadyExistsMsg"),
                        NbBundle.getMessage(this.getClass(), "HashDbCreateDatabaseDialog.fileExistsErr"),
                        JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
                    cancelSelection();
                }
                return;
            }
            super.approveSelection();
        }
    };
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setDragEnabled(false);
    fileChooser.setMultiSelectionEnabled(false);
}

From source file:org.yccheok.jstock.gui.IndicatorPanel.java

private boolean promptToSaveSignificantEdits(ListSelectionEx _listSelectionEx) {
    final boolean hasSignificantEdits = ((IndicatorDefaultDrawing) this.view.getDrawing())
            .hasSignificantEdits();//  ww w. j av  a 2s  .  c  o  m
    if (false == hasSignificantEdits) {
        return true;
    }
    String output = MessagesBundle.getString("question_message_current_drawing_is_modified_save_it");
    if (_listSelectionEx != null) {
        /* There is a previous selected project. */
        output = MessageFormat.format(
                MessagesBundle.getString("question_message_current_drawing_is_modified_save_it_template"),
                _listSelectionEx.projectName);
    }
    // We have a unsaved drawing. Prompt user to save it.
    final int result = javax.swing.JOptionPane.showConfirmDialog(JStock.instance(), output,
            MessagesBundle.getString("question_title_current_drawing_is_modified_save_it"),
            javax.swing.JOptionPane.YES_NO_CANCEL_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE);

    if (result == JOptionPane.YES_OPTION) {
        // Do not use this.Save(false). this.Save(false) will only save the
        // project in current active tab and current selected project.
        // We just want to save current selected project, regardless current
        // active tab.
        // this.Save(false);
        if (_listSelectionEx != null) {
            // There is a previous selection.
            if (this.jList1 == _listSelectionEx.list) {
                this._alertIndicatorSave(_listSelectionEx.projectName, false);
            } else if (this.jList2 == _listSelectionEx.list) {
                this._moduleIndicatorSave(_listSelectionEx.projectName, false);
            }
        } else {
            // No choice. We will save to curent active tab, by prompting user
            // enter his desired project name.
            if (this.jTabbedPane1.getSelectedIndex() == 0) {
                this._alertIndicatorSave(null, false);
            } else if (this.jTabbedPane1.getSelectedIndex() == 1) {
                this._moduleIndicatorSave(null, false);
            }
        }
    }

    if (result == JOptionPane.CANCEL_OPTION) {
        final ListSelectionListener[] listSelectionListeners1 = this.jList1.getListSelectionListeners();
        final ListSelectionListener[] listSelectionListeners2 = this.jList2.getListSelectionListeners();
        try {
            for (ListSelectionListener listSelectionListener : listSelectionListeners1) {
                this.jList1.removeListSelectionListener(listSelectionListener);
            }
            for (ListSelectionListener listSelectionListener : listSelectionListeners2) {
                this.jList2.removeListSelectionListener(listSelectionListener);
            }
            // User chooses cancel. Select back previous project.
            if (_listSelectionEx != null) {
                if (_listSelectionEx.list == this.jList1) {
                    this.jList1.setSelectedValue(_listSelectionEx.projectName, true);
                    this.jList2.clearSelection();
                } else {
                    assert (_listSelectionEx.list == this.jList2);
                    this.jList2.setSelectedValue(_listSelectionEx.projectName, true);
                    this.jList1.clearSelection();
                }
            } else {
                // User chooses cancel. Clear all the lists, since previously, there are
                // no selection at all.
                this.jList1.clearSelection();
                this.jList2.clearSelection();
            }
        } finally {
            // Do it within finally block, just to be safe.
            for (ListSelectionListener listSelectionListener : listSelectionListeners1) {
                this.jList1.addListSelectionListener(listSelectionListener);
            }
            for (ListSelectionListener listSelectionListener : listSelectionListeners2) {
                this.jList2.addListSelectionListener(listSelectionListener);
            }
        }
    }

    return result != JOptionPane.CANCEL_OPTION;
}

From source file:org.yccheok.jstock.gui.IndicatorPanel.java

public boolean promptToSaveSignificantEdits() {
    final boolean hasSignificantEdits = ((IndicatorDefaultDrawing) this.view.getDrawing())
            .hasSignificantEdits();/*  w  w w .  j av a  2s . c o m*/
    if (false == hasSignificantEdits) {
        return true;
    }
    String output = MessagesBundle.getString("question_message_current_drawing_is_modified_save_it");
    // Unlike Save, in promptToSaveSignificantEdits, we will try our best to save the selected project,
    // even it is not within our visible range (The jTabbedPane is not being selected)
    if (this.jList1.getSelectedValue() != null) {
        output = MessageFormat.format(
                MessagesBundle.getString("question_message_current_drawing_is_modified_save_it_template"),
                this.jList1.getSelectedValue());
    } else if (this.jList2.getSelectedValue() != null) {
        output = MessageFormat.format(
                MessagesBundle.getString("question_message_current_drawing_is_modified_save_it_template"),
                this.jList2.getSelectedValue());
    }
    // We have a unsaved drawing. Prompt user to save it.
    final int result = javax.swing.JOptionPane.showConfirmDialog(JStock.instance(), output,
            MessagesBundle.getString("question_title_current_drawing_is_modified_save_it"),
            javax.swing.JOptionPane.YES_NO_CANCEL_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE);
    if (result == JOptionPane.YES_OPTION) {
        // Do not use this.Save(false). this.Save(false) will only save the
        // project in current active tab and current selected project.
        // We just want to save current selected project, regardless current
        // active tab.
        // this.Save(false);
        if (this.jList1.getSelectedValue() != null) {
            this.alertIndicatorSave(false);
        } else if (this.jList2.getSelectedValue() != null) {
            this.moduleIndicatorSave(false);
        } else {
            // No choice. We will save to curent active tab, by prompting user
            // enter his desired project name.
            this.Save(false);
        }
    }
    return result != JOptionPane.CANCEL_OPTION;
}

From source file:org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.java

/**
 * Gets the popup menu factory for flagging login requests.
 * //w ww.  j ava2  s . co  m
 * @return the popup flag login request menu factory
 */
private PopupMenuItemSiteNodeContextMenuFactory getPopupFlagLoginRequestMenuFactory() {
    PopupMenuItemSiteNodeContextMenuFactory popupFlagLoginRequestMenuFactory = new PopupMenuItemSiteNodeContextMenuFactory(
            Constant.messages.getString("context.flag.popup")) {
        private static final long serialVersionUID = 8927418764L;

        @Override
        public PopupMenuItemContext getContextMenu(Context context, String parentMenu) {
            return new PopupMenuItemContext(context, parentMenu,
                    MessageFormat.format(
                            Constant.messages.getString("authentication.method.fb.popup.login.request"),
                            context.getName())) {

                private static final long serialVersionUID = 1967885623005183801L;
                private ExtensionUserManagement usersExtension;
                private Context uiSharedContext;

                /**
                 * Make sure the user acknowledges the Users corresponding to this context will
                 * be deleted.
                 * 
                 * @return true, if successful
                 */
                private boolean confirmUsersDeletion(Context uiSharedContext) {
                    usersExtension = (ExtensionUserManagement) Control.getSingleton().getExtensionLoader()
                            .getExtension(ExtensionUserManagement.NAME);
                    if (usersExtension != null) {
                        if (usersExtension.getSharedContextUsers(uiSharedContext).size() > 0) {
                            int choice = JOptionPane.showConfirmDialog(this,
                                    Constant.messages.getString("authentication.dialog.confirmChange.label"),
                                    Constant.messages.getString("authentication.dialog.confirmChange.title"),
                                    JOptionPane.OK_CANCEL_OPTION);
                            if (choice == JOptionPane.CANCEL_OPTION) {
                                return false;
                            }
                        }
                    }
                    return true;
                }

                @Override
                public void performAction(SiteNode sn) {
                    // Manually create the UI shared contexts so any modifications are done
                    // on an UI shared Context, so changes can be undone by pressing Cancel
                    SessionDialog sessionDialog = View.getSingleton().getSessionDialog();
                    sessionDialog.recreateUISharedContexts(Model.getSingleton().getSession());
                    uiSharedContext = sessionDialog.getUISharedContext(this.getContext().getIndex());

                    // Do the work/changes on the UI shared context
                    if (this.getContext().getAuthenticationMethod() instanceof FormBasedAuthenticationMethod) {
                        log.info(
                                "Selected new login request via PopupMenu. Changing existing Form-Based Authentication instance for Context "
                                        + getContext().getIndex());
                        FormBasedAuthenticationMethod method = (FormBasedAuthenticationMethod) uiSharedContext
                                .getAuthenticationMethod();

                        try {
                            method.setLoginRequest(sn);
                        } catch (Exception e) {
                            log.error("Failed to set login request: " + e.getMessage(), e);
                            return;
                        }

                        // Show the session dialog without recreating UI Shared contexts
                        View.getSingleton().showSessionDialog(Model.getSingleton().getSession(),
                                ContextAuthenticationPanel.buildName(this.getContext().getIndex()), false);
                    } else {
                        log.info(
                                "Selected new login request via PopupMenu. Creating new Form-Based Authentication instance for Context "
                                        + getContext().getIndex());
                        FormBasedAuthenticationMethod method = new FormBasedAuthenticationMethod();

                        try {
                            method.setLoginRequest(sn);
                        } catch (Exception e) {
                            log.error("Failed to set login request: " + e.getMessage(), e);
                            return;
                        }
                        if (!confirmUsersDeletion(uiSharedContext)) {
                            log.debug("Cancelled change of authentication type.");
                            return;
                        }
                        uiSharedContext.setAuthenticationMethod(method);

                        // Show the session dialog without recreating UI Shared contexts
                        // NOTE: First init the panels of the dialog so old users data gets
                        // loaded and just then delete the users
                        // from the UI data model, otherwise the 'real' users from the
                        // non-shared context would be loaded
                        // and would override any deletions made.
                        View.getSingleton().showSessionDialog(Model.getSingleton().getSession(),
                                ContextAuthenticationPanel.buildName(this.getContext().getIndex()), false,
                                new Runnable() {

                                    @Override
                                    public void run() {
                                        // Removing the users from the 'shared context' (the UI)
                                        // will cause their removal at
                                        // save as well
                                        if (usersExtension != null)
                                            usersExtension.removeSharedContextUsers(uiSharedContext);
                                    }
                                });
                    }
                }
            };
        }

        @Override
        public int getParentMenuIndex() {
            return 3;
        }
    };
    return popupFlagLoginRequestMenuFactory;
}

From source file:org.zaproxy.zap.extension.beanshell.BeanShellConsoleFrame.java

private JButton getBtnLoad() {
    if (btnLoad == null) {
        btnLoad = new JButton();
        btnLoad.setText(Constant.messages.getString("beanshell.button.load"));

        btnLoad.addActionListener(new ActionListener() {
            @Override// www.  ja  va  2 s  . c  om
            public void actionPerformed(ActionEvent e) {
                if (getBeanShellPanel().isSaved() == false) {
                    int confirm = view
                            .showConfirmDialog(Constant.messages.getString("beanshell.dialog.unsaved"));
                    if (confirm == JOptionPane.CANCEL_OPTION)
                        return;
                }
                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().getTxtEditor().discardAllEdits();
                        getBeanShellPanel().setSaved(true);
                        currentScriptFile = fc.getSelectedFile();
                    } catch (IOException ex) {
                        log.error(ex.getMessage(), ex);
                        View.getSingleton().showWarningDialog(
                                Constant.messages.getString("beanshell.error.message.loading.script"));
                    }
                }
            }
        });
    }
    return btnLoad;
}

From source file:org.zaproxy.zap.extension.history.PopupMenuExportURLs.java

/**
 * This method initializes this/*from  ww w .j a  v a  2  s .  co m*/
 * 
 * @return void
 */
private void initialize() {
    this.setText(Constant.messages.getString("exportUrls.popup"));

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

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

            JTree site = extension.getView().getSiteTreePanel().getTreeSite();

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

            boolean isAppend = true;
            if (file.exists()) {
                int rc = extension.getView()
                        .showYesNoCancelDialog(Constant.messages.getString("file.overwrite.warning"));
                if (rc == JOptionPane.CANCEL_OPTION) {
                    return;
                } else if (rc == JOptionPane.YES_OPTION) {
                    isAppend = false;
                }
            }
            boolean html = file.getName().toLowerCase().endsWith(".htm")
                    || file.getName().toLowerCase().endsWith(".html");

            BufferedWriter fw = null;
            try {
                fw = new BufferedWriter(new FileWriter(file, isAppend));
                exportURLs((SiteNode) site.getModel().getRoot(), fw, html);

            } catch (Exception e1) {
                log.warn(e1.getStackTrace(), e1);
                extension.getView().showWarningDialog(
                        Constant.messages.getString("file.save.error") + file.getAbsolutePath() + ".");
            } finally {
                try {
                    fw.close();
                } catch (Exception e2) {
                    log.warn(e2.getStackTrace(), e2);
                }
            }
        }
    });

}

From source file:pcgen.gui2.PCGenFrame.java

public void closeCharacter(CharacterFacade character) {
    if (character.isDirty()) {
        int ret = JOptionPane.showConfirmDialog(this,
                LanguageBundle.getFormattedString("in_savePcChoice", character //$NON-NLS-1$
                        .getNameRef().get()),
                Constants.APPLICATION_NAME, JOptionPane.YES_NO_CANCEL_OPTION);
        if (ret == JOptionPane.CANCEL_OPTION) {
            return;
        }//w w w  .  j  av  a 2  s  .  c o  m
        if (ret == JOptionPane.YES_OPTION) {
            saveCharacter(character);
        }
    }
    CharacterManager.removeCharacter(character);
}