Example usage for javax.swing JOptionPane showOptionDialog

List of usage examples for javax.swing JOptionPane showOptionDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 

Source Link

Document

Brings up a dialog with a specified icon, where the initial choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.

Usage

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.report.ReportFactory.java

public static void parser(String projectName, BufferedReader htmlReportReader, UIResponseObserver observer,
        ReportType reportType) {//from  w ww .  j  a v  a2s.  co  m
    String tmpLine = null;
    ArrayList<CodeMatchesPrecision> list = new ArrayList<CodeMatchesPrecision>();
    ArrayList<String> data = new ArrayList<String>();
    int insertedCnt = 0;

    if (htmlReportReader == null) {
        log.debug("Fail to generate " + projectName + " " + reportType + " Report");
        observer.setFailMessage("Fail to generate " + projectName + " " + reportType + " Report");
        return;
    }

    String msgHead = " > Creating Report : " + projectName + "\n";
    String pMessage = " >> Parsing [" + reportType.getType() + "] HTML file.";
    log.debug(pMessage);

    try {
        StringBuffer tmpValue = new StringBuffer("");
        while ((tmpLine = htmlReportReader.readLine()) != null) {
            tmpLine = tmpLine.trim();
            if (tmpLine.startsWith("<table border='0' cellspacing='0' cellpadding='0' class='reportTable'")) {
                while ((tmpLine = htmlReportReader.readLine()) != null) {
                    tmpLine = tmpLine.trim();
                    if (tmpLine.startsWith("</thead>")) {
                        break;
                    }
                }
                break;
            }
        }

        while ((tmpLine = htmlReportReader.readLine()) != null) {
            tmpLine = tmpLine.trim();
            if (tmpLine.startsWith("<tr ")) {
                int index = 0;
                while ((tmpLine = htmlReportReader.readLine()) != null) {
                    tmpLine = tmpLine.trim();
                    if (tmpLine.startsWith("<td ")) {
                        while ((tmpLine = htmlReportReader.readLine()) != null) {
                            tmpLine = tmpLine.trim();
                            if (tmpLine.startsWith("</td>")) {
                                String removedTagValue = removeHtmlTag(tmpValue);
                                data.add(removedTagValue);
                                tmpValue.setLength(0);
                                ++index;
                                break;
                            }
                            tmpValue.append(tmpLine);
                        }
                    }
                    if (tmpLine.startsWith("</tr>")) {
                        if (hasNoData(index)) {
                            break;
                        }
                        CodeMatchesPrecision codeMatchesPrecision = new CodeMatchesPrecision();
                        codeMatchesPrecision.setFile(data.get(0));
                        codeMatchesPrecision.setSize(Tools.transStringToInteger(data.get(1)));
                        codeMatchesPrecision.setFileLine(Tools.transStringToInteger(data.get(2)));
                        codeMatchesPrecision.setTotalLines(Tools.transStringToInteger(data.get(3)));
                        codeMatchesPrecision.setComponent(data.get(4));
                        codeMatchesPrecision.setVersion(data.get(5));
                        codeMatchesPrecision.setLicense(data.get(6));
                        codeMatchesPrecision.setUsage(data.get(7));
                        codeMatchesPrecision.setStatus(data.get(8));
                        codeMatchesPrecision.setPercentage(data.get(9));
                        codeMatchesPrecision.setMatchedFile(data.get(10));
                        codeMatchesPrecision.setMatchedFileLine(Tools.transStringToInteger(data.get(11)));
                        codeMatchesPrecision.setFileComment(data.get(12));
                        codeMatchesPrecision.setComponentComment(data.get(13));
                        list.add(codeMatchesPrecision);
                        data.clear();

                        insertedCnt++;
                        if (insertedCnt % 10000 == 0) {
                            log.debug("codeMatchesPrecision insertedCnt: " + insertedCnt);
                            if (observer != null) {
                                observer.pushMessageWithHeader(
                                        msgHead + pMessage + "\n >>> Inserted data count : " + insertedCnt);
                            }
                            insertCodematchTable(projectName, list);
                            list.clear();
                        }
                        break;
                    }
                }
            }
            if (tmpLine.startsWith("</table>")) {
                log.debug("codeMatchesPrecision insertedCnt: " + insertedCnt);
                insertCodematchTable(projectName, list);
                list.clear();
                break;
            }
        }
    } catch (IOException e) {
        ReportAPIWrapper.log.warn(e);
        String[] buttonOK = { "OK" };
        JOptionPane.showOptionDialog(null, "Out Of Memory Error", "Java heap space", JOptionPane.OK_OPTION,
                JOptionPane.ERROR_MESSAGE, null, buttonOK, "OK");
    }
    ReportAPIWrapper.log.debug("codeMatchesPrecision insertedCnt finally : " + insertedCnt);
}

