Example usage for javax.swing JOptionPane YES_NO_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_OPTION

Introduction

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

Prototype

int YES_NO_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:net.sf.firemox.ui.MdbListener.java

/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 *//*w  w  w. ja v  a 2s .  c  om*/
public void actionPerformed(ActionEvent e) {
    if ("menu_options_tbs_more".equals(e.getActionCommand())) {
        // goto "more TBS" page
        try {
            WebBrowser.launchBrowser("http://sourceforge.net/project/showfiles.php?group_id="
                    + IdConst.PROJECT_ID + "&package_id=107882");
        } catch (Exception e1) {
            JOptionPane.showOptionDialog(MagicUIComponents.magicForm,
                    LanguageManager.getString("error") + " : " + e1.getMessage(),
                    LanguageManager.getString("web-pb"), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE,
                    UIHelper.getIcon("wiz_update_error.gif"), null, null);
        }
        return;
    }
    if ("menu_options_tbs_update".equals(e.getActionCommand())) {
        // update the current TBS
        XmlConfiguration.main(new String[] { "-g", MToolKit.tbsName });
        return;
    }
    if ("menu_options_tbs_rebuild".equals(e.getActionCommand())) {
        /*
         * rebuild completely the current TBS
         */
        XmlConfiguration.main(new String[] { "-f", "-g", MToolKit.tbsName });
        return;
    }

    // We change the TBS

    // Wait for confirmation
    if (JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(MagicUIComponents.magicForm,
            LanguageManager.getString("warn-disconnect"), LanguageManager.getString("disconnect"),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, UIHelper.getIcon("wiz_update.gif"), null,
            null)) {

        // Save the current settings before changing TBS
        Magic.saveSettings();

        // Copy this settings file to the profile directory of this TBS
        final File propertyFile = MToolKit.getFile(IdConst.FILE_SETTINGS);
        try {
            FileUtils.copyFile(propertyFile, MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false));

            // Delete the current settings file of old TBS
            propertyFile.delete();

            // Load the one of the new TBS
            abstractMainForm.setMdb(e.getActionCommand());
            Configuration.loadTemplateFile(
                    MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false).getAbsolutePath());

            // Copy the saved configuration of new TBS
            FileUtils.copyFile(MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false), propertyFile);
            Log.info("Successful TBS swith to " + MToolKit.tbsName);

            // Restart the game
            System.exit(IdConst.EXIT_CODE_RESTART);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:Framework.java

private boolean quitConfirmed(JFrame frame) {
    String s1 = "Quit";
    String s2 = "Cancel";
    Object[] options = { s1, s2 };
    int n = JOptionPane.showOptionDialog(frame, "Windows are still open.\nDo you really want to quit?",
            "Quit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, s1);
    if (n == JOptionPane.YES_OPTION) {
        return true;
    } else {/*from w  ww  . j  av a 2 s.c  om*/
        return false;
    }
}

From source file:org.jtheque.ui.impl.UIUtilsImpl.java

@Override
public boolean askUserForConfirmation(final String text, final String title) {
    boolean yes = false;

    Window parent = null;//  w w w. j  a  va 2 s . c  o  m

    if (SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class) != null) {
        parent = SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class);
    }

    final Window p = parent;

    final int[] response = new int[1];

    if (SwingUtilities.isEventDispatchThread()) {
        response[0] = JOptionPane.showConfirmDialog(parent, text, title, JOptionPane.YES_NO_OPTION);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    response[0] = JOptionPane.showConfirmDialog(p, text, title, JOptionPane.YES_NO_OPTION);
                }
            });
        } catch (InterruptedException e) {
            LoggerFactory.getLogger(getClass()).error(e.getMessage(), e);
        } catch (InvocationTargetException e) {
            LoggerFactory.getLogger(getClass()).error(e.getMessage(), e);
        }
    }

    if (response[0] == JOptionPane.YES_OPTION) {
        yes = true;
    }

    return yes;
}

From source file:net.sf.taverna.t2.activities.localworker.actions.LocalworkerActivityConfigurationAction.java

/**
 * If the localworker has not been changed it pops up a {@link JOptionPane} warning the user
 * that they change things at their own risk. Otherwise just show the config view
 *//* w w w .ja v  a 2s .  c om*/
public void actionPerformed(ActionEvent e) {
    Object[] options = { "Continue", "Cancel" };
    Configuration configuration = scufl2Tools.configurationFor(activity, activity.getParent());
    JsonNode json = configuration.getJson();
    if (!json.get("isAltered").booleanValue()) {
        int n = JOptionPane.showOptionDialog(null,
                "Changing the properties of a Local Worker may affect its behaviour. Do you want to continue?",
                "WARNING", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a
                // custom Icon
                options, options[0]);

        if (n == 0) {
            // continue was clicked so prepare for config
            openDialog();
        } else {
            // do nothing
        }
    } else {
        openDialog();
    }
}

From source file:eu.ggnet.dwoss.redtape.action.StateTransitionAction.java

