Example usage for javax.swing JOptionPane CLOSED_OPTION

List of usage examples for javax.swing JOptionPane CLOSED_OPTION

Introduction

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

Prototype

int CLOSED_OPTION

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

Click Source Link

Document

Return value from class method if user closes window without selecting anything, more than likely this should be treated as either a CANCEL_OPTION or NO_OPTION.

Usage

From source file:gov.nij.er.ui.EntityResolutionDemo.java

private void saveParameters(File file) {
    if (file.exists()) {
        int option = promptParametersFileOverwrite();
        if (option == JOptionPane.NO_OPTION || option == JOptionPane.CLOSED_OPTION
                || option == JOptionPane.CANCEL_OPTION) {
            return;
        }/*from www.  j a va  2 s.  c o m*/
    }
    File enhancedFile = file;
    if (!file.getName().contains(SINGLE_DOT)) {
        enhancedFile = new File(file.getAbsolutePath() + SINGLE_DOT + PARAMETER_FILE_EXTENSION);
    }
    ObjectOutput output = null;
    try {
        output = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(enhancedFile)));
        output.writeObject(parametersTableModel.getAttributeParameters());
        LOG.debug("Wrote parameters to file " + enhancedFile.getAbsolutePath());
    } catch (IOException ex) {
        error("Error writing parameters to a file.");
        ex.printStackTrace();
    } finally {
        try {
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.sshtools.j2ssh.authentication.UserGridCredential.java

private static GSSCredential chooseCert(int proxyType, int lifetimeHours, SshConnectionProperties props)
        throws IOException, IllegalArgumentException, IllegalStateException {
    String dProfile = PreferencesStore.get(SshTerminalPanel.PREF_BROWSER_PROFILE, null);
    String dDN = PreferencesStore.get(SshTerminalPanel.PREF_BROWSER_DN, null);
    if (props instanceof SshToolsConnectionProfile) {
        SshToolsConnectionProfile profile = (SshToolsConnectionProfile) props;
        dProfile = profile.getApplicationProperty(SshTerminalPanel.PREF_BROWSER_PROFILE, dProfile);
        dDN = profile.getApplicationProperty(SshTerminalPanel.PREF_BROWSER_DN, dDN);
    }/*w w w  .j  a va2  s . co  m*/

    String profile = Browser.getCurrentBrowser();
    if (profile == null) {
        String profiles[] = Browser.getBrowserList();
        if (profiles == null)
            return null;
        if (profiles.length == 0) {
            JOptionPane.showMessageDialog(props.getWindow(), "No browsers found", "GSI-SSHTerm Authentication",
                    JOptionPane.ERROR_MESSAGE);
            return null;
        }
        if (profiles.length == 1) {
            Browser.setBrowser(profiles[0]); //user chooses profile.
        } else {
            boolean chosen = false;
            if (dProfile != null) {
                for (String p : profiles) {
                    if (p.equals(dProfile)) {
                        chosen = true;
                        Browser.setBrowser(p);
                    }
                }
            }
            if (!chosen) {
                JComboBox combo = new JComboBox(profiles);
                int ret = JOptionPane.showOptionDialog(props.getWindow(), "Please choose browser to use:",
                        "Grid Authentication", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                        new Object[] { combo, "OK" }, null);
                if (ret == JOptionPane.CLOSED_OPTION)
                    new IOException("Canceled by user.");
                Browser.setBrowser(profiles[combo.getSelectedIndex()]); //user chooses profile.
            }
        }
        profile = Browser.getCurrentBrowser();
    }
    String dnlist[] = null;
    try {
        dnlist = Browser.getDNlist(new PasswordPrompt(props));
    } catch (IOException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (KeyStoreException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (CertificateException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
        log.debug("Could not access keystore in profile: " + profile + " : " + e);
    } catch (javax.security.auth.login.FailedLoginException e) {
        JOptionPane.showMessageDialog(props.getWindow(), e.getMessage(), "Incorrect Password",
                JOptionPane.ERROR_MESSAGE);
        return null;
    } catch (GeneralSecurityException e) {
        if (e.getMessage().indexOf("version>=1.5") >= 0) {
            JOptionPane.showMessageDialog(props.getWindow(), e.getMessage(), "GSI-SSHTerm Authentication",
                    JOptionPane.ERROR_MESSAGE);
        } else {
            e.printStackTrace();
            errorReport(props.getWindow(), "Could not access keystore in profile: " + profile, e);
            log.debug("Could not access keystore in profile: " + profile + " : " + e);
        }
    }
    if (dnlist == null)
        return null;
    int index = -1;
    if (dnlist.length == 0) {
        JOptionPane.showMessageDialog(props.getWindow(), "No Certificates found", "GSI-SSHTerm Authentication",
                JOptionPane.ERROR_MESSAGE);
        return null;
    }
    if (dnlist.length == 1) {
        index = 0;
    } else {
        if (dDN != null) {
            for (int i = 0; i < dnlist.length; i++) {
                if (dnlist[i].equals(dDN)) {
                    index = i;
                }
            }
        }
        if (index == -1) {
            JComboBox dnCombo = new JComboBox(dnlist);

            int ret = JOptionPane.showOptionDialog(props.getWindow(), "Please choose certificate to use:",
                    "GSI-SSHTerm Authentication", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { dnCombo, "OK" }, null);
            if (ret == JOptionPane.CLOSED_OPTION)
                new IOException("Canceled by user.");
            index = dnCombo.getSelectedIndex();
        }
    }
    try {
        GSSCredential gssproxy = Browser.getGridProxy(dnlist[index], proxyType, lifetimeHours);

        if (SAVE_BROWSER_PROXY) {
            GlobusCredential proxy = ((GlobusGSSCredentialImpl) gssproxy).getGlobusCredential();
            ProxyHelper.saveProxy(proxy, props);
        }
        return gssproxy;
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e);
        log.debug("Could not load certificate from browser: " + e);
    } catch (GlobusCredentialException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e);
        log.debug("Could not load certificate from browser: " + e);
    } catch (GSSException e) {
        e.printStackTrace();
        errorReport(props.getWindow(), "Could not load certificate from profile: " + profile, e);
        log.debug("Could not load certificate from browser: " + e);
    }
    return null;
}

From source file:com.mirth.connect.client.ui.SettingsPanelServer.java

public void doBackup() {
    if (isSaveEnabled()) {
        int option = JOptionPane.showConfirmDialog(this, "Would you like to save the settings first?");

        if (option == JOptionPane.YES_OPTION) {
            if (!doSave()) {
                return;
            }// ww w.ja  va2 s  .co m
        } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            return;
        }
    }

    final String backupDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    final File exportFile = getFrame().createFileForExport(backupDate.substring(0, 10) + " Mirth Backup.xml",
            "XML");

    if (exportFile != null) {
        final String workingId = getFrame().startWorking("Exporting server config...");

        SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

            public Void doInBackground() {
                ServerConfiguration configuration = null;

                try {
                    configuration = getFrame().mirthClient.getServerConfiguration();
                } catch (ClientException e) {
                    getFrame().alertThrowable(SettingsPanelServer.this, e);
                    return null;
                }

                // Update resource names
                for (Channel channel : configuration.getChannels()) {
                    getFrame().updateResourceNames(channel, configuration.getResourceProperties().getList());
                }

                configuration.setDate(backupDate);
                String backupXML = ObjectXMLSerializer.getInstance().serialize(configuration);

                getFrame().exportFile(backupXML, exportFile, "Server Configuration");
                return null;
            }

            public void done() {
                getFrame().stopWorking(workingId);
            }
        };

        worker.execute();
    }
}