From source file:com.floreantpos.ui.views.SwitchboardView.java

protected void doCloseOrder() {
    Ticket ticket = getFirstSelectedTicket();

    if (ticket == null) {
        return;/* w ww.  ja v  a 2s.  c o  m*/
    }

    ticket = TicketDAO.getInstance().loadFullTicket(ticket.getId());

    int due = (int) POSUtil.getDouble(ticket.getDueAmount());
    if (due != 0) {
        POSMessageDialog.showError(this, Messages.getString("SwitchboardView.5")); //$NON-NLS-1$
        return;
    }

    int option = JOptionPane.showOptionDialog(Application.getPosWindow(),
            Messages.getString("SwitchboardView.6") + ticket.getId() + Messages.getString("SwitchboardView.7"), //$NON-NLS-1$//$NON-NLS-2$
            POSConstants.CONFIRM, JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);

    if (option != JOptionPane.OK_OPTION) {
        return;
    }

    OrderController.closeOrder(ticket);

    //tickteListViewObj.updateTicketList();
    updateTicketList();
}

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.report.DefaultEntityListCreator.java

protected ReportEntityList buildEntityList(BufferedReader XmlReportReader, ArrayList<String> entityKeyList,
        ArrayList<String> duplicationCheckingField) {
    ReportEntityList reportEntityList = new ReportEntityList();
    ReportEntity reportEntity = new ReportEntity();
    String tmpLine = null;//from  ww w  .  j a va2  s.  c  om
    StringBuffer value = new StringBuffer();
    int index = 0;

    if (duplicationCheckingField == null) {
        duplicationCheckingField = new ArrayList<String>();
    }
    boolean entityDuplicationCheck = (duplicationCheckingField.size() > 0) ? true : false;
    HashSet<String> entityDuplicationCheckKeySet = new HashSet<String>();
    String duplicationCheckString = "";

    int totalCnt = 0;
    int insertedCnt = 0;

    try {
        while ((tmpLine = XmlReportReader.readLine()) != null) {

            totalCnt++;
            if (totalCnt % 10000 == 0) {
                log.debug("buildEntityList cnt: " + totalCnt + ", insertedCnt: " + insertedCnt);
            }
            if (totalCnt > Property.getInstance().getMaxNumOfReportEntity()) {

                log.error("Report Entity is larger than MAX_NUM_OF_REPORT_ENTITY: "
                        + Property.getInstance().getMaxNumOfReportEntity());
                JOptionPane.showMessageDialog(null,
                        "[OUT OF MEMORY] Project loading has been failed.\n"
                                + "Please, Reanalyze this project with smallar files.\n"
                                + "to reduce the size of project.\n",
                        "Program Exit - Project size is too big", JOptionPane.ERROR_MESSAGE);
                System.exit(0);
            }

            if (tmpLine.startsWith(ROW_END_TAG)) {

                if (entityDuplicationCheck == true) {
                    if (entityDuplicationCheckKeySet.contains(duplicationCheckString) == false) {
                        reportEntityList.addEntity(reportEntity);
                        insertedCnt++;
                    }

                    entityDuplicationCheckKeySet.add(duplicationCheckString);
                    duplicationCheckString = "";
                } else {
                    reportEntityList.addEntity(reportEntity);
                    insertedCnt++;
                }

                reportEntity = new ReportEntity();
                index = 0;
                if (XmlReportReader.readLine().equals(TABLE_END_TAG)) {
                    break; // read <Row ss:Index="#">
                }
            } else {
                int startIndex = tmpLine.indexOf(DATA_START_TAG);
                if (startIndex > 0) {
                    tmpLine = tmpLine.substring(startIndex + DATA_START_TAG_LEN);
                }
                int endIndex = tmpLine.indexOf(DATA_END_TAG_WITH_NS);
                if (endIndex >= 0) {
                    value.append(tmpLine.substring(0, endIndex));
                    if (entityDuplicationCheck == true) {
                        String currentKey = entityKeyList.get(index);
                        if (duplicationCheckingField.contains(currentKey))
                            duplicationCheckString += value.toString() + "-";
                    }
                    reportEntity.setValue(entityKeyList.get(index), value.toString());
                    index++;
                    value = new StringBuffer();

                } else {
                    value.append(tmpLine);
                }

            }

        }
    } catch (IOException e) {
        log.warn(e);
        String[] buttonOK = { "OK" };
        JOptionPane.showOptionDialog(null, "Out Of Memory Error", "Java heap space", JOptionPane.OK_OPTION,
                JOptionPane.ERROR_MESSAGE, null, buttonOK, "OK");
    }
    log.debug("total buildEntityList cnt: " + totalCnt + ", inserted cnt: " + insertedCnt);
    return reportEntityList;
}

