Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

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

Prototype

int OK_OPTION

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

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:org.colombbus.tangara.EditorFrame.java

/**
 * This method initializes refreshButton
 *
 * @return javax.swing.JButton/*from w  ww . j  a va  2 s  .  c o  m*/
 */
private JButton getRefreshButton() {
    if (refreshButton == null) {
        refreshButton = new JButton();
        refreshButton.setBackground(new Color(156, 199, 213));
        refreshButton.setText(Messages.getString("EditorFrame.button.clean")); //$NON-NLS-1$
        refreshButton.setFont(new Font("Lucida Grande", Font.PLAIN, 13)); //$NON-NLS-1$
        refreshButton.setIcon(new ImageIcon(getClass().getResource("/org/colombbus/tangara/cross.png"))); //$NON-NLS-1$
        refreshButton.setPreferredSize(new Dimension(75, 30));
        refreshButton.setForeground(new Color(51, 51, 51));
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                graphicsPane.freeze(true);
                String message = Messages.getString("EditorFrame.confirmClean.text"); //$NON-NLS-1$
                String title = Messages.getString("EditorFrame.confirmClean.title"); //$NON-NLS-1$
                Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") }; //$NON-NLS-1$ //$NON-NLS-2$
                int answer = JOptionPane.showOptionDialog(EditorFrame.this, message, title, optionType,
                        JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                if (answer == JOptionPane.OK_OPTION) {
                    refresh();
                }
                graphicsPane.freeze(false);
                commandPane.requestFocus();
            }
        });
    }
    return refreshButton;
}

From source file:org.colombbus.tangara.net.FileReceptionDialog.java

/**
 * This method initializes this/*  ww w .j  av a  2 s. co m*/
 * 
 */
public void setVisible() {
    final String[] options = { Messages.getString("FileReceptionDialog.saveButton"),
            Messages.getString("FileReceptionDialog.cancelButton") };
    final String title = Messages.getString("FileReceptionDialog.title");
    final int optionType = JOptionPane.OK_CANCEL_OPTION;
    final int messageType = JOptionPane.QUESTION_MESSAGE;
    final Icon icon = null;

    int choosenOption = JOptionPane.showOptionDialog(owner, message, title, optionType, messageType, icon,
            options, options[0]);
    if (choosenOption == JOptionPane.OK_OPTION)
        setTargetFile();
}

From source file:org.colombbus.tangara.net.FileReceptionDialog.java

private void setTargetFile() {
    File targetDir = Configuration.instance().getUserHome();
    JFileChooser chooserDlg = new JFileChooser(targetDir);

    String filterMsg = Messages.getString("FileReceptionDialog.filter.allFiles");
    SimpleFileFilter filter = new SimpleFileFilter(filterMsg);
    chooserDlg.setFileFilter(filter);/*from ww w  .j a va2  s.c o  m*/

    File originalSelFile = new File(targetDir, sourceFilename);
    File curSelFile = originalSelFile;
    boolean showDialog = true;
    while (showDialog) {
        chooserDlg.setSelectedFile(curSelFile);
        int userAction = chooserDlg.showSaveDialog(owner);
        curSelFile = chooserDlg.getSelectedFile();
        switch (userAction) {
        case JFileChooser.CANCEL_OPTION:
            showDialog = false;
            break;
        case JFileChooser.APPROVE_OPTION:
            if (curSelFile.exists()) {
                String title = Messages.getString("FileReceptionDialog.overwrite.title");
                String msgPattern = Messages.getString("FileReceptionDialog.overwrite.message");
                String overwriteMsg = MessageFormat.format(msgPattern, curSelFile.getName());
                Object[] options = { Messages.getString("FileReceptionDialog.yes"),
                        Messages.getString("FileReceptionDialog.no") };
                int userChoice = JOptionPane.showOptionDialog(owner, overwriteMsg, title,
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a
                        // custom Icon
                        options, // the titles of buttons
                        options[0]);
                if (userChoice == JOptionPane.OK_OPTION) {
                    if (saveFileAs(curSelFile)) {
                        showDialog = false;
                    }
                }
            } else if (saveFileAs(curSelFile)) {
                showDialog = false;
            }
            break;
        case JFileChooser.ERROR_OPTION:
            LOG.error("Error in file chooser dialog");
            // TODO what to do in case of error ? Retry ?
            showDialog = false;
            break;
        }
    }
}

From source file:org.columba.mail.main.MailMain.java

