Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

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

Prototype

int NO_OPTION

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

Click Source Link

Document

Return value from class method if NO is chosen.

Usage

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java

private void chooseImportType() {
    int rv = UIRegistry.askYesNoLocalized(SL_CHS_IMP, SL_CHS_LOC, getResourceString("SL_CHOOSEIMPMSG"),
            "SL_CHOOSEIMPMSG_TITLE");
    if (rv == JOptionPane.YES_OPTION || rv == JOptionPane.NO_OPTION) {
        importSchema(rv == JOptionPane.NO_OPTION);
    }//from   www.  j  ava  2  s  .com
}

From source file:net.sf.jhylafax.SendDialog.java

private boolean checkPostScript(String filename) {
    try {/*from   w  w w .java 2  s .  c  o m*/
        if (!HylaFAXClientHelper.isPostscript(filename)) {
            if (Dialogs.showConfirmDialog(this,
                    i18n.tr("Do you really want to send the non PostScript file \"{0}\"?", filename),
                    i18n.tr("JHylaFAX - Send non PostScript file"), JOptionPane.YES_NO_OPTION,
                    Settings.CONFIRM_NONPS) == JOptionPane.NO_OPTION) {
                return false;
            }
        }
    } catch (IOException e) {
        logger.debug("Error checking for PostScript", e);
        ErrorDialog.showError(this, i18n.tr("Could not check for PostScript"), i18n.tr("JHylaFAX Error"), e);
        return false;
    }
    return true;
}

From source file:net.sf.profiler4j.console.Console.java

public void openProject() {

    if (client.isConnected()) {
        int ret = JOptionPane.showConfirmDialog(mainFrame, "Proceed and disconnect?", "Open Profiling Project",
                JOptionPane.YES_NO_OPTION);
        if (ret == JOptionPane.NO_OPTION) {
            return;
        }//from  www . jav  a 2 s  . c  om
    }

    if (checkUnsavedChanges()) {
        return;
    }

    if (client.isConnected()) {
        disconnect();
        if (client.isConnected()) {
            return;
        }
    }
    JFileChooser fc = new JFileChooser(lastDir);
    fc.addChoosableFileFilter(projectFilter);
    if (fc.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
        File selFile = fc.getSelectedFile();
        SAXBuilder builder = new SAXBuilder();
        Document doc = null;
        try {
            doc = builder.build(selFile);
        } catch (JDOMException e) {
            error("XML Error", e);
        } catch (IOException e) {
            error("I/O Error", e);
        }
        if (doc != null) {
            Project p = new Project();
            Element el = doc.getRootElement();
            p.setHostname(el.getChildText("Host"));
            p.setPort(Integer.parseInt(el.getChildText("Port")));
            Element rulesEl = el.getChild("Rules");

            p.setAccess(Rule.AccessOption.valueOf(rulesEl.getAttributeValue("access")));
            p.setBeanprops(Boolean.parseBoolean(rulesEl.getAttributeValue("beanProps")));

            p.getRules().clear();
            for (Iterator i = rulesEl.getChildren("Rule").iterator(); i.hasNext();) {
                Element r = (Element) i.next();
                Rule rule = new Rule(r.getText(), Rule.Action.valueOf(r.getAttributeValue("action")));
                p.getRules().add(rule);
            }

            // Backwards compatible way to read the export pattern
            // If it is not there, we leave the defaults as they are,
            // otherwise we set the saved setting.
            Element export = el.getChild(PROJECT_XML_ELEMENT__EXPORT_PATTERN);
            if (null != export) {
                String enabled = export.getAttributeValue(PROJECT_XML_ATTRIBUTE__ENABLED);
                p.setExportAutomaticallyEnabled(Boolean.valueOf(enabled));
                p.setExportPattern(export.getAttributeValue(PROJECT_XML_ATTRIBUTE__PATTERN));
            }

            p.setFile(selFile);
            p.clearChanged();
            this.project = p;
            lastDir = selFile.getParentFile();
        }
    }

}

From source file:es.emergya.ui.plugins.admin.AdminRoles.java

