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:org.keyboardplaying.xtt.ui.action.ConfirmClearPrefsAction.java

@Override
public void perform() throws ActionException {
    int confirm = JOptionPane.showConfirmDialog(null, i18nHelper.getMessage("warning.prefs.clear.close"),
            "Are you sure?", JOptionPane.YES_NO_OPTION);
    if (confirm == JOptionPane.YES_OPTION) {
        clearPrefsAction.perform();/*from   www  .  ja va 2  s  .  co m*/
        disposeAllWindows();
    }
}

From source file:calendarexportplugin.exporter.CalExporter.java

public boolean exportPrograms(Program[] programs, CalendarExportSettings settings,
        AbstractPluginProgramFormating formatting) {
    mSavePath = getSavePath(settings);// w w w  . ja  va2 s.c o  m

    File file = chooseFile(programs);

    if (file == null) {
        return false;
    }

    if (file.exists()) {
        int result = JOptionPane.showConfirmDialog(CalendarExportPlugin.getInstance().getBestParentFrame(),
                mLocalizer.msg("overwriteMessage", "The File \n{0}\nalready exists. Overwrite it?",
                        file.getAbsolutePath()),
                mLocalizer.msg("overwriteTitle", "Overwrite?"), JOptionPane.YES_NO_OPTION);
        if (result != JOptionPane.YES_OPTION) {
            return false;
        }
    }

    mSavePath = file.getAbsolutePath();

    setSavePath(settings, mSavePath);
    export(file, programs, settings, formatting);

    return true;
}

From source file:hr.fer.zemris.vhdllab.platform.gui.dialog.AbstractOptionPaneDialogManager.java

private Object[] getOptionsForType(int optionType) {
    switch (optionType) {
    case JOptionPane.DEFAULT_OPTION:
        return getOption("ok");
    case JOptionPane.YES_NO_CANCEL_OPTION:
        return getOption("yes", "no", "cancel");
    case JOptionPane.YES_NO_OPTION:
        return getOption("yes", "no");
    case JOptionPane.OK_CANCEL_OPTION:
        return getOption("ok", "cancel");
    default://from  w  ww .j  a  va  2s . co m
        throw new IllegalStateException("Unknown option: " + optionType);
    }
}

From source file:net.pms.newgui.Splash.java

@Override
public void mouseClicked(MouseEvent e) {
    int isShowSplashScreen = JOptionPane.showConfirmDialog(null, Messages.getString("Splash.1"),
            Messages.getString("Splash.2"), JOptionPane.YES_NO_OPTION);
    if (isShowSplashScreen == 0) {
        configuration.setShowSplashScreen(false);
        try {/*w  w w.  j av a2 s .com*/
            configuration.save();
        } catch (ConfigurationException e1) {
            LOGGER.error("Error when saving the Splash Screen setting", e1);
        }
    }
}

From source file:com.sec.ose.osi.ui.ApplicationCloseMgr.java

