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.freeplane.core.ui.components.OptionalDontShowMeAgainDialog.java

private OptionalDontShowMeAgainDialog show() {
    final String property = getProperty();
    if (StringUtils.equals(property, "true")) {
        mResult = JOptionPane.OK_OPTION;
        return this;
    }//from   w  ww.ja  v  a2s. c o m
    if (mMessageType == BOTH_OK_AND_CANCEL_OPTIONS_ARE_STORED && StringUtils.equals(property, "false")) {
        mResult = JOptionPane.CANCEL_OPTION;
        return this;
    }
    mDialog = null;
    mDialog = new JDialog(mParent, TextUtils.getText(mTitleId));
    mDialog.setModal(true);
    mDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    final AbstractAction cancelAction = new AbstractAction() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public void actionPerformed(final ActionEvent pE) {
            close(JOptionPane.CANCEL_OPTION);
        }
    };
    final AbstractAction okAction = new AbstractAction() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public void actionPerformed(final ActionEvent pE) {
            close(JOptionPane.OK_OPTION);
        }
    };
    UITools.addEscapeActionToDialog(mDialog, cancelAction);
    mDialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent pE) {
            close(JOptionPane.CANCEL_OPTION);
        }
    });
    mDialog.getContentPane().setLayout(new GridBagLayout());
    mDialog.getContentPane().add(new JLabel(TextUtils.getText(mMessageId)), new GridBagConstraints(1, 0, 1, 1,
            1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0));
    final ImageIcon questionMark;
    if (mMessageType == ONLY_OK_SELECTION_IS_SHOWN) {
        questionMark = new ImageIcon(
                ResourceController.getResourceController().getResource("/images/icons/messagebox_warning.png"));
    } else {
        questionMark = new ImageIcon(
                ResourceController.getResourceController().getResource("/images/icons/help.png"));
    }
    mDialog.getContentPane().add(new JLabel(questionMark), new GridBagConstraints(0, 0, 1, 2, 1.0, 2.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0));
    String boxString;
    if (mMessageType != OptionalDontShowMeAgainDialog.BOTH_OK_AND_CANCEL_OPTIONS_ARE_STORED) {
        boxString = "OptionalDontShowMeAgainDialog.dontShowAgain";
    } else {
        boxString = "OptionalDontShowMeAgainDialog.rememberMyDescision";
    }
    mDontShowAgainBox = new JCheckBox(TextUtils.getRawText(boxString));
    MenuBuilder.setLabelAndMnemonic(mDontShowAgainBox, null);
    mDialog.getContentPane().add(mDontShowAgainBox, new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0));
    final String okText;
    if (mMessageType == ONLY_OK_SELECTION_IS_SHOWN) {
        okText = TextUtils.getRawText("ok");
    } else {
        okText = TextUtils.getRawText("OptionalDontShowMeAgainDialog.ok");
    }
    final JButton okButton = new JButton(okText);
    MenuBuilder.setLabelAndMnemonic(okButton, null);
    okButton.addActionListener(okAction);
    mDialog.getContentPane().add(okButton, new GridBagConstraints(2, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0));
    if (mMessageType != ONLY_OK_SELECTION_IS_SHOWN) {
        final JButton cancelButton = new JButton(TextUtils.getRawText("OptionalDontShowMeAgainDialog.cancel"));
        MenuBuilder.setLabelAndMnemonic(cancelButton, null);
        cancelButton.addActionListener(cancelAction);
        mDialog.getContentPane().add(cancelButton, new GridBagConstraints(3, 3, 1, 1, 1.0, 1.0,
                GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0));
    }
    mDialog.getRootPane().setDefaultButton(okButton);
    mDialog.pack();
    if (mNode != null) {
        UITools.setDialogLocationRelativeTo(mDialog, mNode);
    } else {
        mDialog.setLocationRelativeTo(null);
    }
    mDialog.setVisible(true);
    return this;
}

From source file:org.gcaldaemon.gui.ConfigEditor.java

public final void error(String title, String message, Exception e) {
    if (message == null || message.length() < 5) {
        message = e.getClass().getName() + ": " + message; //$NON-NLS-1$
    }/*from   www .  j  a  v a 2  s  . co m*/
    log.error(message, e);
    status(message);
    TOOLKIT.beep();
    String[] options = new String[1];
    options[0] = Messages.getString("ok"); //$NON-NLS-1$
    JOptionPane.showOptionDialog(this, message, title, JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null,
            options, null);
}

