Changeset 4936 in josm for trunk/src


Ignore:
Timestamp:
2012-02-15T15:28:58+01:00 (12 years ago)
Author:
bastiK
Message:

remove old migration code; keep class structure for next migration step Array -> ListOfStructs

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  
    2222import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    2323import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    24 import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefMigration;
     24import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefHelper;
    2525import org.openstreetmap.josm.gui.preferences.SourceEntry;
    2626import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    6767    /**
    6868     * IconReference is used to remember the associated style source for
    69      * each icon URL. 
     69     * each icon URL.
    7070     * 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
    7272     * source files.
    7373     */
     
    167167        styles.clear();
    168168
    169         Collection<? extends SourceEntry> sourceEntries = MapPaintPrefMigration.INSTANCE.get();
     169        Collection<? extends SourceEntry> sourceEntries = MapPaintPrefHelper.INSTANCE.get();
    170170
    171171        for (SourceEntry entry : sourceEntries) {
     
    305305        }
    306306        styles.setStyleSources(data);
    307         MapPaintPrefMigration.INSTANCE.put(data);
     307        MapPaintPrefHelper.INSTANCE.put(data);
    308308        fireMapPaintSylesUpdated();
    309309        styles.clearCached();
     
    331331            s.active = !s.active;
    332332        }
    333         MapPaintPrefMigration.INSTANCE.put(data);
     333        MapPaintPrefHelper.INSTANCE.put(data);
    334334        if (sel.length == 1) {
    335335            fireMapPaintStyleEntryUpdated(sel[0]);
     
    346346            styles.add(source);
    347347            source.loadStyleSource();
    348             MapPaintPrefMigration.INSTANCE.put(styles.getStyleSources());
     348            MapPaintPrefHelper.INSTANCE.put(styles.getStyleSources());
    349349            fireMapPaintSylesUpdated();
    350350            styles.clearCached();
  • trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java

    r4874 r4936  
    8181        @Override
    8282        public Collection<? extends SourceEntry> getInitialSourcesList() {
    83             return MapPaintPrefMigration.INSTANCE.get();
     83            return MapPaintPrefHelper.INSTANCE.get();
    8484        }
    8585
     
    8888            List<SourceEntry> activeStyles = activeSourcesModel.getSources();
    8989
    90             boolean changed = MapPaintPrefMigration.INSTANCE.put(activeStyles);
     90            boolean changed = MapPaintPrefHelper.INSTANCE.put(activeStyles);
    9191
    9292            if (tblIconPaths != null) {
     
    106106        @Override
    107107        public Collection<ExtendedSourceEntry> getDefault() {
    108             return MapPaintPrefMigration.INSTANCE.getDefault();
     108            return MapPaintPrefHelper.INSTANCE.getDefault();
    109109        }
    110110
     
    170170    }
    171171
    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");
    180178        }
    181179
     
    183181        public List<SourceEntry> get() {
    184182            List<SourceEntry> ls = super.get();
    185             if (adapt_elemstyles_xml(ls)) {
    186                 put(ls);
    187             }
    188183            if (insertNewDefaults(ls)) {
    189184                put(ls);
    190185            }
    191186            return ls;
    192         }
    193 
    194         /**
    195          * The internal path of elemstyles.xml has changed, this
    196          * 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;
    207187        }
    208188
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r4874 r4936  
    14171417    }
    14181418
    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
    14521421        private final String pref;
    14531422
    1454         public SourcePrefMigration(String oldPref, String oldPrefEnableDefaults, String pref) {
    1455             this.oldPref = oldPref;
    1456             this.oldPrefEnableDefaults = oldPrefEnableDefaults;
     1423        public SourcePrefHelper(String pref) {
    14571424            this.pref = pref;
    14581425        }
     
    14651432
    14661433        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
    15211438            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 
    15291439            for (Collection<String> sourcePref : mappaintSrc) {
    15301440                SourceEntry e = deserialize(new ArrayList<String>(sourcePref));
     
    15351445            return entries;
    15361446        }
     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        }
    15371455    }
    15381456
  • trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java

    r4874 r4936  
    179179        @Override
    180180        public Collection<? extends SourceEntry> getInitialSourcesList() {
    181             return PresetPrefMigration.INSTANCE.get();
     181            return PresetPrefHelper.INSTANCE.get();
    182182        }
    183183
     
    186186            List<SourceEntry> activeStyles = activeSourcesModel.getSources();
    187187
    188             boolean changed = PresetPrefMigration.INSTANCE.put(activeStyles);
     188            boolean changed = PresetPrefHelper.INSTANCE.put(activeStyles);
    189189
    190190            if (tblIconPaths != null) {
     
    204204        @Override
    205205        public Collection<ExtendedSourceEntry> getDefault() {
    206             return PresetPrefMigration.INSTANCE.getDefault();
     206            return PresetPrefHelper.INSTANCE.getDefault();
    207207        }
    208208
     
    297297    }
    298298
    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");
    333305        }
    334306
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r4721 r4936  
    6767import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    6868import org.openstreetmap.josm.gui.preferences.SourceEntry;
    69 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference.PresetPrefMigration;
     69import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference.PresetPrefHelper;
    7070import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    7171import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority;
     
    12401240        LinkedList<String> sources = new LinkedList<String>();
    12411241
    1242         for (SourceEntry e : (new PresetPrefMigration()).get()) {
     1242        for (SourceEntry e : (new PresetPrefHelper()).get()) {
    12431243            sources.add(e.url);
    12441244        }
Note: See TracChangeset for help on using the changeset viewer.