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:us.daveread.basicquery.BasicQuery.java

/**
 * Open or create a SQL statement file./*from  w  ww.j av a  2s.c  o m*/
 */
private void openSQLFile() {
    JFileChooser fileMenu;
    FileFilter defaultFileFilter = null;
    FileFilter preferredFileFilter = null;
    File chosenSQLFile;
    int returnVal;

    chosenSQLFile = null;

    // Save current information, including SQL Statements
    saveConfig();

    // Allow user to choose/create new file for SQL Statements
    fileMenu = new JFileChooser(new File(queryFilename));

    for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) {
        if (filterDefinition.name().startsWith("QUERY")) {
            final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(),
                    filterDefinition.acceptedSuffixes());
            if (filterDefinition.isPreferredOption()) {
                preferredFileFilter = fileFilter;
            }
            fileMenu.addChoosableFileFilter(fileFilter);
            if (filterDefinition.description().equals(latestChosenQueryFileFilterDescription)) {
                defaultFileFilter = fileFilter;
            }
        }
    }

    if (defaultFileFilter != null) {
        fileMenu.setFileFilter(defaultFileFilter);
    } else if (latestChosenQueryFileFilterDescription != null
            && latestChosenQueryFileFilterDescription.startsWith("All")) {
        fileMenu.setFileFilter(fileMenu.getAcceptAllFileFilter());
    } else if (preferredFileFilter != null) {
        fileMenu.setFileFilter(preferredFileFilter);
    }

    fileMenu.setSelectedFile(new File(queryFilename));
    fileMenu.setDialogTitle(Resources.getString("dlgSQLFileTitle"));
    fileMenu.setDialogType(JFileChooser.OPEN_DIALOG);
    fileMenu.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileMenu.setMultiSelectionEnabled(false);

    if (fileMenu.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        chosenSQLFile = fileMenu.getSelectedFile();

        // Adjust file suffix if necessary
        final FileFilter fileFilter = fileMenu.getFileFilter();
        if (fileFilter != null && fileFilter instanceof SuffixFileFilter
                && !fileMenu.getFileFilter().accept(chosenSQLFile)) {
            chosenSQLFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(chosenSQLFile);
        }

        if (!chosenSQLFile.exists()) {
            returnVal = JOptionPane.showConfirmDialog(this,
                    Resources.getString("dlgNewSQLFileText", chosenSQLFile.getName()),
                    Resources.getString("dlgNewSQLFileTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            if (returnVal == JOptionPane.NO_OPTION) {
                querySelection.removeAllItems();
                queryText.setText("");
                QueryHistory.getInstance().clearAllQueries();

                // Update GUI
                setPrevNextIndication();
            } else if (returnVal == JOptionPane.CANCEL_OPTION) {
                chosenSQLFile = null;
            }
        } else {
            setQueryFilename(chosenSQLFile.getAbsolutePath());
            querySelection.removeAllItems();
            queryText.setText("");
            loadCombo(querySelection, queryFilename);
            QueryHistory.getInstance().clearAllQueries();

            // Update GUI
            setPrevNextIndication();
        }
    }

    try {
        latestChosenQueryFileFilterDescription = fileMenu.getFileFilter().getDescription();
    } catch (Throwable throwable) {
        LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable);
    }

    if (chosenSQLFile != null) {
        setQueryFilename(chosenSQLFile.getAbsolutePath());
        saveConfig();
    }
}

From source file:VASSAL.build.GameModule.java

/**
 * Prompt user to save open game and modules/extensions being edited
 * @return true if shutDown should proceed, i.e. user did not cancel
 *//*from w  ww. j  a  v  a  2 s.  c  om*/
public boolean shutDown() {
    boolean cancelled;
    getGameState().setup(false);
    cancelled = getGameState().isGameStarted();

    if (!cancelled) {
        if (getDataArchive() instanceof ArchiveWriter && !buildString().equals(lastSavedConfiguration)) {
            switch (JOptionPane.showConfirmDialog(frame, Resources.getString("GameModule.save_module"), //$NON-NLS-1$
                    "", JOptionPane.YES_NO_CANCEL_OPTION)) { //$NON-NLS-1$
            case JOptionPane.YES_OPTION:
                save();
                break;
            case JOptionPane.CANCEL_OPTION:
                cancelled = true;
            }
        }
        for (ModuleExtension ext : getComponentsOf(ModuleExtension.class)) {
            cancelled = !ext.confirmExit();
        }
    }

    if (!cancelled) {
        Prefs p = null;

        // write and close module prefs
        try {
            p = getPrefs();
            p.write();
            p.close();
        } catch (IOException e) {
            WriteErrorDialog.error(e, p.getFile());
        } finally {
            IOUtils.closeQuietly(p);
        }

        // write and close global prefs
        try {
            p = getGlobalPrefs();
            p.write();
            p.close();
        } catch (IOException e) {
            WriteErrorDialog.error(e, p.getFile());
        } finally {
            IOUtils.closeQuietly(p);
        }

        // close the module
        try {
            archive.close();
        } catch (IOException e) {
            ReadErrorDialog.error(e, archive.getName());
        }

        log.info("Exiting");
    }

    return !cancelled;
}

