Changeset 3869 in josm for trunk/src/org
- Timestamp:
- 2011-02-08T11:54:02+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java
r3864 r3869 14 14 import javax.swing.BorderFactory; 15 15 import javax.swing.JCheckBox; 16 import javax.swing.JComboBox;17 import javax.swing.JLabel;18 16 import javax.swing.JPanel; 19 17 import javax.swing.event.ChangeEvent; … … 24 22 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 25 23 import org.openstreetmap.josm.tools.GBC; 24 import org.openstreetmap.josm.tools.Predicate; 25 import org.openstreetmap.josm.tools.Utils; 26 26 27 27 public class MapPaintPreference implements PreferenceSetting { … … 178 178 put(ls); 179 179 } 180 if (insertNewDefaults(ls)) { 181 put(ls); 182 } 180 183 return ls; 181 184 } … … 196 199 } 197 200 201 /** 202 * If the selection of default styles changes in future releases, add 203 * the new entries to the user-configured list. Remember the known URLs, 204 * so an item that was deleted explicitly is not added again. 205 */ 206 private boolean insertNewDefaults(List<SourceEntry> list) { 207 boolean changed = false; 208 209 Collection<String> knownDefaults = new TreeSet<String>(Main.pref.getCollection("mappaint.style.known-defaults")); 210 211 Collection<ExtendedSourceEntry> defaults = getDefault(); 212 int insertionIdx = 0; 213 for (final SourceEntry def : defaults) { 214 int i = Utils.indexOf(list, 215 new Predicate<SourceEntry>() { 216 @Override 217 public boolean evaluate(SourceEntry se) { 218 return Utils.equal(def.url, se.url); 219 } 220 }); 221 if (i == -1 && !knownDefaults.contains(def.url)) { 222 list.add(insertionIdx, def); 223 insertionIdx++; 224 changed = true; 225 } else { 226 if (i > insertionIdx) { 227 insertionIdx = i + 1; 228 } 229 } 230 } 231 232 for (SourceEntry def : defaults) { 233 knownDefaults.add(def.url); 234 } 235 if (Main.pref.putCollection("mappaint.style.known-defaults", knownDefaults)) { 236 changed = true; 237 } 238 239 return changed; 240 } 241 198 242 @Override 199 243 public Collection<ExtendedSourceEntry> getDefault() { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r3865 r3869 39 39 } 40 40 return null; 41 } 42 43 public static <T> int indexOf(Iterable<? extends T> collection, Predicate<? super T> predicate) { 44 int i = 0; 45 for (T item : collection) { 46 if (predicate.evaluate(item)) 47 return i; 48 i++; 49 } 50 return -1; 41 51 } 42 52
Note:
See TracChangeset
for help on using the changeset viewer.