Changeset 5220 in josm


Ignore:
Timestamp:
May 7, 2012 11:32:59 PM (13 months ago)
Author:
bastiK
Message:

change to new preference format for mappaint styles and presets

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  
    3131import java.util.Comparator; 
    3232import java.util.EventObject; 
     33import java.util.HashMap; 
    3334import java.util.Iterator; 
    3435import java.util.List; 
     36import java.util.Map; 
    3537import java.util.concurrent.CopyOnWriteArrayList; 
    3638import java.util.regex.Matcher; 
     
    668670        @Override 
    669671        public int compareTo(ExtendedSourceEntry o) { 
    670             if (url.startsWith("resource") && !o.url.startsWith("resource")) { 
     672            if (url.startsWith("resource") && !o.url.startsWith("resource")) 
    671673                return -1; 
    672             } 
    673             if (o.url.startsWith("resource")) { 
     674            if (o.url.startsWith("resource")) 
    674675                return 1; 
    675             } else { 
     676            else 
    676677                return getDisplayName().compareToIgnoreCase(o.getDisplayName()); 
    677             } 
    678678        } 
    679679    } 
     
    14401440    abstract public static class SourcePrefHelper { 
    14411441 
     1442        private final String prefOld; 
    14421443        private final String pref; 
    14431444 
    1444         public SourcePrefHelper(String pref) { 
     1445        public SourcePrefHelper(String pref, String prefOld) { 
    14451446            this.pref = pref; 
     1447            this.prefOld = prefOld; 
    14461448        } 
    14471449 
    14481450        abstract public Collection<ExtendedSourceEntry> getDefault(); 
    14491451 
    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); 
    14531458 
    14541459        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) 
    14571474                return new ArrayList<SourceEntry>(getDefault()); 
    14581475 
    14591476            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)); 
    14621479                if (e != null) { 
    14631480                    entries.add(e); 
    14641481                } 
    14651482            } 
     1483            if (migration) { 
     1484                put(entries); 
     1485            } 
    14661486            return entries; 
    14671487        } 
    14681488 
    14691489        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>>(); 
    14711491            for (SourceEntry e : entries) { 
    14721492                setting.add(serialize(e)); 
    14731493            } 
    1474             return Main.pref.putArray(pref, setting); 
     1494            return Main.pref.putListOfStructs(pref, setting); 
    14751495        } 
    14761496    } 
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java

    r3894 r5220  
    4242    public boolean active; 
    4343 
    44     public SourceEntry(String url, String name, String shortdescription, Boolean active) { 
     44    public SourceEntry(String url, String name, String title, Boolean active) { 
    4545        this.url = url; 
    4646        this.name = equal(name, "") ? null : name; 
    47         this.title = equal(shortdescription, "") ? null : shortdescription; 
     47        this.title = equal(title, "") ? null : title; 
    4848        this.active = active; 
    4949    } 
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java

    r4968 r5220  
    99import java.util.Arrays; 
    1010import java.util.Collection; 
     11import java.util.HashMap; 
    1112import java.util.List; 
     13import java.util.Map; 
    1214import java.util.TreeSet; 
    1315 
     
    2426import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 
    2527import org.openstreetmap.josm.gui.preferences.SourceEditor; 
    26 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 
    2728import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 
    2829import org.openstreetmap.josm.gui.preferences.SourceEntry; 
    2930import org.openstreetmap.josm.gui.preferences.SourceProvider; 
    3031import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 
     32import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 
    3133import org.openstreetmap.josm.tools.GBC; 
    3234import org.openstreetmap.josm.tools.Predicate; 
     
    183185 
    184186        public MapPaintPrefHelper() { 
    185             super("mappaint.style.sources-list"); 
     187            super("mappaint.style.entries", "mappaint.style.sources-list"); 
    186188        } 
    187189 
     
    251253 
    252254        @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); 
    264274            if (entryStr.size() < 4) 
    265275                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; 
    271282        } 
    272283    } 
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreference.java

    r4968 r5220  
    88import java.io.IOException; 
    99import java.util.ArrayList; 
    10 import java.util.Arrays; 
    1110import java.util.Collection; 
    1211import java.util.Collections; 
    1312import java.util.HashMap; 
    1413import java.util.List; 
     14import java.util.Map; 
    1515 
    1616import javax.swing.BorderFactory; 
     
    3030import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 
    3131import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 
    32 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 
    3332import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener; 
    3433import org.openstreetmap.josm.gui.preferences.SourceEditor; 
     
    3736import org.openstreetmap.josm.gui.preferences.SourceProvider; 
    3837import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 
     38import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 
    3939import org.openstreetmap.josm.gui.tagging.TaggingPreset; 
    4040import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu; 
     
    5252        } 
    5353    } 
    54      
     54 
    5555    private TaggingPresetPreference() { 
    5656        super(); 
     
    313313 
    314314        public PresetPrefHelper() { 
    315             super("taggingpreset.sources-list"); 
     315            super("taggingpreset.entries", "taggingpreset.sources-list"); 
    316316        } 
    317317 
     
    325325 
    326326        @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); 
    333342            if (entryStr.size() < 2) 
    334343                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 
    339350    } 
    340351 
Note: See TracChangeset for help on using the changeset viewer.