Changeset 4936 in josm
- Timestamp:
- 2012-02-15T15:28:58+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r4820 r4936 22 22 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 23 23 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 24 import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPref Migration;24 import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefHelper; 25 25 import org.openstreetmap.josm.gui.preferences.SourceEntry; 26 26 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 67 67 /** 68 68 * IconReference is used to remember the associated style source for 69 * each icon URL. 69 * each icon URL. 70 70 * This is necessary because image URLs can be paths relative 71 * to the source file and we have cascading of properties from different 71 * to the source file and we have cascading of properties from different 72 72 * source files. 73 73 */ … … 167 167 styles.clear(); 168 168 169 Collection<? extends SourceEntry> sourceEntries = MapPaintPref Migration.INSTANCE.get();169 Collection<? extends SourceEntry> sourceEntries = MapPaintPrefHelper.INSTANCE.get(); 170 170 171 171 for (SourceEntry entry : sourceEntries) { … … 305 305 } 306 306 styles.setStyleSources(data); 307 MapPaintPref Migration.INSTANCE.put(data);307 MapPaintPrefHelper.INSTANCE.put(data); 308 308 fireMapPaintSylesUpdated(); 309 309 styles.clearCached(); … … 331 331 s.active = !s.active; 332 332 } 333 MapPaintPref Migration.INSTANCE.put(data);333 MapPaintPrefHelper.INSTANCE.put(data); 334 334 if (sel.length == 1) { 335 335 fireMapPaintStyleEntryUpdated(sel[0]); … … 346 346 styles.add(source); 347 347 source.loadStyleSource(); 348 MapPaintPref Migration.INSTANCE.put(styles.getStyleSources());348 MapPaintPrefHelper.INSTANCE.put(styles.getStyleSources()); 349 349 fireMapPaintSylesUpdated(); 350 350 styles.clearCached(); -
trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java
r4874 r4936 81 81 @Override 82 82 public Collection<? extends SourceEntry> getInitialSourcesList() { 83 return MapPaintPref Migration.INSTANCE.get();83 return MapPaintPrefHelper.INSTANCE.get(); 84 84 } 85 85 … … 88 88 List<SourceEntry> activeStyles = activeSourcesModel.getSources(); 89 89 90 boolean changed = MapPaintPref Migration.INSTANCE.put(activeStyles);90 boolean changed = MapPaintPrefHelper.INSTANCE.put(activeStyles); 91 91 92 92 if (tblIconPaths != null) { … … 106 106 @Override 107 107 public Collection<ExtendedSourceEntry> getDefault() { 108 return MapPaintPref Migration.INSTANCE.getDefault();108 return MapPaintPrefHelper.INSTANCE.getDefault(); 109 109 } 110 110 … … 170 170 } 171 171 172 public static class MapPaintPrefMigration extends SourceEditor.SourcePrefMigration { 173 174 public final static MapPaintPrefMigration INSTANCE = new MapPaintPrefMigration(); 175 176 public MapPaintPrefMigration() { 177 super("mappaint.style.sources", 178 "mappaint.style.enable-defaults", 179 "mappaint.style.sources-list"); 172 public static class MapPaintPrefHelper extends SourceEditor.SourcePrefHelper { 173 174 public final static MapPaintPrefHelper INSTANCE = new MapPaintPrefHelper(); 175 176 public MapPaintPrefHelper() { 177 super("mappaint.style.sources-list"); 180 178 } 181 179 … … 183 181 public List<SourceEntry> get() { 184 182 List<SourceEntry> ls = super.get(); 185 if (adapt_elemstyles_xml(ls)) {186 put(ls);187 }188 183 if (insertNewDefaults(ls)) { 189 184 put(ls); 190 185 } 191 186 return ls; 192 }193 194 /**195 * The internal path of elemstyles.xml has changed, this196 * can be removed when a few months have passed.197 */198 private boolean adapt_elemstyles_xml(List<SourceEntry> ls) {199 boolean changed = false;200 for (SourceEntry se : ls) {201 if (se.url.equals("resource://data/elemstyles.xml")) {202 se.url = "resource://styles/standard/elemstyles.xml";203 changed = true;204 }205 }206 return changed;207 187 } 208 188 -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r4874 r4936 1417 1417 } 1418 1418 1419 1420 /** 1421 * Convert mappaint and preset source preferences from a simple list to 1422 * array with one line for each source entry. 1423 * 1424 * MapPaint: 1425 * 1426 * Old format 1427 * key: mappaint.style.sources 1428 * value: list of "<name>=<url>" pairs. The "<name>=" part is optional. 1429 * The style is always active. 1430 * default: empty list 1431 * 1432 * key: mappaint.style.enable-defaults 1433 * value: if true, the default style "resource://data/elemstyles.xml" should 1434 * be loaded. 1435 * default: true 1436 * 1437 * New format 1438 * key: mappaint.style.sources-list 1439 * value: each line is a list with entries: url, name, shortdescription, active 1440 * default: 1441 * One line: "resource://data/elemstyles.xml", "standard", tr("Internal Style"), true 1442 * 1443 * Tagging Preset: 1444 * 1445 * the same, but "name" and "active" are not needed and omitted 1446 * 1447 */ 1448 abstract public static class SourcePrefMigration { 1449 1450 private final String oldPref; 1451 private final String oldPrefEnableDefaults; 1419 abstract public static class SourcePrefHelper { 1420 1452 1421 private final String pref; 1453 1422 1454 public SourcePrefMigration(String oldPref, String oldPrefEnableDefaults, String pref) { 1455 this.oldPref = oldPref; 1456 this.oldPrefEnableDefaults = oldPrefEnableDefaults; 1423 public SourcePrefHelper(String pref) { 1457 1424 this.pref = pref; 1458 1425 } … … 1465 1432 1466 1433 public List<SourceEntry> get() { 1467 List<SourceEntry> entries = readNewFormatImpl(); 1468 if (entries == null) { 1469 1470 entries = readOldFormat(); 1471 put(entries); 1472 return entries; 1473 } 1474 return entries; 1475 } 1476 1477 public boolean put(Collection<? extends SourceEntry> entries) { 1478 boolean changed = false; 1479 if (entries.isEmpty()) { 1480 changed |= Main.pref.put(pref + "._empty_", true); 1481 changed |= Main.pref.putArray(pref, null); 1482 } else { 1483 Collection<Collection<String>> setting = new ArrayList<Collection<String>>(); 1484 for (SourceEntry e : entries) { 1485 setting.add(serialize(e)); 1486 } 1487 changed |= Main.pref.put(pref + "._empty_", null); 1488 changed |= Main.pref.putArray(pref, setting); 1489 } 1490 return changed; 1491 } 1492 1493 public List<SourceEntry> readOldFormat() { 1494 List<SourceEntry> result = new ArrayList<SourceEntry>(); 1495 if (Main.pref.getBoolean(oldPrefEnableDefaults, true)) { 1496 result.addAll(getDefault()); 1497 } 1498 1499 List<String> lines = new LinkedList<String>(Main.pref.getCollection(oldPref)); 1500 for (String line : lines) { 1501 String[] a = null; 1502 if (line.indexOf("=") >= 0) { 1503 a = line.split("=", 2); 1504 } else { 1505 a = new String[] { null, line }; 1506 } 1507 result.add(new SourceEntry(a[1], a[0], null, true)); 1508 } 1509 1510 return result; 1511 } 1512 1513 public Collection<? extends SourceEntry> readNewFormat() { 1514 List<SourceEntry> entries = readNewFormatImpl(); 1515 if (entries == null) 1516 return getDefault(); 1517 return entries; 1518 } 1519 1520 private List<SourceEntry> readNewFormatImpl() { 1434 Collection<Collection<String>> mappaintSrc = Main.pref.getArray(pref, null); 1435 if (mappaintSrc == null) 1436 return new ArrayList<SourceEntry>(getDefault()); 1437 1521 1438 List<SourceEntry> entries = new ArrayList<SourceEntry>(); 1522 Collection<Collection<String>> mappaintSrc = Main.pref.getArray(pref, null);1523 if (mappaintSrc == null || mappaintSrc.isEmpty()) {1524 if (Main.pref.getBoolean(pref + "._empty_", false))1525 return Collections.<SourceEntry>emptyList();1526 return null;1527 }1528 1529 1439 for (Collection<String> sourcePref : mappaintSrc) { 1530 1440 SourceEntry e = deserialize(new ArrayList<String>(sourcePref)); … … 1535 1445 return entries; 1536 1446 } 1447 1448 public boolean put(Collection<? extends SourceEntry> entries) { 1449 Collection<Collection<String>> setting = new ArrayList<Collection<String>>(); 1450 for (SourceEntry e : entries) { 1451 setting.add(serialize(e)); 1452 } 1453 return Main.pref.putArray(pref, setting); 1454 } 1537 1455 } 1538 1456 -
trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java
r4874 r4936 179 179 @Override 180 180 public Collection<? extends SourceEntry> getInitialSourcesList() { 181 return PresetPref Migration.INSTANCE.get();181 return PresetPrefHelper.INSTANCE.get(); 182 182 } 183 183 … … 186 186 List<SourceEntry> activeStyles = activeSourcesModel.getSources(); 187 187 188 boolean changed = PresetPref Migration.INSTANCE.put(activeStyles);188 boolean changed = PresetPrefHelper.INSTANCE.put(activeStyles); 189 189 190 190 if (tblIconPaths != null) { … … 204 204 @Override 205 205 public Collection<ExtendedSourceEntry> getDefault() { 206 return PresetPref Migration.INSTANCE.getDefault();206 return PresetPrefHelper.INSTANCE.getDefault(); 207 207 } 208 208 … … 297 297 } 298 298 299 public static class PresetPrefMigration extends SourceEditor.SourcePrefMigration { 300 301 public final static PresetPrefMigration INSTANCE = new PresetPrefMigration(); 302 303 public PresetPrefMigration() { 304 super("taggingpreset.sources", 305 "taggingpreset.enable-defaults", 306 "taggingpreset.sources-list"); 307 } 308 309 @Override 310 public List<SourceEntry> get() { 311 List<SourceEntry> ls = new ArrayList<SourceEntry>(super.get()); 312 if (removeDeprecated(ls)) { 313 put(ls); 314 } 315 return ls; 316 } 317 318 /** 319 * FIXME: The internal path of elemstyles.xml has changed, this 320 * can be removed in summer 2011. 321 */ 322 private boolean removeDeprecated(List<SourceEntry> ls) { 323 boolean changed = false; 324 Iterator<SourceEntry> it = ls.iterator(); 325 while (it.hasNext()) { 326 SourceEntry se = it.next(); 327 if (se.url.equals("resource://data/elemstyles.xml")) { 328 it.remove(); 329 changed = true; 330 } 331 } 332 return changed; 299 public static class PresetPrefHelper extends SourceEditor.SourcePrefHelper { 300 301 public final static PresetPrefHelper INSTANCE = new PresetPrefHelper(); 302 303 public PresetPrefHelper() { 304 super("taggingpreset.sources-list"); 333 305 } 334 306 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r4721 r4936 67 67 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 68 68 import org.openstreetmap.josm.gui.preferences.SourceEntry; 69 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference.PresetPref Migration;69 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference.PresetPrefHelper; 70 70 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 71 71 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; … … 1240 1240 LinkedList<String> sources = new LinkedList<String>(); 1241 1241 1242 for (SourceEntry e : (new PresetPref Migration()).get()) {1242 for (SourceEntry e : (new PresetPrefHelper()).get()) { 1243 1243 sources.add(e.url); 1244 1244 }
Note:
See TracChangeset
for help on using the changeset viewer.