Example usage for javax.swing JOptionPane YES_NO_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_CANCEL_OPTION

Introduction

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

Prototype

int YES_NO_CANCEL_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

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

private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
    SaveSession session;/*w  ww .  j  ava 2 s .c  o m*/
    frame.block();
    try {
        SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs)
                .withEncoding(encoding);
        BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
        if (selectedOnly) {
            session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(),
                    panel.getSelectedEntries(), prefs);
        } 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.getMainTable().findEntry(ex.getEntry());
            int topShow = Math.max(0, row - 3);
            panel.getMainTable().setRowSelectionInterval(row, row);
            panel.getMainTable().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.toPath());
            panel.getBibDatabaseContext().getMetaData().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.toPath());
            panel.getBibDatabaseContext().getMetaData().setEncoding(encoding);
        } else {
            commit = false;
        }
    }

    return commit;
}

From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java

private void constructDownloadPanelWithOption(String downloadUrl, Object[] options) {
    String nVMsg = newVersionMsg;
    if (os.equalsIgnoreCase("CentOS") || os.equalsIgnoreCase("Ubuntu")) {
        nVMsg = nVMsg + "\nIf choosing Update automatically, you need to enter a sudo password later.";
    }/* w  w w  . ja v  a 2  s . com*/

    if (os.startsWith("mac")) {
        JOptionPane.showMessageDialog(null, "New version is available on App Store. Please upgrade.");
        if (options.length == 2) { // forced upgrade needed
            System.exit(1);
        } else {
            nogo = false;
            return;
        }
    }

    int n = JOptionPane.showOptionDialog(null, nVMsg, "New Version Notification",
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);

    if (n == 0) {
        saveAndInstall(downloadUrl);
        nogo = true;
    } else if (n == 1) {
        try {
            saveFile(downloadUrl);
            nogo = false;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (n == 2) {
        nogo = false;
    }
}

From source file:de.lazyzero.kkMulticopterFlashTool.KKMulticopterFlashTool.java

private void checkVersion() {
    logger.log(Level.INFO, "Check the version: " + VERSION + (isBeta ? " beta " + betaVersion : "")
            + " online is version: " + firmwareReader.getActualVersion());
    if (firmwareReader.getActualVersion() > Double.parseDouble(VERSION)) {
        //         JOptionPane.showMessageDialog(this, _("update"));
        String[] choices = { _("downloads.download"), _("Cancel") };
        int result = JOptionPane.showOptionDialog(this, _("update"), "", JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.INFORMATION_MESSAGE, null, choices, choices[0]);
        if (result == 0) {
            kkMenu.openURL("http://kkflashtool.de");
            System.exit(0);/*  www  .  j  a  va 2  s.  c o  m*/
        }
    }
}

From source file:fr.vdl.android.holocolors.HoloColorsDialog.java

private void unzipFile(File zipFile) throws Exception {
    File outputFolder = new File(resPathTextField.getText());

    boolean overwriteAll = false;
    boolean overwriteNone = false;
    Object[] overwriteOptions = { "Overwrite this file", "Overwrite all", "Do not overwrite this file",
            "Do not overwrite any file" };

    ZipInputStream zis = null;//w  w w.ja va  2s .  com
    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
    try {
        zis = new ZipInputStream(new FileInputStream(zipFile));
        ZipEntry ze = zis.getNextEntry();
        while (ze != null) {
            String fileName = ze.getName().replaceFirst("res/", "");
            File newFile = new File(outputFolder + File.separator + fileName);

            new File(newFile.getParent()).mkdirs();

            boolean overwrite = overwriteAll || (!newFile.exists());
            if (newFile.exists() && newFile.isFile() && !overwriteAll && !overwriteNone) {
                int option = JOptionPane.showOptionDialog(ahcPanel,
                        newFile.getName() + " already exists, overwrite ?", "File exists",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
                        new ImageIcon(getClass().getResource("/icons/H64.png")), overwriteOptions,
                        overwriteOptions[0]);

                switch (option) {
                case 0:
                    overwrite = true;
                    break;
                case 1:
                    overwrite = true;
                    overwriteAll = true;
                    break;
                case 2:
                    overwrite = false;
                    break;
                case 3:
                    overwrite = false;
                    overwriteNone = true;
                    break;
                default:
                    overwrite = false;
                }
            }

            if (overwrite && !fileName.endsWith(File.separator)) {
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.close();
            }
            ze = zis.getNextEntry();
        }

        zis.closeEntry();
        zis.close();
    } finally {
        if (zis != null) {
            try {
                zis.close();
            } catch (IOException e) {
            }
        }
    }
}

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

private int promptParametersFileOverwrite() {
    return JOptionPane.showConfirmDialog(this, "The file exists, overwrite?", "Existing file",
            JOptionPane.YES_NO_CANCEL_OPTION);
}

From source file:latexstudio.editor.EditorTopComponent.java

public UnsavedWorkState canOpen() {

    if (isModified() && !isPreviewDisplayed()) {
        int userChoice = JOptionPane.showConfirmDialog(this,
                "This document has been modified. Do you want to save it first?", "Save document",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (userChoice == JOptionPane.YES_OPTION) {
            return UnsavedWorkState.SAVE_AND_OPEN;
        } else if (userChoice == JOptionPane.NO_OPTION) {
            return UnsavedWorkState.OPEN;
        } else {//from w  w w  .ja v  a 2  s.c o m
            return UnsavedWorkState.CANCEL;
        }

    } else {
        return UnsavedWorkState.OPEN;
    }
}

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

/**
 * @param args// ww  w.  j a  v a  2  s. co m
 */
public static void main(String[] args) {
    log.debug("********* Current [" + (new File(".").getAbsolutePath()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    // This is for Windows and Exe4J, turn the args into System Properties
    for (String s : args) {
        String[] pairs = s.split("="); //$NON-NLS-1$
        if (pairs.length == 2) {
            log.debug("[" + pairs[0] + "][" + pairs[1] + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            if (pairs[0].startsWith("-D")) //$NON-NLS-1$
            {
                System.setProperty(pairs[0].substring(2, pairs[0].length()), pairs[1]);
            }
        }
    }

    // Now check the System Properties
    String appDir = System.getProperty("appdir"); //$NON-NLS-1$
    if (StringUtils.isNotEmpty(appDir)) {
        UIRegistry.setDefaultWorkingPath(appDir);
    }

    String appdatadir = System.getProperty("appdatadir"); //$NON-NLS-1$
    if (StringUtils.isNotEmpty(appdatadir)) {
        UIRegistry.setBaseAppDataDir(appdatadir);
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            //              Set App Name, MUST be done very first thing!
            UIRegistry.setAppName("Specify"); //$NON-NLS-1$

            // Then set this
            IconManager.setApplicationClass(Specify.class);
            IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$
            IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$
            IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$

            try {
                UIHelper.OSTYPE osType = UIHelper.getOSType();
                if (osType == UIHelper.OSTYPE.Windows) {
                    //UIManager.setLookAndFeel(new WindowsLookAndFeel());
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

                } else if (osType == UIHelper.OSTYPE.Linux) {
                    //UIManager.setLookAndFeel(new GTKLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new SkyKrupp());
                    //PlasticLookAndFeel.setPlasticTheme(new DesertBlue());
                    //PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());
                    //PlasticLookAndFeel.setPlasticTheme(new ExperienceRoyale());
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                }
            } catch (Exception e) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerFrame.class, e);
                e.printStackTrace();
            }

            AppPreferences localPrefs = AppPreferences.getLocalPrefs();
            localPrefs.setDirPath(UIRegistry.getAppDataDir());

            //Specify.adjustLocaleFromPrefs();

            System.setProperty(AppContextMgr.factoryName, "edu.ku.brc.specify.config.SpecifyAppContextMgr"); // Needed by AppContextMgr //$NON-NLS-1$
            System.setProperty(SchemaI18NService.factoryName,
                    "edu.ku.brc.specify.config.SpecifySchemaI18NService"); // Needed for Localization and Schema //$NON-NLS-1$
            System.setProperty(UIFieldFormatterMgr.factoryName,
                    "edu.ku.brc.specify.ui.SpecifyUIFieldFormatterMgr"); // Needed for CatalogNumbering //$NON-NLS-1$
            System.setProperty(WebLinkMgr.factoryName, "edu.ku.brc.specify.config.SpecifyWebLinkMgr"); // Needed for WebLnkButton //$NON-NLS-1$
            System.setProperty(DataObjFieldFormatMgr.factoryName,
                    "edu.ku.brc.specify.config.SpecifyDataObjFieldFormatMgr"); // Needed for WebLnkButton //$NON-NLS-1$

            SpecifyDataObjFieldFormatMgr.setDoingLocal(true);
            SpecifyUIFieldFormatterMgr.setDoingLocal(true);
            SpecifyWebLinkMgr.setDoingLocal(true);

            Object[] options = { getResourceString("SchemaLocalizerFrame.FULL_SCHEMA"), //$NON-NLS-1$ 
                    getResourceString("SchemaLocalizerFrame.WB_SCHEMA") }; //$NON-NLS-1$
            int retVal = JOptionPane.showOptionDialog(null,
                    getResourceString("SchemaLocalizerFrame.WHICH_SCHEMA"), //$NON-NLS-1$
                    getResourceString("SchemaLocalizerFrame.CHOOSE_SCHEMA"), JOptionPane.YES_NO_CANCEL_OPTION, //$NON-NLS-1$
                    JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

            SchemaLocalizerFrame sla;
            if (retVal == JOptionPane.NO_OPTION) {
                DBTableIdMgr schema = new DBTableIdMgr(false);
                schema.initialize(new File(XMLHelper.getConfigDirPath("specify_workbench_datamodel.xml"))); //$NON-NLS-1$
                sla = new SchemaLocalizerFrame(SpLocaleContainer.WORKBENCH_SCHEMA, schema);

            } else {
                sla = new SchemaLocalizerFrame(SpLocaleContainer.CORE_SCHEMA, DBTableIdMgr.getInstance());
            }

            AppContextMgr.getInstance().setHasContext(true);

            sla.createDisplay();
            sla.pack();
            Dimension size = sla.getSize();
            size.width += 250;
            sla.setSize(size);
            UIHelper.centerAndShow(sla);

            final SchemaLocalizerFrame slaf = sla;
            slaf.setDefaultCloseOperation(EXIT_ON_CLOSE);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    slaf.chooseCurrentLocale();
                }
            });
        }
    });

}