@Override
public void actionPerformed(ActionEvent e) {
    //TODO: All the extra checks for hints don't feel like the optimum

    //Invoice//  w  w  w.  ja v a 2s .  c o m
    if (((RedTapeStateTransition) transition).getHints()
            .contains(RedTapeStateTransition.Hint.CREATES_INVOICE)) {
        int confirmInvoice = JOptionPane.showOptionDialog(parent,
                "Eine Rechnung wird unwiederruflich erstellt. Mchten Sie fortfahren?", "Rechnungserstellung",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
        if (confirmInvoice == JOptionPane.CANCEL_OPTION)
            return;
    }

    //Cancel
    if (((RedTapeStateTransition) transition).equals(RedTapeStateTransitions.CANCEL)) {
        int confirmInvoice = JOptionPane.showOptionDialog(parent,
                "Der Vorgang wird storniert.\nMchten Sie fortfahren?", "Abbrechen des Vorganges",
                JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
        if (confirmInvoice == JOptionPane.NO_OPTION)
            return;
    }

    if (((RedTapeStateTransition) transition).getHints()
            .contains(RedTapeStateTransition.Hint.ADDS_SETTLEMENT)) {
        SettlementViewCask view = new SettlementViewCask();
        OkCancelDialog<SettlementViewCask> dialog = new OkCancelDialog<>(parent, "Zahlung hinterlegen", view);
        dialog.setVisible(true);
        if (dialog.getCloseType() == CloseType.OK) {
            for (Document.Settlement settlement : view.getSettlements()) {
                cdoc.getDocument().add(settlement);
            }
        } else {
            return;
        }
    }
    if (((RedTapeStateTransition) transition).getHints()
            .contains(RedTapeStateTransition.Hint.UNIT_LEAVES_STOCK)) {
        for (Position p : cdoc.getDocument().getPositions(PositionType.PRODUCT_BATCH).values()) {
            //TODO not the best but fastest solution for now, this must be changed later
            if (StringUtils.isBlank(p.getRefurbishedId())) {
                if (JOptionPane.showConfirmDialog(parent,
                        "Der Vorgang enthlt Neuware, wurden alle Seriennummern erfasst?",
                        "Bitte verifizieren", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION)
                    return;
            }
        }
    }
    Dossier d = lookup(RedTapeWorker.class).stateChange(cdoc, transition, lookup(Guardian.class).getUsername())
            .getDossier();
    controller.reloadSelectionOnStateChange(d);
}

From source file:com.dragoniade.deviantart.deviation.SearchRss.java

public List<Deviation> search(ProgressDialog progress, Collection collection) {
    if (user == null) {
        throw new IllegalStateException("You must set the user before searching.");
    }//from  ww w. j  a v  a 2  s . c o m
    if (search == null) {
        throw new IllegalStateException("You must set the search type before searching.");
    }
    if (total < 0) {
        progress.setText("Fetching total (0)");
        total = retrieveTotal(progress, collection);
        progress.setText("Total: " + total);
    }

    String searchQuery = search.getSearch().replace("%username%", user);
    String queryString = "http://backend.deviantart.com/rss.xml?q=" + searchQuery
            + (collection == null ? "" : "/" + collection.getId()) + "&type=deviation&offset=" + offset;
    GetMethod method = new GetMethod(queryString);
    List<Deviation> results = new ArrayList<Deviation>(OFFSET);
    try {
        int sc = -1;
        do {
            sc = client.executeMethod(method);
            if (sc != 200) {
                LoggableException ex = new LoggableException(method.getResponseBodyAsString());
                Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex);

                int res = DialogHelper.showConfirmDialog(owner,
                        "An error has occured when contacting deviantART : error " + sc + ". Try again?",
                        "Continue?", JOptionPane.YES_NO_OPTION);
                if (res == JOptionPane.NO_OPTION) {
                    return null;
                }
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                }
            }
        } while (sc != 200);

        XmlToolkit toolkit = XmlToolkit.getInstance();

        Element responses = toolkit.parseDocument(method.getResponseBodyAsStream());
        method.releaseConnection();

        HashMap<String, String> prefixes = new HashMap<String, String>();
        prefixes.put("media", responses.getOwnerDocument().lookupNamespaceURI("media"));
        NamespaceContext context = toolkit.getNamespaceContext(prefixes);

        List<?> deviations = toolkit.getMultipleNodes(responses, "channel/item");
        if (deviations.size() == 0) {
            return results;
        }

        for (Object obj : deviations) {
            Element deviation = (Element) obj;

            Deviation da = new Deviation();
            da.setId(getId(toolkit.getNodeAsString(deviation, "guid")));
            da.setArtist(toolkit.getNodeAsString(deviation, "media:credit", context));
            da.setCategory(toolkit.getNodeAsString(deviation, "media:category", context));
            da.setTitle(toolkit.getNodeAsString(deviation, "media:title", context));
            da.setUrl(toolkit.getNodeAsString(deviation, "link"));
            da.setTimestamp(parseDate(toolkit.getNodeAsString(deviation, "pubDate")));
            da.setMature(!"nonadult".equals(toolkit.getNodeAsString(deviation, "media:rating", context)));
            da.setCollection(collection);

            Element documentNode = (Element) toolkit.getSingleNode(deviation,
                    "media:content[@medium='document']", context);
            Element imageNode = (Element) toolkit.getSingleNode(deviation, "media:content[@medium='image']",
                    context);
            Element videoNode = (Element) toolkit.getSingleNode(deviation, "media:content[@medium='video']",
                    context);

            if (imageNode != null) {
                String content = imageNode.getAttribute("url");
                String filename = Deviation.extractFilename(content);
                da.setImageDownloadUrl(content);
                da.setImageFilename(filename);

                da.setResolution(imageNode.getAttribute("width") + "x" + imageNode.getAttribute("height"));
            }

            if (documentNode != null) {
                String content = documentNode.getAttribute("url");
                String filename = Deviation.extractFilename(content);
                da.setDocumentDownloadUrl(content);
                da.setDocumentFilename(filename);
            }

            if (videoNode != null) {
                String content = videoNode.getAttribute("url");
                if (!content.endsWith("/")) {
                    content = content + "/";
                }
                String filename = Deviation.extractFilename(content);
                da.setDocumentDownloadUrl(content);
                da.setDocumentFilename(filename);
            }

            results.add(da);
        }
        offset = offset + deviations.size();
        return results;
    } catch (HttpException e) {
        DialogHelper.showMessageDialog(owner, "Error contacting deviantART : " + e.getMessage() + ".", "Error",
                JOptionPane.ERROR_MESSAGE);
        return null;
    } catch (IOException e) {
        DialogHelper.showMessageDialog(owner, "Error contacting deviantART : " + e.getMessage() + ".", "Error",
                JOptionPane.ERROR_MESSAGE);
        return null;
    }
}

From source file:com.aw.swing.mvp.ui.msg.MessageDisplayerImpl.java

public static boolean showConfirmMessage(Component parentContainer, String messageConfirm, int icon,
        int defaultButton) {
    ProcessMsgBlocker.instance().removeMessage();
    int result = JOptionPane.showOptionDialog(parentContainer, messageConfirm, GENERIC_MESSAGE_TITLE,
            JOptionPane.YES_NO_OPTION, icon, null, options, options[defaultButton]);
    return (result == JOptionPane.YES_OPTION);
}

From source file:de.bley.word.menu.GuiMenu.java

private void addListener() {

    button.addActionListener(new ActionListener() {
        @Override/*from w  w w  .j  a  v  a 2s. c  o m*/
        public void actionPerformed(ActionEvent e) {
            saveData();
            refreshList();
        }
    });

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {

            if (!textfield.getText().equals("") && !textfield.getText().equals(PropertieManager.getInstance()
                    .getZuordnung().getReader().readFile(zuordnung.getPath().getFilepath()))) {

                int confirmed = JOptionPane.showConfirmDialog(null, "Daten speichern?", "Beenden",
                        JOptionPane.YES_NO_OPTION);

                if (confirmed == JOptionPane.YES_OPTION) {
                    saveData();
                }
            }
        }
    });

}

