Example usage for javax.swing JOptionPane CANCEL_OPTION

List of usage examples for javax.swing JOptionPane CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

To view the source code for javax.swing JOptionPane CANCEL_OPTION.

Click Source Link

Document

Return value from class method if CANCEL is chosen.

Usage

From source file:pcgen.gui2.PCGenFrame.java

public boolean closeAllCharacters() {
    final int CLOSE_OPT_CHOOSE = 2;
    ListFacade<CharacterFacade> characters = CharacterManager.getCharacters();
    if (characters.isEmpty()) {
        return true;
    }// w ww .j  a  v  a  2s  .  c  o m
    int saveAllChoice = CLOSE_OPT_CHOOSE;

    List<CharacterFacade> characterList = new ArrayList<>();
    List<CharacterFacade> unsavedPCs = new ArrayList<>();
    for (CharacterFacade characterFacade : characters) {
        if (characterFacade.isDirty()) {
            unsavedPCs.add(characterFacade);
        } else {
            characterList.add(characterFacade);
        }
    }
    if (unsavedPCs.size() > 1) {
        Object[] options = new Object[] { LanguageBundle.getString("in_closeOptSaveAll"), //$NON-NLS-1$
                LanguageBundle.getString("in_closeOptSaveNone"), //$NON-NLS-1$
                LanguageBundle.getString("in_closeOptChoose"), //$NON-NLS-1$
                LanguageBundle.getString("in_cancel") //$NON-NLS-1$
        };
        saveAllChoice = JOptionPane.showOptionDialog(this, LanguageBundle.getString("in_closeOptSaveTitle"), //$NON-NLS-1$
                Constants.APPLICATION_NAME, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, options, options[0]);
    }
    if (saveAllChoice == 3) {
        // Cancel
        return false;
    }
    if (saveAllChoice == 1) {
        // Save none
        CharacterManager.removeAllCharacters();
        return true;
    }

    for (CharacterFacade character : unsavedPCs) {
        int saveSingleChoice = JOptionPane.YES_OPTION;

        if (saveAllChoice == CLOSE_OPT_CHOOSE) {
            saveSingleChoice = JOptionPane.showConfirmDialog(this,
                    LanguageBundle.getFormattedString("in_savePcChoice", character //$NON-NLS-1$
                            .getNameRef().get()),
                    Constants.APPLICATION_NAME, JOptionPane.YES_NO_CANCEL_OPTION);
        }

        if (saveSingleChoice == JOptionPane.YES_OPTION) {//If you get here then the user either selected "Yes to All" or "Yes"
            if (saveCharacter(character)) {
                characterList.add(character);
            }
        } else if (saveSingleChoice == JOptionPane.NO_OPTION) {
            characterList.add(character);
        } else if (saveSingleChoice == JOptionPane.CANCEL_OPTION) {
            return false;
        }
    }

    for (CharacterFacade character : characterList) {
        CharacterManager.removeCharacter(character);
    }
    return characters.isEmpty();
}

From source file:pcgen.gui2.PCGenFrame.java

/**
 * Loads a character from a file. Any sources that are required for
 * this character are loaded first, then the character is loaded
 * from the file and a tab is opened for it.
 * @param pcgFile a file specifying the character to be loaded
 *///from  w w  w . j a  v  a  2 s.co m
