Example usage for javax.swing JOptionPane showConfirmDialog

List of usage examples for javax.swing JOptionPane showConfirmDialog

Introduction

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

Prototype

public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
        throws HeadlessException 

Source Link

Document

Brings up a dialog where the number of choices is determined by the optionType parameter.

Usage

From source file:Main.java

/**
 * visualizzazione messaggio HTML//from w  w  w .  j  av  a2s . com
 *
 * @param pFrame frame di provenienza (di solito e' <code>this</code>).
 * @param pTask task di provenienza del messaggio (di solito e'
 * <code>TASK_NAME</code>).
 * @param pMessaggio messaggio da visualizzare
 * @return JOptionPane.CANCEL_OPTION o OK_OPTION
 */
public static int dispWarning(JFrame pFrame, String pTask, String pMessaggio) {
    //
    return (JOptionPane.showConfirmDialog(pFrame, formattaHTML(pMessaggio), WARNING_TITLE,
            JOptionPane.OK_CANCEL_OPTION));
}

From source file:commonline.query.gui.action.ClearDatabaseAction.java

public void actionPerformed(ActionEvent actionEvent) {
    if (JOptionPane.showConfirmDialog(parent, "Are you sure you want to clear the databases?", "Clear DB",
            JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
        SwingWorker worker = new SwingWorker<Void, Void>() {
            protected Void doInBackground() throws Exception {
                for (RecordParserDataSource dataSource : dataSources) {
                    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
                    for (RecordLayoutTableInfo tableInfo : dataSource.getTableInfos()) {
                        try {
                            jdbcTemplate.execute("delete from " + tableInfo.getTableName());
                        } catch (Exception err) {
                            throw new RuntimeException("Problem clearing table:" + tableInfo.getTableName()
                                    + ", in DB:" + dataSource.getUrl(), err);
                        }/*w  ww.  ja  v  a  2  s.c  o m*/
                    }
                }
                return null;
            }
        };
        worker.execute();
    }
}

From source file:Main.java

@Override
public void actionPerformed(ActionEvent e) {
    MyPanel patientPicker = new MyPanel();
    int result = JOptionPane.showConfirmDialog(swingFoo, patientPicker, "Select Something",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        swingFoo.setFileFieldText(patientPicker.getSelectedItem());
    }/* w w w.  java2s .c om*/
    patientPicker.setVisible(true);
}

From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java

public static JSONObject getPreviousLoginDetails() {
    JSONObject loginInfo = AuthManager.refreshAccessToken();
    if (loginInfo == null) {
        return null;
    }// ww  w. jav a2s . com
    final AtomicInteger option = new AtomicInteger();
    Runnable r = new Runnable() {
        public void run() {
            option.set(JOptionPane.showConfirmDialog(CraftProxyClient.getGUI(),
                    "Login as " + AuthManager.getUsername() + "?", "Login", JOptionPane.YES_NO_OPTION));
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(r);
        } catch (InvocationTargetException | InterruptedException e) {
            return null;
        }
    }
    if (option.get() == 0) {
        return loginInfo;
    } else {
        return null;
    }
}

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  ww .  ja  v  a  2 s  .c o  m*/
        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:Main.java

/**
 * visualizzazione messaggio HTML da tabella errori.
 *
 * @param pFrame frame di provenienza (di solito e' <code>this</code>).
 * @param pTask task di provenienza del messaggio (di solito e'
 * <code>TASK_NAME</code>).//from   w  ww. j  av a 2 s  .c om
 * @param pError codice del messaggio
 * @param pMessaggio ulteriori dati da visualizzare
 * @return JOptionPane.CANCEL_OPTION o OK_OPTION
 */
public static int dispWarning(JFrame pFrame, String pTask, String pError, String pMessaggio) {
    //
    return (JOptionPane.showConfirmDialog(pFrame, componiStringaWarning(pError, pMessaggio), WARNING_TITLE,
            JOptionPane.OK_CANCEL_OPTION));
}

From source file:css.variable.converter.CSSVariableConverter.java

/**
 * Ask which file is the main file(so we can get variables)
 *
 * @return The Main File that has the ":root" identifier for variables.
 * @throws HeadlessException/*from  w ww  . j  a  v a  2 s . c  o  m*/
 */
private static File getMainCSSFile() throws HeadlessException {
    // Convert CSS Filenames into a string array
    String[] cssStrNames = new String[theCSSList.size()];
    for (int i = 0; i < theCSSList.size(); i++) {
        cssStrNames[i] = theCSSList.get(i).getName();
    }

    // Create JComboBox and prompt to choose main file
    RootFilePanel getCSSRoot = new RootFilePanel(cssStrNames);
    JOptionPane.showConfirmDialog(null, getCSSRoot, "Select your CSS File with root variables",
            JOptionPane.OK_CANCEL_OPTION);
    int index = getCSSRoot.getSelectedIndex();
    if (index == -1) {
        return null;
    }
    return theCSSList.get(index);
}

From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java

/**
 * @param args/*from   w  w w.  ja v a  2s.  co  m*/
 * @throws Exception
 */
public static void main(String args[]) throws Exception {
    /*try
    {
    List<String>   list = FileUtils.readLines(new File("/Users/rods/drop.sql"));
    Vector<String> list2 = new Vector<String>();
    for (String line : list)
    {
        list2.add(line+";");
    }
    FileUtils.writeLines(new File("/Users/rods/drop2.sql"), list2);
    return;
            
    } catch (Exception ex)
    {
    ex.printStackTrace();
    }*/

    // Set App Name, MUST be done very first thing!
    UIRegistry.setAppName("Specify"); //$NON-NLS-1$

    log.debug("********* Current [" + (new File(".").getAbsolutePath()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    UIRegistry.setEmbeddedDBPath(UIRegistry.getDefaultEmbeddedDBPath()); // on the local machine

    AppBase.processArgs(args);

    final SpecifyDBConverter converter = new SpecifyDBConverter();

    Logger logger = LogManager.getLogger("edu.ku.brc");
    if (logger != null) {
        logger.setLevel(Level.ALL);
        System.out.println("Setting " + logger.getName() + " to " + logger.getLevel());
    }

    logger = LogManager.getLogger(edu.ku.brc.dbsupport.HibernateUtil.class);
    if (logger != null) {
        logger.setLevel(Level.INFO);
        System.out.println("Setting " + logger.getName() + " to " + logger.getLevel());
    }

    // Create Specify Application
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            try {
                if (!System.getProperty("os.name").equals("Mac OS X")) {
                    UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new DesertBlue());
                }
            } catch (Exception e) {
                log.error("Can't change L&F: ", e);
            }

            Pair<String, String> namePair = null;
            try {
                if (converter.selectedDBsToConvert(false)) {
                    namePair = converter.chooseTable("Select a DB to Convert", "Specify 5 Databases", true);
                }

            } catch (SQLException ex) {
                ex.printStackTrace();
                JOptionPane.showConfirmDialog(null, "The Converter was unable to login.", "Error",
                        JOptionPane.CLOSED_OPTION);
            }

            if (namePair != null) {
                frame = new ProgressFrame("Converting");

                converter.processDB();
            } else {
                JOptionPane.showConfirmDialog(null, "The Converter was unable to login.", "Error",
                        JOptionPane.CLOSED_OPTION);
                System.exit(0);
            }
        }
    });
}

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

/**
 * Initialisiuerung der Komponenten./*from w  w w.j a  v a 2  s  . co  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);
}