From source file:edu.ku.brc.specify.config.init.RegisterSpecify.java

/**
 * @param title/*  ww w  .  j a v  a  2  s  . com*/
 * @return
 */
private boolean askToReg(final String typeTitle, final String typeName) {
    Object[] options = { getResourceString("YES"), //$NON-NLS-1$
            getResourceString("NO") //$NON-NLS-1$
    };
    int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
            getLocalizedMessage("SpReg.DO_REG", typeTitle, typeName), //$NON-NLS-1$
            getResourceString("SpReg.DO_REG_TITLE"), //$NON-NLS-1$
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

    return userChoice == JOptionPane.YES_OPTION;
}

From source file:net.chaosserver.timelord.swingui.AddTimeDialog.java

/**
 * @param evt the action event//from   www. j av a 2 s  .  c  om
 */
public void actionPerformed(ActionEvent evt) {
    if (ACTION_OK.equals(evt.getActionCommand())) {
        Object selectedItem = comboBox.getSelectedItem();

        if (log.isDebugEnabled()) {
            log.debug("ComboBox selected item is ["
                    + ((selectedItem == null) ? "null" : selectedItem.getClass().getName()) + "] with value ["
                    + ((selectedItem == null) ? "null" : selectedItem) + "]");
        }

        TimelordTask timelordTask = null;

        if (selectedItem instanceof TimelordTask) {
            timelordTask = (TimelordTask) selectedItem;
        } else if (selectedItem instanceof String) {
            String taskName = (String) selectedItem;
            int result = JOptionPane.showConfirmDialog(this, "Add new [" + taskName + "] Task?", "Add Task",
                    JOptionPane.YES_NO_OPTION);

            if (result == 0) {
                timelordTask = timelordData.addTask(taskName);
            }
        }

        if (timelordTask != null) {
            TimelordTaskDay timelordTaskDay = timelordTask.getTaskDay(addDate, true);

            timelordTaskDay.addHours(DateUtil.getSmallestTimeIncremented());

            if (timelordTask.isHidden()) {
                timelordTask.setHidden(true);
            }

            this.setVisible(false);
        }
    }
}