protected SummaryAction getSummaryAction(final Rol r) {
    SummaryAction action = new SummaryAction(r) {

        private static final long serialVersionUID = -601099799668196685L;

        @Override//w w  w  .j ava 2s . co m
        protected JFrame getSummaryDialog() {
            final String titulo;
            final String cabecera;
            if (isNew) {
                titulo = i18n.getString("admin.roles.tituloVentana.nuevo"); //$NON-NLS-1$
                cabecera = i18n.getString("admin.roles.cabecera.nuevo");//$NON-NLS-1$
            } else {
                titulo = i18n.getString("admin.roles.tituloVentana.existente"); //$NON-NLS-1$
                cabecera = i18n.getString("admin.roles.cabecera.existente");//$NON-NLS-1$
            }
            final String label_cabecera = i18n.getString("admin.roles7"); //$NON-NLS-1$
            final String label_pie = i18n.getString("admin.roles8"); //$NON-NLS-1$
            final String centered_label = i18n.getString("admin.roles9"); //$NON-NLS-1$
            final String left_label = i18n.getString("admin.roles10"); //$NON-NLS-1$
            final String right_label = i18n.getString("admin.roles11"); //$NON-NLS-1$

            final Flota[] left_items = RolConsultas.getDisponibles(r);
            final Flota[] right_items = RolConsultas.getAsigned(r);
            final AdminPanel.SaveOrUpdateAction<Rol> guardar = roles.new SaveOrUpdateAction<Rol>(r) {

                private static final long serialVersionUID = 7447770196943361404L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (textfieldCabecera.getText().trim().isEmpty()) {
                        JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.roles13")); //$NON-NLS-1$
                    } else if (isNew && RolConsultas.alreadyExists(textfieldCabecera.getText().trim())) {
                        JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.roles14")); //$NON-NLS-1$
                    } else if (textfieldCabecera.getText().isEmpty()) {
                        JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.roles15")); //$NON-NLS-1$
                    } else if (cambios) {
                        int i = JOptionPane.showConfirmDialog(super.frame, i18n.getString("admin.roles16"), //$NON-NLS-1$
                                i18n.getString("admin.roles17"), //$NON-NLS-1$
                                JOptionPane.YES_NO_CANCEL_OPTION);

                        if (i == JOptionPane.YES_OPTION) {

                            if (original == null) {
                                original = new Rol();
                            }

                            original.setInfoAdicional(textfieldPie.getText());
                            original.setNombre(textfieldCabecera.getText());

                            HashSet<Flota> flotas = new HashSet<Flota>();
                            for (Object r : ((DefaultListModel) right.getModel()).toArray()) {
                                if (r instanceof Flota) {
                                    flotas.add((Flota) r);
                                } else {
                                    log.error(i18n.getString("admin.roles18")); //$NON-NLS-1$
                                }
                            }
                            original.setFlotas(flotas);

                            RolAdmin.saveOrUpdate(original);
                            PluginEventHandler.fireChange(AdminRoles.this);

                            cambios = false;
                            original = null;

                            roles.setTableData(getAll(new Rol()));

                            closeFrame();
                        } else if (i == JOptionPane.NO_OPTION) {
                            closeFrame();
                        }
                    } else {
                        closeFrame();
                    }
                }
            };

            d = generateIconDialog(label_cabecera, label_pie, centered_label, titulo, left_items, right_items,
                    left_label, right_label, guardar, LogicConstants.getIcon(i18n.getString("admin.roles19")),
                    cabecera, null); //$NON-NLS-1$ //$NON-NLS-2$

            if (r != null) {
                textfieldCabecera.setText(r.getNombre());
                // textfieldCabecera.setEnabled(false);
                textfieldCabecera.setEditable(false);
                textfieldPie.setText(r.getInfoAdicional());
            } else {
                textfieldCabecera.setText(""); //$NON-NLS-1$
                textfieldCabecera.setEnabled(true);
                textfieldPie.setText(""); //$NON-NLS-1$
            }
            cambios = false;

            return d;
        }
    };

    return action;
}

From source file:es.emergya.ui.plugins.admin.AdminSquads.java