synchronized public void exit() {

    log.debug("exit() - identifyQueueSize: " + IdentifyQueue.getInstance().size());

    ComponentAPIWrapper.save();//from  ww w .  j  ava2s  . co  m

    if (IdentifyQueue.getInstance().size() <= 0) {

        CacheableMgr.getInstance().saveToCache();

        UserRequestHandler.getInstance().handle(UserRequestHandler.DELETE_IDENTIFICATION_TABLE, null, true, // progress
                false // result
        );

        log.debug("OSIT EXIT...");
        System.exit(0);
    }

    log.debug("show message dialog to confirm exit or not");

    String[] buttonList = { "Yes", "No" };
    int choice = JOptionPane.showOptionDialog(null,
            "Identification Queue is not empty.(size : " + IdentifyQueue.getInstance().size() + ")\n"
                    + "If you close this application with non-empty queue.\n"
                    + "identification process for this queue will start again.\n"
                    + "But it's not recommended. (Data loss problem)\n" + "Do you really want to exit now?\n",
            "Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttonList, "Yes");
    if (choice == JOptionPane.NO_OPTION) {
        return; // will not exit. 
    }

    log.debug("user select yes option and create thread");

    JDlgExitMessage dlgExitMessage = new JDlgExitMessage();
    String message = "OSI try to sync with Protex Server.\n" + "It takes several minutes to finish.";
    DialogDisplayerThread aDialogDiaplayerThread = new DialogDisplayerThread(message, dlgExitMessage);
    CompleteSendingThread aCompleteSendingThread = new CompleteSendingThread(aDialogDiaplayerThread);

    log.debug("Thread start");

    aDialogDiaplayerThread.execute();

    aCompleteSendingThread.start();

    dlgExitMessage.setVisible(true); // block

    CacheableMgr.getInstance().saveToCache();

    log.debug("OSIT EXIT...");
    System.exit(0);
}

From source file:ca.uviccscu.lp.utils.Utils.java

@Deprecated
public static boolean checkDir(File f) {
    l.trace("Checking dir: " + f.getAbsolutePath());
    try {/*from  w w  w  .ja va2s  .  c om*/
        boolean a = f.isDirectory();
        if (a) {
            if (f.listFiles().length != 0) {
                l.error("Directory not empty");
                //JDialog jd = new JDialog((JFrame) null, true);
                int resp = JOptionPane.showConfirmDialog(null,
                        "Directory nonempty: " + f.getAbsolutePath() + ". Proceed? (will wipe)",
                        "Confirm deletion", JOptionPane.YES_NO_OPTION);
                if (resp == JOptionPane.YES_OPTION) {
                    FileUtils.deleteDirectory(f);
                } else {
                    l.fatal("Delete denied");
                    System.exit(1);
                }
            }
        }
        FileUtils.forceMkdir(f);
        File test = new File(f.getAbsolutePath() + File.separator + "test.file");
        boolean c = test.createNewFile();
        return c;
    } catch (Exception e) {
        l.fatal("Az directory creation error", e);
        return false;
    }
}

From source file:net.sf.taverna.t2.renderers.SVGRenderer.java

@SuppressWarnings("serial")
public JComponent getComponent(Path path) throws RendererException {
    if (DataBundles.isValue(path) || DataBundles.isReference(path)) {
        long approximateSizeInBytes = 0;
        try {/* w ww .  j  a  va 2s . c  om*/
            approximateSizeInBytes = RendererUtils.getSizeInBytes(path);
        } catch (Exception ex) {
            logger.error("Failed to get the size of the data", ex);
            return new JTextArea("Failed to get the size of the data (see error log for more details): \n"
                    + ex.getMessage());
        }

        if (approximateSizeInBytes > MEGABYTE) {
            int response = JOptionPane.showConfirmDialog(null, "Result is approximately "
                    + bytesToMeg(approximateSizeInBytes)
                    + " MB in size, there could be issues with rendering this inside Taverna\nDo you want to continue?",
                    "Render as SVG?", JOptionPane.YES_NO_OPTION);

            if (response != JOptionPane.YES_OPTION) {
                return new JTextArea(
                        "Rendering cancelled due to size of data. Try saving and viewing in an external application.");
            }
        }

        String resolve = null;
        try {
            // Resolve it as a string
            resolve = RendererUtils.getString(path);
        } catch (Exception e) {
            logger.error("Reference Service failed to render data as string", e);
            return new JTextArea(
                    "Reference Service failed to render data as string (see error log for more details): \n"
                            + e.getMessage());
        }

        final JSVGCanvas svgCanvas = new JSVGCanvas();
        File tmpFile = null;
        try {
            tmpFile = File.createTempFile("taverna", "svg");
            tmpFile.deleteOnExit();
            FileUtils.writeStringToFile(tmpFile, resolve, "utf8");
        } catch (IOException e) {
            logger.error("SVG Renderer: Failed to write the data to temporary file", e);
            return new JTextArea(
                    "Failed to write the data to temporary file (see error log for more details): \n"
                            + e.getMessage());
        }
        try {
            svgCanvas.setURI(tmpFile.toURI().toASCIIString());
        } catch (Exception e) {
            logger.error("Failed to create SVG renderer", e);
            return new JTextArea(
                    "Failed to create SVG renderer (see error log for more details): \n" + e.getMessage());
        }
        JPanel jp = new JPanel() {
            @Override
            protected void finalize() throws Throwable {
                svgCanvas.stopProcessing();
                super.finalize();
            }
        };
        jp.add(svgCanvas);
        return jp;
    } else {
        logger.error("Failed to obtain the data to render: data is not a value or reference");
        return new JTextArea("Failed to obtain the data to render: data is not a value or reference");
    }
}

From source file:components.CustomDialog.java

/** Creates the reusable dialog. */
public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) {
    super(aFrame, true);
    dd = parent;//from   w w  w.  j a v  a2 s  .co m

    magicWord = aWord.toUpperCase();
    setTitle("Quiz");

    textField = new JTextField(10);

    //Create an array of the text and components to be displayed.
    String msgString1 = "What was Dr. SEUSS's real last name?";
    String msgString2 = "(The answer is \"" + magicWord + "\".)";
    Object[] array = { msgString1, msgString2, textField };

    //Create an array specifying the number of dialog buttons
    //and their text.
    Object[] options = { btnString1, btnString2 };

    //Create the JOptionPane.
    optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options,
            options[0]);

    //Make this dialog display it.
    setContentPane(optionPane);

    //Handle window closing correctly.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            /*
             * Instead of directly closing the window,
             * we're going to change the JOptionPane's
             * value property.
             */
            optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
        }
    });

    //Ensure the text field always gets the first focus.
    addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent ce) {
            textField.requestFocusInWindow();
        }
    });

    //Register an event handler that puts the text into the option pane.
    textField.addActionListener(this);

    //Register an event handler that reacts to option pane state changes.
    optionPane.addPropertyChangeListener(this);
}