From source file:com.openbravo.pos.admin.RolesViewTree.java

/**
 *
 * @return @throws BasicException/* w  w w  . j av  a 2 s  .  co m*/
 */
@Override
public Object createValue() throws BasicException {
    Object[] role = new Object[4];
    role = new Object[4];
    role[0] = m_oId == null ? UUID.randomUUID().toString() : m_oId;
    role[1] = m_jName.getText();
    role[2] = Formats.BYTEA.parseValue(buildPermissionsStr());
    role[3] = jRightsLevel.getValue();

    if (!hasPermissions) {
        Object[] options = { AppLocal.getIntString("Button.NoPermissionsYes"),
                AppLocal.getIntString("Button.NoPermissionsNo") };
        if (JOptionPane.showOptionDialog(this,
                AppLocal.getIntString("Message.adminpermissions1") + m_jName.getText() + " "
                        + AppLocal.getIntString("Message.adminpermissions2"),
                AppLocal.getIntString("Message.adminwarning"), JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[1]) == 1) {
            // Re-instate original permissions for this role
            role = new Object[4];
            role[0] = m_oId == null ? UUID.randomUUID().toString() : m_oId;
            role[1] = m_jName.getText();
            role[2] = Formats.BYTEA.parseValue(m_dlAdmin.findRolePermissions(role[0].toString()));
            role[3] = m_dlAdmin.getRightsLevel(m_jName.getText());
            return role;
        }
    }
    return role;
}

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

private void checkLicence() {
    try {//from  www.j a v  a2  s.  c om
        String userHome = System.getProperty("user.home");
        File holoColorsFolder = new File(userHome + File.separator + ".holocolors");
        File licenceFile = new File(holoColorsFolder, ".licence");
        File noDonationFile = new File(holoColorsFolder, ".nodonation");

        if (noDonationFile.exists()) {
            return;
        }

        int usage = 1;
        boolean showPopup = false;
        if (!holoColorsFolder.exists()) {
            holoColorsFolder.mkdir();
            showPopup = true;
            licenceFile.createNewFile();
        } else {
            Scanner in = new Scanner(new FileReader(licenceFile));
            if (in.hasNextInt()) {
                usage = in.nextInt() + 1;
            }
            in.close();
        }
        if (usage > 10) {
            usage = 1;
            showPopup = true;
        }
        Writer out = new BufferedWriter(new FileWriter(licenceFile));
        out.write(String.valueOf(usage));
        out.close();

        if (showPopup) {
            Object[] donationOption = { "Make a donation", "Maybe later", "No Never" };
            int option = JOptionPane.showOptionDialog(ahcPanel,
                    "Thanks for using Android Holo Colors!\n\nAndroid Holo Colors (website and plugin) is free to use.\nIf you save time and money with it, please make a donation.",
                    "Support Android Holo Colors", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                    new ImageIcon(getClass().getResource("/icons/H64.png")), donationOption, donationOption[0]);
            if (option == 0) {
                openWebpage(
                        "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XQSBX55A2Z46U");
            }
            if (option == 2) {
                noDonationFile.createNewFile();
            }
        }
    } catch (Exception e) {
        // no matter, nothing to do
        e.printStackTrace();
    }
}

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

