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:GUI.VentanaPrincipal.java

public void SalirPrograma() {
    if ((JOptionPane.showConfirmDialog(this, "Realmente desea salir de la aplicacin?",
            "Salir del Monitor 1 de Bases de Datos", JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION)) {
        System.exit(0);/*  w w w.  j  ava2 s. c  om*/
    }
}

From source file:net.sf.nmedit.nordmodular.NmFileService.java

public static NMPatch openPatch(File file, File sourceFile, final String title, boolean showExceptionDialog) {
    NMContextData data = NMContextData.sharedInstance();

    try {/*from w w  w  . j  a  va 2  s.c om*/
        boolean setFilePointerToNull = false;
        if (isFileAlreadyOpen(file)) {
            if (JOptionPane.showConfirmDialog(Nomad.sharedInstance().getWindow().getRootPane(),
                    "File \"" + file + "\" is already open.\nDo you want to open a copy of the file?",
                    "Open...", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
                Nomad.sharedInstance().setSelectedDocumentByFile(file);
                return null;
            }

            setFilePointerToNull = true;
        }

        NMPatch patch = NMPatch.createPatchFromFile(file);
        patch.setEditSupportEnabled(false);

        if (title != null)
            patch.setName(title);

        final PatchDocument pd = createPatchDoc(patch);

        if (setFilePointerToNull) {
            if (sourceFile != null) {
                String name = sourceFile.getName();
                if (name.toLowerCase().endsWith(".pch"))
                    name = name.substring(0, name.length() - 4);
                patch.setName(name);
            }
        } else {
            if (sourceFile != null) {
                patch.setProperty("file", sourceFile);
                pd.setURI(sourceFile);
            }
        }

        patch.setEditSupportEnabled(true);
        patch.setModified(false);
        DocumentManager dm = Nomad.sharedInstance().getDocumentManager();
        dm.add(pd);
        dm.setSelection(pd);

        return patch;

    } catch (Exception e) {
        Log log = LogFactory.getLog(NmFileService.class);
        if (log.isWarnEnabled()) {
            log.warn("open failed: " + file, e);
        }
        if (showExceptionDialog) {
            ExceptionDialog.showErrorDialog(Nomad.sharedInstance().getWindow().getRootPane(),
                    "Could not open file '" + file + "' (" + e.getMessage() + ")", "Could not open file", e);
        }
    }

    return null;
}

From source file:de.bley.word.menu.ClickedGuiMenu.java

/**
 * Initialisiuerung der Komponenten.//from  w ww  .j  a  v a  2 s.c  o m
 */
private void setup() {
    path = PropertieManager.getInstance().getZuordnung().getPath().getFilepath();
    initComponents();
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            if (!jEditorPane1.getText().equals("")) {

                if (!jEditorPane1.getText()
                        .equals(PropertieManager.getInstance().getZuordnung().getReader().readFile(path))) {
                    int confirmed = JOptionPane.showConfirmDialog(null, "Speichern der Daten?", "Beenden",
                            JOptionPane.YES_NO_OPTION);

                    if (confirmed == JOptionPane.YES_OPTION) {
                        saveData();
                        dispose();
                    }
                }
            }
        }
    });
    read();
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }

    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | javax.swing.UnsupportedLookAndFeelException ex) {
        log.debug("NewJFrame" + ex);
    }

}

From source file:au.com.jwatmuff.eventmanager.util.GUIUtils.java

public static boolean confirmAction(Frame parent, String verb, String object) {
    int status = JOptionPane.showConfirmDialog(parent, "Are you sure you wish to " + verb + " " + object + "?",
            "Confirm " + StringUtils.capitalize(verb), JOptionPane.YES_NO_OPTION);
    return (status == JOptionPane.YES_OPTION);
}

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Displays a plot of the given data sets as a dialog with a save as PNG option
 * @param parent component to set the dialog relative to
 * @param title the name of the Plot and the header of the dialog
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 *///from  ww w.ja  v  a2s. c  o m
public static void plotWithDialog(Component parent, String title, XYDataset dataset1, XYDataset dataset2) {
    JFreeChart chart = plot(title, dataset1, dataset2);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1024, 768));
    chartPanel.setMouseZoomable(true, false);

    String[] options = { "Print", "OK" };
    int response = JOptionPane.showOptionDialog(parent // Center in window.
            , chartPanel, title // Title in titlebar
            , JOptionPane.YES_NO_OPTION // Option type
            , JOptionPane.PLAIN_MESSAGE // messageType
            , null // Icon (none)
            , options // Button text as above.
            , "OK" // Default button
    );

    if (response == 0) {
        getPlotAsPNG(title, dataset1, dataset2);
    }
}

