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:de.evaluationtool.gui.EvaluationFrameActionListener.java

private ReferenceFormat formatChooser(Collection<ReferenceFormat> formats) {
    ReferenceFormat[] formatsArray = formats.toArray(new ReferenceFormat[0]);
    String[] options = new String[formats.size()];
    for (int i = 0; i < formats.size(); i++) {
        options[i] = formatsArray[i].getDescription();
    }/*from ww w  . jav  a 2 s.c  o  m*/
    int result = JOptionPane.showOptionDialog(frame, "Please choose a reference format.",
            "Choose a reference format", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
            options, options[0]);
    if (result == JOptionPane.CLOSED_OPTION)
        return null;
    return formatsArray[result];
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDRResultsController.java

@Override
protected void tryToCreateFile(File pdfFile) {
    try {/* w  ww  . ja  v  a  2  s . co m*/
        boolean success = pdfFile.createNewFile();
        if (success) {
            doseResponseController.showMessage("Pdf Report successfully created!", "Report created",
                    JOptionPane.INFORMATION_MESSAGE);
        } else {
            Object[] options = { "Yes", "No", "Cancel" };
            int showOptionDialog = JOptionPane.showOptionDialog(null,
                    "File already exists. Do you want to replace it?", "", JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options, options[2]);
            // if YES, user wants to delete existing file and replace it
            if (showOptionDialog == 0) {
                boolean delete = pdfFile.delete();
                if (!delete) {
                    return;
                }
                // if NO, returns already existing file
            } else if (showOptionDialog == 1) {
                return;
            }
        }
    } catch (IOException ex) {
        doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    try (FileOutputStream fileOutputStream = new FileOutputStream(pdfFile)) {
        // actually create PDF file
        createPdfFile(fileOutputStream);
    } catch (IOException ex) {
        doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:marytts.tools.voiceimport.DatabaseImportMain.java

protected void askIfSave() throws IOException {
    if (bnl.hasChanged()) {
        int answer = JOptionPane.showOptionDialog(this, "Do you want to save the list of basenames?", "Save?",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (answer == JOptionPane.YES_OPTION) {
            JFileChooser fc = new JFileChooser();
            fc.setSelectedFile(new File(db.getProp(db.BASENAMEFILE)));
            int returnVal = fc.showSaveDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                bnl.write(fc.getSelectedFile());
            }//from  w  ww . j a va2  s .  c o m
        }
    } else {
        System.exit(0);
    }
}

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

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

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

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

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

From source file:net.chaosserver.timelord.swingui.Timelord.java

/**
 * Returns if the system is already running based on the creation of a lock
 * file that is deleted when the JVM exits and creates a new instance of the
 * lockfile for this JVM. If the lockfile is detected it presents a dialog
 * giving an option for the end user to overwrite the lock file.
 *
 * @return indicates another instance of timelord is already running
 *//*from w ww . j a  v a2  s.  c o  m*/
public boolean isAlreadyRunning() {
    boolean alreadyRunning = false;
    File homeDirectory = new File(System.getProperty("user.home"));
    File lockFile = new File(homeDirectory, "Timelord.lockfile");

    if (lockFile.exists()) {
        String startAnyway = "Start Anyway";
        String dontStart = "Cancel Start";
        Object[] options = { dontStart, startAnyway };
        int result = JOptionPane.showOptionDialog(null,
                "A lockfile for an instance of timelord " + "has been found.  If you are already "
                        + "running timelord, click \"" + dontStart + "\" and use the running program.",
                "Timelord Already Running", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null,
                options, dontStart);

        if (result == 0) {
            alreadyRunning = true;
        }
    }

    if (!alreadyRunning) {
        try {
            lockFile.createNewFile();
            lockFile.deleteOnExit();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    return alreadyRunning;
}

From source file:net.pms.encoders.MEncoderVideo.java

@Override
public JComponent config() {
    // Apply the orientation for the locale
    Locale locale = new Locale(configuration.getLanguage());
    ComponentOrientation orientation = ComponentOrientation.getOrientation(locale);
    String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation);

    FormLayout layout = new FormLayout(colSpec, ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.EMPTY_BORDER);
    builder.setOpaque(false);/* w  w  w.  jav a  2  s.  c  o m*/

    CellConstraints cc = new CellConstraints();

    checkBox = new JCheckBox(Messages.getString("MEncoderVideo.0"));
    checkBox.setContentAreaFilled(false);

    if (configuration.getSkipLoopFilterEnabled()) {
        checkBox.setSelected(true);
    }

    checkBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setSkipLoopFilterEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"),
            FormLayoutUtil.flip(cc.xyw(1, 1, 15), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    mencodermt = new JCheckBox(Messages.getString("MEncoderVideo.35"));
    mencodermt.setContentAreaFilled(false);

    if (configuration.getMencoderMT()) {
        mencodermt.setSelected(true);
    }

    mencodermt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setMencoderMT(mencodermt.isSelected());
        }
    });

    mencodermt.setEnabled(Platform.isWindows() || Platform.isMac());

    builder.add(mencodermt, FormLayoutUtil.flip(cc.xy(1, 3), colSpec, orientation));
    builder.add(checkBox, FormLayoutUtil.flip(cc.xyw(3, 3, 12), colSpec, orientation));

    noskip = new JCheckBox(Messages.getString("MEncoderVideo.2"));
    noskip.setContentAreaFilled(false);

    if (configuration.isMencoderNoOutOfSync()) {
        noskip.setSelected(true);
    }

    noskip.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderNoOutOfSync((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    builder.add(noskip, FormLayoutUtil.flip(cc.xy(1, 5), colSpec, orientation));

    JButton button = new JButton(Messages.getString("MEncoderVideo.29"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPanel codecPanel = new JPanel(new BorderLayout());
            final JTextArea textArea = new JTextArea();
            textArea.setText(configuration.getMencoderCodecSpecificConfig());
            textArea.setFont(new Font("Courier", Font.PLAIN, 12));
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new java.awt.Dimension(900, 100));

            final JTextArea textAreaDefault = new JTextArea();
            textAreaDefault.setText(DEFAULT_CODEC_CONF_SCRIPT);
            textAreaDefault.setBackground(Color.WHITE);
            textAreaDefault.setFont(new Font("Courier", Font.PLAIN, 12));
            textAreaDefault.setEditable(false);
            textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync());
            JScrollPane scrollPaneDefault = new JScrollPane(textAreaDefault);
            scrollPaneDefault.setPreferredSize(new java.awt.Dimension(900, 450));

            JPanel customPanel = new JPanel(new BorderLayout());
            intelligentsync = new JCheckBox(Messages.getString("MEncoderVideo.3"));
            intelligentsync.setContentAreaFilled(false);

            if (configuration.isMencoderIntelligentSync()) {
                intelligentsync.setSelected(true);
            }

            intelligentsync.addItemListener(new ItemListener() {
                @Override
                public void itemStateChanged(ItemEvent e) {
                    configuration.setMencoderIntelligentSync((e.getStateChange() == ItemEvent.SELECTED));
                    textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync());

                }
            });

            JLabel label = new JLabel(Messages.getString("MEncoderVideo.33"));
            customPanel.add(label, BorderLayout.NORTH);
            customPanel.add(scrollPane, BorderLayout.SOUTH);

            codecPanel.add(intelligentsync, BorderLayout.NORTH);
            codecPanel.add(scrollPaneDefault, BorderLayout.CENTER);
            codecPanel.add(customPanel, BorderLayout.SOUTH);

            while (JOptionPane.showOptionDialog(
                    SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), codecPanel,
                    Messages.getString("MEncoderVideo.34"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) {
                String newCodecparam = textArea.getText();
                DLNAMediaInfo fakemedia = new DLNAMediaInfo();
                DLNAMediaAudio audio = new DLNAMediaAudio();
                audio.setCodecA("ac3");
                fakemedia.setCodecV("mpeg4");
                fakemedia.setContainer("matroska");
                fakemedia.setDuration(45d * 60);
                audio.getAudioProperties().setNumberOfChannels(2);
                fakemedia.setWidth(1280);
                fakemedia.setHeight(720);
                audio.setSampleFrequency("48000");
                fakemedia.setFrameRate("23.976");
                fakemedia.getAudioTracksList().add(audio);
                String result[] = getSpecificCodecOptions(newCodecparam, fakemedia,
                        new OutputParams(configuration), "dummy.mpg", "dummy.srt", false, true);

                if (result.length > 0 && result[0].startsWith("@@")) {
                    String errorMessage = result[0].substring(2);
                    JOptionPane.showMessageDialog(
                            SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), errorMessage,
                            Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE);
                } else {
                    configuration.setMencoderCodecSpecificConfig(newCodecparam);
                    break;
                }
            }
        }
    });
    builder.add(button, FormLayoutUtil.flip(cc.xy(1, 11), colSpec, orientation));

    forcefps = new JCheckBox(Messages.getString("MEncoderVideo.4"));
    forcefps.setContentAreaFilled(false);
    if (configuration.isMencoderForceFps()) {
        forcefps.setSelected(true);
    }
    forcefps.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderForceFps(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    builder.add(forcefps, FormLayoutUtil.flip(cc.xyw(1, 7, 2), colSpec, orientation));

    yadif = new JCheckBox(Messages.getString("MEncoderVideo.26"));
    yadif.setContentAreaFilled(false);
    if (configuration.isMencoderYadif()) {
        yadif.setSelected(true);
    }
    yadif.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderYadif(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(yadif, FormLayoutUtil.flip(cc.xyw(3, 7, 7), colSpec, orientation));

    scaler = new JCheckBox(Messages.getString("MEncoderVideo.27"));
    scaler.setContentAreaFilled(false);
    scaler.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderScaler(e.getStateChange() == ItemEvent.SELECTED);
            scaleX.setEnabled(configuration.isMencoderScaler());
            scaleY.setEnabled(configuration.isMencoderScaler());
        }
    });
    builder.add(scaler, FormLayoutUtil.flip(cc.xyw(3, 5, 7), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.28"), FormLayoutUtil
            .flip(cc.xy(9, 5, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    scaleX = new JTextField("" + configuration.getMencoderScaleX());
    scaleX.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            try {
                configuration.setMencoderScaleX(Integer.parseInt(scaleX.getText()));
            } catch (NumberFormatException nfe) {
                logger.debug("Could not parse scaleX from \"" + scaleX.getText() + "\"");
            }
        }
    });
    builder.add(scaleX, FormLayoutUtil.flip(cc.xy(11, 5), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.30"), FormLayoutUtil
            .flip(cc.xy(13, 5, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    scaleY = new JTextField("" + configuration.getMencoderScaleY());
    scaleY.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            try {
                configuration.setMencoderScaleY(Integer.parseInt(scaleY.getText()));
            } catch (NumberFormatException nfe) {
                logger.debug("Could not parse scaleY from \"" + scaleY.getText() + "\"");
            }
        }
    });
    builder.add(scaleY, FormLayoutUtil.flip(cc.xy(15, 5), colSpec, orientation));

    if (configuration.isMencoderScaler()) {
        scaler.setSelected(true);
    } else {
        scaleX.setEnabled(false);
        scaleY.setEnabled(false);
    }

    builder.addLabel(Messages.getString("MEncoderVideo.6"),
            FormLayoutUtil.flip(cc.xy(1, 13), colSpec, orientation));
    mencoder_custom_options = new JTextField(configuration.getMencoderCustomOptions());
    mencoder_custom_options.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderCustomOptions(mencoder_custom_options.getText());
        }
    });
    builder.add(mencoder_custom_options, FormLayoutUtil.flip(cc.xyw(3, 13, 13), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.93"),
            FormLayoutUtil.flip(cc.xy(1, 15), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.28") + " (%)", FormLayoutUtil
            .flip(cc.xy(1, 15, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    ocw = new JTextField(configuration.getMencoderOverscanCompensationWidth());
    ocw.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderOverscanCompensationWidth(ocw.getText());
        }
    });
    builder.add(ocw, FormLayoutUtil.flip(cc.xy(3, 15), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.30") + " (%)",
            FormLayoutUtil.flip(cc.xy(5, 15), colSpec, orientation));
    och = new JTextField(configuration.getMencoderOverscanCompensationHeight());
    och.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderOverscanCompensationHeight(och.getText());
        }
    });
    builder.add(och, FormLayoutUtil.flip(cc.xy(7, 15), colSpec, orientation));

    cmp = builder.addSeparator(Messages.getString("MEncoderVideo.8"),
            FormLayoutUtil.flip(cc.xyw(1, 17, 15), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    builder.addLabel(Messages.getString("MEncoderVideo.16"), FormLayoutUtil
            .flip(cc.xy(1, 27, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));

    mencoder_noass_scale = new JTextField(configuration.getMencoderNoAssScale());
    mencoder_noass_scale.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssScale(mencoder_noass_scale.getText());
        }
    });

    builder.addLabel(Messages.getString("MEncoderVideo.17"),
            FormLayoutUtil.flip(cc.xy(5, 27), colSpec, orientation));

    mencoder_noass_outline = new JTextField(configuration.getMencoderNoAssOutline());
    mencoder_noass_outline.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssOutline(mencoder_noass_outline.getText());
        }
    });

    builder.addLabel(Messages.getString("MEncoderVideo.18"),
            FormLayoutUtil.flip(cc.xy(9, 27), colSpec, orientation));

    mencoder_noass_blur = new JTextField(configuration.getMencoderNoAssBlur());
    mencoder_noass_blur.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssBlur(mencoder_noass_blur.getText());
        }
    });

    builder.addLabel(Messages.getString("MEncoderVideo.19"),
            FormLayoutUtil.flip(cc.xy(13, 27), colSpec, orientation));

    mencoder_noass_subpos = new JTextField(configuration.getMencoderNoAssSubPos());
    mencoder_noass_subpos.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssSubPos(mencoder_noass_subpos.getText());
        }
    });

    builder.add(mencoder_noass_scale, FormLayoutUtil.flip(cc.xy(3, 27), colSpec, orientation));
    builder.add(mencoder_noass_outline, FormLayoutUtil.flip(cc.xy(7, 27), colSpec, orientation));
    builder.add(mencoder_noass_blur, FormLayoutUtil.flip(cc.xy(11, 27), colSpec, orientation));
    builder.add(mencoder_noass_subpos, FormLayoutUtil.flip(cc.xy(15, 27), colSpec, orientation));

    ass = new JCheckBox(Messages.getString("MEncoderVideo.20"));
    ass.setContentAreaFilled(false);
    ass.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e != null) {
                configuration.setMencoderAss(e.getStateChange() == ItemEvent.SELECTED);
            }
        }
    });
    builder.add(ass, FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation));
    ass.setSelected(configuration.isMencoderAss());
    ass.getItemListeners()[0].itemStateChanged(null);

    fc = new JCheckBox(Messages.getString("MEncoderVideo.21"));
    fc.setContentAreaFilled(false);
    fc.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderFontConfig(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(fc, FormLayoutUtil.flip(cc.xyw(3, 23, 5), colSpec, orientation));
    fc.setSelected(configuration.isMencoderFontConfig());

    assdefaultstyle = new JCheckBox(Messages.getString("MEncoderVideo.36"));
    assdefaultstyle.setContentAreaFilled(false);
    assdefaultstyle.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderAssDefaultStyle(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(assdefaultstyle, FormLayoutUtil.flip(cc.xyw(8, 23, 4), colSpec, orientation));
    assdefaultstyle.setSelected(configuration.isMencoderAssDefaultStyle());

    builder.addLabel(Messages.getString("MEncoderVideo.92"),
            FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation));
    subq = new JTextField(configuration.getMencoderVobsubSubtitleQuality());
    subq.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderVobsubSubtitleQuality(subq.getText());
        }
    });
    builder.add(subq, FormLayoutUtil.flip(cc.xyw(3, 29, 1), colSpec, orientation));

    configuration.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (event.getPropertyName() == null) {
                return;
            }
            if ((!event.isBeforeUpdate())
                    && event.getPropertyName().equals(PmsConfiguration.KEY_DISABLE_SUBTITLES)) {
                boolean enabled = !configuration.isDisableSubtitles();
                ass.setEnabled(enabled);
                assdefaultstyle.setEnabled(enabled);
                fc.setEnabled(enabled);
                mencoder_noass_scale.setEnabled(enabled);
                mencoder_noass_outline.setEnabled(enabled);
                mencoder_noass_blur.setEnabled(enabled);
                mencoder_noass_subpos.setEnabled(enabled);
                ocw.setEnabled(enabled);
                och.setEnabled(enabled);
                subq.setEnabled(enabled);

                if (enabled) {
                    ass.getItemListeners()[0].itemStateChanged(null);
                }
            }
        }
    });

    JPanel panel = builder.getPanel();

    // Apply the orientation to the panel and all components in it
    panel.applyComponentOrientation(orientation);

    return panel;
}