protected SummaryAction getSummaryAction(final Patrulla p) {
    SummaryAction action = new SummaryAction(p) {

        private static final long serialVersionUID = -8344125339845145826L;

        @Override//from   w w  w  . j ava  2 s .c o m
        protected JFrame getSummaryDialog() {
            final String label_cabecera = "Nombre Patrulla:";
            final String label_pie = "Info Adicional:";
            final String centered_label = "Recursos:";
            final String left_label = "Recursos disponibles";
            final String right_label = "Recursos asignados";
            final String titulo, cabecera;
            if (isNew) {
                titulo = i18n.getString("Squads.barraTitulo.nuevo");
                cabecera = i18n.getString("Squads.cabecera.nuevo");

            } else {
                titulo = i18n.getString("Squads.barraTitulo.existente");
                cabecera = i18n.getString("Squads.cabecera.existente");
            }
            final Recurso[] left_items = RecursoConsultas.getNotAsigned(p);
            for (Recurso r : left_items)
                r.setTipoToString(Recurso.TIPO_TOSTRING.PATRULLA);
            final Recurso[] right_items = RecursoConsultas.getAsigned(p);
            for (Recurso r : right_items)
                r.setTipoToString(Recurso.TIPO_TOSTRING.PATRULLA);
            final AdminPanel.SaveOrUpdateAction<Patrulla> guardar = squads.new SaveOrUpdateAction<Patrulla>(p) {

                private static final long serialVersionUID = 7447770296943341404L;

                @Override
                public void actionPerformed(ActionEvent e) {

                    if (isNew && PatrullaConsultas.alreadyExists(textfieldCabecera.getText())) {
                        JOptionPane.showMessageDialog(super.frame, "Ya existe una patrulla con ese nombre.");
                    } else if (textfieldCabecera.getText().isEmpty()) {
                        JOptionPane.showMessageDialog(super.frame, "El nombre es obligatorio.");
                    } else if (cambios) {
                        int i = JOptionPane.showConfirmDialog(super.frame, "Desea guardar los cambios?",
                                "Guardar", JOptionPane.YES_NO_CANCEL_OPTION);

                        if (i == JOptionPane.YES_OPTION) {

                            if (original == null) {
                                original = new Patrulla();
                            }

                            original.setInfoAdicional(textfieldPie.getText());
                            original.setNombre(textfieldCabecera.getText());

                            HashSet<Recurso> recursos = new HashSet<Recurso>();
                            for (Object r : ((DefaultListModel) right.getModel()).toArray()) {
                                if (r instanceof Recurso) {
                                    recursos.add((Recurso) r);
                                    ((Recurso) r).setPatrullas(original);
                                } else {
                                    log.error("El objeto no era un recurso");
                                }
                            }
                            original.setRecursos(recursos);

                            PatrullaAdmin.saveOrUpdate(original);
                            PluginEventHandler.fireChange(AdminSquads.this);

                            cambios = false;
                            original = null;

                            squads.setTableData(getAll(new Patrulla()));

                            closeFrame();
                        } else if (i == JOptionPane.NO_OPTION) {
                            closeFrame();
                        }
                    } else {
                        closeFrame();
                    }
                }
            };

            // if (d == null)
            d = generateIconDialog(label_cabecera, label_pie, centered_label, titulo, left_items, right_items,
                    left_label, right_label, guardar, LogicConstants.getIcon("tittleficha_icon_patrulla"),
                    cabecera, null);

            if (p != null) {
                textfieldCabecera.setText(p.getNombre());
                textfieldPie.setText(p.getInfoAdicional());
                textfieldCabecera.setEditable(false);
            } else {
                textfieldCabecera.setText("");
                textfieldPie.setText("");
            }
            cambios = false;

            return d;
        }
    };

    return action;
}

From source file:com.dragoniade.deviantart.deviation.SearchStream.java