From source file:de.erdesignerng.visual.MessagesHelper.java

public static boolean displayQuestionMessage(Component aParent, String aMessage, String aQuestionText,
        String aMessageKey, Object... aReplacementValues) {
    return JOptionPane.showConfirmDialog(aParent, StringEscapeUtils.unescapeJava(aMessage),
            StringEscapeUtils.unescapeJava(aQuestionText), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
}

From source file:com.babynamesUI.java

protected void processWindowEvent(WindowEvent e) {

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {

        //System.exit(0); //remove on release

        int exit = JOptionPane.showConfirmDialog(this, "Are you sure?", "Confirm Exit?",
                JOptionPane.YES_NO_OPTION);
        if (exit == JOptionPane.YES_OPTION) {
            System.exit(0);//from w ww . ja v  a 2  s. com
        }

    } else {

        super.processWindowEvent(e);
    }
}

From source file:oct.util.Util.java

public static OCT getOCT(BufferedImage octImage, OCTAnalysisUI octAnalysisUI, String octFileName) {
    boolean exit = false;
    //ask the user for the x-scale
    double xscale = 0;
    do {// w  ww . j  av a2 s.c  om
        String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT X-axis scale (microns per pixel):",
                "X-Scale input", JOptionPane.QUESTION_MESSAGE);
        if (!(res == null || res.isEmpty())) {
            xscale = Util.parseNumberFromInput(res);
        }
        if (res == null || res.isEmpty() || xscale <= 0) {
            exit = JOptionPane.showConfirmDialog(octAnalysisUI,
                    "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.",
                    "Input Error", JOptionPane.YES_NO_OPTION,
                    JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION;
        }
    } while (!exit && xscale <= 0);
    if (exit) {
        return null;
    }
    //ask the user for the y-scale
    double yscale = 0;
    do {
        String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT Y-axis scale (microns per pixel):",
                "Y-Scale input", JOptionPane.QUESTION_MESSAGE);
        if (!(res == null || res.isEmpty())) {
            yscale = Util.parseNumberFromInput(res);
        }
        if (res == null || res.isEmpty() || yscale <= 0) {
            exit = JOptionPane.showConfirmDialog(octAnalysisUI,
                    "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.",
                    "Input Error", JOptionPane.YES_NO_OPTION,
                    JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION;
        }
    } while (!exit && yscale <= 0);
    if (exit) {
        return null;
    }

    //store values and return OCT object
    OCTAnalysisManager octMngr = OCTAnalysisManager.getInstance();
    octMngr.setXscale(xscale);
    octMngr.setYscale(yscale);
    return new OCT(octImage, octFileName);
}

From source file:groovesquid.UpdateCheckThread.java

@Override
public void run() {
    UpdateCheck updateCheck = gson.fromJson(getFile(updateFile), UpdateCheck.class);
    if (updateCheck.getClients() != null)
        Grooveshark.setClients(updateCheck.getClients());

    if (Utils.compareVersions(updateCheck.getVersion(), Main.getVersion()) > 0) {
        if (JOptionPane.showConfirmDialog(null,
                "New version (v" + updateCheck.getVersion()
                        + ") is available! Do you want to download the new version (recommended)?",
                "New version", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
            try {
                Desktop.getDesktop().browse(java.net.URI.create("http://groovesquid.com/#download"));
            } catch (IOException ex) {
                log.log(Level.SEVERE, null, ex);
            }/*  w ww .  j  a v a  2s . c  o  m*/
        }
    }
}

From source file:ca.sqlpower.wabit.swingui.action.DeleteWabitServerWorkspaceAction.java

public void actionPerformed(ActionEvent e) {
    try {//  w  ww. j  av  a2  s  .  c  o m
        WabitSwingSessionImpl activeSwingSession = (WabitSwingSessionImpl) context.getActiveSwingSession();
        if (activeSwingSession == null) {
            JOptionPane.showMessageDialog(context.getFrame(), "That button refreshes the current workspace,\n"
                    + "but there is no workspace selected right now.");
            return;
        }
        int choice = JOptionPane.showConfirmDialog(context.getFrame(),
                "By deleting this workspace, " + "you will not be able to recover any of its contents.\n"
                        + "Are you sure you want to delete it?",
                "Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

        if (choice == JOptionPane.YES_OPTION) {
            activeSwingSession.delete();
        }
    } catch (ClientProtocolException ex) {
        throw new RuntimeException(ex);
    } catch (URISyntaxException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}