Example usage for javax.swing JOptionPane YES_NO_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_OPTION

Introduction

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

Prototype

int YES_NO_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:ElectionGUI.java

private void createElectionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createElectionBtnActionPerformed
    //Confirmation of discarding an election2D that is not saved
    boolean discard = true;
    if (election2D != null && !saved) {
        int response = JOptionPane.showConfirmDialog(null,
                "Current " + "election is not saved, are you sure you want to create " + "a new election?" + eol
                        + "Press \"No\" to save current " + "election in a file.",
                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

        if (response == JOptionPane.NO_OPTION) {
            discard = false;/*from   ww w .  j av  a  2 s . c o m*/
            systemTxt.append("-Election creation cancelled." + eol);
        }
    }

    if (discard) {
        //Input validation
        String err = "";

        try {
            int x = Integer.parseInt(nTxtField.getText());
            if (x < 1 || x > 1000) {
                throw (new Exception());
            }
            n = x;
        } catch (Exception e) {
            nTxtField.setBackground(Color.cyan);
            err = err + "-Error: Value " + nTxtField.getText() + " is not "
                    + "a valid voter population size. Enter a valid " + "integer (max 1000)." + eol;
        }

        try {
            int x = Integer.parseInt(mTxtField.getText());
            if (x < 1 || x > 1000) {
                throw (new Exception());
            }
            m = x;
        } catch (Exception e) {
            mTxtField.setBackground(Color.cyan);
            err = err + "-Error: Value " + mTxtField.getText() + " is not "
                    + "a valid candidate population size. Enter a valid " + "integer (max 1000)." + eol;
        }

        try {
            int x = Integer.parseInt(kTxtField.getText());
            if (x < 1 || x > 100 || x > m) {
                throw (new Exception());
            }
            k = x;
        } catch (Exception e) {
            kTxtField.setBackground(Color.cyan);
            err = err + "-Error: Value " + kTxtField.getText() + " is not "
                    + "a valid committee size. Maximum size is the minimum "
                    + "between 100 and the candidate population." + eol;
        }

        try {
            int x = Integer.parseInt(xLimitTxtField.getText());
            if (x < 1 || x > 100) {
                throw (new Exception());
            }
            xLimit = x;
        } catch (Exception e) {
            xLimitTxtField.setBackground(Color.cyan);
            err = err + "-Error: Maximum x-Axis value goes up to 100." + eol;
        }

        try {
            int x = Integer.parseInt(yLimitTxtField.getText());
            if (x < 1 || x > 100) {
                throw (new Exception());
            }
            yLimit = x;
        } catch (Exception e) {
            yLimitTxtField.setBackground(Color.cyan);
            err = err + "-Error: Maximum y-Axis value goes up to 100." + eol;
        }

        try {
            int x = Integer.parseInt(nClusterTxtField.getText());
            if (x < 1 || x > 20) {
                throw (new Exception());
            }
            nClusters = x;
        } catch (Exception e) {
            nClusterTxtField.setBackground(Color.cyan);
            err = err + "-Error: Maximum number of voter clusters is 20." + eol;
        }

        try {
            int x = Integer.parseInt(mClusterTxtField.getText());
            if (x < 1 || x > 20) {
                throw (new Exception());
            }
            mClusters = x;
        } catch (Exception e) {
            mClusterTxtField.setBackground(Color.cyan);
            err = err + "-Error: Maximum number of candidate clusters " + "is 20." + eol;
        }

        if (err != "") {
            systemTxt.append(err);
        } else {
            nTxtField.setBackground(Color.white);
            mTxtField.setBackground(Color.white);
            kTxtField.setBackground(Color.white);
            xLimitTxtField.setBackground(Color.white);
            yLimitTxtField.setBackground(Color.white);
            nClusterTxtField.setBackground(Color.white);
            mClusterTxtField.setBackground(Color.white);

            ArrayList<Voter> voters = new ArrayList();
            ArrayList<Candidate> candidates = new ArrayList();

            int tempN = n;
            int tempM = m;

            boolean finalCluster = false;
            boolean cancelled = false;
            String card = "square";

            for (int i = 0; i < nClusters; i++) {
                String title = "Voter Cluster " + (i + 1) + "/" + nClusters;
                String footnote = "Voters remaining: " + tempN;
                if (i + 1 == nClusters) {
                    finalCluster = true;
                }
                DistributionDialog dd = new DistributionDialog(this, true, tempN, xLimit, yLimit,
                        Person.personType.VOTER, title, footnote, finalCluster, card);

                dd.setVisible(true);
                if (dd.isCancelled()) {
                    cancelled = true;
                    break;
                }
                tempN = tempN - dd.getClusterSize();
                voters.addAll((ArrayList<Voter>) (ArrayList<?>) dd.getIndividuals());

                card = dd.getCard();
            }

            finalCluster = false;
            if (!cancelled) {
                for (int i = 0; i < mClusters; i++) {
                    String title = "Candidate Cluster " + (i + 1) + "/" + mClusters;

                    String footnote = "Candidates remaining: " + tempM;
                    if (i + 1 == mClusters) {
                        finalCluster = true;
                    }
                    DistributionDialog dd = new DistributionDialog(this, true, tempM, xLimit, yLimit,
                            Person.personType.CANDIDATE, title, footnote, finalCluster, card);

                    dd.setVisible(true);
                    if (dd.isCancelled()) {
                        cancelled = true;
                        break;
                    }
                    tempM = tempM - dd.getClusterSize();
                    candidates.addAll((ArrayList<Candidate>) (ArrayList<?>) dd.getIndividuals());

                    card = dd.getCard();
                }
            }

            if (!cancelled) {
                for (int i = 0; i < voters.size(); i++) {
                    voters.get(i).setName("v" + i);
                }

                for (int i = 0; i < candidates.size(); i++) {
                    candidates.get(i).setName("c" + i);
                }

                election2D = new Election(k, voters, candidates, true);
                clearGraphPanels();
                plotResultsBtn.setEnabled(true);
                saveElectionBtn.setEnabled(true);
                consistencyBtn.setEnabled(false);
                systemTxt.append("-New election created." + eol);
                saved = false;
            } else {
                systemTxt.append("-Election creation cancelled." + eol);
            }
        }
    }
}