From source file:edu.ku.brc.af.ui.forms.SubViewBtn.java

/**
 * /*  w  w w .  j  a  va  2  s .c om*/
 */
protected void showForm() {
    //boolean isParentNew = parentObj instanceof FormDataObjIFace ? ((FormDataObjIFace)parentObj).getId() == null : false;
    boolean isNewObject = MultiView.isOptionOn(options, MultiView.IS_NEW_OBJECT);
    boolean isEdit = MultiView.isOptionOn(options, MultiView.IS_EDITTING) || isNewObject;

    String closeBtnTitle = isEdit ? getResourceString("DONE") : getResourceString("CLOSE");

    ViewBasedDisplayDialog dlg = new ViewBasedDisplayDialog((Frame) UIRegistry.getTopWindow(),
            subviewDef.getViewSetName(), subviewDef.getViewName(), null, // What is this argument???
            frameTitle, closeBtnTitle, view.getClassName(), cellName, // idFieldName
            isEdit | isNewObject, false, cellName, mvParent,
            options | MultiView.HIDE_SAVE_BTN | MultiView.DONT_ADD_ALL_ALTVIEWS
                    | MultiView.USE_ONLY_CREATION_MODE,
            CustomDialog.CANCEL_BTN | (StringUtils.isNotEmpty(helpContext) ? CustomDialog.HELP_BTN : 0)) {

        /* (non-Javadoc)
         * @see edu.ku.brc.ui.db.ViewBasedDisplayDialog#cancelButtonPressed()
         */
        @Override
        protected void cancelButtonPressed() {
            multiView.aboutToShutdown();

            FormViewObj fvo = multiView.getCurrentViewAsFormViewObj();
            if (fvo != null) {
                FormValidator validator = multiView.getCurrentValidator();
                if (validator != null && validator.getState() != UIValidatable.ErrorType.Valid) {
                    boolean isNew = fvo.isNewlyCreatedDataObj();
                    String msgKey = isNew ? "MV_INCOMPLETE_DATA_NEW" : "MV_INCOMPLETE_DATA";
                    String btnKey = isNew ? "MV_REMOVE_ITEM" : "MV_DISCARD_ITEM";
                    Object[] optionLabels = { getResourceString(btnKey), getResourceString("CANCEL") };
                    int rv = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(),
                            getResourceString(msgKey), getResourceString("MV_INCOMPLETE_DATA_TITLE"),
                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionLabels,
                            optionLabels[0]);
                    if (rv == JOptionPane.NO_OPTION) {
                        return;
                    }
                }
            }
            super.cancelButtonPressed();
        }

    };

    dlg.setHelpContext("SUBVIEW_FORM_HELP");

    dlg.setCancelLabel(closeBtnTitle);
    frame = dlg;
    multiView = frame.getMultiView();

    // Only get the data from the parent the first time.
    if (parentObj != null && dataObj == null) {
        DataProviderSessionIFace sessionLocal = null;
        try {
            DataObjectGettable getter = DataObjectGettableFactory.get(parentObj.getClass().getName(),
                    FormHelper.DATA_OBJ_GETTER);
            sessionLocal = parentObj.getId() != null ? DataProviderFactory.getInstance().createSession() : null;

            // rods - 07/22/08 - Apparently Merge just doesn't work the way it seems it should
            // so instead we will just go get the parent again.
            if (parentObj.getId() != null) {
                parentObj = (FormDataObjIFace) sessionLocal.get(parentObj.getDataClass(), parentObj.getId());
            }

            Object[] objs = UIHelper.getFieldValues(subviewDef, parentObj, getter);
            if (objs == null) {
                try {
                    Class<?> cls = Class.forName(view.getClassName());
                    if (FormDataObjIFace.class.isAssignableFrom(cls)) {
                        dataObj = cls.newInstance();
                        ((FormDataObjIFace) dataObj).initialize();
                        parentObj.addReference((FormDataObjIFace) dataObj, subviewDef.getName());
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SubViewBtn.class, ex);
                }

            } else {
                dataObj = objs[0];
            }
            multiView.setParentDataObj(parentObj);
            multiView.setData(dataObj);
            CommandDispatcher.dispatch(new CommandAction("Data_Entry", "SHOW_SUBVIEW",
                    new Pair<Object, Object>(parentObj, dataObj)));

        } catch (Exception ex) {
            ex.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SubViewBtn.class, ex);

        } finally {
            if (sessionLocal != null) {
                sessionLocal.close();
            }
        }
    } else {
        multiView.setParentDataObj(parentObj);
        DataProviderSessionIFace sessionLocal = null;
        try {
            sessionLocal = DataProviderFactory.getInstance().createSession();
            multiView.setSession(sessionLocal);
            if (dataObj instanceof Set<?>) {
                for (Object obj : ((Set<?>) dataObj)) {
                    if (obj instanceof FormDataObjIFace && ((FormDataObjIFace) obj).getId() != null) {
                        sessionLocal.attach(obj);
                    }

                }
            } else if (dataObj instanceof FormDataObjIFace && ((FormDataObjIFace) dataObj).getId() != null) {
                sessionLocal.attach(dataObj);
            }
            multiView.setData(dataObj);
            multiView.setSession(null);

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            sessionLocal.close();
        }
    }

    multiView.setClassToCreate(classToCreate);

    FormValidator formVal = null;
    if (multiView.getCurrentViewAsFormViewObj() != null) {
        formVal = multiView.getCurrentViewAsFormViewObj().getValidator();
        if (formVal != null) {
            formVal.setEnabled(true);
            multiView.addCurrentValidator();
            if (multiView.getCurrentViewAsFormViewObj() != null) {
                final ResultSetController rsc = multiView.getCurrentViewAsFormViewObj().getRsController();
                if (rsc != null && rsc.getNewRecBtn() != null) {
                    rsc.getNewRecBtn().setEnabled(true);
                    /*if (rsc.getLength() == 0)
                    {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run()
                        {
                            //rsc.getNewRecBtn().doClick();
                        }
                    });
                    }*/
                }
            }
        }
    }

    dlg.createUI();
    frame.getCancelBtn().setEnabled(true);

    frame.showDisplay(true);

    if (formVal != null) {
        multiView.removeCurrentValidator();
    }

    FormViewObj fvo = null;
    if (multiView != null) {
        if (frame.isEditMode()) {
            frame.getMultiView().getDataFromUI();
            FormViewObj.traverseToGetDataFromForms(frame.getMultiView());

            updateBtnText();

            mvParent.getCurrentValidator().validateRoot();
        }
    } else {

    }

    CommandDispatcher.dispatch(new CommandAction("Data_Entry", "CLOSE_SUBVIEW",
            new Triple<Object, Object, Object>(fvo, parentObj, dataObj)));

    frame.dispose();
    frame = null;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDoseResponseController.java

