Changeset 2929 in josm for trunk/src/org


Ignore:
Timestamp:
2010-02-03T05:23:56+01:00 (15 years ago)
Author:
mjulius
Message:

fixes #4470 - Remembers choice does not remember correctly - based on patch by Nakor
OptionDialogs and ConfirmationDialogs now remember their enabled status and return value only if the user has either chosen Yes/OK or No.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java

    r2831 r2929  
    8787     * a NO and a CANCEL button
    8888     *
    89      * Replies true, if the selected option is equal to <code>trueOption</code>, otherwise false.
    90      * Replies true, if the dialog is not displayed because the respective preference option
    91      * <code>preferenceKey</code> is set to false.
     89     * Returns one of the constants JOptionPane.YES_OPTION, JOptionPane.NO_OPTION,
     90     * JOptionPane.CANCEL_OPTION or JOptionPane.CLOSED_OPTION depending on the action chosen by
     91     * the user.
    9292     *
    9393     * @param preferenceKey the preference key
     
    100100     * @param defaultOption the default option
    101101     *
    102      *
    103      * @return the index of the selected option. {@see JOptionPane#CLOSED_OPTION} if the dialog was closed.
    104      * {@see ConditionalOptionPaneUtil#DIALOG_DISABLED_OPTION} if the dialog is disabled.
    105      *
     102     * @return the option selected by user. {@see JOptionPane#CLOSED_OPTION} if the dialog was closed.
    106103     */
    107104    static public int showOptionDialog(String preferenceKey, Component parent, Object message, String title, int optionType, int messageType, Object [] options, Object defaultOption) throws HeadlessException {
    108         if (!getDialogShowingEnabled(preferenceKey))
    109             return DIALOG_DISABLED_OPTION;
     105        int ret = getDialogReturnValue(preferenceKey);
     106        if (!getDialogShowingEnabled(preferenceKey) && ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)))
     107            return ret;
    110108        MessagePanel pnl = new MessagePanel(false, message);
    111         int ret = JOptionPane.showOptionDialog(parent, pnl, title, optionType, messageType, null,options,defaultOption);
    112 
    113         if(!pnl.getDialogShowingEnabled())
     109        ret = JOptionPane.showOptionDialog(parent, pnl, title, optionType, messageType, null, options, defaultOption);
     110
     111        if (((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)) && !pnl.getDialogShowingEnabled()) {
    114112            setDialogShowingEnabled(preferenceKey, false);
     113            setDialogReturnValue(preferenceKey, ret);
     114        }
    115115        return ret;
    116116    }
    117117
    118118    /**
    119      * Displays an confirmation dialog with some option buttons given by <code>optionType</code>.
     119     * Displays a confirmation dialog with some option buttons given by <code>optionType</code>.
    120120     * It is always on top even if there are other open windows like detached dialogs,
    121121     * relation editors, history browsers and the like.
     
    129129     * Replies true, if the selected option is equal to <code>trueOption</code>, otherwise false.
    130130     * Replies true, if the dialog is not displayed because the respective preference option
    131      * <code>preferenceKey</code> is set to false.
     131     * <code>preferenceKey</code> is set to false and the user has previously chosen
     132     * <code>trueOption</code>.
    132133     *
    133134     * @param preferenceKey the preference key
     
    147148     */
    148149    static public boolean showConfirmationDialog(String preferenceKey, Component parent, Object message, String title, int optionType, int messageType, int trueOption) throws HeadlessException {
    149         if (!getDialogShowingEnabled(preferenceKey) && (getDialogReturnValue(preferenceKey) >= 0))
    150             return getDialogReturnValue(preferenceKey) == trueOption;
     150        int ret = getDialogReturnValue(preferenceKey);
     151        if (!getDialogShowingEnabled(preferenceKey) && ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)))
     152            return ret == trueOption;
    151153        MessagePanel pnl = new MessagePanel(false, message);
    152         int ret = JOptionPane.showConfirmDialog(parent, pnl, title, optionType, messageType);
    153         if ((ret >= 0) && !pnl.getDialogShowingEnabled()) {
     154        ret = JOptionPane.showConfirmDialog(parent, pnl, title, optionType, messageType);
     155        if (((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)) && !pnl.getDialogShowingEnabled()) {
    154156            setDialogShowingEnabled(preferenceKey, false);
    155157            setDialogReturnValue(preferenceKey, ret);
     
    181183        MessagePanel pnl = new MessagePanel(false, message);
    182184        JOptionPane.showMessageDialog(parent, pnl, title, messageType);
    183         if(!pnl.getDialogShowingEnabled())
     185        if(!pnl.getDialogShowingEnabled()) {
    184186            setDialogShowingEnabled(preferenceKey, false);
     187        }
    185188    }
    186189
Note: See TracChangeset for help on using the changeset viewer.