From source file:jmemorize.gui.swing.frames.MainFrame.java

/**
 * If lesson was modified this shows a dialog that asks if the user wants to
 * save the lesson before closing it./*  www . ja v a 2s. c om*/
 * 
 * @return <code>true</code> if user chose not to cancel the lesson close
 *         operation. If this method return <code>false</code> the closing
 *         of jMemorize was canceled.
 */
public boolean allowTheUserToSaveIfClosing() {
    // first check the editCardFrame for unsaved changes
    final EditCardFrame editFrame = EditCardFrame.getInstance();
    if (editFrame.isVisible() && !editFrame.close()) {
        return false; // user canceled closing of edit card frame
    }

    if (!m_newCardManager.closeAllFrames()) // close all addCard frames
    {
        return false;
    }

    // then see if lesson should to be saved
    final Lesson lesson = m_main.getLesson();
    if (lesson.canSave()) {
        final int n = JOptionPane.showConfirmDialog(MainFrame.this, Localization.get("MainFrame.SAVE_MODIFIED"), //$NON-NLS-1$
                "Warning", //$NON-NLS-1$
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);

        if (n == JOptionPane.OK_OPTION) {
            try {
                jMemorizeIO.saveLesson(lesson);

                jMemorizeIO.reset();
            } catch (final Exception exception) {
                final File file = jMemorizeIO.getFile();
                final Object[] args = { file != null ? file.getName() : "?" };
                final MessageFormat form = new MessageFormat(Localization.get(LC.ERROR_SAVE));
                final String msg = form.format(args);
                Main.logThrowable(msg, exception);

                new ErrorDialog(this, msg, exception).setVisible(true);
            }
            // if lesson was saved return true, false otherwise
            return !lesson.canSave();
        }

        // if NO chosen continue, otherwise CANCEL was chosen
        return n == JOptionPane.NO_OPTION;
    }

    return true;
}

