Ticket #8969: non-persistent-checkbox.patch

File non-persistent-checkbox.patch, 7.6 KB (added by windu.2b, 13 years ago)
  • src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java

    From 0676521ba57b2bf8dca5d7db3cce87f6e7233add Mon Sep 17 00:00:00 2001
    From: windu2b <windu.2b@gmail.com>
    Date: Sun, 18 Aug 2013 22:55:16 +0200
    Subject: [PATCH] Adds a non-persistent checkbox which allows to add several
     duplicate elements in one shot.
    
    The option is non-persistent : it is reset before and after each attempt to add.
    ---
     .../josm/gui/ConditionalOptionPaneUtil.java        | 68 ++++++++++++++++++++--
     .../dialogs/relation/GenericRelationEditor.java    |  7 ++-
     2 files changed, 67 insertions(+), 8 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java b/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java
    index 86346b0..7e8900e 100644
    a b public class ConditionalOptionPaneUtil {  
    5555    }
    5656
    5757    /**
     58     * Replies the preference value for the preference key "message." + <code>prefKey</code>.
     59     * The default value if the preference key is missing is true.
     60     *
     61     * @param  prefKey the preference key
     62     * @return the preference value for the preference key "message." + <code>prefKey</code>
     63     */
     64    public static boolean getNonPersistentDialogShowingEnabled(String prefKey) {
     65        return Main.pref.getBoolean("message."+prefKey+"_nonPersistent", true);
     66    }
     67
     68    /**
     69     * sets the value for the preference key "message." + <code>prefKey</code>.
     70     *
     71     * @param prefKey the key
     72     * @param enabled the value
     73     */
     74    public static void setNonPersistentDialogShowingEnabled(String prefKey, boolean enabled) {
     75        Main.pref.put("message."+prefKey+"_nonPersistent", enabled);
     76    }
     77
     78    /**
    5879     * Returns the preference value for the preference key "message." + <code>prefKey</code> + ".value".
    5980     * The default value if the preference key is missing is -1.
    6081     *
    public class ConditionalOptionPaneUtil {  
    7697    }
    7798
    7899    /**
     100     * Returns the preference value for the preference key "message." + <code>prefKey</code> + "_nonPersistent" + ".value".
     101     * The default value if the preference key is missing is -1.
     102     *
     103     * @param  prefKey the preference key
     104     * @return the preference value for the preference key "message." + <code>prefKey</code> + ".value"
     105     */
     106    public static Integer getNonPersistentDialogReturnValue(String prefKey) {
     107        return Main.pref.getInteger("message."+prefKey+"_nonPersistent"+".value", -1);
     108    }
     109
     110    /**
     111     * sets the value for the preference key "message." + <code>prefKey</code> + "_nonPersistent" + ".value".
     112     *
     113     * @param prefKey the key
     114     * @param value the value
     115     */
     116    public static void setNonPersistentDialogReturnValue(String prefKey, Integer value) {
     117        Main.pref.putInteger("message."+prefKey+"_nonPersistent"+".value", value);
     118    }
     119
     120    /**
    79121     * Displays an confirmation dialog with some option buttons given by <code>optionType</code>.
    80122     * It is always on top even if there are other open windows like detached dialogs,
    81123     * relation editors, history browsers and the like.
    public class ConditionalOptionPaneUtil {  
    102144     * @return the option selected by user. {@link JOptionPane#CLOSED_OPTION} if the dialog was closed.
    103145     */
    104146    static public int showOptionDialog(String preferenceKey, Component parent, Object message, String title, int optionType, int messageType, Object [] options, Object defaultOption) throws HeadlessException {
    105         int ret = getDialogReturnValue(preferenceKey);
    106         if (!getDialogShowingEnabled(preferenceKey) && ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)))
     147        int ret = getDialogReturnValue(preferenceKey) | getNonPersistentDialogReturnValue(preferenceKey);
     148        if ((!getDialogShowingEnabled(preferenceKey) || !getNonPersistentDialogShowingEnabled(preferenceKey)) && ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)))
    107149            return ret;
    108150        MessagePanel pnl = new MessagePanel(false, message);
    109151        ret = JOptionPane.showOptionDialog(parent, pnl, title, optionType, messageType, null, options, defaultOption);
    110152
    111         if (((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)) && !pnl.getDialogShowingEnabled()) {
    112             setDialogShowingEnabled(preferenceKey, false);
    113             setDialogReturnValue(preferenceKey, ret);
     153        if ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)) {
     154            if(!pnl.getDialogShowingEnabled() ) {
     155                setDialogShowingEnabled(preferenceKey, false);
     156                setDialogReturnValue(preferenceKey, ret);
     157            }
     158            if( !pnl.getNonPersistentDialogShowingEnabled()) {
     159                setNonPersistentDialogShowingEnabled(preferenceKey, false);
     160                setNonPersistentDialogReturnValue(preferenceKey, ret);
     161            }
    114162        }
    115163        return ret;
    116164    }
    public class ConditionalOptionPaneUtil {  
    196244     */
    197245    private static class MessagePanel extends JPanel {
    198246        JCheckBox cbShowDialog;
     247        JCheckBox cbShowNonPersistentDialog;
    199248
    200249        public MessagePanel(boolean donotshow, Object message) {
    201250            cbShowDialog = new JCheckBox(tr("Do not show again (remembers choice)"));
    202251            cbShowDialog.setSelected(donotshow);
     252            cbShowNonPersistentDialog = new JCheckBox(tr("Do not show again (just this time)"));
     253            cbShowNonPersistentDialog.setSelected(donotshow);
    203254            setLayout(new GridBagLayout());
    204255
    205256            if (message instanceof Component) {
    public class ConditionalOptionPaneUtil {  
    207258            } else {
    208259                add(new JLabel(message.toString()),GBC.eop());
    209260            }
    210             add(cbShowDialog, GBC.eol());
     261            add(cbShowDialog, GBC.std());
     262            add(cbShowNonPersistentDialog, GBC.eol());
    211263        }
    212264
    213265        public boolean getDialogShowingEnabled() {
    214266            return !cbShowDialog.isSelected();
    215267        }
     268
     269        public boolean getNonPersistentDialogShowingEnabled() {
     270            return !cbShowNonPersistentDialog.isSelected();
     271        }
    216272    }
    217273}
  • src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
    index fdfc49a..1f1a600 100644
    a b public class GenericRelationEditor extends RelationEditor {  
    769769            if (primitives == null || primitives.isEmpty())
    770770                return primitives;
    771771            ArrayList<OsmPrimitive> ret = new ArrayList<OsmPrimitive>();
     772            ConditionalOptionPaneUtil.setNonPersistentDialogShowingEnabled("add_primitive_to_relation", true);
     773            ConditionalOptionPaneUtil.setNonPersistentDialogReturnValue("add_primitive_to_relation", 0);
    772774            for (OsmPrimitive primitive : primitives) {
    773775                if (primitive instanceof Relation && getRelation() != null && getRelation().equals(primitive)) {
    774776                    warnOfCircularReferences(primitive);
    public class GenericRelationEditor extends RelationEditor {  
    783785                    ret.add(primitive);
    784786                }
    785787            }
     788            ConditionalOptionPaneUtil.setNonPersistentDialogShowingEnabled("add_primitive_to_relation", true);
     789            ConditionalOptionPaneUtil.setNonPersistentDialogReturnValue("add_primitive_to_relation", 0);
    786790            return ret;
    787791        }
    788792    }