/**
 * @param args//from   ww  w.  j av 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:org.fhaes.jsea.JSEAFrame.java

/**
 * Initialize the menu/toolbar actions.//from  www .j  a  va  2s  .c om
 */
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:com.floreantpos.ui.views.SwitchboardView.java

protected void doAssignDriver() {
    try {//ww w.jav a  2s . c o m

        Ticket ticket = getFirstSelectedTicket();

        if (ticket == null) {
            return;
        }

        if (!ticket.getOrderType().isDelivery()) {
            POSMessageDialog.showError(this, Messages.getString("SwitchboardView.8")); //$NON-NLS-1$
            return;
        }

        User assignedDriver = ticket.getAssignedDriver();
        if (assignedDriver != null) {
            int option = JOptionPane.showOptionDialog(Application.getPosWindow(),
                    Messages.getString("SwitchboardView.9"), POSConstants.CONFIRM, //$NON-NLS-1$
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);

            if (option != JOptionPane.YES_OPTION) {
                return;
            }
        }

        orderServiceExtension.assignDriver(ticket.getId());
    } catch (Exception e) {
        PosLog.error(getClass(), e);
        POSMessageDialog.showError(this, e.getMessage());
        LogFactory.getLog(SwitchboardView.class).error(e);
    }
}

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

/**
 * //  w  w  w .ja  va 2s. 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");
    }
}

From source file:com.jwmsolutions.timeCheck.gui.TodoForm.java

private void jchkCompletedActionPerformed(ActionEvent evt) {
    String todoName = (String) jcbTodos.getSelectedItem();
    boolean isCompletedTodo = StringUtils.containsIgnoreCase(todoName,
            CoreObject.getConfig().getString(Constants.CONFIG_COMPLETED_ITEM_TAG));
    if (jchkCompleted.isSelected() && !isCompletedTodo) {
        String message = "This to-do item will be marked as completed. Are you sure to continue?";
        String title = "Complete To-Do Item";
        int optionType = JOptionPane.YES_NO_OPTION;
        int messageType = JOptionPane.QUESTION_MESSAGE;
        int selectedOption = JOptionPane.showOptionDialog(this, message, title, optionType, messageType, null,
                null, null);/*from  w  ww  .j a va  2 s  .  co m*/
        if (selectedOption == JOptionPane.YES_OPTION) {
            String todoDescription = (String) jcbTodos.getSelectedItem();
            BasecampTodoItem todoItem = CoreObject.getTodoMap().get(todoDescription);
            Integer todoItemId = todoItem.getId();
            String statusCode = BasecampBusiness.completeTodoItem(todoItemId.toString());
            if (statusCode.trim().equals("200") || statusCode.trim().equals("201")) {
                jtfHours.setText("0");
                jDateChooser_IL.setDate(new Date());
                jchkCompleted.setSelected(false);
                jtfDescription.setText("");
                CoreObject.reloadTodoMap();
                lblMessages.setText("ToDo has been completed!");
            } else {
                lblMessages.setText("Failed! Status: " + statusCode);
            }

        } else {
            jchkCompleted.setSelected(false);
        }
    } else {
        if (isCompletedTodo) {
            String message = "This to-do item will be marked as uncompleted. Are you sure to activate the item?";
            String title = "Activate To-Do Item";
            int optionType = JOptionPane.YES_NO_OPTION;
            int messageType = JOptionPane.QUESTION_MESSAGE;
            int selectedOption = JOptionPane.showOptionDialog(this, message, title, optionType, messageType,
                    null, null, null);
            if (selectedOption == JOptionPane.YES_OPTION) {
                String todoDescription = (String) jcbTodos.getSelectedItem();
                BasecampTodoItem todoItem = CoreObject.getTodoMap().get(todoDescription);
                Integer todoItemId = todoItem.getId();
                String statusCode = BasecampBusiness.uncompleteTodoItem(todoItemId.toString());
                if (statusCode.trim().equals("200") || statusCode.trim().equals("201")) {
                    jtfHours.setText("0");
                    jDateChooser_IL.setDate(new Date());
                    jchkCompleted.setSelected(false);
                    jtfDescription.setText("");
                    CoreObject.reloadTodoMap();
                    lblMessages.setText("ToDo is now active!");
                } else {
                    lblMessages.setText("Failed! Status: " + statusCode);
                }
            } else {
                jchkCompleted.setSelected(true);
            }
        }
    }
}