From source file:org.fhaes.jsea.JSEAFrame.java

/**
 * Initialize the menu/toolbar actions.//  w  w  w  .j a  va  2 s. com
 */
private void initActions() {

    final JFrame glue = this;

    actionFileExit = new FHAESAction("Close", "close.png") { //$NON-NLS-1$

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            dispose();
        }
    };

    actionChartProperties = new FHAESAction("Chart properties", "properties.png") { //$NON-NLS-1$

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            ChartEditor editor = ChartEditorManager
                    .getChartEditor(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart());
            int result = JOptionPane.showConfirmDialog(glue, editor, "Properties", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE);
            if (result == JOptionPane.OK_OPTION) {
                editor.updateChart(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart());
            }
        }
    };

    actionReset = new FHAESAction("Reset", "filenew.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            Object[] options = { "Yes", "No", "Cancel" };
            int n = JOptionPane.showOptionDialog(glue, "Are you sure you want to start a new analysis?",
                    "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                    options[2]);

            if (n == JOptionPane.YES_OPTION) {
                setToDefault();
            }
        }
    };

    actionRun = new FHAESAction("Run analysis", "run.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            runAnalysis();
        }
    };

    actionSaveAll = new FHAESAction("Save all results", "save_all.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            File f;
            try {
                f = new File(file.getAbsolutePath() + File.separator + "report.txt");
                saveReportTXT(f);

                f = new File(file.getAbsolutePath() + File.separator + "report.pdf");
                saveReportPDF(f);

                f = new File(file.getAbsolutePath() + File.separator + "chart.png");
                saveChartPNG(f);

                f = new File(file.getAbsolutePath() + File.separator + "chart.pdf");
                saveChartPDF(f);

                f = new File(file.getAbsolutePath() + File.separator + "data.xls");
                saveDataXLS(f);

                f = new File(file.getAbsolutePath());
                saveDataCSV(f);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    actionSaveData = new FHAESAction("Save data tables", "table.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            try {
                saveDataCSV(file);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    actionSaveReport = new FHAESAction("Save report", "report.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            // Set file filters
            fc.setAcceptAllFileFilterUsed(false);
            TXTFileFilter txtfilter = new TXTFileFilter();
            PDFFilter pdffilter = new PDFFilter();
            fc.addChoosableFileFilter(txtfilter);
            fc.addChoosableFileFilter(pdffilter);
            fc.setFileFilter(txtfilter);
            FileFilter chosenFilter;

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                chosenFilter = fc.getFileFilter();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            // Handle file type and extensions nicely
            if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) {
                if (chosenFilter.equals(txtfilter)) {
                    file = new File(file.getAbsoluteFile() + ".txt");
                } else if (chosenFilter.equals(pdffilter)) {
                    file = new File(file.getAbsoluteFile() + ".pdf");
                }
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("txt")
                    && chosenFilter.equals("pdf")) {
                chosenFilter = txtfilter;
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf")
                    && chosenFilter.equals("txt")) {
                chosenFilter = pdffilter;
            }

            // If file already exists confirm overwrite
            if (file.exists()) {
                // Check we have write access to this file
                if (!file.canWrite()) {
                    JOptionPane.showMessageDialog(glue, "You do not have write permission to this file",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int n = JOptionPane.showConfirmDialog(glue,
                        "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?",
                        "Overwrite file?", JOptionPane.YES_NO_OPTION);
                if (n != JOptionPane.YES_OPTION) {
                    return;
                }
            }

            // Do save
            try {

                if (chosenFilter.equals(txtfilter)) {
                    saveReportTXT(file);
                } else if (chosenFilter.equals(pdffilter)) {
                    saveReportPDF(file);
                } else {
                    log.error("No export file format chosen.  Shouldn't be able to get here!");
                }
            } catch (IOException e) {
                JOptionPane.showMessageDialog(glue, "Unable to save report.  Check log file.", "Warning",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }

        }
    };

    actionSaveChart = new FHAESAction("Save chart", "barchart.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            if (jsea == null)
                return;

            File file;
            JFileChooser fc;

            // Open file chooser in last folder if possible
            if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) {
                fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null));
            } else {
                fc = new JFileChooser();
            }

            // Set file filters
            fc.setAcceptAllFileFilterUsed(false);
            PNGFilter pngfilter = new PNGFilter();
            PDFFilter pdffilter = new PDFFilter();
            fc.addChoosableFileFilter(pngfilter);
            fc.addChoosableFileFilter(pdffilter);
            fc.setFileFilter(pngfilter);
            FileFilter chosenFilter;

            // Show dialog and get specified file
            int returnVal = fc.showSaveDialog(glue);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                chosenFilter = fc.getFileFilter();
                App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath());
            } else {
                return;
            }

            // Handle file type and extensions nicely
            if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) {
                if (chosenFilter.equals(pngfilter)) {
                    file = new File(file.getAbsoluteFile() + ".png");
                } else if (chosenFilter.equals(pdffilter)) {
                    file = new File(file.getAbsoluteFile() + ".pdf");
                }
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("png")
                    && chosenFilter.equals("pdf")) {
                chosenFilter = pngfilter;
            } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf")
                    && chosenFilter.equals("png")) {
                chosenFilter = pdffilter;
            }

            // If file already exists confirm overwrite
            if (file.exists()) {
                // Check we have write access to this file
                if (!file.canWrite()) {
                    JOptionPane.showMessageDialog(glue, "You do not have write permission to this file",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int n = JOptionPane.showConfirmDialog(glue,
                        "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?",
                        "Overwrite file?", JOptionPane.YES_NO_OPTION);
                if (n != JOptionPane.YES_OPTION) {
                    return;
                }
            }

            // Do save
            try {

                if (chosenFilter.equals(pngfilter)) {
                    saveChartPNG(file);

                } else if (chosenFilter.equals(pdffilter)) {

                    saveChartPDF(file);
                } else {
                    log.error("No export file format chosen.  Shouldn't be able to get here!");
                }
            } catch (IOException e) {
                JOptionPane.showMessageDialog(glue, "Unable to save chart.  Check log file.", "Warning",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }

        }
    };

    actionCopy = new FHAESAction("Copy", "edit_copy.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            copyCurrentSelectionToClipboard();
        }
    };

    actionLagMap = new FHAESAction("LagMap", "lagmap22.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            launchLagMap();
        }
    };

}