public List<Collection> getCollections() {
    List<Collection> collections = new ArrayList<Collection>();

    if (search.getCollection() == null) {
        collections.add(null);//from w ww  .j a v  a2  s .co m
        return collections;
    }

    String queryString = "http://" + user + ".deviantart.com/" + search.getCollection() + "/";
    GetMethod method = new GetMethod(queryString);

    try {
        int sc = -1;
        do {
            sc = client.executeMethod(method);
            if (sc != 200) {
                LoggableException ex = new LoggableException(method.getResponseBodyAsString());
                Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex);

                int res = DialogHelper.showConfirmDialog(owner,
                        "An error has occured when contacting deviantART : error " + sc + ". Try again?",
                        "Continue?", JOptionPane.YES_NO_OPTION);
                if (res == JOptionPane.NO_OPTION) {
                    return null;
                }
            }
        } while (sc != 200);

        InputStream is = method.getResponseBodyAsStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte[] buffer = new byte[4096];
        int read = -1;
        while ((read = is.read(buffer)) > -1) {
            baos.write(buffer, 0, read);
        }
        String charsetName = method.getResponseCharSet();
        String body = baos.toString(charsetName);
        String regex = user + ".deviantart.com/" + search.getCollection() + "/([0-9]+)\"[^>]*>([^<]+)<";
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(body);
        while (matcher.find()) {
            String id = matcher.group(1);
            String name = matcher.group(2);
            Collection c = new Collection(Long.parseLong(id), name);
            collections.add(c);
        }
    } catch (IOException e) {
    } finally {
        method.releaseConnection();
    }
    collections.add(null);
    return collections;
}

From source file:ca.uviccscu.lp.persistence.ChooseFolderDialog.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    String path = jTextField3.getText();
    File f = new File(path);
    l.trace("WFolder path entered: [" + path + "]");
    int verification = SettingsManager.verifyWorkingFolder(path);
    l.trace("Initial WFolder verification: " + verification);
    if (verification != 0) {
        switch (verification) {
        case (1): {
            if (path == null || path.equals("")) {
                verification = 8;/*from  w  ww .  j  a v a 2s .  c om*/
                l.trace("WFolder  verification ch: " + verification);
                JOptionPane.showMessageDialog(this, "Path field empty!", "WFolder creation error",
                        JOptionPane.ERROR_MESSAGE);
            }
            if (verification == 1) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    java.util.logging.Logger.getLogger(ChooseFolderDialog.class.getName()).log(Level.SEVERE,
                            null, ex);
                }
                int resp = JOptionPane.showConfirmDialog(this, "Directory doesn't exist! Create?",
                        "WFolder creation warning", JOptionPane.YES_NO_OPTION);
                if (resp == JOptionPane.YES_OPTION) {
                    verification = 0;
                    l.trace("WFolder verification ch: " + verification);
                } else if (resp == JOptionPane.NO_OPTION) {
                    verification = 7;
                    l.trace("WFolder verification ch: " + verification);
                }
            }
            break;
        }
        case (2): {
            if (path == null || path.equals("")) {
                verification = 8;
                l.trace("WFolder verification ch: " + verification);
                JOptionPane.showMessageDialog(this, "Path field empty!", "WFolder creation error",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Path not absolute!", "WFolder creation error",
                        JOptionPane.ERROR_MESSAGE);
            }
            break;
        }
        case (3): {
            JOptionPane.showMessageDialog(this, "Can't read!", "WFolder creation error",
                    JOptionPane.ERROR_MESSAGE);
            break;
        }
        case (4): {
            JOptionPane.showMessageDialog(this, "Can't write!", "WFolder creation error",
                    JOptionPane.ERROR_MESSAGE);
            break;
        }
        case (5): {
            JOptionPane.showMessageDialog(this, "File error!", "WFolder creation error",
                    JOptionPane.ERROR_MESSAGE);
            break;
        }
        case (6): {
            //JOptionPane.showMessageDialog(this, "File error!", "WFolder creation error", JOptionPane.ERROR_MESSAGE);
            l.error("Directory not empty");
            l.trace("WFolder verification ch: " + verification);
            //JDialog jd = new JDialog((JFrame) null, true);
            int resp = JOptionPane.showConfirmDialog(null,
                    "Directory nonempty: " + f.getAbsolutePath() + ". Wipe and proceed?", "Confirm deletion",
                    JOptionPane.YES_NO_OPTION);
            if (resp == JOptionPane.YES_OPTION) {
                try {
                    FileUtils.deleteDirectory(f);
                    verification = 0;
                } catch (IOException ex) {
                    l.fatal("Can't wipe directory", ex);
                    System.exit(1);
                }
            }
            break;
        }
        }
    }
    l.trace("Final WFolder verification: " + verification);
    if (verification == 0) {
        Shared.lastFolder_path = path;
        Shared.lastFolder_verification = verification;
        Shared.lastFolder_wasCancelled = false;
        this.setVisible(false);
    }
}

