Example usage for javax.swing JOptionPane YES_NO_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_CANCEL_OPTION

Introduction

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

Prototype

int YES_NO_CANCEL_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:processing.app.Editor.java

/**
 * Check if the sketch is modified and ask user to save changes.
 * @return false if canceling the close/quit operation
 *///from w w  w  .jav a2s .c o  m
protected boolean checkModified() {
    if (!sketch.isModified())
        return true;

    // As of Processing 1.0.10, this always happens immediately.
    // http://dev.processing.org/bugs/show_bug.cgi?id=1456

    toFront();

    String prompt = I18n.format(_("Save changes to \"{0}\"?  "), sketch.getName());

    if (!OSUtils.isMacOS()) {
        int result = JOptionPane.showConfirmDialog(this, prompt, _("Close"), JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        switch (result) {
        case JOptionPane.YES_OPTION:
            return handleSave(true);
        case JOptionPane.NO_OPTION:
            return true; // ok to continue
        case JOptionPane.CANCEL_OPTION:
        case JOptionPane.CLOSED_OPTION: // Escape key pressed
            return false;
        default:
            throw new IllegalStateException();
        }

    } else {
        // This code is disabled unless Java 1.5 is being used on Mac OS X
        // because of a Java bug that prevents the initial value of the
        // dialog from being set properly (at least on my MacBook Pro).
        // The bug causes the "Don't Save" option to be the highlighted,
        // blinking, default. This sucks. But I'll tell you what doesn't
        // suck--workarounds for the Mac and Apple's snobby attitude about it!
        // I think it's nifty that they treat their developers like dirt.

        // Pane formatting adapted from the quaqua guide
        // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
        JOptionPane pane = new JOptionPane(_("<html> " + "<head> <style type=\"text/css\">"
                + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"
                + "</style> </head>" + "<b>Do you want to save changes to this sketch<BR>"
                + " before closing?</b>" + "<p>If you don't save, your changes will be lost."),
                JOptionPane.QUESTION_MESSAGE);

        String[] options = new String[] { _("Save"), _("Cancel"), _("Don't Save") };
        pane.setOptions(options);

        // highlight the safest option ala apple hig
        pane.setInitialValue(options[0]);

        // on macosx, setting the destructive property places this option
        // away from the others at the lefthand side
        pane.putClientProperty("Quaqua.OptionPane.destructiveOption", new Integer(2));

        JDialog dialog = pane.createDialog(this, null);
        dialog.setVisible(true);

        Object result = pane.getValue();
        if (result == options[0]) { // save (and close/quit)
            return handleSave(true);

        } else if (result == options[2]) { // don't save (still close/quit)
            return true;

        } else { // cancel?
            return false;
        }
    }
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

    File toDelete = new File("pluginClasses");
    String[] deleteArray = toDelete.list();
    if (deleteArray != null) {
        for (String fileName : deleteArray) {
            File f = new File("pluginClasses/" + fileName);
            f.delete();//from w w w  .  j ava 2  s  .  c  o  m
        }
    }
    if (clientCore.isAdmin() && AdminRefs.getInstance().unsavedSettings()) {
        Object[] opt = { "Save", "Discard", "Cancel" };

        String message = "There are unsaved Server Settings.\nDo you want to save them?";
        int op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

        if (op == 0) {
            AdminRefs.getInstance().saveSettings();
        }

        if (op == 2) {
            return;
        }
    }

    if (ClientOptions.getInstance().unsavedSettings()) {
        Object[] opt = { "Save", "Discard", "Cancel" };

        String message = "There are unsaved Client Settings.\nDo you want to save them?";
        int op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

        if (op == 0) {
            ClientOptions.getInstance().saveSettings();
        }

        if (op == 2) {
            return;
        }
    }

    QueryHistorySupport.getInstance().saveQueryHistory();

    if (clientCore.isAdmin()) {
        AdminRefs.getInstance().shutdownServer();
    }

    System.exit(0);
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

@SuppressWarnings("empty-statement")
private void jMenuItemShutdownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemShutdownActionPerformed
    Object[] opt = { "Yes", "No" };

    String message = "Are you shure you want to shutdown the server?";
    int op = JOptionPane.showOptionDialog(this, message, "Shut down Server", JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, opt, opt[1]);

    if (op == 0) {
        //Logout from GUI Server
        if (clientCore.isAdmin()) {

            if (AdminRefs.getInstance().unsavedSettings()) {
                Object[] opt1 = { "Save", "Discard" };

                message = "There are unsaved Server Settings.\nDo you want to save them?";
                op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt1, opt1[0]);

                if (op == 0) {
                    AdminRefs.getInstance().saveSettings();
                }/*from   w  w  w.ja v  a  2s  .  c  o m*/

            }
        }

        if (clientCore.isUser()) {
            if (ClientOptions.getInstance().unsavedSettings()) {
                Object[] opt2 = { "Save", "Discard" };

                message = "There are unsaved Client Settings.\nDo you want to save them?";
                op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt2, opt2[0]);

                if (op == 0) {
                    ClientOptions.getInstance().saveSettings();
                }
            }
        }

        QueryHistorySupport.getInstance().saveQueryHistory();

        if (clientCore.isAdmin()) {
            AdminRefs.getInstance().shutdownServer();
        }

        System.exit(0);
    }
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
    //Logout from GUI Server
    try {/*from w w  w .  j av a  2  s  .  co  m*/
        if (clientCore.isAdmin() && AdminRefs.getInstance().unsavedSettings()) {
            Object[] opt = { "Save", "Discard", "Cancel" };

            String message = "There are unsaved Server Settings.\nDo you want to save them?";
            int op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings",
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

            if (op == 0) {
                AdminRefs.getInstance().saveSettings();
            }

            if (op == 2) {
                return;
            }
        }

        if (clientCore.isUser() && ClientOptions.getInstance().unsavedSettings()) {
            Object[] opt = { "Save", "Discard", "Cancel" };

            String message = "There are unsaved Client Settings.\nDo you want to save them?";
            int op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings",
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

            if (op == 0) {
                ClientOptions.getInstance().saveSettings();
            }

            if (op == 2) {
                return;
            }
        }

        if (clientCore.isAdmin()) {
            AdminRefs.getInstance().logout();
        }

        searchTree.unexportSearchSignal();
        clientCore.getUser().logout();

    } catch (RemoteException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
    File toDelete = new File("pluginClasses");
    String[] deleteArray = toDelete.list();
    if (deleteArray != null) {
        for (String fileName : deleteArray) {
            File f = new File("pluginClasses/" + fileName);
            f.delete();
        }
    }
    QueryHistorySupport.getInstance().saveQueryHistory();

    if (Main.isFixedClient()) {
        clientCore.stopKeepAlives();
        this.dispose();

        TrayIconCreator.getInstance().distroyTrayIcon();
    } else {
        System.exit(0);
    }
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
    File toDelete = new File("pluginClasses");
    String[] deleteArray = toDelete.list();
    if (deleteArray != null) {
        for (String fileName : deleteArray) {
            File f = new File("pluginClasses/" + fileName);
            f.delete();//from  w  w  w  .  j  a v a2  s .  co m
        }
    }
    if (clientCore.isAdmin() && AdminRefs.getInstance().unsavedSettings()) {
        Object[] opt = { "Save", "Discard", "Cancel" };

        String message = "There are unsaved Server Settings.\nDo you want to save them?";
        int op = JOptionPane.showOptionDialog(this, message, "Unsaved Server Settings",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

        if (op == 0) {
            AdminRefs.getInstance().saveSettings();
        }

        if (op == 2) {
            return;
        }
    }

    if (ClientOptions.getInstance().unsavedSettings()) {
        Object[] opt = { "Save", "Discard", "Cancel" };

        String message = "There are unsaved Client Settings.\nDo you want to save them?";
        int op = JOptionPane.showOptionDialog(this, message, "Unsaved Client Settings",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opt, opt[2]);

        if (op == 0) {
            ClientOptions.getInstance().saveSettings();
        }

        if (op == 2) {
            return;
        }
    }

    QueryHistorySupport.getInstance().saveQueryHistory();

    if (clientCore.isAdmin()) {
        AdminRefs.getInstance().shutdownServer();
    }

    System.exit(0);
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jTreeResultsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTreeResultsKeyReleased
    if (KeyEvent.VK_DELETE == evt.getKeyCode() && clientCore.isAdmin()) {
        ArrayList<String> files = getSelectedLocalFiles();

        if (files != null && !files.isEmpty()) {
            try {
                Object[] opt = { "Remove and Delete", "Remove", "Cancel" };
                String message = "Are you sure you want to remove these files from Index Engine?";

                int op = JOptionPane.showOptionDialog(this, message, "Remove Files",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, opt, opt[2]);

                if (op == 0) {
                    AdminRefs.getInstance().getIndexOptions().removeFilesFromIndexer(files, true);
                }/* ww  w.  jav  a2 s . co  m*/
                if (op == 1) {
                    AdminRefs.getInstance().getIndexOptions().removeFilesFromIndexer(files, false);
                }
            } catch (RemoteException ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

public static boolean saveYesNoCancel(String titleMessage) {
    return saveYesNoCancel(titleMessage, JOptionPane.YES_NO_CANCEL_OPTION);
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

public static boolean saveYesNoCancel() {
    QueryBuilderPanel builderPanel = Globals.getMainFrame().getQueryBuilderPanel();
    if (!builderPanel.isCleaned()) {
        String message;/*from w ww  .j a v  a 2 s  . com*/
        if (Globals.isChartLoaded()) {
            if (!chartModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.chart.save");
        } else if (Globals.isReportLoaded()) {
            if (!reportModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.report.save");
        } else {
            if (!queryModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.query.save");
        }

        int option = JOptionPane.showConfirmDialog(Globals.getMainFrame(), message,
                I18NSupport.getString("exit"), JOptionPane.YES_NO_CANCEL_OPTION);
        if ((option == JOptionPane.CANCEL_OPTION) || (option == JOptionPane.CLOSED_OPTION)) {
            return false;
        } else if (option == JOptionPane.YES_OPTION) {
            if (Globals.isChartLoaded()) {
                SaveChartAction action = new SaveChartAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            } else if (Globals.isReportLoaded()) {
                SaveReportAction action = new SaveReportAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            } else {
                SaveQueryAction action = new SaveQueryAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:savant.view.swing.BookmarkSheet.java

public BookmarkSheet(Container c) {

    // set the layout of the data sheet
    c.setLayout(new BorderLayout());
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    /**//from   ww  w.j a va  2 s .c  o  m
     * Create a toolbar. 
     */
    JMenuBar toolbar = new JMenuBar();
    toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
    c.add(toolbar, BorderLayout.NORTH);

    JButton previousButton = new JButton();
    previousButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UP));
    previousButton.setToolTipText("Go to previous bookmark [ Ctrl+( ]");
    previousButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    previousButton.putClientProperty("JButton.segmentPosition", "first");
    previousButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToPreviousBookmark();
        }

    });
    toolbar.add(previousButton);

    JButton nextButton = new JButton();
    nextButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.DOWN));
    nextButton.setToolTipText("Go to next bookmark [ Ctrl+) ]");
    nextButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    nextButton.putClientProperty("JButton.segmentPosition", "last");
    nextButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToNextBookmark();
        }

    });
    toolbar.add(nextButton);

    JButton goButton = new JButton("Go");
    goButton.setToolTipText("Go to selected bookmark");
    goButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    goButton.putClientProperty("JButton.segmentPosition", "only");
    goButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToSelectedBookmark();
        }

    });
    toolbar.add(goButton);

    toolbar.add(Box.createGlue());

    addButton = new JButton();
    addButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_ADD));
    addButton.setToolTipText("Add bookmark for current range");
    addButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    addButton.putClientProperty("JButton.segmentPosition", "first");
    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            BookmarkController fc = BookmarkController.getInstance();
            fc.addCurrentRangeToBookmarks();
        }
    });
    toolbar.add(addButton);

    JButton deleteButton = new JButton();
    deleteButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_RM));
    deleteButton.setToolTipText("Delete selected bookmarks");
    deleteButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    deleteButton.putClientProperty("JButton.segmentPosition", "last");
    deleteButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            BookmarkController fc = BookmarkController.getInstance();
            int[] selectedRows = table.getSelectedRows();
            Arrays.sort(selectedRows);
            boolean delete = false;

            if (selectedRows.length > 0 && confirmDelete) {
                Object[] options = { "Yes", "No", "Yes, don't ask again" };
                JLabel message = new JLabel(
                        "Are you sure you want to delete " + selectedRows.length + " item(s)?");
                message.setPreferredSize(new Dimension(300, 20));
                int confirmDeleteDialog = JOptionPane.showOptionDialog(DialogUtils.getMainWindow(), message,
                        "Confirm Delete", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                        options, options[0]);

                if (confirmDeleteDialog == 0) {
                    delete = true;
                } else if (confirmDeleteDialog == 2) {
                    delete = true;
                    confirmDelete = false;
                }
            } else if (selectedRows.length > 0 && !confirmDelete) {
                delete = true;
            }

            if (delete) {
                for (int i = selectedRows.length - 1; i >= 0; i--) {
                    fc.removeBookmark(selectedRows[i]);
                }
            }
        }
    });
    toolbar.add(deleteButton);

    toolbar.add(Box.createGlue());

    JButton loadButton = new JButton();
    loadButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.OPEN));
    loadButton.setToolTipText("Load bookmarks from file");
    loadButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    loadButton.putClientProperty("JButton.segmentPosition", "first");
    loadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            loadBookmarks(table);
        }
    });
    toolbar.add(loadButton);

    JButton saveButton = new JButton();
    saveButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SAVE));
    saveButton.setToolTipText("Save bookmarks to file");
    saveButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    saveButton.putClientProperty("JButton.segmentPosition", "last");
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveBookmarks(table);
        }
    });
    toolbar.add(saveButton);

    // create a table (the most important component)
    table = new JTable(new BookmarksTableModel());
    table.setAutoCreateRowSorter(true);
    table.setFillsViewportHeight(true);
    table.setShowGrid(true);
    table.setGridColor(Color.gray);
    //table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

    // add the table and its header to the subpanel
    c.add(table.getTableHeader());

    add(table);

    final JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    sp.setWheelScrollingEnabled(false);
    sp.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            sp.getVerticalScrollBar().setValue(sp.getVerticalScrollBar().getValue() + e.getUnitsToScroll() * 2);
        }
    });

    c.add(sp);

    // add glue to fill the remaining space
    add(Box.createGlue());
}