From source file:com.dragoniade.deviantart.deviation.SearchStream.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  av a  2s.  c om*/
    if (search == null) {
        throw new IllegalStateException("You must set the search type before searching.");
    }
    String searchQuery = search.getSearch().replace("%username%", user);
    String queryString = "http://www.deviantart.com/global/difi.php?c=Stream;thumbs;" + searchQuery + ","
            + offset + "," + OFFSET + "&t=xml";
    GetMethod method = new GetMethod(queryString);
    List<Deviation> results = new ArrayList<Deviation>(OFFSET);
    try {
        int sc = -1;
        do {
            sc = client.executeMethod(method);
            if (sc != 200) {
                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();

        StringBuilder stringBuilder = new StringBuilder();
        InputStream inputStream = method.getResponseBodyAsStream();
        int b;
        boolean isOpening = false;
        while ((b = inputStream.read()) > -1) {
            if (b > 127) {
                isOpening = false;
                continue;
            }
            char c = (char) b;
            if (isOpening && Character.isDigit(c)) {
                stringBuilder.append('_');
            }
            if (isOpening && c == '/') {
                stringBuilder.append(c);
                continue;
            }
            isOpening = (c == '<');
            stringBuilder.append(c);
        }

        Element responses = toolkit.parseDocument(stringBuilder.toString());
        method.releaseConnection();

        total = toolkit.getNodeAsInt(responses, "response/calls/response/content/total");
        List<?> deviations = toolkit.getMultipleNodes(responses, "response/calls/response/content/deviations");
        if (total == 0) {
            return results;
        }
        for (Object obj : deviations) {
            Element deviation = (Element) obj;

            Deviation da = new Deviation();
            da.setId(toolkit.getNodeAsLong(deviation, "id"));
            da.setArtist(toolkit.getNodeAsString(deviation, "artist"));
            da.setCategory(toolkit.getNodeAsString(deviation, "category"));
            da.setTitle(toolkit.getNodeAsString(deviation, "title"));
            da.setUrl(toolkit.getNodeAsString(deviation, "url"));
            da.setTimestamp(new Date(toolkit.getNodeAsLong(deviation, "ts") * 1000));
            da.setMature("1".equals(toolkit.getNodeAsString(deviation, "is_mature")));
            da.setCollection(collection);

            String filenameStr = toolkit.getNodeAsString(deviation, "filename");
            String imageUrl = toolkit.getNodeAsString(deviation, "image/url");

            String primaryFilename = Deviation.extractFilename(filenameStr);
            da.setDocumentDownloadUrl(DOWNLOAD_URL + da.getId() + "/");
            da.setDocumentFilename(primaryFilename);

            if (imageUrl != null) {
                String secondaryFilename = Deviation.extractFilename(imageUrl);
                da.setImageDownloadUrl(imageUrl);
                da.setImageFilename(secondaryFilename);
                da.setResolution(toolkit.getNodeAsString(deviation, "image/width") + "x"
                        + toolkit.getNodeAsString(deviation, "image/height"));
            }

            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.floreantpos.bo.actions.DataExportAction.java

@Override
public void actionPerformed(ActionEvent e) {
    Session session = null;//  ww  w  .j a  v a 2  s . com
    Transaction transaction = null;
    FileWriter fileWriter = null;
    GenericDAO dao = new GenericDAO();

    try {
        JFileChooser fileChooser = getFileChooser();
        int option = fileChooser.showSaveDialog(com.floreantpos.util.POSUtil.getBackOfficeWindow());
        if (option != JFileChooser.APPROVE_OPTION) {
            return;
        }

        File file = fileChooser.getSelectedFile();
        if (file.exists()) {
            option = JOptionPane.showConfirmDialog(com.floreantpos.util.POSUtil.getFocusedWindow(),
                    Messages.getString("DataExportAction.1") + file.getName() + "?", //$NON-NLS-1$//$NON-NLS-2$
                    Messages.getString("DataExportAction.3"), //$NON-NLS-1$
                    JOptionPane.YES_NO_OPTION);
            if (option != JOptionPane.YES_OPTION) {
                return;
            }
        }

        // fixMenuItemModifierGroups();

        JAXBContext jaxbContext = JAXBContext.newInstance(Elements.class);
        Marshaller m = jaxbContext.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

        StringWriter writer = new StringWriter();

        session = dao.createNewSession();
        transaction = session.beginTransaction();

        Elements elements = new Elements();

        //          * 2. USERS
        //          * 3. TAX
        //          * 4. MENU_CATEGORY
        //          * 5. MENU_GROUP
        //          * 6. MENU_MODIFIER
        //          * 7. MENU_MODIFIER_GROUP
        //          * 8. MENU_ITEM
        //          * 9. MENU_ITEM_SHIFT
        //          * 10. RESTAURANT
        //          * 11. USER_TYPE
        //          * 12. USER_PERMISSION
        //          * 13. SHIFT

        elements.setTaxes(TaxDAO.getInstance().findAll(session));
        elements.setMenuCategories(MenuCategoryDAO.getInstance().findAll(session));
        elements.setMenuGroups(MenuGroupDAO.getInstance().findAll(session));
        elements.setMenuModifiers(MenuModifierDAO.getInstance().findAll(session));
        elements.setMenuModifierGroups(MenuModifierGroupDAO.getInstance().findAll(session));
        elements.setMenuItems(MenuItemDAO.getInstance().findAll(session));
        elements.setMenuItemModifierGroups(MenuItemModifierGroupDAO.getInstance().findAll(session));

        //           elements.setUsers(UserDAO.getInstance().findAll(session));
        //           
        //           elements.setMenuItemShifts(MenuItemShiftDAO.getInstance().findAll(session));
        //           elements.setRestaurants(RestaurantDAO.getInstance().findAll(session));
        //           elements.setUserTypes(UserTypeDAO.getInstance().findAll(session));
        //           elements.setUserPermissions(UserPermissionDAO.getInstance().findAll(session));
        //           elements.setShifts(ShiftDAO.getInstance().findAll(session));

        m.marshal(elements, writer);

        transaction.commit();

        fileWriter = new FileWriter(file);
        fileWriter.write(writer.toString());
        fileWriter.close();

        POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(),
                Messages.getString("DataExportAction.4")); //$NON-NLS-1$

    } catch (Exception e1) {
        transaction.rollback();
        PosLog.error(getClass(), e1);
        POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), e1.getMessage());
    } finally {
        IOUtils.closeQuietly(fileWriter);
        dao.closeSession(session);
    }
}