Changeset 1062 in josm for trunk


Ignore:
Timestamp:
2008-11-02T14:28:20+01:00 (16 years ago)
Author:
stoecker
Message:

added prefs support for collections

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r1058 r1062  
    221221        public static void loadPlugins(boolean early) {
    222222                List<String> plugins = new LinkedList<String>();
    223                 if (Main.pref.hasKey("plugins"))
    224                         plugins.addAll(Arrays.asList(Main.pref.get("plugins").split(",")));
     223                Collection<String> cp = Main.pref.getCollection("plugins", null);
     224                if (cp != null)
     225                        plugins.addAll(cp);
    225226                if (System.getProperty("josm.plugins") != null)
    226227                        plugins.addAll(Arrays.asList(System.getProperty("josm.plugins").split(",")));
     
    232233                        {
    233234                                plugins.remove(p);
     235                                Main.pref.removeFromCollection("plugins", p);
    234236                                System.out.println(tr("Warning - loading of {0} plugin was requested. This plugin is no longer required.", p));
    235237                        }
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1025 r1062  
    1010import java.io.PrintWriter;
    1111import java.util.ArrayList;
     12import java.util.Arrays;
    1213import java.util.Collection;
    1314import java.util.LinkedList;
     
    401402        }
    402403
     404        synchronized public Collection<String> getCollection(String key, Collection<String> def) {
     405                String s = get(key);
     406                if(s != null)
     407                {
     408                        /* handle old comma separated stuff - remove in future */
     409                        if(s.indexOf(',') >= 0)
     410                                return Arrays.asList(s.split(","));
     411                        else
     412                                return Arrays.asList(s.split(";"));
     413                }
     414                else if(def != null)
     415                        return def;
     416                return null;
     417        }
     418        synchronized public void removeFromCollection(String key, String value) {
     419                ArrayList<String> a = new ArrayList<String>(getCollection(key, null));
     420                if(a != null)
     421                {
     422                        a.remove(value);
     423                        putCollection(key, a);
     424                }
     425        }
     426        synchronized public void putCollection(String key, Collection<String> val) {
     427                String s = null;
     428                if(val != null)
     429                {
     430                        for(String a : val)
     431                        {
     432                                if(s != null)
     433                                        s += ";" + a;
     434                                else
     435                                        s = a;
     436                        }
     437                }
     438
     439                put(key, s);
     440        }
     441
    403442        private void setSystemProperties() {
    404443                Properties sysProp = System.getProperties();
Note: See TracChangeset for help on using the changeset viewer.