Example usage for javax.swing JOptionPane JOptionPane

List of usage examples for javax.swing JOptionPane JOptionPane

Introduction

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

Prototype

public JOptionPane(Object message, int messageType, int optionType) 

Source Link

Document

Creates an instance of JOptionPane to display a message with the specified message type and options.

Usage

From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerActions.java

@SuppressWarnings("serial")
private AbstractAction createDeleteSelectedLogFilesAction() {
    return new AbstractAction() {
        @Override/*from w  w  w  . j  ava2  s. co  m*/
        public void actionPerformed(ActionEvent e) {
            if (!gui.validateAndSetUI()) {
                gui.popupErrorConfigurationDialog();
                return;
            }
            AsyncTask task = new AsyncTask() {
                @Override
                public Object run() throws Exception {
                    gui.deleteSelectedLogFilesButton.setEnabled(false);

                    Object[] objArray = gui.logFilesList.getSelectedValues();
                    if (objArray.length == 0)
                        return null;

                    JOptionPane jop = new JOptionPane(
                            I18n.text("Are you sure you want to delete selected log files from remote system?"),
                            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                    JDialog dialog = jop.createDialog(gui.frameCompHolder,
                            I18n.text("Remote Delete Confirmation"));
                    dialog.setModalityType(ModalityType.DOCUMENT_MODAL);
                    dialog.setVisible(true);
                    Object userChoice = jop.getValue();
                    try {
                        if (((Integer) userChoice) != JOptionPane.YES_OPTION) {
                            return null;
                        }
                    } catch (Exception e2) {
                        NeptusLog.pub().error(e2.getMessage());
                        return null;
                    }
                    gui.deleteSelectedLogFoldersButton.setEnabled(true);

                    LinkedHashSet<LogFileInfo> logFiles = new LinkedHashSet<LogFileInfo>();
                    for (Object comp : objArray) {
                        if (resetting)
                            break;

                        try {
                            LogFileInfo lfx = (LogFileInfo) comp;
                            if (worker.deleteLogFileFromServer(lfx))
                                logFiles.add(lfx);
                        } catch (Exception e) {
                            NeptusLog.pub().debug(e.getMessage());
                        }
                    }
                    if (!resetting) {
                        LogsDownloaderWorkerGUIUtil.updateLogFilesStateDeleted(logFiles,
                                gui.downloadWorkersHolder, worker.getDirBaseToStoreFiles(),
                                worker.getLogLabel());

                        worker.updateFilesListGUIForFolderSelected();
                    }
                    return true;
                }

                @Override
                public void finish() {
                    gui.deleteSelectedLogFilesButton.setEnabled(true);
                    gui.logFilesList.revalidate();
                    gui.logFilesList.repaint();
                    gui.logFilesList.setEnabled(true);
                    gui.logFolderList.revalidate();
                    gui.logFolderList.repaint();
                    gui.logFolderList.setEnabled(true);
                    try {
                        this.getResultOrThrow();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };

            AsyncWorker.getWorkerThread().postTask(task);
        }
    };
}

From source file:savant.view.swing.BookmarkSheet.java

private void loadBookmarks(JTable table) {
    final BookmarksTableModel btm = (BookmarksTableModel) table.getModel();
    List<Bookmark> bookmarks = btm.getData();

    if (bookmarks.size() > 0) {
        String message = "Clear existing bookmarks?";
        String title = "Clear Bookmarks";
        // display the JOptionPane showConfirmDialog
        int reply = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION) {
            btm.clearData();/*  ww w.j a  v  a2  s  .c o  m*/
            BookmarkController.getInstance().clearBookmarks();
        }
    }

    final File selectedFile = DialogUtils.chooseFileForOpen("Load Bookmarks", null, null);

    // set the genome
    if (selectedFile != null) {

        int result = JOptionPane.showOptionDialog(null, "Would you like to add padding to each bookmark range?",
                "Add a margin?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        final boolean addMargin = (result == JOptionPane.YES_OPTION);

        Window w = SwingUtilities.getWindowAncestor(BookmarkSheet.this);
        JOptionPane optionPane = new JOptionPane(
                "<html>Loading bookmarks from file.<br>This may take a moment.</html>",
                JOptionPane.INFORMATION_MESSAGE, JOptionPane.CANCEL_OPTION);
        final JDialog dialog = new JDialog(w, "Loading Bookmarks", Dialog.ModalityType.MODELESS);
        dialog.setContentPane(optionPane);
        dialog.pack();
        dialog.setLocationRelativeTo(w);
        dialog.setVisible(true);
        new Thread("BookmarkSheet.loadBookmarks") {
            @Override
            public void run() {
                try {
                    BookmarkController.getInstance().addBookmarksFromFile(selectedFile, addMargin);
                    btm.fireTableDataChanged();
                } catch (Exception ex) {
                    DialogUtils.displayError("Error", "Unable to load bookmarks: " + ex.getMessage());
                } finally {
                    dialog.setVisible(false);
                    dialog.dispose();
                }
            }
        }.start();
    }
}