public void loadCharacterFromFile(final File pcgFile) {
    if (!PCGFile.isPCGenCharacterFile(pcgFile)) {
        JOptionPane.showMessageDialog(this, LanguageBundle.getFormattedString("in_loadPcInvalid", pcgFile), //$NON-NLS-1$
                LanguageBundle.getString("in_loadPcFailTtile"), //$NON-NLS-1$
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (!pcgFile.canRead()) {
        JOptionPane.showMessageDialog(this, LanguageBundle.getFormattedString("in_loadPcNoRead", pcgFile), //$NON-NLS-1$
                LanguageBundle.getString("in_loadPcFailTtile"), //$NON-NLS-1$
                JOptionPane.ERROR_MESSAGE);
        return;
    }

    SourceSelectionFacade sources = CharacterManager.getRequiredSourcesForCharacter(pcgFile, this);
    if (sources == null) {
        JOptionPane.showMessageDialog(this, LanguageBundle.getFormattedString("in_loadPcNoSources", pcgFile), //$NON-NLS-1$
                LanguageBundle.getString("in_loadPcFailTtile"), //$NON-NLS-1$
                JOptionPane.ERROR_MESSAGE);
    } else if (!sources.getCampaigns().isEmpty()) {
        // Check if the user has asked that sources not be loaded with the character
        boolean dontLoadSources = currentSourceSelection.get() != null && !PCGenSettings.OPTIONS_CONTEXT
                .initBoolean(PCGenSettings.OPTION_AUTOLOAD_SOURCES_WITH_PC, true);
        boolean sourcesSame = checkSourceEquality(sources, currentSourceSelection.get());
        boolean gameModesSame = checkGameModeEquality(sources, currentSourceSelection.get());
        if (!dontLoadSources && !sourcesSame && gameModesSame) {
            Object[] btnNames = new Object[] { LanguageBundle.getString("in_loadPcDiffSourcesLoaded"),
                    LanguageBundle.getString("in_loadPcDiffSourcesCharacter"),
                    LanguageBundle.getString("in_cancel") };
            int choice = JOptionPane.showOptionDialog(this,
                    LanguageBundle.getFormattedString("in_loadPcDiffSources",
                            getFormattedCampaigns(currentSourceSelection.get()),
                            getFormattedCampaigns(sources)),
                    LanguageBundle.getString("in_loadPcSourcesLoadTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, btnNames, null);
            if (choice == JOptionPane.CANCEL_OPTION) {
                return;
            }
            if (choice == JOptionPane.YES_OPTION) {
                openCharacter(pcgFile, currentDataSetRef.get());
                return;
            }
        }

        if (dontLoadSources) {
            if (!checkSourceEquality(sources, currentSourceSelection.get())) {
                Logging.log(Logging.WARNING, "Loading character with different sources. Character: " + sources
                        + " current: " + currentSourceSelection.get());
            }
            openCharacter(pcgFile, currentDataSetRef.get());
        } else if (loadSourceSelection(sources)) {
            loadSourcesThenCharacter(pcgFile);
        } else {
            JOptionPane.showMessageDialog(this, LanguageBundle.getString("in_loadPcIncompatSource"), //$NON-NLS-1$
                    LanguageBundle.getString("in_loadPcFailTtile"), //$NON-NLS-1$
                    JOptionPane.ERROR_MESSAGE);
        }
    } else if (currentDataSetRef.get() != null) {
        if (showWarningConfirm(Constants.APPLICATION_NAME,
                LanguageBundle.getFormattedString("in_loadPcSourcesLoadQuery", //$NON-NLS-1$
                        pcgFile))) {
            openCharacter(pcgFile, currentDataSetRef.get());
        }
    } else {
        // No character sources and no sources loaded.
        JOptionPane.showMessageDialog(this, LanguageBundle.getFormattedString("in_loadPcNoSources", pcgFile), //$NON-NLS-1$
                LanguageBundle.getString("in_loadPcFailTtile"), //$NON-NLS-1$
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:picocash.Picocash.java

@Override
protected void initialize(String[] arg0) {
    ServiceDiscover.getAll(IPicocashPersistenceManager.class);
    Services.setSelectedPersistenceMan(ServiceDiscover.getSingleton(IPicocashPersistenceManager.class));

    Services.getSelectedPersistenceMan().setDatabaseName("test.mmoc");
    try {/*from   w  w  w . jav  a  2s.  co  m*/
        Services.getSelectedPersistenceMan().initDB();
    } catch (Exception ex) {
        log.fatal("Exception while restarting database:", ex);
        exit();
    }

    PicocashIcons.init();

    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

    addExitListener(new ExitListener() {

        @Override
        public boolean canExit(EventObject event) {
            if (changesAvailable) {
                int retValue = JOptionPane.showConfirmDialog(getMainFrame(), "Das sollte der Title sein",
                        "und die Message", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (retValue == JOptionPane.OK_OPTION) {
                    save();
                }
                return retValue == JOptionPane.OK_OPTION || retValue == JOptionPane.CANCEL_OPTION;
            }
            return true;
        }

        @Override
        public void willExit(EventObject event) {
            Services.getSelectedPersistenceMan().close();
        }
    });
    super.initialize(arg0);
}

From source file:processing.app.Editor.java

/**
 * Check if the sketch is modified and ask user to save changes.
 * @return false if canceling the close/quit operation
 *///  www  . ja  va  2  s  .  c  om
protected boolean checkModified() {
    if (!sketch.isModified())
        return true;

    // As of Processing 1.0.10, this always happens immediately.
    // http://dev.processing.org/bugs/show_bug.cgi?id=1456

    toFront();

    String prompt = I18n.format(_("Save changes to \"{0}\"?  "), sketch.getName());

    if (!OSUtils.isMacOS()) {
        int result = JOptionPane.showConfirmDialog(this, prompt, _("Close"), JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        switch (result) {
        case JOptionPane.YES_OPTION:
            return handleSave(true);
        case JOptionPane.NO_OPTION:
            return true; // ok to continue
        case JOptionPane.CANCEL_OPTION:
        case JOptionPane.CLOSED_OPTION: // Escape key pressed
            return false;
        default:
            throw new IllegalStateException();
        }

    } else {
        // This code is disabled unless Java 1.5 is being used on Mac OS X
        // because of a Java bug that prevents the initial value of the
        // dialog from being set properly (at least on my MacBook Pro).
        // The bug causes the "Don't Save" option to be the highlighted,
        // blinking, default. This sucks. But I'll tell you what doesn't
        // suck--workarounds for the Mac and Apple's snobby attitude about it!
        // I think it's nifty that they treat their developers like dirt.

        // Pane formatting adapted from the quaqua guide
        // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
        JOptionPane pane = new JOptionPane(_("<html> " + "<head> <style type=\"text/css\">"
                + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"
                + "</style> </head>" + "<b>Do you want to save changes to this sketch<BR>"
                + " before closing?</b>" + "<p>If you don't save, your changes will be lost."),
                JOptionPane.QUESTION_MESSAGE);

        String[] options = new String[] { _("Save"), _("Cancel"), _("Don't Save") };
        pane.setOptions(options);

        // highlight the safest option ala apple hig
        pane.setInitialValue(options[0]);

        // on macosx, setting the destructive property places this option
        // away from the others at the lefthand side
        pane.putClientProperty("Quaqua.OptionPane.destructiveOption", new Integer(2));

        JDialog dialog = pane.createDialog(this, null);
        dialog.setVisible(true);

        Object result = pane.getValue();
        if (result == options[0]) { // save (and close/quit)
            return handleSave(true);

        } else if (result == options[2]) { // don't save (still close/quit)
            return true;

        } else { // cancel?
            return false;
        }
    }
}

From source file:pt.lsts.neptus.mra.MRAFilesHandler.java

/**
 * Open LSF Log file//  w ww.ja v  a2  s  . c  o  m
 * @param f
 * @return
 */
private boolean openLSF(File f) {
    mra.getBgp().block(true);
    mra.getBgp().setText(I18n.text("Loading LSF Data"));

    if (!f.exists()) {
        mra.getBgp().block(false);
        GuiUtils.errorMessage(mra, I18n.text("Invalid LSF file"), I18n.text("LSF file does not exist!"));
        return false;
    }

    final File lsfDir = f.getParentFile();

    //IMCDefinition.pathToDefaults = ConfigFetch.getDefaultIMCDefinitionsLocation();

    boolean alreadyConverted = false;
    if (lsfDir.isDirectory()) {
        if (new File(lsfDir, "mra/lsf.index").canRead())
            alreadyConverted = true;

    } else if (new File(lsfDir, "mra/lsf.index").canRead())
        alreadyConverted = true;

    if (alreadyConverted) {
        int option = GuiUtils.confirmDialogWithCancel(mra, I18n.text("Open Log"),
                I18n.text("This log seems to have already been indexed. Index again?"));

        if (option == JOptionPane.YES_OPTION) {
            try {
                FileUtils.deleteDirectory(new File(lsfDir, "mra"));
            } catch (Exception e) {
                NeptusLog.pub().error("Error while trying to delete mra/ folder", e);
            }
        }

        if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            mra.getBgp().block(false);
            return false;
        }
    }

    mra.getBgp().setText(I18n.text("Loading LSF Data"));

    try {
        LsfLogSource source = new LsfLogSource(f, new LsfIndexListener() {

            @Override
            public void updateStatus(String messageToDisplay) {
                mra.getBgp().setText(messageToDisplay);
            }
        });

        updateMissionFilesOpened(f);

        mra.getBgp().setText(I18n.text("Starting interface"));
        openLogSource(source);
        mra.getBgp().setText(I18n.text("Done"));

        mra.getBgp().block(false);
        return true;
    } catch (Exception e) {
        mra.getBgp().block(false);
        e.printStackTrace();
        GuiUtils.errorMessage(mra, I18n.text("Invalid LSF index"), I18n.text(e.getMessage()));
        return false;
    }
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java

@Override
public void mouseClicked(MouseEvent event, final StateRenderer2D source) {

    if (event.getButton() == MouseEvent.BUTTON3) {
        final LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType();
        JPopupMenu popup = new JPopupMenu();
        for (String type : positions.keySet()) {
            JMenu menu = new JMenu(type + "s");
            for (final AssetPosition p : positions.get(type)) {

                if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection)
                    continue;

                Color c = cmap.getColor(1 - (p.getAge() / (7200000.0)));
                String htmlColor = String.format("#%02X%02X%02X", c.getRed(), c.getGreen(), c.getBlue());
                menu.add("<html><b>" + p.getAssetName() + "</b> <font color=" + htmlColor + ">" + getAge(p)
                        + "</font>").addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                source.focusLocation(p.getLoc());
                            }//ww  w.ja v  a 2  s.  co m
                        });
            }
            popup.add(menu);
        }

        popup.addSeparator();
        popup.add("Settings").addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                PluginUtils.editPluginProperties(SituationAwareness.this, true);
            }
        });

        popup.add("Fetch asset properties").addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //                    for (AssetTrack track : assets.values()) {
                //                        track.setColor(new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
                //                    }
                fetchAssetProperties();
            }
        });

        popup.add("Select location sources").addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                JPanel p = new JPanel();
                p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));

                for (ILocationProvider l : localizers) {
                    JCheckBox check = new JCheckBox(l.getName());
                    check.setSelected(true);
                    p.add(check);
                    check.setSelected(updateMethodNames.contains(l.getName()));
                }

                int op = JOptionPane.showConfirmDialog(getConsole(), p, "Location update sources",
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (op == JOptionPane.CANCEL_OPTION)
                    return;

                Vector<String> methods = new Vector<String>();
                for (int i = 0; i < p.getComponentCount(); i++) {

                    if (p.getComponent(i) instanceof JCheckBox) {
                        JCheckBox sel = (JCheckBox) p.getComponent(i);
                        if (sel.isSelected())
                            methods.add(sel.getText());
                    }
                }
                updateMethods = StringUtils.join(methods, ", ");
                propertiesChanged();
            }
        });

        popup.add("Select hidden positions types").addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                JPanel p = new JPanel();
                p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));

                for (String type : positions.keySet()) {
                    JCheckBox check = new JCheckBox(type);
                    check.setSelected(true);
                    p.add(check);
                    check.setSelected(hiddenPosTypes.contains(type));
                }

                int op = JOptionPane.showConfirmDialog(getConsole(), p, "Position types to be hidden",
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (op == JOptionPane.CANCEL_OPTION)
                    return;

                Vector<String> types = new Vector<String>();
                for (int i = 0; i < p.getComponentCount(); i++) {

                    if (p.getComponent(i) instanceof JCheckBox) {
                        JCheckBox sel = (JCheckBox) p.getComponent(i);
                        if (sel.isSelected())
                            types.add(sel.getText());
                    }
                }
                hiddenTypes = StringUtils.join(types, ", ");
                propertiesChanged();
            }
        });

        popup.addSeparator();
        popup.add("Decision Support").addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (dialogDecisionSupport == null) {
                    dialogDecisionSupport = new JDialog(getConsole());
                    dialogDecisionSupport.setModal(false);
                    dialogDecisionSupport.setAlwaysOnTop(true);
                    dialogDecisionSupport.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
                }
                ArrayList<AssetPosition> tags = new ArrayList<AssetPosition>();
                LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType();
                Vector<AssetPosition> spots = positions.get("SPOT Tag");
                Vector<AssetPosition> argos = positions.get("Argos Tag");
                if (spots != null)
                    tags.addAll(spots);
                if (argos != null)
                    tags.addAll(argos);
                if (!assets.containsKey(getConsole().getMainSystem())) {
                    GuiUtils.errorMessage(getConsole(), "Decision Support", "UUV asset position is unknown");
                    return;
                }
                supportTable.setAssets(assets.get(getConsole().getMainSystem()).getLatest(), tags);
                JXTable table = new JXTable(supportTable);
                dialogDecisionSupport.setContentPane(new JScrollPane(table));
                dialogDecisionSupport.invalidate();
                dialogDecisionSupport.validate();
                dialogDecisionSupport.setSize(600, 300);
                dialogDecisionSupport.setTitle("Decision Support Table");
                dialogDecisionSupport.setVisible(true);
                dialogDecisionSupport.toFront();
                GuiUtils.centerOnScreen(dialogDecisionSupport);
            }
        });
        popup.show(source, event.getX(), event.getY());
    }
    super.mouseClicked(event, source);
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

