Example usage for javax.swing JOptionPane YES_OPTION

List of usage examples for javax.swing JOptionPane YES_OPTION

Introduction

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

Prototype

int YES_OPTION

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

Click Source Link

Document

Return value from class method if YES is chosen.

Usage

From source file:com.floreantpos.bo.actions.DataExportAction.java

@Override
public void actionPerformed(ActionEvent e) {
    Session session = null;/* w  w w .j ava 2 s .c  o m*/
    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);
    }
}

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

/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 *///from  w ww.  j  av a 2 s .com
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:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java

public void openPDF(boolean isInternalR, File pdf, Component comp) throws FileNotFoundException {
    if (isInternalR) {
        try {//from w  ww .j a v a2s . co  m
            Desktop.getDesktop().open(pdf);
        } catch (Exception ex) {
            log.info(ex.getMessage());
            String msg = "Unable to open PDF format through java. Would you like to save "
                    + pdf.getAbsoluteFile() + " in a new location?";
            JOptionPane pane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.YES_NO_CANCEL_OPTION, null, null, JOptionPane.YES_OPTION);
            JDialog dialog = pane.createDialog(comp, "Report PDF");
            dialog.setVisible(true);
            Object choice = pane.getValue();
            if (choice.equals(JOptionPane.YES_OPTION)) {
                jfcFiles = new JFileChooser();
                jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                int state = jfcFiles.showSaveDialog(comp);

                if (state == JFileChooser.APPROVE_OPTION) {
                    File file = checkFileExtension(".pdf");
                    log.info("Opening: " + file.getName() + ".");
                    if (file != null)
                        pdf.renameTo(file);
                } else {
                    log.info("Open command cancelled by user.");
                }
            }
        }
    }
}

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

public static boolean showConfirmMessage(Component parentContainer, String messageConfirm) {
    ProcessMsgBlocker.instance().removeMessage();
    int result = JOptionPane.showConfirmDialog(parentContainer, messageConfirm, GENERIC_MESSAGE_TITLE,
            JOptionPane.YES_NO_OPTION);
    return (result == JOptionPane.YES_OPTION);
}

From source file:javaapplication3.SolidscapeDialog.java

public void SolidscapeDialogStart() {
    instance = new InstanceCall();
    setTitle("Add Information about" + new File(BPath.getText()).getName());
    hideErrorFields();//from  w w  w  .  j a v  a2s .c o m
    Date date = Calendar.getInstance().getTime();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    this.dateRunTxt.setText(sdf.format(date));
    this.setLocationRelativeTo(null);
    //search database for buildName
    //File BPathfile = new File(BPath.getText().replace("\\", "\\\\"));
    setVisible(true);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent we) {
            String ObjButtons[] = { "Yes", "No" };
            int PromptResult = JOptionPane.showOptionDialog(null, "Save as an Open Build?", "Save",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons, ObjButtons[1]);
            if (PromptResult == JOptionPane.YES_OPTION) {
                gatherScrapThenExit();
                PrinterBuild.selectAllFiles("Solidscape");
                dispose();
            } else {
                ResultSet r = SolidscapeMain.dba.searchPendingByBuildName(new File(BPath.getText()).getName());
                try {
                    while (r.next()) {
                        SolidscapeMain.dba.updatePendingJobsBuildName(r.getString("buildName"),
                                r.getString("fileName"));
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(SolidscapeDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                ResultSet s = SolidscapeMain.dba
                        .searchSolidscapeByBuildName(new File(BPath.getText()).getName());
                try {
                    while (s.next()) {
                        SolidscapeMain.dba.deleteByBuildName(s.getString("buildName"), "solidscape");
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(SolidscapeDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
                dispose();
            }
        }
    });
}

From source file:com.qspin.qtaste.testapi.impl.generic.UtilityImpl.java

@Override
public boolean getUserConfirmation(final String title, final String message) throws QTasteException {
    final MutableBoolean confirmed = new MutableBoolean();
    try {/*from  www.  j  a  va 2 s. co  m*/
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                int result = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
                confirmed.setValue(result == JOptionPane.YES_OPTION);
            }
        });
    } catch (Exception e) {
        throw new QTasteException("Error while showing user confirmation dialog", e);
    }
    return confirmed.booleanValue();
}

From source file:SwingThreadingWait.java