private void checkDefaultClient() {
    // Check if Columba is the default mail client
    SystemDefaultMailClientHandler defaultClientHandler = new SystemDefaultMailClientHandler();
    IDefaultItem item = new DefaultItem(MailConfig.getInstance().get("options"));

    boolean checkDefault = item.getBooleanWithDefault("options/defaultclient", "check", true);

    if (checkDefault && defaultClientHandler.platfromSupportsDefaultMailClient()) {
        if (!defaultClientHandler.isDefaultMailClient()) {

            JPanel panel = new JPanel(new BorderLayout(0, 10));

            panel.add(//from  www. j a va 2  s  .  c  om
                    new MultiLineLabel(MailResourceLoader.getString("dialog", "defaultclient", "make_default")),
                    BorderLayout.NORTH);

            JCheckBox askAgain = new JCheckBox(
                    MailResourceLoader.getString("dialog", "defaultclient", "ask_no_more"));
            panel.add(askAgain, BorderLayout.CENTER);

            // Some error in the client/server communication
            // --> fall back to default login process

            // @author hubms: wait until the first frame is displayable
            // fix for bug [#CA-177]
            while (!(FrameManager.getInstance().getActiveFrame().isDisplayable())) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    LOG.severe(e.getMessage());
                }
            }

            // fix for bug [#CA-199] java 1.6.0-b105 trick
            if (!FrameManager.getInstance().getActiveFrame().isValid())
                FrameManager.getInstance().getActiveFrame().doLayout();

            int result = JOptionPane.showConfirmDialog(FrameManager.getInstance().getActiveFrame(), panel,
                    MailResourceLoader.getString("dialog", "defaultclient", "title"),
                    JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                defaultClientHandler.setDefaultMailClient();
            }

            item.setBoolean("options/defaultclient", "check", !askAgain.isSelected());
        }
    }
}

From source file:org.datacleaner.actions.OpenAnalysisJobActionListener.java

/**
 * Opens a job file//  ww w. j a v  a  2 s  . c o  m
 * 
 * @param file
 * @return
 */
