Example usage for javax.swing JOptionPane showOptionDialog

List of usage examples for javax.swing JOptionPane showOptionDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 

Source Link

Document

Brings up a dialog with a specified icon, where the initial choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.

Usage

From source file:no.java.ems.client.swing.EmsClient.java

public static AuthenticationDialog runAuthenticationDialog(Component component) {
    AuthenticationDialog message = new AuthenticationDialog();
    JOptionPane.showOptionDialog(component, message, "Authenticate", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.INFORMATION_MESSAGE, null, null, null);
    return message;
}

From source file:ome.formats.importer.gui.FileQueueHandler.java

/**
 * Import cancelled dialog/*from w  ww  .j a  v a 2 s . co  m*/
 * 
 * @param frame parent frame
 * @return - true / false if import cancelled
 */
private boolean cancelImportDialog(Component frame) {
    String s1 = "OK";
    String s2 = "Force Quit Now";
    Object[] options = { s1, s2 };
    int n = JOptionPane.showOptionDialog(frame, "Click 'OK' to cancel after the current file has\n"
            + "finished importing, or click 'Force Quit Now' to\n"
            + "force the importer to quit importing immediately.\n\n"
            + "You should only force quit the importer if there\n"
            + "has been an import problem, as this leaves partial\n" + "files in your server dataset.\n\n",
            "Cancel Import", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, s1);
    if (n == JOptionPane.NO_OPTION) {
        return true;
    } else {
        return false;
    }
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Quit Confirmation pop up dialog/*from www .j  a v a2s  .c  om*/
 * 
 * @param parent - parent component
 * @param message - message to use instead of default
 * @return boolean if quit (true) or cancel dialog (false)
 */
public static boolean quitConfirmed(Component parent, String message) {
    if (message == null) {
        message = "Do you really want to close the application?\n"
                + "Doing so will cancel any running imports.";
    }
    String s1 = "No";
    String s2 = "Yes";
    Object[] options = { s2, s1 };
    int n = JOptionPane.showOptionDialog(parent, message, "Exit Application", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, s1);
    //b/c of switch of location
    if (n == JOptionPane.YES_OPTION) {
        return true;
    } else {
        return false;
    }
}

From source file:ome.formats.importer.gui.HistoryTable.java

/**
 * Clear the history table of all data/*from w  w  w. j a  va  2s .  c o  m*/
 */
private void ClearHistory() {
    String message = "This will delete your import history. \n" + "Are you sure you want to continue?";
    Object[] o = { "Yes", "No" };

    int result = JOptionPane.showOptionDialog(this, message, "Warning", -1, JOptionPane.WARNING_MESSAGE, null,
            o, o[1]);
    if (result == 0) //yes clicked
    {
        try {
            db.wipeDataSource(getExperimenterID());
        } catch (ServerError e) {
            log.error("exception.", e);
        }
        updateOutlookBar();
        getItemQuery(-1, getExperimenterID(), searchField.getText(), fromDate.getDate(), toDate.getDate());
    }
}

From source file:op.controlling.PnlControlling.java

private JPanel createContentPanel4Hygiene() {
    JPanel pnlContent = new JPanel(new VerticalLayout());

    JPanel pnlPrevalence = new JPanel(new BorderLayout());
    final JButton btnPrevalence = GUITools.createHyperlinkButton("opde.controlling.hygiene.prevalence", null,
            null);//from w  w w. j  a  v  a2s  .  c o  m
    final JDateChooser jdc = new JDateChooser(new Date());
    final JCheckBox cbAnonymous = new JCheckBox(SYSTools.xx("misc.msg.anon"));
    cbAnonymous.setSelected(true);

    jdc.setMaxSelectableDate(new Date());

    btnPrevalence.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OPDE.getMainframe().setBlocked(true);
            SwingWorker worker = new SwingWorker() {
                @Override
                protected Object doInBackground() throws Exception {
                    MREPrevalenceSheets mre = new MREPrevalenceSheets(new LocalDate(), cbAnonymous.isSelected(),
                            progressClosure);
                    return mre.createSheet();
                }

                @Override
                protected void done() {
                    try {
                        File source = (File) get();

                        Object[] options = { SYSTools.xx("prevalence.optiondialog.option1"),
                                SYSTools.xx("prevalence.optiondialog.option2"),
                                SYSTools.xx("opde.wizards.buttontext.cancel") };

                        int n = JOptionPane.showOptionDialog(OPDE.getMainframe(),
                                SYSTools.xx("prevalence.optiondialog.question"),
                                SYSTools.xx("prevalence.optiondialog.title"), JOptionPane.YES_NO_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                        File copyTargetDirectory = null;

                        if (n == 1) {
                            JFileChooser chooser = new JFileChooser();
                            chooser.setDialogTitle("title");
                            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                            chooser.setMultiSelectionEnabled(false);
                            chooser.setAcceptAllFileFilterUsed(false);

                            if (chooser.showOpenDialog(pnlPrevalence) == JFileChooser.APPROVE_OPTION) {
                                copyTargetDirectory = chooser.getSelectedFile();
                            }
                        }

                        if (copyTargetDirectory != null) {
                            FileUtils.copyFile(source, copyTargetDirectory);
                        } else {
                            if (n == 0) {
                                SYSFilesTools.handleFile((File) get(), Desktop.Action.OPEN);
                            }
                        }

                    } catch (Exception e) {
                        OPDE.fatal(e);
                    }

                    OPDE.getDisplayManager().setProgressBarMessage(null);
                    OPDE.getMainframe().setBlocked(false);
                }
            };
            worker.execute();
        }
    });
    pnlPrevalence.add(btnPrevalence, BorderLayout.WEST);

    JPanel optionPanel = new JPanel();
    optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.LINE_AXIS));

    optionPanel.add(cbAnonymous);
    optionPanel.add(jdc);

    pnlPrevalence.add(optionPanel, BorderLayout.EAST);
    pnlContent.add(pnlPrevalence);

    return pnlContent;
}