public void actionPerformed(ActionEvent e) {
    start = System.currentTimeMillis();
    new Thread(new Runnable() {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }//  w  w  w.jav  a2s  . c o  m

                final int elapsed = (int) ((System.currentTimeMillis() - start) / 1000);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        counter.setText("Time elapsed: " + elapsed + "s");
                    }
                });

                if (elapsed == 4) {
                    try {
                        final int[] answer = new int[1];
                        SwingUtilities.invokeAndWait(new Runnable() {
                            public void run() {
                                answer[0] = JOptionPane.showConfirmDialog(SwingThreadingWait.this,
                                        "Abort long operation?", "Abort?", JOptionPane.YES_NO_OPTION);
                            }
                        });
                        if (answer[0] == JOptionPane.YES_OPTION) {
                            return;
                        }
                    } catch (InterruptedException e1) {
                    } catch (InvocationTargetException e1) {
                    }
                }
            }
        }
    }).start();
}

From source file:com.tiempometa.muestradatos.JReadTags.java

private void deleteAllButtonActionPerformed(ActionEvent e) {
    int response = JOptionPane.showConfirmDialog(this,
            "Se borrarn todos los tags de la base de datos.\nEsta operacin no se puede deshacer.\nContinuar?",
            "Borrar todos los tags", JOptionPane.WARNING_MESSAGE);
    if (response == JOptionPane.YES_OPTION) {
        try {//www. j  a  v  a  2  s. c o m
            rfidDao.deleteAll();
            tagTableModel.setData(new ArrayList<Rfid>());
            tagTableModel.fireTableDataChanged();
        } catch (SQLException e1) {
            JOptionPane.showMessageDialog(this, "No se pudieron borrar todos los tags. " + e1.getMessage(),
                    "Error borrando tags", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.mirth.connect.client.ui.ExportChannelLibrariesDialog.java

private void initComponents(Channel channel) {
    label1 = new JLabel("   The following code template libraries are linked to this channel:");
    label1.setIcon(UIManager.getIcon("OptionPane.questionIcon"));

    librariesTextPane = new JTextPane();
    librariesTextPane.setContentType("text/html");
    HTMLEditorKit editorKit = new HTMLEditorKit();
    StyleSheet styleSheet = editorKit.getStyleSheet();
    styleSheet.addRule(".export-channel-libraries-dialog {font-family:\"Tahoma\";font-size:11;text-align:top}");
    librariesTextPane.setEditorKit(editorKit);
    librariesTextPane.setEditable(false);
    librariesTextPane.setBackground(getBackground());
    librariesTextPane.setBorder(null);/*from   www. ja v  a2s.c  om*/

    StringBuilder librariesText = new StringBuilder("<html><ul class=\"export-channel-libraries-dialog\">");
    for (CodeTemplateLibrary library : PlatformUI.MIRTH_FRAME.codeTemplatePanel.getCachedCodeTemplateLibraries()
            .values()) {
        if (library.getEnabledChannelIds().contains(channel.getId()) || (library.isIncludeNewChannels()
                && !library.getDisabledChannelIds().contains(channel.getId()))) {
            librariesText.append("<li>").append(StringEscapeUtils.escapeHtml4(library.getName()))
                    .append("</li>");
        }
    }
    librariesText.append("</ul></html>");
    librariesTextPane.setText(librariesText.toString());
    librariesTextPane.setCaretPosition(0);

    librariesScrollPane = new JScrollPane(librariesTextPane);

    label2 = new JLabel("Do you wish to include these libraries in the channel export?");

    alwaysChooseCheckBox = new JCheckBox(
            "Always choose this option by default in the future (may be changed in the Administrator settings)");

    yesButton = new JButton("Yes");
    yesButton.setMnemonic('Y');
    yesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            result = JOptionPane.YES_OPTION;
            if (alwaysChooseCheckBox.isSelected()) {
                Preferences.userNodeForPackage(Mirth.class).putBoolean("exportChannelCodeTemplateLibraries",
                        true);
            }
            dispose();
        }
    });

    noButton = new JButton("No");
    noButton.setMnemonic('N');
    noButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            result = JOptionPane.NO_OPTION;
            if (alwaysChooseCheckBox.isSelected()) {
                Preferences.userNodeForPackage(Mirth.class).putBoolean("exportChannelCodeTemplateLibraries",
                        false);
            }
            dispose();
        }
    });

    cancelButton = new JButton("Cancel");
    cancelButton.setMnemonic('C');
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            result = JOptionPane.CANCEL_OPTION;
            dispose();
        }
    });
}

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 {//  w  w w  .  j  a  v  a  2  s .co m
        return false;
    }
}