From source file:com.piusvelte.taplock.server.TapLockServer.java

private static void initialize() {
    (new File(APP_PATH)).mkdir();
    if (OS == OS_WIN)
        Security.addProvider(new BouncyCastleProvider());
    System.out.println("APP_PATH: " + APP_PATH);
    try {//w  w w  .j av a  2  s. c  o m
        sLogFileHandler = new FileHandler(sLog);
    } catch (SecurityException e) {
        writeLog("sLogFileHandler init: " + e.getMessage());
    } catch (IOException e) {
        writeLog("sLogFileHandler init: " + e.getMessage());
    }

    File propertiesFile = new File(sProperties);
    if (!propertiesFile.exists()) {
        try {
            propertiesFile.createNewFile();
        } catch (IOException e) {
            writeLog("propertiesFile.createNewFile: " + e.getMessage());
        }
    }

    Properties prop = new Properties();

    try {
        prop.load(new FileInputStream(sProperties));
        if (prop.isEmpty()) {
            prop.setProperty(sPassphraseKey, sPassphrase);
            prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray));
            prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging));
            prop.store(new FileOutputStream(sProperties), null);
        } else {
            if (prop.containsKey(sPassphraseKey))
                sPassphrase = prop.getProperty(sPassphraseKey);
            else
                prop.setProperty(sPassphraseKey, sPassphrase);
            if (prop.containsKey(sDisplaySystemTrayKey))
                sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey));
            else
                prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray));
            if (prop.containsKey(sDebuggingKey))
                sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey));
            else
                prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging));
        }
    } catch (FileNotFoundException e) {
        writeLog("prop load: " + e.getMessage());
    } catch (IOException e) {
        writeLog("prop load: " + e.getMessage());
    }

    if (sLogFileHandler != null) {
        sLogger = Logger.getLogger("TapLock");
        sLogger.setUseParentHandlers(false);
        sLogger.addHandler(sLogFileHandler);
        SimpleFormatter sf = new SimpleFormatter();
        sLogFileHandler.setFormatter(sf);
        writeLog("service starting");
    }

    if (sDisplaySystemTray && SystemTray.isSupported()) {
        final SystemTray systemTray = SystemTray.getSystemTray();
        Image trayIconImg = Toolkit.getDefaultToolkit()
                .getImage(TapLockServer.class.getResource("/systemtrayicon.png"));
        final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock");
        trayIcon.setImageAutoSize(true);
        PopupMenu popupMenu = new PopupMenu();
        MenuItem aboutItem = new MenuItem("About");
        CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray");
        toggleSystemTrayIcon.setState(sDisplaySystemTray);
        CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging");
        toggleDebugging.setState(sDebugging);
        MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server");
        popupMenu.add(aboutItem);
        popupMenu.add(toggleSystemTrayIcon);
        if (OS == OS_WIN) {
            MenuItem setPasswordItem = new MenuItem("Set password");
            popupMenu.add(setPasswordItem);
            setPasswordItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JPanel panel = new JPanel();
                    JLabel label = new JLabel("Enter your Windows account password:");
                    JPasswordField passField = new JPasswordField(32);
                    panel.add(label);
                    panel.add(passField);
                    String[] options = new String[] { "OK", "Cancel" };
                    int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION,
                            JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
                    if (option == 0) {
                        String password = encryptString(new String(passField.getPassword()));
                        if (password != null) {
                            Properties prop = new Properties();
                            try {
                                prop.load(new FileInputStream(sProperties));
                                prop.setProperty(sPasswordKey, password);
                                prop.store(new FileOutputStream(sProperties), null);
                            } catch (FileNotFoundException e1) {
                                writeLog("prop load: " + e1.getMessage());
                            } catch (IOException e1) {
                                writeLog("prop load: " + e1.getMessage());
                            }
                        }
                    }
                }
            });
        }
        popupMenu.add(toggleDebugging);
        popupMenu.add(shutdownItem);
        trayIcon.setPopupMenu(popupMenu);
        try {
            systemTray.add(trayIcon);
        } catch (AWTException e) {
            writeLog("systemTray.add: " + e.getMessage());
        }
        aboutItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String newline = System.getProperty("line.separator");
                newline += newline;
                JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel"
                        + newline
                        + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version."
                        + newline
                        + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details."
                        + newline
                        + "You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>."
                        + newline + "Bryan Emmanuel piusvelte@gmail.com");
            }
        });
        toggleSystemTrayIcon.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED);
                if (!sDisplaySystemTray)
                    systemTray.remove(trayIcon);
            }
        });
        toggleDebugging.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                setDebugging(e.getStateChange() == ItemEvent.SELECTED);
            }
        });
        shutdownItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                shutdown();
            }
        });
    }
    synchronized (sConnectionThreadLock) {
        (sConnectionThread = new ConnectionThread()).start();
    }
}