From source file:openqcm.mainGUI.java

/**
 * Creates new form mainGUI// www  .  j  ava 2 s  . c  o  m
 */
public mainGUI() {
    // Show the splash screen
    appInit();

    // Generated code initialize GUI components
    initComponents();
    CommentSection cs = new CommentSection();
    cs.setVisible(true);
    jButton3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // display/center the jdialog when the button is pressed
            DateFormat df = new SimpleDateFormat("HH:mm:ss");
            Date dateobj = new Date();
            cs.addData(df.format(dateobj), jTextArea1.getText().toString());
        }

    });
    //add listener to the button
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent we) {
            String ObjButtons[] = { "Yes", "No" };
            int PromptResult = JOptionPane.showOptionDialog(null, "Are you sure you want to exit?",
                    "Online Examination System", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null,
                    ObjButtons, ObjButtons[1]);
            if (PromptResult == 0) {
                System.exit(0);
            }
        }

    });

    // Register a RawDataListener to receive data from Arduino.
    link.addRawDataListener(this);
}

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

/**
 * This will parse a document.//from ww  w .j ava  2s .  c o  m
 *
 * @param file The file addressing the document.
 * @throws IOException If there is an error parsing the document.
 */
private void parseDocument(File file, String password) throws IOException {
    while (true) {
        try {
            document = PDDocument.load(file, password);
        } catch (InvalidPasswordException ipe) {
            // https://stackoverflow.com/questions/8881213/joptionpane-to-get-password
            JPanel panel = new JPanel();
            JLabel label = new JLabel("Password:");
            JPasswordField pass = new JPasswordField(10);
            panel.add(label);
            panel.add(pass);
            String[] options = new String[] { "OK", "Cancel" };
            int option = JOptionPane.showOptionDialog(null, panel, "Enter password", JOptionPane.NO_OPTION,
                    JOptionPane.PLAIN_MESSAGE, null, options, "");
            if (option == 0) {
                password = new String(pass.getPassword());
                continue;
            }
            throw ipe;
        }
        break;
    }
    printMenuItem.setEnabled(true);
    reopenMenuItem.setEnabled(true);
}

From source file:org.bibsonomy.plugin.jabref.worker.ImportPostsByCriteriaWorker.java