From source file:org.gcaldaemon.gui.ConfigEditor.java

public final void info(String title, String message) {
    status(message);/*from ww w .j a va  2  s. com*/
    String[] options = new String[1];
    options[0] = Messages.getString("ok"); //$NON-NLS-1$
    JOptionPane.showOptionDialog(this, message, title, JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE,
            null, options, null);
}

From source file:org.gtdfree.GTDFree.java

/**
 * @param application// ww w.j  a va 2 s  .  c  o m
 * @throws IOException
 */
private void checkForUpdates(boolean notifyOnSame) {
    VersionInfo[] v = null;
    VersionInfo current = new VersionInfo(getEngine().getConfiguration());
    if (closed) {
        return;
    }
    try {
        v = getEngine().checkForNewVersions(current);
    } catch (IOException e1) {
        logger.error(Messages.getString("GTDFree.CheckFailed"), e1); //$NON-NLS-1$
        return;
    }

    if (closed) {
        return;
    }

    if (v.length == 0) {
        if (notifyOnSame) {
            JOptionPane.showMessageDialog(getJFrame(), Messages.getString("GTDFree.UpToDate"), //$NON-NLS-1$
                    Messages.getString("GTDFree.UpdateCheck"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
        }
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append("<html><body><p>"); //$NON-NLS-1$
        sb.append(Messages.getString("GTDFree.Update.1")); //$NON-NLS-1$
        sb.append(" '"); //$NON-NLS-1$
        sb.append(current.toFullVersionString());
        sb.append("'. "); //$NON-NLS-1$
        if (v.length == 1) {
            sb.append(Messages.getString("GTDFree.Update.2a")); //$NON-NLS-1$
        } else {
            sb.append(Messages.getString("GTDFree.Update.2b")); //$NON-NLS-1$
        }
        sb.append("</p><ul>"); //$NON-NLS-1$

        for (int i = 0; i < v.length; i++) {
            sb.append("<li>'"); //$NON-NLS-1$
            sb.append(v[i].toFullVersionString());
            if (v[i].notes != null && v[i].notes.length() > 0) {
                sb.append("' "); //$NON-NLS-1$
                sb.append(Messages.getString("GTDFree.Update.3")); //$NON-NLS-1$
                sb.append("<br/>'"); //$NON-NLS-1$
                sb.append(v[i].notes);
            }
            sb.append("'.</li>"); //$NON-NLS-1$
        }
        sb.append("</ul></body></html>"); //$NON-NLS-1$

        if (closed) {
            return;
        }

        int option = JOptionPane.showOptionDialog(getJFrame(), sb.toString(),
                Messages.getString("GTDFree.UpdateCheck"), //$NON-NLS-1$
                JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
                new Object[] { Messages.getString("GTDFree.VisitDL"), Messages.getString("GTDFree.Close") }, //$NON-NLS-1$ //$NON-NLS-2$
                0);
        if (closed) {
            System.exit(0);
            return;
        }
        if (option == 0) {
            try {
                Desktop.getDesktop().browse(new URI(getEngine().getConfiguration().getProperty("download.url", //$NON-NLS-1$
                        "http://gtd-free.sourceforge.net/download.html"))); //$NON-NLS-1$
            } catch (Exception e) {
                logger.error(Messages.getString("GTDFree.LoadFailed"), e); //$NON-NLS-1$
            }
        }
    }
}

From source file:org.intermine.install.swing.ProjectEditor.java

/**
 * Change the look and feel of the application.
 *
 * @param laf The new Look and Feel information.
 *
 * @return <code>true</code> if the look and feel changed ok, <code>false</code>
 * if not./*  w  ww .  ja  va2  s  . co  m*/
 *
 * @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html#dynamic">
 * The Swing Tutorial</a>
 */
public boolean changeLookAndFeel(LookAndFeelInfo laf) {
    assert SwingUtilities.isEventDispatchThread() : "Can only change L&F from event thread";

    if (laf.getName().equals(UIManager.getLookAndFeel().getName())) {
        return true;
    }

    boolean changeOk = false;
    try {
        UIManager.setLookAndFeel(laf.getClassName());
        SwingUtilities.updateComponentTreeUI(this);
        SwingUtilities.updateComponentTreeUI(modelViewerFrame);
        for (Window w : getOwnedWindows()) {
            SwingUtilities.updateComponentTreeUI(w);
        }

        changeOk = true;
    } catch (Exception e) {
        logger.error("Failed to change look and feel: " + e.getMessage());
        logger.debug("", e);

        int choice = JOptionPane.showConfirmDialog(this,
                Messages.getMessage("preferences.lookandfeel.changefailed.message", e.getMessage()),
                Messages.getMessage("preferences.lookandfeel.changefailed.title"), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE);

        changeOk = choice == JOptionPane.OK_OPTION;
    }

    return changeOk;
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Displays an error message when a user tries to delete more than one column at a time.
 *//*ww w  . ja  v a2 s . c o  m*/
protected void showColumnErrorMessage() {
    if (!(table.getSelectedColumns().length > 1)) {
        spreadsheetFunctions.deleteColumn(table.getSelectedColumn());
    } else {

        optionPane = new JOptionPane(
                "<html>Multiple column select detected!<p>Please select only one column!</p></html>",
                JOptionPane.OK_OPTION);
        optionPane.setIcon(selectOneColumnWarningIcon);
        UIHelper.applyOptionPaneBackground(optionPane, UIHelper.BG_COLOR);
        optionPane.addPropertyChangeListener(this);
        parentFrame.showJDialogAsSheet(optionPane.createDialog(this, "Delete Column"));
    }
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Delete column given an index.//from   ww w  .  j av a 2 s . c  o m
 *
 * @param vColIndex - column to remove.
 */
protected void deleteColumn(int vColIndex) {
    spreadsheet.curColDelete = vColIndex;
    spreadsheet.currentState = Spreadsheet.DELETING_COLUMN;

    TableColumn col = spreadsheet.getTable().getColumnModel().getColumn(spreadsheet.curColDelete);

    if (!col.getHeaderValue().toString().equals(TableReferenceObject.ROW_NO_TEXT)) {
        if (spreadsheet.getTableReferenceObject().isRequired(col.getHeaderValue().toString())
                && !areMultipleOccurences(col.getHeaderValue().toString())) {
            spreadsheet.optionPane = new JOptionPane(
                    "<html>This column can not be deleted due to it being a required field in this assay!</html>",
                    JOptionPane.OK_OPTION);
            spreadsheet.optionPane.setIcon(spreadsheet.requiredColumnWarningIcon);
            UIHelper.applyOptionPaneBackground(spreadsheet.optionPane, UIHelper.BG_COLOR);

            spreadsheet.optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent event) {
                    if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                        spreadsheet.getParentFrame().hideSheet();
                    }
                }
            });

            spreadsheet.getParentFrame()
                    .showJDialogAsSheet(spreadsheet.optionPane.createDialog(spreadsheet, "Can not delete"));
        } else {
            spreadsheet.optionPane = new JOptionPane(
                    "<html>Are you sure you want to delete this column? <p>This Action can not be undone!</p></html>",
                    JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_OPTION,
                    spreadsheet.confirmRemoveColumnIcon);
            UIHelper.applyOptionPaneBackground(spreadsheet.optionPane, UIHelper.BG_COLOR);
            spreadsheet.optionPane.addPropertyChangeListener(spreadsheet);
            spreadsheet.getParentFrame().showJDialogAsSheet(
                    spreadsheet.optionPane.createDialog(spreadsheet, "Confirm Delete Column"));
        }
    }
}