From source file:savant.view.swing.Savant.java

private void initBookmarksPanel() {

    DockableFrame df = DockableFrameFactory.createFrame("Bookmarks", DockContext.STATE_HIDDEN,
            DockContext.DOCK_SIDE_EAST);
    df.setAvailableButtons(//from  w  ww  . j av  a  2 s . c  o  m
            DockableFrame.BUTTON_AUTOHIDE | DockableFrame.BUTTON_FLOATING | DockableFrame.BUTTON_MAXIMIZE);
    auxDockingManager.addFrame(df);
    MiscUtils.setFrameVisibility("Bookmarks", false, auxDockingManager);

    df.getContentPane().setLayout(new BorderLayout());

    //JPanel tablePanel = createTabPanel(jtp, "Bookmarks");
    favoriteSheet = new BookmarkSheet(df.getContentPane());
    BookmarkController bc = BookmarkController.getInstance();
    bc.addListener(favoriteSheet);
    bc.addListener(new Listener<BookmarksChangedEvent>() {
        @Override
        public void handleEvent(BookmarksChangedEvent event) {
            if (showBookmarksChangedDialog) {
                //Custom button text
                Object[] options = { "OK", "Don't show again" };
                int n = JOptionPane.showOptionDialog(Savant.this,
                        event.isAdded()
                                ? "Bookmark added at " + event.getBookmark().getReference() + ":"
                                        + event.getBookmark().getRange()
                                : "Bookmark removed at " + event.getBookmark().getRange(),
                        "Bookmarks changed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE,
                        null, options, options[0]);

                if (n == 1) {
                    showBookmarksChangedDialog = false;
                }
            }
        }
    });
}