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:com.ejie.uda.jsonI18nEditor.Editor.java

public boolean closeCurrentSession() {
    if (isDirty()) {
        int result = JOptionPane.showConfirmDialog(this, MessageBundle.get("dialogs.save.text"),
                MessageBundle.get("dialogs.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            saveResources();/*from  www.  jav a2  s.  c  o  m*/
        }
        return result != JOptionPane.CANCEL_OPTION;
    }
    return true;
}

From source file:lu.fisch.moenagade.model.Project.java

public boolean askToSave(boolean forceSave) {
    try {/* w  w w.ja  v a2 s . co  m*/
        if ((!isEmpty() && isChanged()) || forceSave) {
            int answ = JOptionPane.showConfirmDialog(frame, "Do you want to save the current project?",
                    "Save project?", JOptionPane.YES_NO_CANCEL_OPTION);
            if (answ == JOptionPane.YES_OPTION) {
                if (directoryName == null)
                    return saveWithAskingLocation();
                else
                    return save();
            } else if (answ == JOptionPane.NO_OPTION) {
                return !forceSave;
            } else
                return false;
        }
        return true;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(frame, "A terrible error occured!\n" + e.getMessage() + "\n", "Error",
                JOptionPane.ERROR_MESSAGE, Moenagade.IMG_ERROR);
        return false;
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Prompt the user with yes/no/cancel. Yes exits and saves, no exits
 * without/*from w w  w.  j  av  a 2 s.c  om*/
 * saving and cancel doesn't quit.
 */
/* package */void quit() {
    if (validateData()) {

        final int state = JOptionPane.showConfirmDialog(SubjectiveFrame.this,
                "Save data?  Data will be saved in same file as it was read from.", "Exit",
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (JOptionPane.YES_OPTION == state) {
            try {
                save();
                setVisible(false);
            } catch (final IOException ioe) {
                JOptionPane.showMessageDialog(null, "Error writing to data file: " + ioe.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
            }

        } else if (JOptionPane.NO_OPTION == state) {
            setVisible(false);
        }
    }
}

From source file:org.fhaes.jsea.JSEAFrame.java

private void launchLagMap() {

    Object[] options = { "Yes", "No", "Cancel" };
    int n = JOptionPane.showOptionDialog(this,
            "LagMap is an interactive web application written by Wendy Gross and run within your web browser.\nWould you like to continue?",
            "Lauch LagMap", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
            options[2]);/*from  w w  w .j a  v  a 2s. c  o m*/

    if (n == JOptionPane.YES_OPTION)
        Platform.browseWebpage(RemoteHelp.LAUNCH_LAG_MAP, this);

}

From source file:cl.almejo.vsim.gui.SimWindow.java

private int askSaveNow() {
    return JOptionPane.showConfirmDialog(this, Messages.t("file.save.now.message"),
            Messages.t("file.save.now.title"), JOptionPane.YES_NO_CANCEL_OPTION);
}

From source file:jeplus.gui.EPlusEditorPanel.java

@Override
public void closeTextPanel() {
    // Confirm save before open another file
    if (this.isContentChanged()) {
        int ans = JOptionPane.showConfirmDialog(this,
                "The contents of " + CurrentFileName + " has been modified. \nDo you want to save the changes?",
                "Save to file?", JOptionPane.YES_NO_CANCEL_OPTION);
        if (ans == JOptionPane.CANCEL_OPTION) {
            return;
        } else if (ans == JOptionPane.YES_OPTION) {
            this.cmdSaveActionPerformed(null);
        }// w w  w . j  a  v  a2  s.  c  om
    }
    if (ContainerComponent instanceof Frame) {
        ((Frame) ContainerComponent).dispose();
    } else if (ContainerComponent instanceof Dialog) {
        ((Dialog) ContainerComponent).dispose();
    } else if (ContainerComponent instanceof JTabbedPane && TabId > 0) {
        //((JTabbedPane)ContainerComponent).remove(this.TabId);
        ((JTabbedPane) ContainerComponent).remove(this);
        TabId = 0;
    }
}

From source file:net.sf.firemox.DeckBuilder.java

/**
 * check if the current deck has been modified since it has been saved. If the
 * current deck has been modified, we ask to the user if he want to save it
 * before loading another.// w  ww . j  a v  a 2 s .c o  m
 * 
 * @return true if the user has chosen to save the deck before continuing and
 *         if the save has success. False otherwise
 */
private boolean verifyModification() {
    if (!modifiedSinceSave) {
        // no modification since the last save
        return true;
    }

    // ask to the user if we save the current deck before loading another
    Object[] options = { "Ok", "No", "Cancel" };
    switch (JOptionPane.showOptionDialog(form,
            "Current deck has been modified, save it before loading another?", "Save changes",
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, null)) {
    case 0:
        // YES part
        return saveCurrentDeck();
    case 1:
        // NO part
        return true;
    default:
        // CANCEL part
        return false;
    }
}

From source file:cl.almejo.vsim.gui.SimWindow.java

private int askSaveBeforeQuit() {
    return JOptionPane.showConfirmDialog(this, Messages.t("action.save.before.quit.message"),
            Messages.t("action.save.before.quit.title"), JOptionPane.YES_NO_CANCEL_OPTION);
}

From source file:org.fhaes.fhsamplesize.view.FHSampleSize.java

/**
 * Open a JFileChooser and return the file that the user specified for saving. Takes a parameter that specifies the type of file. Either
 * TAB or PNG.//from w ww . j  a va 2 s. co m
 * 
 * @return
 */
private File getFileFromSaveDialog(String fileTypeToSave) {

    String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null);
    JFileChooser fc = new JFileChooser(lastVisitedFolder);
    File outputFile;

    if (fileTypeToSave == "TAB") {
        TABFilter filterTAB = new TABFilter();
        fc.addChoosableFileFilter(filterTAB);
        fc.setFileFilter(filterTAB);
        fc.setDialogTitle("Export table as text file...");

    } else if (fileTypeToSave == "PDF") {
        PDFFilter filterPDF = new PDFFilter();
        fc.addChoosableFileFilter(filterPDF);
        fc.setFileFilter(filterPDF);
        fc.setDialogTitle("Export chart as PDF...");
    }

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);

    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        outputFile = fc.getSelectedFile();

        if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") {
            log.debug("Output file extension not set by user");

            if (fc.getFileFilter().getDescription().equals(new CSVFileFilter().getDescription())) {
                log.debug("Adding csv extension to output file name");
                outputFile = new File(outputFile.getAbsolutePath() + ".csv");
            } else if (fc.getFileFilter().getDescription().equals(new PDFFilter().getDescription())) {
                log.debug("Adding pdf extension to output file name");
                outputFile = new File(outputFile.getAbsolutePath() + ".pdf");
            }
        } else {
            log.debug("Output file extension set my user to '"
                    + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'");
        }

        App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath());
    } else {
        return null;
    }

    if (outputFile.exists()) {
        Object[] options = { "Overwrite", "No", "Cancel" };

        // notes about parameters: null (don't use custom icon), options (the titles of buttons), options[0] (default button title)
        int response = JOptionPane.showOptionDialog(App.mainFrame,
                "The file '" + outputFile.getName() + "' already exists.  Are you sure you want to overwrite?",
                "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                options[0]);

        if (response != JOptionPane.YES_OPTION)
            return null;
    }
    return outputFile;
}

From source file:mondrian.gui.Workbench.java

private int confirmFrameClose(JInternalFrame schemaFrame, SchemaExplorer se) {
    if (se.isDirty()) {
        JMenuItem schemaMenuItem = schemaWindowMap.get(desktopPane.getSelectedFrame());
        // yes=0; no=1; cancel=2
        int answer = JOptionPane.showConfirmDialog(null,
                getResourceConverter().getFormattedString("workbench.saveSchemaOnClose.alert",
                        "Save changes to {0}?", se.getSchemaFile().toString()),
                getResourceConverter().getString("workbench.saveSchemaOnClose.title", "Schema"),
                JOptionPane.YES_NO_CANCEL_OPTION);
        switch (answer) {
        case 0:/*ww  w  . jav  a 2  s  .  c  o  m*/
            saveMenuItemActionPerformed(null);
            schemaWindowMap.remove(schemaFrame);
            updateMDXCatalogList();
            schemaFrame.dispose();
            windowMenu.remove(schemaMenuItem);
            break;
        case 1:
            schemaFrame.dispose();
            schemaWindowMap.remove(schemaFrame);
            windowMenu.remove(schemaMenuItem);
            break;
        case 2:
            try {
                schemaFrame.setClosed(false);
                schemaFrame.show();
            } catch (Exception ex) {
                LOGGER.error(ex);
            }
        }
        return answer;
    }
    return 3;
}