- Timestamp:
- 2012-05-07T23:32:59+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r5105 r5220 31 31 import java.util.Comparator; 32 32 import java.util.EventObject; 33 import java.util.HashMap; 33 34 import java.util.Iterator; 34 35 import java.util.List; 36 import java.util.Map; 35 37 import java.util.concurrent.CopyOnWriteArrayList; 36 38 import java.util.regex.Matcher; … … 668 670 @Override 669 671 public int compareTo(ExtendedSourceEntry o) { 670 if (url.startsWith("resource") && !o.url.startsWith("resource")) {672 if (url.startsWith("resource") && !o.url.startsWith("resource")) 671 673 return -1; 672 } 673 if (o.url.startsWith("resource")) { 674 if (o.url.startsWith("resource")) 674 675 return 1; 675 } else {676 else 676 677 return getDisplayName().compareToIgnoreCase(o.getDisplayName()); 677 }678 678 } 679 679 } … … 1440 1440 abstract public static class SourcePrefHelper { 1441 1441 1442 private final String prefOld; 1442 1443 private final String pref; 1443 1444 1444 public SourcePrefHelper(String pref ) {1445 public SourcePrefHelper(String pref, String prefOld) { 1445 1446 this.pref = pref; 1447 this.prefOld = prefOld; 1446 1448 } 1447 1449 1448 1450 abstract public Collection<ExtendedSourceEntry> getDefault(); 1449 1451 1450 abstract public Collection<String> serialize(SourceEntry entry); 1451 1452 abstract public SourceEntry deserialize(List<String> entryStr); 1452 abstract public Map<String, String> serialize(SourceEntry entry); 1453 1454 abstract public SourceEntry deserialize(Map<String, String> entryStr); 1455 1456 // migration can be removed end 2012 1457 abstract public Map<String, String> migrate(Collection<String> old); 1453 1458 1454 1459 public List<SourceEntry> get() { 1455 Collection<Collection<String>> mappaintSrc = Main.pref.getArray(pref, null); 1456 if (mappaintSrc == null) 1460 1461 boolean migration = false; 1462 Collection<Map<String, String>> src = Main.pref.getListOfStructs(pref, (Collection<Map<String, String>>) null); 1463 if (src == null) { 1464 Collection<Collection<String>> srcOldPrefFormat = Main.pref.getArray(prefOld, null); 1465 if (srcOldPrefFormat != null) { 1466 migration = true; 1467 src = new ArrayList<Map<String, String>>(); 1468 for (Collection<String> p : srcOldPrefFormat) { 1469 src.add(migrate(p)); 1470 } 1471 } 1472 } 1473 if (src == null) 1457 1474 return new ArrayList<SourceEntry>(getDefault()); 1458 1475 1459 1476 List<SourceEntry> entries = new ArrayList<SourceEntry>(); 1460 for ( Collection<String> sourcePref : mappaintSrc) {1461 SourceEntry e = deserialize(new ArrayList<String>(sourcePref));1477 for (Map<String, String> sourcePref : src) { 1478 SourceEntry e = deserialize(new HashMap<String, String>(sourcePref)); 1462 1479 if (e != null) { 1463 1480 entries.add(e); 1464 1481 } 1465 1482 } 1483 if (migration) { 1484 put(entries); 1485 } 1466 1486 return entries; 1467 1487 } 1468 1488 1469 1489 public boolean put(Collection<? extends SourceEntry> entries) { 1470 Collection< Collection<String>> setting = new ArrayList<Collection<String>>();1490 Collection<Map<String, String>> setting = new ArrayList<Map<String, String>>(); 1471 1491 for (SourceEntry e : entries) { 1472 1492 setting.add(serialize(e)); 1473 1493 } 1474 return Main.pref.put Array(pref, setting);1494 return Main.pref.putListOfStructs(pref, setting); 1475 1495 } 1476 1496 } -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java
r3894 r5220 42 42 public boolean active; 43 43 44 public SourceEntry(String url, String name, String shortdescription, Boolean active) {44 public SourceEntry(String url, String name, String title, Boolean active) { 45 45 this.url = url; 46 46 this.name = equal(name, "") ? null : name; 47 this.title = equal( shortdescription, "") ? null : shortdescription;47 this.title = equal(title, "") ? null : title; 48 48 this.active = active; 49 49 } -
trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java
r4968 r5220 9 9 import java.util.Arrays; 10 10 import java.util.Collection; 11 import java.util.HashMap; 11 12 import java.util.List; 13 import java.util.Map; 12 14 import java.util.TreeSet; 13 15 … … 24 26 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 25 27 import org.openstreetmap.josm.gui.preferences.SourceEditor; 26 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;27 28 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 28 29 import org.openstreetmap.josm.gui.preferences.SourceEntry; 29 30 import org.openstreetmap.josm.gui.preferences.SourceProvider; 30 31 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 32 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 31 33 import org.openstreetmap.josm.tools.GBC; 32 34 import org.openstreetmap.josm.tools.Predicate; … … 183 185 184 186 public MapPaintPrefHelper() { 185 super("mappaint.style. sources-list");187 super("mappaint.style.entries", "mappaint.style.sources-list"); 186 188 } 187 189 … … 251 253 252 254 @Override 253 public Collection<String> serialize(SourceEntry entry) { 254 return Arrays.asList(new String[] { 255 entry.url, 256 entry.name == null ? "" : entry.name, 257 entry.title == null ? "" : entry.title, 258 Boolean.toString(entry.active) 259 }); 260 } 261 262 @Override 263 public SourceEntry deserialize(List<String> entryStr) { 255 public Map<String, String> serialize(SourceEntry entry) { 256 Map<String, String> res = new HashMap<String, String>(); 257 res.put("url", entry.url); 258 res.put("title", entry.title == null ? "" : entry.title); 259 res.put("active", Boolean.toString(entry.active)); 260 if (entry.name != null) { 261 res.put("ptoken", entry.name); 262 } 263 return res; 264 } 265 266 @Override 267 public SourceEntry deserialize(Map<String, String> s) { 268 return new SourceEntry(s.get("url"), s.get("ptoken"), s.get("title"), Boolean.parseBoolean(s.get("active"))); 269 } 270 271 @Override 272 public Map<String, String> migrate(Collection<String> old) { 273 List<String> entryStr = new ArrayList<String>(old); 264 274 if (entryStr.size() < 4) 265 275 return null; 266 String url = entryStr.get(0); 267 String name = entryStr.get(1); 268 String shortdescription = entryStr.get(2); 269 boolean active = Boolean.parseBoolean(entryStr.get(3)); 270 return new SourceEntry(url, name, shortdescription, active); 276 Map<String, String> res = new HashMap<String, String>(); 277 res.put("url", entryStr.get(0)); 278 res.put("ptoken", entryStr.get(1)); 279 res.put("title", entryStr.get(2)); 280 res.put("active", entryStr.get(3)); 281 return res; 271 282 } 272 283 } -
trunk/src/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreference.java
r4968 r5220 8 8 import java.io.IOException; 9 9 import java.util.ArrayList; 10 import java.util.Arrays;11 10 import java.util.Collection; 12 11 import java.util.Collections; 13 12 import java.util.HashMap; 14 13 import java.util.List; 14 import java.util.Map; 15 15 16 16 import javax.swing.BorderFactory; … … 30 30 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 31 31 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 32 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;33 32 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener; 34 33 import org.openstreetmap.josm.gui.preferences.SourceEditor; … … 37 36 import org.openstreetmap.josm.gui.preferences.SourceProvider; 38 37 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 38 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 39 39 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 40 40 import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu; … … 52 52 } 53 53 } 54 54 55 55 private TaggingPresetPreference() { 56 56 super(); … … 313 313 314 314 public PresetPrefHelper() { 315 super("taggingpreset. sources-list");315 super("taggingpreset.entries", "taggingpreset.sources-list"); 316 316 } 317 317 … … 325 325 326 326 @Override 327 public Collection<String> serialize(SourceEntry entry) { 328 return Arrays.asList(new String[] {entry.url, entry.title == null ? "" : entry.title}); 329 } 330 331 @Override 332 public SourceEntry deserialize(List<String> entryStr) { 327 public Map<String, String> serialize(SourceEntry entry) { 328 Map<String, String> res = new HashMap<String, String>(); 329 res.put("url", entry.url); 330 res.put("title", entry.title == null ? "" : entry.title); 331 return res; 332 } 333 334 @Override 335 public SourceEntry deserialize(Map<String, String> s) { 336 return new SourceEntry(s.get("url"), null, s.get("title"), true); 337 } 338 339 @Override 340 public Map<String, String> migrate(Collection<String> old) { 341 List<String> entryStr = new ArrayList<String>(old); 333 342 if (entryStr.size() < 2) 334 343 return null; 335 String url = entryStr.get(0); 336 String shortdescription = entryStr.get(1); 337 return new SourceEntry(url, null, shortdescription, true); 338 } 344 Map<String, String> res = new HashMap<String, String>(); 345 res.put("url", entryStr.get(0)); 346 res.put("title", entryStr.get(1)); 347 return res; 348 } 349 339 350 } 340 351
Note:
See TracChangeset
for help on using the changeset viewer.