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 {
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| | 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 | /** |
| 58 | 79 | * Returns the preference value for the preference key "message." + <code>prefKey</code> + ".value". |
| 59 | 80 | * The default value if the preference key is missing is -1. |
| 60 | 81 | * |
| … |
… |
public class ConditionalOptionPaneUtil {
|
| 76 | 97 | } |
| 77 | 98 | |
| 78 | 99 | /** |
| | 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 | /** |
| 79 | 121 | * Displays an confirmation dialog with some option buttons given by <code>optionType</code>. |
| 80 | 122 | * It is always on top even if there are other open windows like detached dialogs, |
| 81 | 123 | * relation editors, history browsers and the like. |
| … |
… |
public class ConditionalOptionPaneUtil {
|
| 102 | 144 | * @return the option selected by user. {@link JOptionPane#CLOSED_OPTION} if the dialog was closed. |
| 103 | 145 | */ |
| 104 | 146 | 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))) |
| 107 | 149 | return ret; |
| 108 | 150 | MessagePanel pnl = new MessagePanel(false, message); |
| 109 | 151 | ret = JOptionPane.showOptionDialog(parent, pnl, title, optionType, messageType, null, options, defaultOption); |
| 110 | 152 | |
| 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 | } |
| 114 | 162 | } |
| 115 | 163 | return ret; |
| 116 | 164 | } |
| … |
… |
public class ConditionalOptionPaneUtil {
|
| 196 | 244 | */ |
| 197 | 245 | private static class MessagePanel extends JPanel { |
| 198 | 246 | JCheckBox cbShowDialog; |
| | 247 | JCheckBox cbShowNonPersistentDialog; |
| 199 | 248 | |
| 200 | 249 | public MessagePanel(boolean donotshow, Object message) { |
| 201 | 250 | cbShowDialog = new JCheckBox(tr("Do not show again (remembers choice)")); |
| 202 | 251 | cbShowDialog.setSelected(donotshow); |
| | 252 | cbShowNonPersistentDialog = new JCheckBox(tr("Do not show again (just this time)")); |
| | 253 | cbShowNonPersistentDialog.setSelected(donotshow); |
| 203 | 254 | setLayout(new GridBagLayout()); |
| 204 | 255 | |
| 205 | 256 | if (message instanceof Component) { |
| … |
… |
public class ConditionalOptionPaneUtil {
|
| 207 | 258 | } else { |
| 208 | 259 | add(new JLabel(message.toString()),GBC.eop()); |
| 209 | 260 | } |
| 210 | | add(cbShowDialog, GBC.eol()); |
| | 261 | add(cbShowDialog, GBC.std()); |
| | 262 | add(cbShowNonPersistentDialog, GBC.eol()); |
| 211 | 263 | } |
| 212 | 264 | |
| 213 | 265 | public boolean getDialogShowingEnabled() { |
| 214 | 266 | return !cbShowDialog.isSelected(); |
| 215 | 267 | } |
| | 268 | |
| | 269 | public boolean getNonPersistentDialogShowingEnabled() { |
| | 270 | return !cbShowNonPersistentDialog.isSelected(); |
| | 271 | } |
| 216 | 272 | } |
| 217 | 273 | } |
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 {
|
| 769 | 769 | if (primitives == null || primitives.isEmpty()) |
| 770 | 770 | return primitives; |
| 771 | 771 | ArrayList<OsmPrimitive> ret = new ArrayList<OsmPrimitive>(); |
| | 772 | ConditionalOptionPaneUtil.setNonPersistentDialogShowingEnabled("add_primitive_to_relation", true); |
| | 773 | ConditionalOptionPaneUtil.setNonPersistentDialogReturnValue("add_primitive_to_relation", 0); |
| 772 | 774 | for (OsmPrimitive primitive : primitives) { |
| 773 | 775 | if (primitive instanceof Relation && getRelation() != null && getRelation().equals(primitive)) { |
| 774 | 776 | warnOfCircularReferences(primitive); |
| … |
… |
public class GenericRelationEditor extends RelationEditor {
|
| 783 | 785 | ret.add(primitive); |
| 784 | 786 | } |
| 785 | 787 | } |
| | 788 | ConditionalOptionPaneUtil.setNonPersistentDialogShowingEnabled("add_primitive_to_relation", true); |
| | 789 | ConditionalOptionPaneUtil.setNonPersistentDialogReturnValue("add_primitive_to_relation", 0); |
| 786 | 790 | return ret; |
| 787 | 791 | } |
| 788 | 792 | } |