public static boolean saveYesNoCancel(String titleMessage, int options) {
    final QueryBuilderPanel builderPanel = Globals.getMainFrame().getQueryBuilderPanel();
    if (!builderPanel.isCleaned()) {
        String message;/* www  . j  a  va 2 s.  c  o m*/
        if (Globals.isChartLoaded()) {
            if (!chartModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.chart.save");
        } else if (Globals.isReportLoaded()) {
            if (!reportModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.report.save");
        } else {
            if (!queryModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.query.save");
        }

        int option = JOptionPane.showConfirmDialog(Globals.getMainFrame(), message, titleMessage, options);
        if ((option == JOptionPane.CANCEL_OPTION) || (option == JOptionPane.CLOSED_OPTION)) {
            return false;
        } else if (option == JOptionPane.YES_OPTION) {
            if (Globals.isChartLoaded()) {
                new SaveChartAction().actionPerformed(null);
            } else if (Globals.isReportLoaded()) {
                new SaveReportAction().actionPerformed(null);
            } else {
                new SaveQueryAction().actionPerformed(null);
            }
        }
    }
    return true;
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

public static boolean saveYesNoCancel() {
    QueryBuilderPanel builderPanel = Globals.getMainFrame().getQueryBuilderPanel();
    if (!builderPanel.isCleaned()) {
        String message;/* w w w.  j  a  v a 2  s  . c o  m*/
        if (Globals.isChartLoaded()) {
            if (!chartModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.chart.save");
        } else if (Globals.isReportLoaded()) {
            if (!reportModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.report.save");
        } else {
            if (!queryModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.query.save");
        }

        int option = JOptionPane.showConfirmDialog(Globals.getMainFrame(), message,
                I18NSupport.getString("exit"), JOptionPane.YES_NO_CANCEL_OPTION);
        if ((option == JOptionPane.CANCEL_OPTION) || (option == JOptionPane.CLOSED_OPTION)) {
            return false;
        } else if (option == JOptionPane.YES_OPTION) {
            if (Globals.isChartLoaded()) {
                SaveChartAction action = new SaveChartAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            } else if (Globals.isReportLoaded()) {
                SaveReportAction action = new SaveReportAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            } else {
                SaveQueryAction action = new SaveQueryAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            }
        }
    }
    return true;
}

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();/*from  w w  w  .j  av a 2  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();
    }
}

From source file:SeedGenerator.MainForm.java

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing

    boolean open = false;
    if (threadsSparql != null) {
        for (Thread t : threadsSparql) {
            try {
                if (((WorkerSparql) t).isAlive()) {
                    open = true;//from   w  w  w  .  j  ava  2  s  .c om
                }
            } catch (Exception ex) {
            }
        }
    }
    if (threadsSearchQueue != null) {
        for (Thread t : threadsSearchQueue) {
            try {
                if (((WorkerSearchQueue) t).isAlive()) {
                    open = true;
                }
            } catch (Exception ex) {
            }
        }
    }
    if (threadsAnalysis != null) {
        for (Thread t : threadsAnalysis) {
            try {
                if (((WorkerAnalyze) t).isAlive()) {
                    open = true;
                }

            } catch (Exception ex) {
            }
        }
    }
    if (open) {
        int safe = JOptionPane.showConfirmDialog(null,
                "Please close all threads before closing. Do you want to enforce closing?", "Warning",
                JOptionPane.YES_NO_CANCEL_OPTION);

        if (safe == JOptionPane.YES_OPTION) {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);//yes

        } else if (safe == JOptionPane.CANCEL_OPTION) {
            setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);//cancel
        } else {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);//no
        }
    }

    // TODO add your handling code here:// TODO add your handling code here:
}