From source file:edu.ku.brc.specify.ui.AppBase.java

/**
 * // w  w  w .j ava  2  s  .co  m
 */
protected void checkForUpdates() {
    try {
        UpdateDescriptor updateDesc = UpdateChecker.getUpdateDescriptor(
                UIRegistry.getResourceString("UPDATE_PATH"), ApplicationDisplayMode.UNATTENDED);

        UpdateDescriptorEntry entry = updateDesc.getPossibleUpdateEntry();

        if (entry != null) {
            Object[] options = { getResourceString("Specify.INSTALLUPDATE"), //$NON-NLS-1$
                    getResourceString("Specify.SKIP") //$NON-NLS-1$
            };
            int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
                    getLocalizedMessage("Specify.UPDATE_AVAIL", entry.getNewVersion()), //$NON-NLS-1$
                    getResourceString("Specify.UPDATE_AVAIL_TITLE"), //$NON-NLS-1$
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (userChoice == JOptionPane.YES_OPTION) {
                if (!doExit(false)) {
                    return;
                }

            } else {
                return;
            }
        } else {
            UIRegistry.showLocalizedError("Specify.NO_UPDATE_AVAIL");
            return;
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        UIRegistry.showLocalizedError("Specify.UPDATE_CHK_ERROR");
        return;
    }

    try {
        ApplicationLauncher.Callback callback = new ApplicationLauncher.Callback() {
            public void exited(int exitValue) {
                System.err.println("exitValue: " + exitValue);
                //startApp(doConfig);
            }

            public void prepareShutdown() {
                System.err.println("prepareShutdown");

            }
        };
        ApplicationLauncher.launchApplication("100", null, true, callback);

    } catch (Exception ex) {
        System.err.println("EXPCEPTION");
    }
}