From source file:gui.QTLResultsPanel.java

void saveTXT() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(Prefs.gui_dir));
    fc.setDialogTitle("Save QTL Results");

    while (fc.showSaveDialog(MsgBox.frm) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        // Make sure it has an appropriate extension
        if (!file.exists()) {
            if (file.getName().indexOf(".") == -1) {
                file = new File(file.getPath() + ".csv");
            }//from   w ww . j a v a 2s  .  c o  m
        }

        // Confirm overwrite
        if (file.exists()) {
            int response = MsgBox.yesnocan(file + " already exists.\nDo " + "you want to replace it?", 1);

            if (response == JOptionPane.NO_OPTION) {
                continue;
            } else if (response == JOptionPane.CANCEL_OPTION || response == JOptionPane.CLOSED_OPTION) {
                return;
            }
        }

        // Otherwise it's ok to save...
        Prefs.gui_dir = "" + fc.getCurrentDirectory();
        saveTXTFile(file);
        return;
    }
}

From source file:com.qawaa.gui.PointAnalysisGUI.java

/**
 * ?//from w  w  w  . java2  s  . c  om
 * @param evt
 * @throws InterruptedException 
 */
private static void submitActionPerformed(ActionEvent evt) throws InterruptedException {
    EventDailyPointAnalysisThread edpaThread = EventDailyPointAnalysisThread.Instance();
    EventHourlyPointAnalysisThread ehpaThread = EventHourlyPointAnalysisThread.Instance();
    EventRealTimePointAnalysisThread erpaThread = EventRealTimePointAnalysisThread.Instance();
    if (RUNNING) {
        JOptionPane.showConfirmDialog(null, CONTEXT.getMessage("gobal.stop.dialog.msg", null, Locale.CHINA),
                CONTEXT.getMessage("gobal.stop.dialog.title", null, Locale.CHINA), JOptionPane.CLOSED_OPTION,
                JOptionPane.CLOSED_OPTION);
        return;
    }
    submit.setText(CONTEXT.getMessage("gobal.gui.button.init", null, Locale.CHINA));
    submit.setEnabled(false);
    LOG.info(CONTEXT.getMessage("gobal.db.connect", null, Locale.CHINA));
    Thread.sleep(1000L);
    WebScanControl c = WebScanControl.getInstance();
    try {
        if (!HibernateDataBaseCheck.check()) {
            LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
            submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
            submit.setEnabled(true);
            return;
        }
    } catch (Exception e) {
        LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    }
    LOG.info(CONTEXT.getMessage("gobal.db.connect.success", null, Locale.CHINA));
    Thread.sleep(500L);
    LOG.info(CONTEXT.getMessage("point.event.check", null, Locale.CHINA));
    if (c.isExistEventList()) {
        LOG.error(CONTEXT.getMessage("point.event.null", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    } else {
        LOG.info(CONTEXT.getMessage("point.event.check.success", null, Locale.CHINA));
    }
    LOG.info(CONTEXT.getMessage("point.start", null, Locale.CHINA));
    Thread.sleep(1000L);
    submit.setText(CONTEXT.getMessage("gobal.gui.button.stop", null, Locale.CHINA));
    submit.setEnabled(true);
    RUNNING = true;
    RunTimeListener runTimeListener = new RunTimeListener(runtime_value);
    runTimeListener.start();
    edpaThread.start();
    ehpaThread.start();
    erpaThread.start();
}

From source file:com.qawaa.gui.EventWebScanGUI.java

/**
 * ?//from w w w .  ja  v  a 2  s .  c o  m
 * @param evt
 * @throws InterruptedException 
 */
private static void submitActionPerformed(ActionEvent evt) throws InterruptedException {
    WebSearchScanThread wssThread = WebSearchScanThread.Instance();
    if (RUNNING) {
        wssThread.threadStop();
        JOptionPane.showConfirmDialog(null, CONTEXT.getMessage("gobal.stop.dialog.msg", null, Locale.CHINA),
                CONTEXT.getMessage("gobal.stop.dialog.title", null, Locale.CHINA), JOptionPane.CLOSED_OPTION,
                JOptionPane.CLOSED_OPTION);
        return;
    }
    submit.setText(CONTEXT.getMessage("gobal.gui.button.init", null, Locale.CHINA));
    submit.setEnabled(false);
    LOG.info(CONTEXT.getMessage("gobal.db.connect", null, Locale.CHINA));
    Thread.sleep(1000L);
    WebScanControl c = WebScanControl.getInstance();
    try {
        if (!HibernateDataBaseCheck.check()) {
            LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
            submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
            submit.setEnabled(true);
            return;
        }
    } catch (Exception e) {
        LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    }
    LOG.info(CONTEXT.getMessage("gobal.db.connect.success", null, Locale.CHINA));
    Thread.sleep(500L);
    LOG.info(CONTEXT.getMessage("event.web.scan.event.check", null, Locale.CHINA));
    if (c.isExistEventList()) {
        LOG.error(CONTEXT.getMessage("event.web.scan.event.null", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    } else {
        LOG.info(CONTEXT.getMessage("event.web.scan.event.check.success", null, Locale.CHINA));
    }
    LOG.info(CONTEXT.getMessage("event.web.scan.start", null, Locale.CHINA));
    Thread.sleep(1000L);
    submit.setText(CONTEXT.getMessage("gobal.gui.button.stop", null, Locale.CHINA));
    submit.setEnabled(true);
    RUNNING = true;
    RunTimeListener runTimeListener = new RunTimeListener(runtime_value);
    runTimeListener.start();
    wssThread.start();
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

public boolean promptSave(boolean force) {
    stopTableEditing();//  w  ww .j a v a  2s  .  co m
    int option;

    if (force) {
        option = JOptionPane.showConfirmDialog(parent,
                "You must save the code template changes before continuing. Would you like to save now?");
    } else {
        option = JOptionPane.showConfirmDialog(parent, "Would you like to save the code templates?");
    }

    if (option == JOptionPane.YES_OPTION) {
        CodeTemplateLibrarySaveResult updateSummary = doSaveCodeTemplates(false);

        if (updateSummary == null || updateSummary.isOverrideNeeded() || !updateSummary.isLibrariesSuccess()) {
            return false;
        } else {
            for (CodeTemplateUpdateResult result : updateSummary.getCodeTemplateResults().values()) {
                if (!result.isSuccess()) {
                    return false;
                }
            }
        }
    } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION
            || (option == JOptionPane.NO_OPTION && force)) {
        return false;
    }

    return true;
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void addEmptyNode(final PhylogenyNode node) {
    if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) {
        errorMessageNoCutCopyPasteInUnrootedDisplay();
        return;/*  www.  ja  v a  2  s. c o m*/
    }
    final String label = getASimpleTextRepresentationOfANode(node);
    String msg = "";
    if (ForesterUtil.isEmpty(label)) {
        msg = "How to add the new, empty node?";
    } else {
        msg = "How to add the new, empty node to node" + label + "?";
    }
    final Object[] options = { "As sibling", "As descendant", "Cancel" };
    final int r = JOptionPane.showOptionDialog(this, msg, "Addition of Empty New Node",
            JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
    boolean add_as_sibling = true;
    if (r == 1) {
        add_as_sibling = false;
    } else if (r != 0) {
        return;
    }
    final Phylogeny phy = new Phylogeny();
    phy.setRoot(new PhylogenyNode());
    phy.setRooted(true);
    if (add_as_sibling) {
        if (node.isRoot()) {
            JOptionPane.showMessageDialog(this, "Cannot add sibling to root", "Attempt to add sibling to root",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        phy.addAsSibling(node);
    } else {
        phy.addAsChild(node);
    }
    _phylogeny.externalNodesHaveChanged();
    _phylogeny.hashIDs();
    _phylogeny.recalculateNumberOfExternalDescendants(true);
    resetNodeIdToDistToLeafMap();
    setEdited(true);
    repaint();
}

From source file:net.pms.newgui.GeneralTab.java

public void addPlugins() {
    FormLayout layout = new FormLayout("fill:10:grow",
            "p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p");
    PanelBuilder builder = new PanelBuilder(layout);

    CellConstraints cc = new CellConstraints();
    int i = 1;// w  ww. j  av  a 2s .  c  o m
    for (final ExternalListener listener : ExternalFactory.getExternalListeners()) {
        if (i > 30) {
            logger.warn("Plugin limit of 30 has been reached");
            break;
        }
        JButton bPlugin = new JButton(listener.name());
        // listener to show option screen
        bPlugin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showOptionDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        listener.config(), Messages.getString("Dialog.Options"), JOptionPane.CLOSED_OPTION,
                        JOptionPane.PLAIN_MESSAGE, null, null, null);
            }
        });
        builder.add(bPlugin, cc.xy(1, i++));
    }
    pPlugins.add(builder.getPanel());
}

From source file:de.ailis.xadrian.frames.MainFrame.java

/**
 * Closes the current tab. Prompts for saving unsaved changes before
 * closing. Returns true if the tab was closed or false if it was not
 * closed./*from w  w w . j  a v a2  s  .  c  o  m*/
 *
 * @return True if tab was closed, false if not
 */
public boolean closeCurrentTab() {
    final Component current = getCurrentTab();
    if (current != null) {
        final ComplexEditor editor = (ComplexEditor) current;
        if (editor.isChanged()) {
            final int answer = JOptionPane.showConfirmDialog(null,
                    I18N.getString("confirm.saveChanges", editor.getComplex().getName()),
                    I18N.getTitle("confirm.saveChanges"), JOptionPane.YES_NO_CANCEL_OPTION);
            if (answer == JOptionPane.CLOSED_OPTION)
                return false;
            if (answer == JOptionPane.CANCEL_OPTION)
                return false;
            if (answer == JOptionPane.YES_OPTION) {
                editor.save();
                if (editor.isChanged())
                    return false;
            }
        }

        this.tabs.remove(current);

        // Replace the tab control with the welcome panel if no tabs present
        if (this.tabs.getTabCount() == 0) {
            remove(this.tabs);
            add(this.welcomePanel, BorderLayout.CENTER);
            repaint();
        }

        fireChange();
        return true;
    }
    return false;
}