From source file:volker.streaming.music.gui.NowPlayingFrame.java

public NowPlayingFrame(final File cfgFile) {
    this.cfgFile = cfgFile;

    frame = this;
    setTitle("NowPlaying - LastFM integration");
    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

    lastfmConfig = LastFmConfig.fromFile(cfgFile);
    config = Config.fromFile(cfgFile);/*w w w.  j a  va 2  s .c  om*/

    configPanel = new ConfigPanel(this, lastfmConfig);

    previewTrack = new Track("Beyonce", "Halo", "I Am... Sasha Fierce");
    formatter = new Formatter(Formatter.DEFAULT_EXCEPTIONS);
    formatPanel = new FormatPanel(this, config, formatter, previewTrack);

    apiPanel = new ApiPanel(config, lastfmConfig, formatter);

    saveButton = new JButton("Save configuration");
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveConfig();
        }
    });
    savePanel = new JPanel(new GridBagLayout());
    savePanel.add(saveButton);

    layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);

    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(configPanel)
                    .addComponent(formatPanel).addComponent(apiPanel).addComponent(savePanel))
            .addContainerGap());

    layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap().addComponent(configPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(formatPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(apiPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(savePanel).addContainerGap());

    pack();

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            LastFmConfig storedLfm = LastFmConfig.fromFile(cfgFile);
            Config stored = Config.fromFile(cfgFile);
            if (!stored.contentEquals(config) || !storedLfm.contentEquals(lastfmConfig)) {
                int opt = JOptionPane.showConfirmDialog(frame,
                        "You have unsaved configuration changes.\nDo you want to save them?", "Unsaved changes",
                        JOptionPane.YES_NO_CANCEL_OPTION);
                switch (opt) {
                case JOptionPane.YES_OPTION:
                    saveConfig();
                case JOptionPane.NO_OPTION:
                    System.exit(0);
                    break;
                case JOptionPane.CANCEL_OPTION:
                    break;
                default:
                    LOG.error("Unknown response to closing window");
                }
            } else {
                System.exit(0);
            }
        }
    });
}

From source file:wjhk.jupload2.policies.DefaultUploadPolicy.java

/**
 * If debug is off, the log window may not be visible. We switch the debug
 * to on, to be sure that some information will be displayed to the user. <BR>
 * If debug is -1, the log window remains hidden.
 * /*from w w  w.  j a  v  a 2 s.c om*/
 * @see wjhk.jupload2.policies.UploadPolicy#displayErr(java.lang.String,
 *      java.lang.Exception, int)
 */
public int displayErr(String errorText, Exception exception, int optionTypes) {
    // Then, we display it to the user.
    String alertMsg = errorText;
    // Then, the message body can be completed by the exception message.
    if (exception != null && (errorText == null || errorText.equals(""))) {
        // Ok, we have an exception.
        if (exception.getCause() != null) {
            alertMsg = exception.getCause().getMessage();
        } else {
            alertMsg = exception.getMessage();
        }
    }

    // The message displayed depend on the debug level:
    if (getDebugLevel() >= 30 && exception != null) {
        alertMsg = exception.getClass().getName() + ": " + alertMsg;
    }

    // Display the message to the user. The kind of alert box depends on the
    // given options:
    int buttonClicked = 0;
    switch (optionTypes) {
    case -1:
        // Standard message box.
        alertStr(alertMsg);
        buttonClicked = JOptionPane.OK_OPTION;
        break;
    case JOptionPane.OK_CANCEL_OPTION:
    case JOptionPane.YES_NO_CANCEL_OPTION:
    case JOptionPane.YES_NO_OPTION:
        buttonClicked = confirmDialogStr(alertMsg, optionTypes);
        break;
    default:
        // This is a problem. Let's display it to the user as a standard
        // alert box.
        alertStr(alertMsg);
        buttonClicked = JOptionPane.OK_OPTION;
        // Then, we log this new problem.
        String msg = "Unknown optionType in displayErr(String, Exception, int)";
        alertStr(msg);
        logErr(msg, null);
    }

    // First, we log the error.
    logErr(errorText, exception);

    return buttonClicked;
}