public Injector openAnalysisJob(FileObject file) {
    JaxbJobReader reader = new JaxbJobReader(_configuration);
    try {
        AnalysisJobBuilder ajb = reader.create(file);

        return openAnalysisJob(file, ajb);
    } catch (NoSuchComponentException e) {
        final String message;
        if (Version.EDITION_COMMUNITY.equals(Version.getEdition())) {
            message = "<html><p>Failed to open job because of a missing component:</p><pre>" + e.getMessage()
                    + "</pre>"
                    + "<p>This may happen if the job requires a <a href=\"http://datacleaner.org/editions\">Commercial Edition of DataCleaner</a>, or an extension that you do not have installed.</p></html>";
        } else {
            message = "<html>Failed to open job because of a missing component: " + e.getMessage()
                    + "<br/><br/>"
                    + "This may happen if the job requires an extension that you do not have installed.</html>";
        }
        WidgetUtils.showErrorMessage("Cannot open job", message);

        return null;
    } catch (NoSuchDatastoreException e) {
        if (_windowContext == null) {
            // This can happen in case of single-datastore + job file
            // bootstrapping of DC
            throw e;
        }

        final AnalysisJobMetadata metadata = reader.readMetadata(file);
        final int result = JOptionPane.showConfirmDialog(null,
                e.getMessage() + "\n\nDo you wish to open this job as a template?", "Error: " + e.getMessage(),
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
        if (result == JOptionPane.OK_OPTION) {
            OpenAnalysisJobAsTemplateDialog dialog = new OpenAnalysisJobAsTemplateDialog(_windowContext,
                    _configuration, file, metadata, Providers.of(this));
            dialog.setVisible(true);
        }
        return null;
    } catch (ComponentConfigurationException e) {
        final String message;
        final Throwable cause = e.getCause();
        if (cause != null) {
            // check for causes of the mis-configuration. If there's a cause
            // with a message, then show the message first and foremost
            // (usually a validation error).
            if (!Strings.isNullOrEmpty(cause.getMessage())) {
                message = cause.getMessage();
            } else {
                message = e.getMessage();
            }
        } else {
            message = e.getMessage();
        }

        WidgetUtils.showErrorMessage("Failed to validate job configuration", message, e);
        return null;
    } catch (RuntimeException e) {
        logger.error("Unexpected failure when opening job: {}", file, e);
        throw e;
    }
}

From source file:org.drools.mas.SimpleClient.java

private void menuSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSaveAsActionPerformed
    JFileChooser saveFileChooser = new JFileChooser();
    saveFileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Model File", "mod"));
    int showDialog = saveFileChooser.showDialog(this, "Save");
    if (showDialog == JFileChooser.APPROVE_OPTION) {
        try {//from w  w w  .j  a  v  a2s.  c  o m
            File selectedFile = saveFileChooser.getSelectedFile();
            if (selectedFile.exists()) {
                int showConfirmDialog = JOptionPane.showConfirmDialog(this, "The file '"
                        + selectedFile.getCanonicalPath() + "' already exstits. Do you want to continue?");
                if (showConfirmDialog != JOptionPane.OK_OPTION) {
                    return;
                }
            }

            if (!selectedFile.getName().endsWith(".mod")) {
                selectedFile = new File(selectedFile.getAbsolutePath() + ".mod");
            }

            String content = ObjectSerializerFactory.getObjectSerializerInstance()
                    .serialize(this.factTableModel.getFacts());
            IOUtils.copy(new ByteArrayInputStream(content.getBytes()), new FileOutputStream(selectedFile));
            JOptionPane.showMessageDialog(this, "File Saved!");

            this.setTitle(selectedFile.getName());

        } catch (Exception ex) {
            Logger.getLogger(SimpleClient.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Error saving file: " + ex.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:org.eobjects.datacleaner.actions.OpenAnalysisJobActionListener.java

/**
 * Opens a job file/*from   w  ww.j a v  a2 s  .c o m*/
 * 
 * @param file
 * @return
 */
public Injector openAnalysisJob(FileObject file) {
    JaxbJobReader reader = new JaxbJobReader(_configuration);
    try {
        AnalysisJobBuilder ajb = reader.create(file);

        return openAnalysisJob(file, ajb);
    } catch (NoSuchDatastoreException e) {
        if (_windowContext == null) {
            // This can happen in case of single-datastore + job file
            // bootstrapping of DC
            throw e;
        }

        AnalysisJobMetadata metadata = reader.readMetadata(file);
        int result = JOptionPane.showConfirmDialog(null,
                e.getMessage() + "\n\nDo you wish to open this job as a template?", "Error: " + e.getMessage(),
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
        if (result == JOptionPane.OK_OPTION) {
            OpenAnalysisJobAsTemplateDialog dialog = new OpenAnalysisJobAsTemplateDialog(_windowContext,
                    _configuration, file, metadata, Providers.of(this));
            dialog.setVisible(true);
        }
        return null;
    }
}

From source file:org.executequery.gui.browser.SSHTunnelConnectionPanel.java

public boolean canConnect() {

    if (useSshCheckbox.isSelected()) {

        if (!hasValue(userNameField)) {

            GUIUtilities/*from w  w  w. j  a v  a 2  s .c o m*/
                    .displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH user name");
            return false;
        }

        if (!hasValue(portField)) {

            GUIUtilities.displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH port");
            return false;
        }

        if (!hasValue(passwordField)) {

            final JPasswordField field = WidgetFactory.createPasswordField();

            JOptionPane optionPane = new JOptionPane(field, JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION);
            JDialog dialog = optionPane.createDialog("Enter SSH password");

            dialog.addWindowFocusListener(new WindowAdapter() {
                @Override
                public void windowGainedFocus(WindowEvent e) {
                    field.requestFocusInWindow();
                }
            });

            dialog.pack();
            dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize()));
            dialog.setVisible(true);
            dialog.dispose();

            int result = Integer.parseInt(optionPane.getValue().toString());
            if (result == JOptionPane.OK_OPTION) {

                String password = MiscUtils.charsToString(field.getPassword());
                if (StringUtils.isNotBlank(password)) {

                    passwordField.setText(password);
                    return true;

                } else {

                    GUIUtilities.displayErrorMessage(
                            "You have selected SSH Tunnel but have not provided an SSH password");

                    // send back here and force them to select cancel if they want to bail

                    return canConnect();
                }

            }
            return false;
        }

    }

    return true;
}

From source file:org.executequery.gui.drivers.AbstractDriverPanel.java

public void findDriverClass(ActionEvent e) {

    if (databaseDriver.isDefaultSunOdbc()) {

        return;/*  w  w  w  .ja va  2 s .c  o  m*/
    }

    if (jarPathListModel.isEmpty()) {

        GUIUtilities.displayErrorMessage(getString("AbstractDriverPanel.pathListEmptyError"));

        return;
    }

    String[] drivers = null;
    try {

        GUIUtilities.showWaitCursor();
        drivers = implementingDriverClasses();

    } finally {

        GUIUtilities.showNormalCursor();
    }

    if (drivers == null || drivers.length == 0) {

        GUIUtilities.displayWarningMessage(getString("AbstractDriverPanel.noDriverClassesError"));
        return;
    }

    SimpleValueSelectionDialog dialog = new SimpleValueSelectionDialog(
            getString("AbstractDriverPanel.selectJdbcDriverLabel"), drivers);

    int result = dialog.showDialog();
    if (result == JOptionPane.OK_OPTION) {

        String value = dialog.getValue();
        if (StringUtils.isNotBlank(value)) {

            classField.setSelectedItem(value);
            databaseDriver.setClassName(value);
        }

    }

}

From source file:org.freeplane.core.ui.components.OptionalDontShowMeAgainDialog.java

private void close(final int pResult) {
    mResult = pResult;/*from w w  w .jav  a 2  s .  c o m*/
    if (mDontShowAgainBox.isSelected()) {
        if (mMessageType == OptionalDontShowMeAgainDialog.ONLY_OK_SELECTION_IS_STORED) {
            if (mResult == JOptionPane.OK_OPTION) {
                setProperty("true");
            }
        } else {
            setProperty((mResult == JOptionPane.OK_OPTION) ? "true" : "false");
        }
    } else {
        setProperty("");
    }
    mDialog.setVisible(false);
    mDialog.dispose();
}