public void run() {

    dialog.setVisible(true);//from  ww w  . jav  a  2  s . c om
    dialog.setProgress(0, 0);

    int numberOfPosts = 0, start = 0, end = PluginProperties.getNumberOfPostsPerRequest(), cycle = 0,
            numberOfPostsPerRequest = PluginProperties.getNumberOfPostsPerRequest();
    boolean continueFetching = false;
    do {
        numberOfPosts = 0;

        List<String> tags = null;
        String search = null;
        switch (type) {
        case TAGS:
            if (criteria.contains(" ")) {
                tags = Arrays.asList(criteria.split("\\s"));
            } else {
                tags = Arrays.asList(new String[] { criteria });
            }
            break;
        case FULL_TEXT:
            search = criteria;
            break;
        }

        try {

            final Collection<Post<BibTex>> result = getLogic().getPosts(BibTex.class, grouping, groupingValue,
                    tags, null, search, null, null, null, null, start, end);
            for (Post<? extends Resource> post : result) {
                dialog.setProgress(numberOfPosts++, numberOfPostsPerRequest);
                BibtexEntry entry = JabRefModelConverter.convertPost(post);

                // clear fields if the fetched posts does not belong to the
                // user
                if (!PluginProperties.getUsername().equals(entry.getField("username"))) {
                    entry.clearField("intrahash");
                    entry.clearField("interhash");
                    entry.clearField("file");
                    entry.clearField("owner");
                }
                dialog.addEntry(entry);
            }

            if (!continueFetching) {
                if (!ignoreRequestSize) {

                    if (!PluginProperties.getIgnoreMorePostsWarning()) {

                        if (numberOfPosts == numberOfPostsPerRequest) {
                            int status = JOptionPane.showOptionDialog(dialog,
                                    "<html>There are probably more than "
                                            + PluginProperties.getNumberOfPostsPerRequest()
                                            + " posts available. Continue importing?<br>You can stop importing entries by hitting the Stop button on the import dialog.",
                                    "More posts available", JOptionPane.YES_NO_OPTION,
                                    JOptionPane.WARNING_MESSAGE, null, null, JOptionPane.YES_OPTION);

                            switch (status) {
                            case JOptionPane.YES_OPTION:
                                continueFetching = true;
                                break;

                            case JOptionPane.NO_OPTION:
                                this.stopFetching();
                                break;
                            default:
                                break;
                            }
                        }
                    }
                }
            }
            start = ((cycle + 1) * numberOfPostsPerRequest);
            end = ((cycle + 2) * numberOfPostsPerRequest);

            cycle++;
        } catch (AuthenticationException ex) {
            (new ShowSettingsDialogAction((JabRefFrame) dialog.getOwner())).actionPerformed(null);
        } catch (Exception ex) {
            LOG.error("Failed to import posts", ex);
        }
    } while (fetchNext() && numberOfPosts >= numberOfPostsPerRequest);

    dialog.entryListComplete();
}

From source file:org.colombbus.tangara.CommandSelection.java

private boolean userConfirmOverride(File destinationFile) {
    String title;//w  ww.  j av  a  2s  .c om
    String pattern;
    if (mode == MODE_PROGRAM_CREATION) {
        title = Messages.getString("CommandSelection.programCreation.override.title");
        pattern = Messages.getString("CommandSelection.programCreation.override.message");
    } else {
        title = Messages.getString("CommandSelection.fileCreation.override.title");
        pattern = Messages.getString("CommandSelection.fileCreation.override.message");
    }
    String message = MessageFormat.format(pattern, destinationFile.getName());
    Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") };
    int optionType = JOptionPane.OK_CANCEL_OPTION;
    int messageType = JOptionPane.QUESTION_MESSAGE;
    Icon icon = null;
    int answer = JOptionPane.showOptionDialog(this, message, title, optionType, messageType, icon, options,
            options[0]);
    return answer == JOptionPane.OK_OPTION;
}

From source file:org.colombbus.tangara.EditorFrame.java

private boolean userConfirmFileOverride(File destinationFile) {
    String messagePattern = Messages.getString("EditorFrame.program.override.message"); //$NON-NLS-1$
    String message = MessageFormat.format(messagePattern, destinationFile.getName());
    String title = Messages.getString("EditorFrame.program.override.title"); //$NON-NLS-1$
    Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") }; //$NON-NLS-1$ //$NON-NLS-2$
    Icon icon = null;/*from  www.ja v  a2  s .co  m*/
    int messageType = JOptionPane.QUESTION_MESSAGE;
    int answer = JOptionPane.showOptionDialog(EditorFrame.this, message, title, optionType, messageType, icon,
            options, options[0]);
    return answer == JOptionPane.OK_OPTION;
}