/**
 * Initialize main view//from   ww  w .  j a v a2 s  .co m
 */
@Override
protected void initMainView() {
    genericDRParentPanel = new GenericDRParentPanel();
    dRPanel = new DRPanel();
    //buttons disabled at start
    genericDRParentPanel.getCancelButton().setEnabled(false);
    genericDRParentPanel.getNextButton().setEnabled(false);
    getCardLayout().first(genericDRParentPanel.getContentPanel());
    onCardSwitch();
    //create a ButtonGroup for the radioButtons used for analysis
    ButtonGroup mainDRRadioButtonGroup = new ButtonGroup();
    //adding buttons to a ButtonGroup automatically deselect one when another one gets selected
    mainDRRadioButtonGroup.add(dRPanel.getInputDRButton());
    mainDRRadioButtonGroup.add(dRPanel.getInitialPlotDRButton());
    mainDRRadioButtonGroup.add(dRPanel.getNormalizedPlotDRButton());
    mainDRRadioButtonGroup.add(dRPanel.getResultsDRButton());
    //select as default first button
    dRPanel.getInputDRButton().setSelected(true);
    //init dataTable
    dataTable = new JTable();
    JScrollPane scrollPane = new JScrollPane(dataTable);
    //the table will take all the viewport height available
    dataTable.setFillsViewportHeight(true);
    scrollPane.getViewport().setBackground(Color.white);
    dataTable.getTableHeader().setReorderingAllowed(false);
    //row and column selection must be false
    //dataTable.setColumnSelectionAllowed(false);
    //dataTable.setRowSelectionAllowed(false);
    dRPanel.getDatatableDRPanel().add(scrollPane, BorderLayout.CENTER);
    setLogTransform(true);

    /**
     * Action listeners for uppermost panel.
     */
    //this button is ONLY used when going from the loading to the analysis
    genericDRParentPanel.getNextButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            genericDRParentPanel.getNextButton().setEnabled(false);
            genericDRParentPanel.getCancelButton().setEnabled(true);
            //save any metadata that was provided manually
            loadGenericDRDataController.setManualMetaData(importedDRDataHolder);
            //switch between child panels
            getCardLayout().next(genericDRParentPanel.getContentPanel());
            onCardSwitch();
        }
    });

    genericDRParentPanel.getCancelButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // warn the user and reset everything
            Object[] options = { "Yes", "No" };
            int showOptionDialog = JOptionPane.showOptionDialog(null,
                    "Current analysis won't be saved. Continue?", "", JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options, options[1]);
            if (showOptionDialog == 0) {
                // reset everything
                resetOnCancel();
            }
        }
    });

    /**
     * Action listeners for shared panel. When button is selected, switch
     * view to corresponding subview
     */
    dRPanel.getInputDRButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //switch shared table view
            updateModelInTable(dRInputController.getTableModel());
            updateTableInfoMessage("This table contains all conditions and their respective responses");
            /**
             * for (int columnIndex = 0; columnIndex <
             * dataTable.getColumnCount(); columnIndex++) {
             * GuiUtils.packColumn(dataTable, columnIndex); }
             */
            dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT));
            //remove other panels
            dRInitialController.getInitialChartPanel().setChart(null);
            dRNormalizedController.getNormalizedChartPanel().setChart(null);
            dRResultsController.getDupeInitialChartPanel().setChart(null);
            dRResultsController.getDupeNormalizedChartPanel().setChart(null);
            dRPanel.getGraphicsDRParentPanel().removeAll();
            dRPanel.getGraphicsDRParentPanel().revalidate();
            dRPanel.getGraphicsDRParentPanel().repaint();
            //add panel to view
            dRPanel.getGraphicsDRParentPanel().add(dRInputController.getdRInputPanel(), gridBagConstraints);
        }
    });

    dRPanel.getInitialPlotDRButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (dRAnalysisGroup != null) {
                if (isFirstFitting()) {
                    initFirstFitting();
                    setFirstFitting(false);
                }
                //switch shared table view
                updateModelInTable(dRInitialController.getTableModel());
                updateTableInfoMessage(
                        "If you checked the box at the import screen, the doses have been log-transformed. Responses have not been changed");
                /**
                 * for (int columnIndex = 0; columnIndex <
                 * dataTable.getColumnCount(); columnIndex++) {
                 * GuiUtils.packColumn(dataTable, columnIndex); }
                 */
                dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT));
                //remove other panels
                dRNormalizedController.getNormalizedChartPanel().setChart(null);
                dRResultsController.getDupeInitialChartPanel().setChart(null);
                dRResultsController.getDupeNormalizedChartPanel().setChart(null);
                dRPanel.getGraphicsDRParentPanel().removeAll();
                dRPanel.getGraphicsDRParentPanel().revalidate();
                dRPanel.getGraphicsDRParentPanel().repaint();
                dRPanel.getGraphicsDRParentPanel().add(dRInitialController.getDRInitialPlotPanel(),
                        gridBagConstraints);
                //Plot fitted data in dose-response curve, along with R annotation
                plotDoseResponse(dRInitialController.getInitialChartPanel(),
                        dRInitialController.getDRInitialPlotPanel().getDoseResponseChartParentPanel(),
                        getDataToFit(false), getdRAnalysisGroup(), false);
            }
        }
    });

    dRPanel.getNormalizedPlotDRButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (dRAnalysisGroup != null) {
                //in case user skips "initial" subview and goes straight to normalization
                if (isFirstFitting()) {
                    initFirstFitting();
                    setFirstFitting(false);
                }
                //switch shared table view
                updateModelInTable(dRNormalizedController.getTableModel());
                updateTableInfoMessage(
                        "Potentially log-transformed doses with their normalized responses per replicate");
                /**
                 * for (int columnIndex = 0; columnIndex <
                 * dataTable.getColumnCount(); columnIndex++) {
                 * GuiUtils.packColumn(dataTable, columnIndex); }
                 */
                dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT));
                //remove other panels
                dRInitialController.getInitialChartPanel().setChart(null);
                dRResultsController.getDupeInitialChartPanel().setChart(null);
                dRResultsController.getDupeNormalizedChartPanel().setChart(null);
                dRPanel.getGraphicsDRParentPanel().removeAll();
                dRPanel.getGraphicsDRParentPanel().revalidate();
                dRPanel.getGraphicsDRParentPanel().repaint();
                dRPanel.getGraphicsDRParentPanel().add(dRNormalizedController.getDRNormalizedPlotPanel(),
                        gridBagConstraints);
                //Plot fitted data in dose-response curve, along with R annotation
                plotDoseResponse(dRNormalizedController.getNormalizedChartPanel(),
                        dRNormalizedController.getDRNormalizedPlotPanel().getDoseResponseChartParentPanel(),
                        getDataToFit(true), getdRAnalysisGroup(), true);
            }
        }
    });

    dRPanel.getResultsDRButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (dRAnalysisGroup != null) {
                //switch shared table view: create and set new table model with most recent statistical values
                // (these values get recalculated after each new fitting)
                dRResultsController.setTableModel(dRResultsController.reCreateTableModel(dRAnalysisGroup));
                updateModelInTable(dRResultsController.getTableModel());
                updateTableInfoMessage(
                        "Statistical values from the curve fit of the initial and normalized data.");

                //remove other panels
                dRInitialController.getInitialChartPanel().setChart(null);
                dRNormalizedController.getNormalizedChartPanel().setChart(null);
                dRPanel.getGraphicsDRParentPanel().removeAll();
                dRPanel.getGraphicsDRParentPanel().revalidate();
                dRPanel.getGraphicsDRParentPanel().repaint();
                dRPanel.getGraphicsDRParentPanel().add(dRResultsController.getdRResultsPanel(),
                        gridBagConstraints);
                //plot curves
                dRResultsController.plotCharts();
            }
        }
    });

    //add views to parent panels
    cellMissyController.getCellMissyFrame().getDoseResponseAnalysisParentPanel().add(genericDRParentPanel,
            gridBagConstraints);
    genericDRParentPanel.getDataLoadingPanel().add(loadGenericDRDataController.getDataLoadingPanel(),
            gridBagConstraints);
    genericDRParentPanel.getDoseResponseParentPanel().add(dRPanel, gridBagConstraints);
}

From source file:marytts.tools.voiceimport.DatabaseImportMain.java

protected void closeGUI() {
    // This doesn't work because Java cannot close the X11 connection, see
    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4420885
    int answer = JOptionPane.showOptionDialog(this,
            "Do you want to close this GUI?\n\n"
                    + "The components that are currently running will continue to run,\n"
                    + "but you will not be able to save settings or select/deselect\n" + "components to run.\n"
                    + "This may be useful when running this tool using 'nohup' on a server\n"
                    + "because it allows you to log off without stopping the process.",
            "Really close GUI?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (answer == JOptionPane.YES_OPTION) {
        this.setVisible(false);
        this.dispose();
    }/*w ww .  j ava  2s  . c o  m*/
}

From source file:charitypledge.Pledge.java

private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {
    JFrame frame = new JFrame();
    int confirm = JOptionPane.showOptionDialog(frame, "Are You Sure to Close this Application?",
            "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (confirm == JOptionPane.YES_OPTION) {
        System.exit(0);//from  w w  w.  j  av a 2s  .c o  m
    }
}