Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

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

Prototype

int OK_OPTION

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

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * Prompt the user to enter a password/*  w  w w  .  j  av a2s .  co  m*/
 * @return The password entered by the user or null of this hit escape/cancel
 */
private char[] askUserForPassword(String message) {
    char[] password = null;

    final JPasswordField masterPassword = new JPasswordField("");
    JOptionPane pane = new JOptionPane(new Object[] { message, masterPassword }, JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = pane.createDialog(mainWindow, Translator.translate("masterPassword"));
    dialog.addWindowFocusListener(new WindowAdapter() {
        public void windowGainedFocus(WindowEvent e) {
            masterPassword.requestFocusInWindow();
        }
    });
    dialog.show();

    if (pane.getValue() != null && pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) {
        password = masterPassword.getPassword();
    }

    return password;
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void deleteRecord() {
    int selectedRow = table.getSelectedRow();
    if (selectedRow < 0) {
        JOptionPane.showMessageDialog(MainFrame.this, "", "",
                JOptionPane.ERROR_MESSAGE);
        return;/*from w  w  w  .  ja  v  a2s . co m*/
    }
    Record record = model.getRecord(table.convertRowIndexToModel(selectedRow));
    System.out.println(record);
    if (JOptionPane.showConfirmDialog(MainFrame.this,
            String.format("??%d?", record.getId()), "",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
        try {
            recordFacade.delete(record);
            searchRecords();
        } catch (Exception e1) {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(MainFrame.this, e1.getMessage(), "", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:ee.ioc.cs.vsle.editor.Editor.java

/**
 * Close application.//from  w  w w. ja v  a2s.  c  o  m
 */
public void exitApplication() {
    int confirmed = JOptionPane.showConfirmDialog(this, "Exit Application?", Menu.EXIT,
            JOptionPane.OK_CANCEL_OPTION);
    switch (confirmed) {
    case JOptionPane.OK_OPTION:

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {

                int state = getExtendedState();

                if ((state & MAXIMIZED_BOTH) == MAXIMIZED_BOTH) {
                    // need to remember window's size in normal mode...looks
                    // ugly,
                    // any other ideas how to get normal size while staying
                    // maximized?
                    setExtendedState(NORMAL);
                }

                RuntimeProperties.setSchemeEditorWindowProps(getBounds(), state);

                RuntimeProperties.save();

                System.exit(0);
            }
        });

        break;
    case JOptionPane.CANCEL_OPTION:
        break;
    }
}

From source file:Forms.CreateGearForm.java

private void showLintErrorDialog(GearSpecLintResult result) {
    Object[] options = { "OK" };
    int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(MasterPanel),
            result.getResponseMessage(), "Lint Error", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE,
            null, options, options[0]);/*from w w  w.  j a v  a 2  s  .c  om*/
}

From source file:idontwant2see.IDontWant2See.java

private AbstractAction getActionInputTitle(final Program p, final String part) {
    return new AbstractAction(mLocalizer.msg("menu.userEntered", "User entered value")) {
        public void actionPerformed(final ActionEvent e) {
            final JCheckBox caseSensitive = new JCheckBox(mLocalizer.msg("caseSensitive", "case sensitive"));
            String title = p.getTitle();
            ArrayList<String> items = new ArrayList<String>();
            if (!StringUtils.isEmpty(part)) {
                String shortTitle = title.trim().substring(0, title.length() - part.length()).trim();
                shortTitle = StringUtils.removeEnd(shortTitle, "-").trim();
                shortTitle = StringUtils.removeEnd(shortTitle, "(").trim();
                items.add(shortTitle + "*");
            }/*from w w w.  j  av  a2s  . com*/
            int index = title.indexOf(" - ");
            if (index > 0) {
                items.add(title.substring(0, index).trim() + "*");
            }
            items.add(title);
            index = title.lastIndexOf(':');
            if (index > 0) {
                items.add(title.substring(0, index).trim() + "*");
            }
            final JComboBox input = new JComboBox(items.toArray(new String[items.size()]));
            input.setEditable(true);

            input.addAncestorListener(new AncestorListener() {
                public void ancestorAdded(final AncestorEvent event) {
                    event.getComponent().requestFocus();
                }

                public void ancestorMoved(final AncestorEvent event) {
                }

                public void ancestorRemoved(final AncestorEvent event) {
                }
            });

            if (JOptionPane.showConfirmDialog(UiUtilities.getLastModalChildOf(getParentFrame()),
                    new Object[] {
                            mLocalizer.msg("exclusionText",
                                    "What should be excluded? (You can use the wildcard *)"),
                            input, caseSensitive },
                    mLocalizer.msg("exclusionTitle", "Exclusion value entering"),
                    JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                String test = "";

                String result = (String) input.getSelectedItem();
                if (result != null) {
                    test = result.replaceAll("\\*+", "\\*").trim();

                    if (test.length() >= 0 && !test.equals("*")) {
                        mSettings.getSearchList()
                                .add(new IDontWant2SeeListEntry(result, caseSensitive.isSelected()));
                        mSettings.setLastEnteredExclusionString(result);
                        updateFilter(!mSettings.isSwitchToMyFilter());
                    }
                }

                if (test.trim().length() <= 1) {
                    JOptionPane.showMessageDialog(UiUtilities.getLastModalChildOf(getParentFrame()),
                            mLocalizer.msg("notValid", "The entered text is not valid."),
                            Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    };
}

From source file:gui.DownloadPanel.java

public void actionClear() {
    int action = JOptionPane.showConfirmDialog(parent, "Do you realy want to delete selected file?",
            "Confirm delete", JOptionPane.OK_CANCEL_OPTION);
    if (action == JOptionPane.OK_OPTION) {
        if (selectedDownload == null)
            return;
        //     download download = selectedDownloadDialog.getDownload();

        clearing = true;/*from   www .j a  va 2 s  . c o  m*/
        downloadsTableModel.clearDownload(selectedDownload);
        if (downloadList.contains(selectedDownload))
            downloadList.remove(selectedDownload);
        clearing = false;

        //    selectedDownloadDialog = null;
        DownloadDialog downloadDialog = getDownloadDialogByDownload(selectedDownload);
        downloadDialogs.remove(downloadDialog);
        downloadDialog.dispose();
        downloadDialog.removeDownloadInfoListener(this);
        downloadDialog = null;

        try {
            databaseController.delete(selectedDownload.getId());
        } catch (SQLException e) {
            //      e.printStackTrace();
        }

        try {
            FileUtils.forceDelete(new File(selectedDownload.getDownloadRangePath() + File.separator
                    + selectedDownload.getDownloadName())); // todo must again
        } catch (IOException e) {
            //      e.printStackTrace();
        }

        selectedDownload = null;
        tableSelectionChanged();
    }
}

From source file:Forms.CreateGearForm.java

private void showSaveErrorDialog() {
    Object[] options = { "OK" };
    int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(MasterPanel),
            "There was a problem saving your Gear Spec. Please try again.", "Lint Error", JOptionPane.OK_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
}

From source file:com.intuit.tank.tools.debugger.ActionProducer.java

/**
 * /*from   w  ww .j  av  a2  s .c  o  m*/
 * @return
 */
public Action getSelectTankAction() {
    Action ret = actionMap.get(ACTION_SELECT_TANK);
    if (ret == null) {
        ret = new AbstractAction(ACTION_SELECT_TANK) {
            private static final long serialVersionUID = 1L;
            final JComboBox cb = getComboBox();

            @Override
            public void actionPerformed(ActionEvent event) {
                try {
                    int selected = JOptionPane.showConfirmDialog(debuggerFrame, cb,
                            "Enter the base URL to Tank:", JOptionPane.OK_CANCEL_OPTION,
                            JOptionPane.QUESTION_MESSAGE);
                    if (selected == JOptionPane.OK_OPTION) {
                        String url = (String) cb.getSelectedItem();
                        if (url != null) {
                            int startInd = url.indexOf('(');
                            int endInd = url.indexOf(')');
                            if (startInd != -1 && endInd != -1) {
                                url = url.substring(startInd + 1, endInd);
                            }
                            url = StringUtils.removeEndIgnoreCase(url, "/");
                            if (!url.startsWith("http")) {
                                url = "http://" + url;
                            }
                            try {
                                new ScriptServiceClient(url).ping();
                                setServiceUrl(url);
                            } catch (Exception e) {
                                showError("Cannot connect to Tank at the url " + url
                                        + ". \nExample: http://tank.mysite.com/");
                            }
                        }
                    }
                } catch (HeadlessException e) {
                    showError("Error opening file: " + e);
                }
            }
        };
        ret.putValue(Action.SHORT_DESCRIPTION, "Enter a Tank URL.");
        actionMap.put(ACTION_SELECT_TANK, ret);
    }
    return ret;
}

From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java

public void reinitializeGroovyConditions() {
    String dialogTitle = "Reinitialize example groovy conditions?";
    String message = "This overwrites all example groovy conditions. Other conditions are not changed!\nReinitialize example groovy conditions right now?";
    int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows
    if (JOptionPane.OK_OPTION != result) {
        return;/* ww w  .  j  a va2  s  .  c om*/
    }

    applicationPreferences.installExampleConditions();
}

From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java

public boolean isConfirmed() {
    Object[] options = { "Yes", "No" };
    int option = JOptionPane.showOptionDialog(panelMain,
            "Are you sure you want to generate '" + model.getFileName() + "' ?", "Confirmation",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
            new ImageIcon(getClass().getResource(ICON_CONFIRM)), options, options[0]);

    return option == JOptionPane.OK_OPTION;
}