From source file:org.isatools.isacreatorconfigurator.configui.DataEntryPanel.java

private void showMessagePane(String message, int messageType) {
    final JOptionPane optionPane = new JOptionPane("<html>" + message + "</html>", JOptionPane.OK_OPTION);
    UIHelper.renderComponent(optionPane, UIHelper.VER_12_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    if (messageType == JOptionPane.ERROR_MESSAGE) {
        optionPane.setIcon(warningIcon);
    } else {/*from   w ww .  j a va 2 s .c  o m*/
        optionPane.setIcon(informationIcon);
    }

    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                applicationContainer.hideSheet();
            }
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            applicationContainer.showJDialogAsSheet(optionPane.createDialog(getThis(), "Message"));
        }
    });

}

From source file:org.jajuk.ui.views.ParameterViewGUIHelper.java

@Override
public void actionPerformed(final ActionEvent e) {
    if (e.getSource() == pv.jbClearHistory) {
        // show confirmation message if required
        if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_CLEAR_HISTORY)) {
            final int iResu = Messages.getChoice(Messages.getString("Confirmation_clear_history"),
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (iResu != JOptionPane.YES_OPTION) {
                return;
            }//from  w  w  w. j a v  a  2 s.  c  o m
        }
        ObservationManager.notify(new JajukEvent(JajukEvents.CLEAR_HISTORY));
    } else if (e.getSource() == pv.scbLAF) {
        // Refresh full GUI at each LAF change as a preview
        UtilGUI.setupSubstanceLookAndFeel((String) pv.scbLAF.getSelectedItem());
        UtilGUI.updateAllUIs();
    } else if (e.getSource() == pv.jbResetRatings) {
        // show confirmation message if required
        if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_RESET_RATINGS)) {
            final int iResu = Messages.getChoice(Messages.getString("Confirmation_reset_ratings"),
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (iResu != JOptionPane.YES_OPTION) {
                return;
            }
        }
        ObservationManager.notify(new JajukEvent(JajukEvents.RATE_RESET));
    } else if (e.getSource() == pv.jbResetPreferences) {
        // show confirmation message if required
        if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_RESET_RATINGS)) {
            final int iResu = Messages.getChoice(Messages.getString("Confirmation_reset_preferences"),
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (iResu != JOptionPane.YES_OPTION) {
                return;
            }
        }
        if (!DeviceManager.getInstance().isAnyDeviceRefreshing()) {
            ObservationManager.notify(new JajukEvent(JajukEvents.PREFERENCES_RESET));
        } else {
            Messages.showErrorMessage(120);
        }
    } else if (e.getSource() == pv.jbOK) {
        updateConfFromGUI();
        // Notify any client than wait for parameters updates
        final Properties details = new Properties();
        details.put(Const.DETAIL_ORIGIN, this);
        ObservationManager.notify(new JajukEvent(JajukEvents.PARAMETERS_CHANGE, details));
        if (someOptionsAppliedAtNextStartup) {
            // Inform user that some parameters will apply only at
            // next startup
            Messages.showInfoMessage(Messages.getString("ParameterView.198"));
            someOptionsAppliedAtNextStartup = false;
        }
        // Update Mute state according to bit-perfect mode
        ActionManager.getAction(JajukActions.MUTE_STATE).setEnabled(!Conf.getBoolean(Const.CONF_BIT_PERFECT));
    } else if (e.getSource() == pv.jbDefault) {
        int resu = Messages.getChoice(Messages.getString("Confirmation_defaults"),
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (resu == JOptionPane.OK_OPTION) {
            Conf.setDefaultProperties();
            updateGUIFromConf();// update UI
            InformationJPanel.getInstance().setMessage(Messages.getString("ParameterView.110"),
                    InformationJPanel.MessageType.INFORMATIVE);
            updateConfFromGUI();
            Messages.showInfoMessage(Messages.getString("ParameterView.198"));
        }
    } else if (e.getSource() == pv.jcbBackup) {
        // if backup option is unchecked, reset backup size
        if (pv.jcbBackup.isSelected()) {
            pv.backupSize.setEnabled(true);
            pv.backupSize.setValue(Conf.getInt(Const.CONF_BACKUP_SIZE));
        } else {
            pv.backupSize.setEnabled(false);
            pv.backupSize.setValue(0);
        }
    } else if ((e.getSource() == pv.jcbProxyNone) || (e.getSource() == pv.jcbProxyHttp)
            || (e.getSource() == pv.jcbProxySocks)) {
        final boolean bUseProxy = !pv.jcbProxyNone.isSelected();
        pv.jtfProxyHostname.setEnabled(bUseProxy);
        pv.jtfProxyPort.setEnabled(bUseProxy);
        pv.jtfProxyLogin.setEnabled(bUseProxy);
        pv.jtfProxyPwd.setEnabled(bUseProxy);
        pv.jlProxyHostname.setEnabled(bUseProxy);
        pv.jlProxyPort.setEnabled(bUseProxy);
        pv.jlProxyLogin.setEnabled(bUseProxy);
        pv.jlProxyPwd.setEnabled(bUseProxy);
    } else if (e.getSource() == pv.jcbAutoCover) {
        if (pv.jcbAutoCover.isSelected()) {
            pv.jcbCoverSize.setEnabled(true);
            pv.jlCoverSize.setEnabled(true);
        } else {
            pv.jlCoverSize.setEnabled(false);
            pv.jcbCoverSize.setEnabled(false);
        }
    } else if (e.getSource() == pv.jcbAudioScrobbler) {
        if (pv.jcbAudioScrobbler.isSelected()) {
            pv.jlASUser.setEnabled(true);
            pv.jtfASUser.setEnabled(true);
            pv.jlASPassword.setEnabled(true);
            pv.jpfASPassword.setEnabled(true);
        } else {
            pv.jlASUser.setEnabled(false);
            pv.jtfASUser.setEnabled(false);
            pv.jlASPassword.setEnabled(false);
            pv.jpfASPassword.setEnabled(false);
        }
    } else if (e.getSource() == pv.scbLanguage) {
        Locale locale = LocaleManager.getLocaleForDesc(((JLabel) pv.scbLanguage.getSelectedItem()).getText());
        final String sLocal = locale.getLanguage();
        final String sPreviousLocal = LocaleManager.getLocale().getLanguage();
        if (!sPreviousLocal.equals(sLocal)) {
            // local has changed
            someOptionsAppliedAtNextStartup = true;
        }
    } else if (e.getSource() == pv.jcbHotkeys) {
        someOptionsAppliedAtNextStartup = true;
    } else if (e.getSource() == pv.jbCatalogRefresh) {
        new Thread("Parameter Catalog refresh Thread") {
            @Override
            public void run() {
                UtilGUI.waiting();
                // Force albums to search for new covers
                AlbumManager.getInstance().resetCoverCache();
                // Clean thumbs
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_50X50);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_100X100);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_150X150);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_200X200);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_250X250);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_300X300);
                UtilGUI.stopWaiting();
                // For catalog view's update
                ObservationManager.notify(new JajukEvent(JajukEvents.DEVICE_REFRESH));
                // Display a message
                Messages.showInfoMessage(Messages.getString("Success"));
            }
        }.start();
    }
    // Bit-perfect and audio normalization/cross fade options are mutually exclusive
    else if (e.getSource().equals(pv.jcbEnableBitPerfect)) {
        pv.jcbUseVolnorm.setEnabled(!pv.jcbEnableBitPerfect.isSelected());
        if (pv.jcbUseVolnorm.isSelected() && pv.jcbEnableBitPerfect.isSelected()) {
            pv.jcbUseVolnorm.setSelected(false);
        }
        pv.crossFadeDuration.setEnabled(!pv.jcbEnableBitPerfect.isSelected());
    } else if (e.getSource().equals(pv.jbReloadRadiosPreset)) {
        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
            @Override
            protected Boolean doInBackground() throws Exception {
                try {
                    java.io.File fPresets = SessionService.getConfFileByPath(Const.FILE_WEB_RADIOS_PRESET);
                    DownloadManager.download(new URL(Const.URL_WEBRADIO_PRESETS), fPresets);
                    WebRadioHelper.loadPresetsRadios(fPresets);
                    return true;
                } catch (Exception ex) {
                    Log.error(ex);
                    return false;
                }
            }

            @Override
            protected void done() {
                try {
                    boolean result = get();
                    if (result) {
                        Messages.showInfoMessage(Messages.getString("Success"));
                        ObservationManager.notify(new JajukEvent(JajukEvents.DEVICE_REFRESH));
                    } else {
                        Messages.showErrorMessage(9);
                    }
                } catch (Exception e) {
                    Log.error(e);
                }
            }
        };
        worker.execute();
    }
}

From source file:org.javaswift.cloudie.CloudiePanel.java

private ContainerSpecification doGetContainerSpec() {
    JTextField name = new JTextField();
    JCheckBox priv = new JCheckBox("private container");
    if (JOptionPane.showConfirmDialog(this, new Object[] { "Name", name, priv }, "Create Container",
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        return new ContainerSpecification(name.getText(), priv.isSelected());
    }// w  w  w. j a  va2  s  .c  o  m
    return null;
}