From source file:net.sf.jabref.exporter.SaveDatabaseAction.java

private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
    SaveSession session;/*from w  ww.jav a 2  s. c  om*/
    frame.block();
    try {
        SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs)
                .withEncoding(encoding);
        BibDatabaseWriter databaseWriter = new BibDatabaseWriter();
        if (selectedOnly) {
            session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), prefs,
                    panel.getSelectedEntries());

        } else {
            session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);

        }
        panel.registerUndoableChanges(session);

    } catch (UnsupportedCharsetException ex2) {
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not save file.") + Localization
                        .lang("Character encoding '%0' is not supported.", encoding.displayName()),
                Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex == SaveException.FILE_LOCKED) {
            throw ex;
        }
        if (ex.specificEntry()) {
            // Error occured during processing of
            // be. Highlight it:
            int row = panel.mainTable.findEntry(ex.getEntry());
            int topShow = Math.max(0, row - 3);
            panel.mainTable.setRowSelectionInterval(row, row);
            panel.mainTable.scrollTo(topShow);
            panel.showEntry(ex.getEntry());
        } else {
            LOGGER.error("Problem saving file", ex);
        }

        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not save file.") + ".\n" + ex.getMessage(),
                Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");

    } finally {
        frame.unblock();
    }

    boolean commit = true;
    if (!session.getWriter().couldEncodeAll()) {
        FormBuilder builder = FormBuilder.create()
                .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:",
                session.getEncoding().displayName())).xy(1, 1);
        builder.add(ta).xy(3, 1);
        builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
        String tryDiff = Localization.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save database"),
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
                new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);

        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"),
                    Localization.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null,
                    Encodings.ENCODINGS_DISPLAYNAMES, encoding);
            if (choice == null) {
                commit = false;
            } else {
                Charset newEncoding = Charset.forName((String) choice);
                return saveDatabase(file, selectedOnly, newEncoding);
            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            commit = false;
        }

    }

    try {
        if (commit) {
            session.commit(file);
            panel.setEncoding(encoding); // Make sure to remember which encoding we used.
        } else {
            session.cancel();
        }
    } catch (SaveException e) {
        int ans = JOptionPane.showConfirmDialog(null,
                Localization.lang("Save failed during backup creation") + ". "
                        + Localization.lang("Save without backup?"),
                Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
        if (ans == JOptionPane.YES_OPTION) {
            session.setUseBackup(false);
            session.commit(file);
            panel.setEncoding(encoding);
        } else {
            commit = false;
        }
    }

    return commit;
}

From source file:edu.ku.brc.af.auth.UserAndMasterPasswordMgr.java

/**
 * @return/*from   www .  j a va2s. c om*/
 */
protected int askToContForCredentials() {
    int userChoice = JOptionPane.NO_OPTION;
    Object[] options = { getResourceString("Continue"), //$NON-NLS-1$
            getResourceString("CANCEL") //$NON-NLS-1$
    };
    loadAndPushResourceBundle("masterusrpwd");

    userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
            getLocalizedMessage("MISSING_CREDS", usersUserName), //$NON-NLS-1$
            getResourceString("MISSING_CREDS_TITLE"), //$NON-NLS-1$
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
    popResourceBundle();

    return userChoice;
}