From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java

/**
 *
 *
 * @param saveAs//from  w  w w . j a  v a  2s .  co m
 * @param file
 * @param profile
 *
 * @return
 */
public File saveConnection(boolean saveAs, File file, SshToolsConnectionProfile profile) {
    if (profile != null) {
        if ((file == null) || saveAs) {
            String prefsDir = super.getApplication().getApplicationPreferencesDirectory().getAbsolutePath();
            JFileChooser fileDialog = new JFileChooser(prefsDir);

            fileDialog.setFileFilter(connectionFileFilter);

            int ret = fileDialog.showSaveDialog(this);

            if (ret == fileDialog.CANCEL_OPTION) {
                return null;
            }

            file = fileDialog.getSelectedFile();

            if (!file.getName().toLowerCase().endsWith(".xml")) {
                file = new File(file.getAbsolutePath() + ".xml");
            }
        }

        try {
            if (saveAs && file.exists()) {
                if (JOptionPane.showConfirmDialog(this, "File already exists. Are you sure?", "File exists",
                        JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION) {
                    return null;
                }
            }

            // Check to make sure its valid
            if (file != null) {
                // Save the connection details to file
                log.debug("Saving connection to " + file.getAbsolutePath());
                profile.save(file.getAbsolutePath());

                if (profile == getCurrentConnectionProfile()) {
                    log.debug("Current connection saved, disabling save action.");
                    setNeedSave(false);
                }

                return file;
            } else {
                showExceptionMessage("The file specified is invalid!", "Save Connection");
            }
        } catch (InvalidProfileFileException e) {
            showExceptionMessage(e.getMessage(), "Save Connection");
        }
    }

    return null;
}

From source file:com.adobe.aem.demomachine.gui.AemDemo.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private void initialize() {

    // Initialize properties
    setDefaultProperties(AemDemoUtils//from ww w .  jav  a 2 s  .co  m
            .loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties"));
    setPersonalProperties(AemDemoUtils.loadProperties(buildFile.getParentFile().getAbsolutePath()
            + File.separator + "conf" + File.separator + "build-personal.properties"));

    // Constructing the main frame
    frameMain = new JFrame();
    frameMain.setBounds(100, 100, 700, 530);
    frameMain.getContentPane().setLayout(null);

    // Main menu bar for the Frame
    JMenuBar menuBar = new JMenuBar();

    JMenu mnAbout = new JMenu("AEM Demo Machine");
    mnAbout.setMnemonic(KeyEvent.VK_A);
    menuBar.add(mnAbout);

    JMenuItem mntmUpdates = new JMenuItem("Check for Updates");
    mntmUpdates.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmUpdates.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "demo_update");
        }
    });
    mnAbout.add(mntmUpdates);

    JMenuItem mntmDoc = new JMenuItem("Help and Documentation");
    mntmDoc.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_H, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmDoc.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_DOCUMENTATION));
        }
    });
    mnAbout.add(mntmDoc);

    JMenuItem mntmScripts = new JMenuItem("Demo Scripts (VPN)");
    mntmScripts.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_SCRIPTS));
        }
    });
    mnAbout.add(mntmScripts);

    JMenuItem mntmDiagnostics = new JMenuItem("Diagnostics");
    mntmDiagnostics.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Map<String, String> env = System.getenv();
            System.out.println("====== System Environment Variables ======");
            for (String envName : env.keySet()) {
                System.out.format("%s=%s%n", envName, env.get(envName));
            }
            System.out.println("====== JVM Properties ======");
            RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
            List<String> jvmArgs = runtimeMXBean.getInputArguments();
            for (String arg : jvmArgs) {
                System.out.println(arg);
            }
            System.out.println("====== Runtime Properties ======");
            Properties props = System.getProperties();
            props.list(System.out);
        }
    });
    mnAbout.add(mntmDiagnostics);

    JMenuItem mntmQuit = new JMenuItem("Quit");
    mntmQuit.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmQuit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(-1);
        }
    });
    mnAbout.add(mntmQuit);

    JMenu mnNew = new JMenu("New");
    menuBar.add(mnNew);

    // New Demo Machine
    JMenuItem mntmNewDemo = new JMenuItem("Demo Environment");
    mntmNewDemo.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmNewDemo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (AemDemo.this.getBuildInProgress()) {

                JOptionPane.showMessageDialog(null,
                        "A Demo Environment is currently being built. Please wait until it is finished.");

            } else {

                final AemDemoNew dialogNew = new AemDemoNew(AemDemo.this);
                dialogNew.setModal(true);
                dialogNew.setVisible(true);
                dialogNew.getDemoBuildName().requestFocus();
                ;

            }
        }
    });
    mnNew.add(mntmNewDemo);

    JMenuItem mntmNewOptions = new JMenuItem("Demo Properties");
    mntmNewOptions.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmNewOptions.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            final AemDemoOptions dialogOptions = new AemDemoOptions(AemDemo.this);
            dialogOptions.setModal(true);
            dialogOptions.setVisible(true);

        }
    });
    mnNew.add(mntmNewOptions);

    JMenu mnUpdate = new JMenu("Add-ons");
    menuBar.add(mnUpdate);

    // Sites Add-on
    JMenu mnSites = new JMenu("Sites");
    mnUpdate.add(mnSites);

    JMenuItem mntmSitesDownloadAddOn = new JMenuItem("Download Demo Add-on");
    mntmSitesDownloadAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_sites");
        }
    });
    mnSites.add(mntmSitesDownloadAddOn);

    JMenuItem mntmSitesDownloadFP = new JMenuItem("Download Packages (PackageShare)");
    mntmSitesDownloadFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_sites_packages");
        }
    });
    mnSites.add(mntmSitesDownloadFP);

    // Assets Add-on
    JMenu mnAssets = new JMenu("Assets");
    mnUpdate.add(mnAssets);

    JMenuItem mntmAssetsDownloadAddOn = new JMenuItem("Download Demo Add-on");
    mntmAssetsDownloadAddOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_assets");
        }
    });
    mnAssets.add(mntmAssetsDownloadAddOn);

    JMenuItem mntmAssetsDownloadFP = new JMenuItem("Download Packages (PackageShare)");
    mntmAssetsDownloadFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_assets_packages");
        }
    });
    mnAssets.add(mntmAssetsDownloadFP);

    // Communities Add-on
    JMenu mnCommunities = new JMenu("Communities/Livefyre");
    mnUpdate.add(mnCommunities);

    JMenuItem mntmAemCommunitiesFeaturePacks = new JMenuItem("Download Packages (PackageShare)");
    mntmAemCommunitiesFeaturePacks.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_communities_packages");
        }
    });
    mnCommunities.add(mntmAemCommunitiesFeaturePacks);

    // Forms Add-on
    JMenu mnForms = new JMenu("Forms");
    mnUpdate.add(mnForms);

    JMenuItem mntmAemFormsAddon = new JMenuItem("Download Demo Add-on");
    mntmAemFormsAddon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_forms");
        }
    });
    mnForms.add(mntmAemFormsAddon);

    JMenuItem mntmAemFormsFP = new JMenuItem("Download Packages (PackageShare)");
    mntmAemFormsFP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_forms_packages");
        }
    });
    mnForms.add(mntmAemFormsFP);

    // Mobile Add-on
    JMenu mnApps = new JMenu("Mobile");
    mnUpdate.add(mnApps);

    JMenuItem mntmAemAppsAddon = new JMenuItem("Download Demo Add-on");
    mntmAemAppsAddon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_apps");
        }
    });
    mnApps.add(mntmAemAppsAddon);

    JMenuItem mntmAemApps = new JMenuItem("Download Packages (PackageShare)");
    mntmAemApps.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_apps_packages");
        }
    });
    mnApps.add(mntmAemApps);

    // Commerce Add-on
    JMenu mnCommerce = new JMenu("Commerce");
    mnUpdate.add(mnCommerce);

    JMenu mnCommerceDownload = new JMenu("Download Packages");
    mnCommerce.add(mnCommerceDownload);

    // Commerce EP
    JMenuItem mnCommerceDownloadEP = new JMenuItem("ElasticPath (PackageShare)");
    mnCommerceDownloadEP.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_commerce_ep");
        }
    });
    mnCommerceDownload.add(mnCommerceDownloadEP);

    // Commerce WebSphere
    JMenuItem mnCommerceDownloadWAS = new JMenuItem("WebSphere (PackageShare)");
    mnCommerceDownloadWAS.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_commerce_websphere");
        }
    });
    mnCommerceDownload.add(mnCommerceDownloadWAS);

    // WeRetail Add-on
    JMenu mnWeRetail = new JMenu("We-Retail");
    mnUpdate.add(mnWeRetail);

    JMenuItem mnWeRetailAddon = new JMenuItem("Download Demo Add-on");
    mnWeRetailAddon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_weretail");
        }
    });
    mnWeRetail.add(mnWeRetailAddon);

    // Download all section
    mnUpdate.addSeparator();

    JMenuItem mntmAemDownloadAll = new JMenuItem("Download All Add-ons");
    mntmAemDownloadAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_all");
        }
    });
    mnUpdate.add(mntmAemDownloadAll);

    JMenu mnInfrastructure = new JMenu("Infrastructure");
    menuBar.add(mnInfrastructure);

    JMenu mnMongo = new JMenu("MongoDB");

    JMenuItem mntmInfraMongoDB = new JMenuItem("Download");
    mntmInfraMongoDB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_mongo");
        }
    });
    mnMongo.add(mntmInfraMongoDB);

    JMenuItem mntmInfraMongoDBInstall = new JMenuItem("Install");
    mntmInfraMongoDBInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_mongo");
        }
    });
    mnMongo.add(mntmInfraMongoDBInstall);
    mnMongo.addSeparator();

    JMenuItem mntmInfraMongoDBStart = new JMenuItem("Start");
    mntmInfraMongoDBStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mongo_start");
        }
    });
    mnMongo.add(mntmInfraMongoDBStart);

    JMenuItem mntmInfraMongoDBStop = new JMenuItem("Stop");
    mntmInfraMongoDBStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mongo_stop");
        }
    });
    mnMongo.add(mntmInfraMongoDBStop);
    mnInfrastructure.add(mnMongo);

    // SOLR options
    JMenu mnSOLR = new JMenu("SOLR");

    JMenuItem mntmInfraSOLR = new JMenuItem("Download");
    mntmInfraSOLR.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_solr");
        }
    });
    mnSOLR.add(mntmInfraSOLR);

    JMenuItem mntmInfraSOLRInstall = new JMenuItem("Install");
    mntmInfraSOLRInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_solr");
        }
    });
    mnSOLR.add(mntmInfraSOLRInstall);
    mnSOLR.addSeparator();

    JMenuItem mntmInfraSOLRStart = new JMenuItem("Start");
    mntmInfraSOLRStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "solr_start");
        }
    });
    mnSOLR.add(mntmInfraSOLRStart);

    JMenuItem mntmInfraSOLRStop = new JMenuItem("Stop");
    mntmInfraSOLRStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "solr_stop");
        }
    });
    mnSOLR.add(mntmInfraSOLRStop);

    mnInfrastructure.add(mnSOLR);

    // MySQL options
    JMenu mnMySQL = new JMenu("MySQL");

    JMenuItem mntmInfraMysql = new JMenuItem("Download");
    mntmInfraMysql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_mysql");
        }
    });
    mnMySQL.add(mntmInfraMysql);

    JMenuItem mntmInfraMysqlInstall = new JMenuItem("Install");
    mntmInfraMysqlInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_mysql");
        }
    });
    mnMySQL.add(mntmInfraMysqlInstall);

    mnMySQL.addSeparator();

    JMenuItem mntmInfraMysqlStart = new JMenuItem("Start");
    mntmInfraMysqlStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mysql_start");
        }
    });
    mnMySQL.add(mntmInfraMysqlStart);

    JMenuItem mntmInfraMysqlStop = new JMenuItem("Stop");
    mntmInfraMysqlStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "mysql_stop");
        }
    });
    mnMySQL.add(mntmInfraMysqlStop);

    mnInfrastructure.add(mnMySQL);

    // James options
    JMenu mnJames = new JMenu("James SMTP/POP");

    JMenuItem mntmInfraJames = new JMenuItem("Download");
    mntmInfraJames.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_james");
        }
    });
    mnJames.add(mntmInfraJames);

    JMenuItem mntmInfraJamesInstall = new JMenuItem("Install");
    mntmInfraJamesInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_james");
        }
    });
    mnJames.add(mntmInfraJamesInstall);
    mnJames.addSeparator();

    JMenuItem mntmInfraJamesStart = new JMenuItem("Start");
    mntmInfraJamesStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "james_start");
        }
    });
    mnJames.add(mntmInfraJamesStart);

    JMenuItem mntmInfraJamesStop = new JMenuItem("Stop");
    mntmInfraJamesStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "james_stop");
        }
    });
    mnJames.add(mntmInfraJamesStop);

    mnInfrastructure.add(mnJames);

    // FFMPEPG options
    JMenu mnFFMPEG = new JMenu("FFMPEG");

    JMenuItem mntmInfraFFMPEG = new JMenuItem("Download");
    mntmInfraFFMPEG.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_ffmpeg");
        }
    });
    mnFFMPEG.add(mntmInfraFFMPEG);

    JMenuItem mntmInfraFFMPEGInstall = new JMenuItem("Install");
    mntmInfraFFMPEGInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "install_ffmpeg");
        }
    });
    mnFFMPEG.add(mntmInfraFFMPEGInstall);

    mnInfrastructure.add(mnFFMPEG);

    mnInfrastructure.addSeparator();

    // InDesignServer options
    JMenu mnInDesignServer = new JMenu("InDesign Server");

    JMenuItem mntmInfraInDesignServerDownload = new JMenuItem("Download");
    mntmInfraInDesignServerDownload.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_indesignserver");
        }
    });
    mnInDesignServer.add(mntmInfraInDesignServerDownload);

    mnInDesignServer.addSeparator();

    JMenuItem mntmInfraInDesignServerStart = new JMenuItem("Start");
    mntmInfraInDesignServerStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "start_indesignserver");
        }
    });
    mnInDesignServer.add(mntmInfraInDesignServerStart);

    JMenuItem mntmInfraInDesignServerStop = new JMenuItem("Stop");
    mntmInfraInDesignServerStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "stop_indesignserver");
        }
    });
    mnInDesignServer.add(mntmInfraInDesignServerStop);

    mnInfrastructure.add(mnInDesignServer);

    mnInfrastructure.addSeparator();

    JMenuItem mntmInfraInstall = new JMenuItem("All in One Setup");
    mntmInfraInstall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "infrastructure");
        }
    });
    mnInfrastructure.add(mntmInfraInstall);

    JMenu mnOther = new JMenu("Other");
    menuBar.add(mnOther);

    JMenu mntmAemDownload = new JMenu("AEM & License files (VPN)");

    JMenuItem mntmAemLoad = new JMenuItem("Download Latest AEM Load");
    mntmAemLoad.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemLoad.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_load");
        }
    });
    mntmAemDownload.add(mntmAemLoad);

    JMenuItem mntmAemSnapshot = new JMenuItem("Download Latest AEM Snapshot");
    mntmAemSnapshot.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemSnapshot.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_snapshot");
        }
    });
    mntmAemDownload.add(mntmAemSnapshot);

    JMenuItem mntmAemDownloadAEM62 = new JMenuItem("Download AEM 6.2");
    mntmAemDownloadAEM62.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem62");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM62);

    JMenuItem mntmAemDownloadAEM61 = new JMenuItem("Download AEM 6.1");
    mntmAemDownloadAEM61.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem61");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM61);

    JMenuItem mntmAemDownloadAEM60 = new JMenuItem("Download AEM 6.0");
    mntmAemDownloadAEM60.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_aem60");
        }
    });
    mntmAemDownload.add(mntmAemDownloadAEM60);

    JMenuItem mntmAemDownloadCQ561 = new JMenuItem("Download CQ 5.6.1");
    mntmAemDownloadCQ561.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_cq561");
        }
    });
    mntmAemDownload.add(mntmAemDownloadCQ561);

    JMenuItem mntmAemDownloadCQ56 = new JMenuItem("Download CQ 5.6");
    mntmAemDownloadCQ56.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_cq56");
        }
    });
    mntmAemDownload.add(mntmAemDownloadCQ56);

    JMenuItem mntmAemDownloadOthers = new JMenuItem("Other Releases & License files");
    mntmAemDownloadOthers.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties,
                    AemDemoConstants.OPTIONS_DOWNLOAD));
        }
    });
    mntmAemDownload.add(mntmAemDownloadOthers);

    mnOther.add(mntmAemDownload);

    JMenuItem mntmAemHotfix = new JMenuItem("Download Latest Hotfixes (PackageShare)");
    mntmAemHotfix.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemHotfix.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_hotfixes_packages");
        }
    });
    mnOther.add(mntmAemHotfix);

    JMenuItem mntmAemAcs = new JMenuItem("Download Latest ACS Commons and Tools");
    mntmAemAcs.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    mntmAemAcs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "download_acs");
        }
    });
    mnOther.add(mntmAemAcs);

    // Adding the menu bar
    frameMain.setJMenuBar(menuBar);

    // Adding other form elements
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(24, 163, 650, 230);
    frameMain.getContentPane().add(scrollPane);

    final JTextArea textArea = new JTextArea("");
    textArea.setEditable(false);
    scrollPane.setViewportView(textArea);

    // List of demo machines available
    JScrollPane scrollDemoList = new JScrollPane();
    scrollDemoList.setBounds(24, 34, 208, 100);
    frameMain.getContentPane().add(scrollDemoList);
    listModelDemoMachines = AemDemoUtils.listDemoMachines(buildFile.getParentFile().getAbsolutePath());
    listDemoMachines = new JList(listModelDemoMachines);
    listDemoMachines.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listDemoMachines.setSelectedIndex(AemDemoUtils.getSelectedIndex(listDemoMachines,
            this.getDefaultProperties(), this.getPersonalProperties(), AemDemoConstants.OPTIONS_BUILD_DEFAULT));
    scrollDemoList.setViewportView(listDemoMachines);

    // Capturing the output stream of ANT commands
    AemDemoOutputStream out = new AemDemoOutputStream(textArea);
    System.setOut(new PrintStream(out));

    JButton btnStart = new JButton("Start");
    btnStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.antTarget(AemDemo.this, "start");

        }
    });

    btnStart.setBounds(250, 29, 117, 29);
    frameMain.getContentPane().add(btnStart);

    // Set Start as the default button
    JRootPane rootPane = SwingUtilities.getRootPane(btnStart);
    rootPane.setDefaultButton(btnStart);

    JButton btnInfo = new JButton("Details");
    btnInfo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            AemDemoUtils.antTarget(AemDemo.this, "details");

        }
    });
    btnInfo.setBounds(250, 59, 117, 29);
    frameMain.getContentPane().add(btnInfo);

    // Rebuild action
    JButton btnRebuild = new JButton("Rebuild");
    btnRebuild.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (AemDemo.this.getBuildInProgress()) {

                JOptionPane.showMessageDialog(null,
                        "A Demo Environment is currently being built. Please wait until it is finished.");

            } else {

                final AemDemoRebuild dialogRebuild = new AemDemoRebuild(AemDemo.this);
                dialogRebuild.setModal(true);
                dialogRebuild.setVisible(true);
                dialogRebuild.getDemoBuildName().requestFocus();
                ;

            }

        }
    });

    btnRebuild.setBounds(250, 89, 117, 29);
    frameMain.getContentPane().add(btnRebuild);

    // Stop action 
    JButton btnStop = new JButton("Stop");
    btnStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            int dialogResult = JOptionPane.showConfirmDialog(null,
                    "Are you sure you really want to stop the running instances?", "Warning",
                    JOptionPane.YES_NO_OPTION);
            if (dialogResult == JOptionPane.NO_OPTION) {
                return;
            }
            AemDemoUtils.antTarget(AemDemo.this, "stop");

        }
    });
    btnStop.setBounds(500, 29, 117, 29);
    frameMain.getContentPane().add(btnStop);

    JButton btnExit = new JButton("Exit");
    btnExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(-1);
        }
    });
    btnExit.setBounds(550, 408, 117, 29);
    frameMain.getContentPane().add(btnExit);

    JButton btnClear = new JButton("Clear");
    btnClear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText("");
        }
    });
    btnClear.setBounds(40, 408, 117, 29);
    frameMain.getContentPane().add(btnClear);

    JButton btnBackup = new JButton("Backup");
    btnBackup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "backup");
        }
    });
    btnBackup.setBounds(500, 59, 117, 29);
    frameMain.getContentPane().add(btnBackup);

    JButton btnRestore = new JButton("Restore");
    btnRestore.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            AemDemoUtils.antTarget(AemDemo.this, "restore");
        }
    });
    btnRestore.setBounds(500, 89, 117, 29);
    frameMain.getContentPane().add(btnRestore);

    JButton btnDelete = new JButton("Delete");
    btnDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int dialogResult = JOptionPane.showConfirmDialog(null,
                    "Are you sure you really want to permanently delete the selected demo configuration?",
                    "Warning", JOptionPane.YES_NO_OPTION);
            if (dialogResult == JOptionPane.NO_OPTION) {
                return;
            }
            AemDemoUtils.antTarget(AemDemo.this, "uninstall");
        }
    });
    btnDelete.setBounds(500, 119, 117, 29);
    frameMain.getContentPane().add(btnDelete);

    JLabel lblSelectYourDemo = new JLabel("Select your Demo Environment");
    lblSelectYourDemo.setBounds(24, 10, 219, 16);
    frameMain.getContentPane().add(lblSelectYourDemo);

    JLabel lblCommandOutput = new JLabel("Command Output");
    lblCommandOutput.setBounds(24, 143, 160, 16);
    frameMain.getContentPane().add(lblCommandOutput);

    // Initializing and launching the ticker
    String tickerOn = AemDemoUtils.getPropertyValue(buildFile, "demo.ticker");
    if (tickerOn == null || (tickerOn != null && tickerOn.equals("true"))) {
        AemDemoMarquee mp = new AemDemoMarquee(AemDemoConstants.Credits, 60);
        mp.setBounds(140, 440, 650, 30);
        frameMain.getContentPane().add(mp);
        mp.start();
    }

    // Launching the download tracker task
    AemDemoDownload aemDownload = new AemDemoDownload(AemDemo.this);
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    executor.scheduleAtFixedRate(aemDownload, 0, 5, TimeUnit.SECONDS);

    // Loading up the README.md file
    String line = null;
    try {
        FileReader fileReader = new FileReader(
                buildFile.getParentFile().getAbsolutePath() + File.separator + "README.md");
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        while ((line = bufferedReader.readLine()) != null) {
            if (line.indexOf("AEM Demo Machine!") > 0) {
                line = line + " (version: " + aemDemoMachineVersion + ")";
            }
            if (!line.startsWith("Double"))
                System.out.println(line);
        }
        bufferedReader.close();
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }

}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private void removeSelectedLineItem() {
    LineItem selectedLineItem = sharedSelectionModel.getSelectedLineItem();
    if (selectedLineItem != null) {
        int reply = JOptionPane.showConfirmDialog(this,
                "Are you sure you want to remove \'" + selectedLineItem.getName() + "\'?", "Remove TLA",
                JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION) {
            int i = selectedLineItem.removeFrom(module);
            UndoableEdit edit = new RemoveLineItemEdit(module, selectedLineItem, i);
            undoHandler.addEdit(edit);/*  w  w  w .  java2  s . c  o m*/
        } else {
            LOGGER.info("Remove cancelled");
        }
    } else {
        LOGGER.warning("Unable to remove this line item");
    }
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

private void handleClastMouseReleased(final MouseEvent e) {
    if (selectedTrackSection != -1) {
        Point releasePos = e.getPoint();
        float[] releaseScenePos = { 0.0f, 0.0f };
        float[] releaseAbsPos = { 0.0f, 0.0f };

        convertMousePointToSceneSpace(releasePos, releaseScenePos);

        if (!SceneGraph.getDepthOrientation()) {
            float t = scenePos[0];
            scenePos[0] = scenePos[1];/*from  w  w w . j a va 2 s  . c  om*/
            scenePos[1] = -t;
        }

        SceneGraph.addClastPoint2(scenePos[0], scenePos[1]);

        convertScenePointToAbsolute(scenePos, releaseAbsPos);
        CorelyzerApp.getApp().getToolFrame().setClastLowerRight(releaseAbsPos);
        float[] clastUpperLeft = CorelyzerApp.getApp().getToolFrame().getClastUpperLeft();

        String trackname = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex)
                .toString();
        String secname = CorelyzerApp.getApp().getSectionListModel().getElementAt(selectedTrackSectionIndex)
                .toString();
        String sessionname = CoreGraph.getInstance().getCurrentSession().getName();

        // Different kinds of annotations
        AnnotationTypeDirectory dir = AnnotationTypeDirectory.getLocalAnnotationTypeDirectory();
        if (dir == null) {
            System.out.println("Null AnnotationTypeDirectory abort.");
            return;
        }

        Enumeration<String> keys = dir.keys();
        Vector<String> annotationOptions = new Vector<String>();
        annotationOptions.add("Cancel");

        while (keys.hasMoreElements()) {
            annotationOptions.add(keys.nextElement());
        }

        Object[] options = annotationOptions.toArray();

        int sel = JOptionPane.showOptionDialog(getPopupParent(), "Which kind of Annotation?",
                "Annotation Form Selector", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                options, options[0]);

        if (sel < 0) {
            return;
        }

        try {
            this.handleAnnotationEvent(options[sel].toString(), sessionname, trackname, secname, clastUpperLeft,
                    releaseAbsPos);
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (InstantiationException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:ca.uhn.hl7v2.testpanel.controller.Controller.java

public int showDialogYesNo(String message) {
    return JOptionPane.showConfirmDialog(provideViewFrameIfItExists(), message, DIALOG_TITLE,
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
}

From source file:de.mendelson.comm.as2.client.AS2Gui.java

/**Starts a dialog that allows to send files manual to a partner
  */// w w w  .ja  v a 2s .c  om
private void sendFileManualFromSelectedTransaction() {
    if (this.configConnection == null) {
        return;
    }
    int requestValue = JOptionPane.showConfirmDialog(this, this.rb.getResourceString("dialog.resend.message"),
            this.rb.getResourceString("dialog.resend.title"), JOptionPane.YES_NO_OPTION);
    if (requestValue != JOptionPane.YES_OPTION) {
        return;
    }
    final String uniqueId = this.getClass().getName() + ".sendFileManualFromSelectedTransaction."
            + System.currentTimeMillis();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            File tempFile = null;
            try {
                AS2Gui.this.as2StatusBar.startProgressIndeterminate(
                        AS2Gui.this.rb.getResourceString("menu.file.resend"), uniqueId);
                int selectedRow = AS2Gui.this.jTableMessageOverview.getSelectedRow();
                if (selectedRow >= 0) {
                    //download the payload for the selected message
                    MessageAccessDB messageAccess = new MessageAccessDB(AS2Gui.this.configConnection,
                            AS2Gui.this.runtimeConnection);
                    JDialogManualSend dialog = new JDialogManualSend(AS2Gui.this, AS2Gui.this.configConnection,
                            AS2Gui.this.runtimeConnection, AS2Gui.this.getBaseClient(),
                            AS2Gui.this.as2StatusBar, AS2Gui.this.rb.getResourceString("uploading.to.server"));
                    AS2Message message = ((TableModelMessageOverview) AS2Gui.this.jTableMessageOverview
                            .getModel()).getRow(selectedRow);
                    if (message != null) {
                        AS2MessageInfo info = (AS2MessageInfo) message.getAS2Info();
                        PartnerAccessDB partnerAccess = new PartnerAccessDB(AS2Gui.this.configConnection,
                                AS2Gui.this.runtimeConnection);
                        Partner sender = partnerAccess.getPartner(info.getSenderId());
                        Partner receiver = partnerAccess.getPartner(info.getReceiverId());
                        List<AS2Payload> payloads = messageAccess.getPayload(info.getMessageId());
                        for (AS2Payload payload : payloads) {
                            message.addPayload(payload);
                        }
                        if (message.getPayloadCount() > 0) {
                            AS2Payload payload = message.getPayload(0);
                            //request the payload file from the server
                            TransferClientWithProgress transferClient = new TransferClientWithProgress(
                                    AS2Gui.this.getBaseClient(), AS2Gui.this.as2StatusBar.getProgressPanel());
                            DownloadRequestFile request = new DownloadRequestFile();
                            request.setFilename(payload.getPayloadFilename());
                            InputStream inStream = null;
                            OutputStream outStream = null;
                            try {
                                DownloadResponseFile response = (DownloadResponseFile) transferClient
                                        .download(request);
                                if (response.getException() != null) {
                                    throw response.getException();
                                }
                                String tempFilename = "as2.bin";
                                if (payload.getOriginalFilename() != null) {
                                    tempFilename = payload.getOriginalFilename();
                                }
                                tempFile = AS2Tools.createTempFile(tempFilename, "");
                                outStream = new FileOutputStream(tempFile);
                                inStream = response.getDataStream();
                                AS2Gui.this.copyStreams(inStream, outStream);
                                outStream.flush();
                            } catch (Throwable e) {
                                AS2Gui.this.logger.severe(e.getMessage());
                                return;
                            } finally {
                                if (inStream != null) {
                                    try {
                                        inStream.close();
                                    } catch (Exception e) {
                                    }
                                }
                                if (outStream != null) {
                                    try {
                                        outStream.close();
                                    } catch (Exception e) {
                                    }
                                }
                            }
                            dialog.initialize(sender, receiver, tempFile.getAbsolutePath());
                        }
                        dialog.performSend();
                        info.setResendCounter(info.getResendCounter() + 1);
                        messageAccess.updateResendCounter(info);
                        Logger.getLogger(AS2Server.SERVER_LOGGER_NAME).log(Level.INFO,
                                AS2Gui.this.rb.getResourceString("resend.performed"), info);
                    }
                    AS2Gui.this.as2StatusBar.stopProgressIfExists(uniqueId);
                }
            } catch (Throwable e) {
                //nop
            } finally {
                AS2Gui.this.as2StatusBar.stopProgressIfExists(uniqueId);
                if (tempFile != null) {
                    tempFile.delete();
                }
            }

        }
    };
    Executors.newSingleThreadExecutor().submit(runnable);
}

From source file:ded.ui.DiagramController.java

/** Try to load a diagram by reading the JSON out of the comment
  * section of the PNG file 'pngName'.  If that succeeds, return
  * non-null, and also set://ww w.  j ava2 s  .  c  o  m
  *
  *   * this.importedFile
  *   * this.dirty
  *   * this.fileName
  *
  * Return null if this failed but we already explained the problem
  * to the user, or the user cancels; or throw an exception otherwise. */
private Diagram loadFromPNG(String pngName) throws Exception {
    // Get the name of the image source file.
    String sourceFileName = pngName.substring(0, pngName.length() - 4);
    File sourceFile = new File(sourceFileName);
    if (sourceFile.exists()) {
        if (SwingUtil.confirmationBox(this,
                "You are trying to open a diagram PNG file \"" + pngName + "\", but the source DED file \""
                        + sourceFileName + "\" is right next to it.  Usually, you should open "
                        + "the source file instead.  Otherwise, that source file "
                        + "will be overwritten when you next save.  Are you sure you want to "
                        + "read the diagram out of the PNG comment?",
                "Are you sure?", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
            return null;
        }
    }

    // Try to read the comment from the file.  If the file is corrupt
    // or cannot be read, this will throw.  But if the comment is merely
    // absent, then this will return null.
    String comment = ImageFileUtil.getPNGComment(new File(pngName));
    if (comment == null || comment.isEmpty()) {
        SwingUtil.errorMessageBox(this, "The PNG file \"" + pngName + "\" does not contain a comment, "
                + "so it is not possible to read the diagram source from it.");
        return null;
    }

    // Do a preliminary sanity check on the comment.
    if (!comment.startsWith("{")) {
        SwingUtil.errorMessageBox(this,
                "The PNG file \"" + pngName + "\" contains a comment, "
                        + "but it does not begin with '{', so it is not a comment " + "created by DED, "
                        + "so it is not possible to read the diagram source from it.");
        return null;
    }

    // Try parsing the comment as diagram JSON.
    Diagram d;
    try {
        d = Diagram.readFromReader(new StringReader(comment));
    } catch (Exception e) {
        this.exnErrorMessageBox("The PNG file \"" + pngName + "\" has a comment that might "
                + "have been created by DED, but parsing that comment as " + "a diagram source file failed", e);
        return null;
    }

    // That worked.  Update the editor state variables.
    this.importedFile = false;

    // Note: We chop off ".png" and treat that as the name for
    // subsequent saves.
    this.setFileName(sourceFileName);

    // The file is not considered dirty because they are no
    // unsaved changes, even though the next save may cause
    // on-disk changes due to overwriting a source file if the
    // user ignored the warning above.
    this.dirty = false;

    return d;
}

From source file:com.sshtools.powervnc.PowerVNCPanel.java

public boolean canClose() {

    if (isConnected()) {
        if (JOptionPane.showConfirmDialog(this, "Close the current session and exit?", "Exit Application",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
            return false;
        }/*w  w  w.  j a  va 2  s  .  co  m*/
    }
    return true;

}

From source file:contactsdirectory.frontend.MainJFrame.java

private void removeContact() {
    if (jListContact.getSelectedIndex() < 0) {
        JOptionPane.showMessageDialog(rootPane, localizedTexts.getString("noContactSelected"), "",
                JOptionPane.INFORMATION_MESSAGE);
        return;//from   w  w w  .  j  a va2  s .c  om
    }

    if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(rootPane,
            localizedTexts.getString("deleteContactMsg"), "", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE)) {
        try {
            Contact contact = (Contact) jListContact.getSelectedValue();

            jProgressBar.setIndeterminate(true);
            jProgressBar.setVisible(true);

            RemoveContactSwingWorker worker = new RemoveContactSwingWorker(contact);
            worker.execute();

            ((DefaultListModel<Contact>) jListContact.getModel()).removeElement(contact);

            jProgressBar.setVisible(false);
            jProgressBar.setIndeterminate(false);
        } catch (RuntimeException e) {
            JOptionPane.showMessageDialog(this, localizedTexts.getString("removeContactErrMsg"),
                    localizedTexts.getString("errorMsgTitle"), JOptionPane.ERROR_MESSAGE);
        }
    }
}