Changeset 930 in josm for trunk/src


Ignore:
Timestamp:
2008-09-07T13:34:24+02:00 (16 years ago)
Author:
stoecker
Message:

fixed preferences handling, reduced number of save processes. Closes bug #1507

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

Legend:

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

    r873 r930  
    183183
    184184        synchronized public void put(final String key, final String value) {
    185                 if (value == null)
    186                         properties.remove(key);
    187                 else
    188                         properties.put(key, value);
    189                 save();
    190                 firePreferenceChanged(key, value);
     185                String oldvalue = properties.get(key);
     186                if(value != null && value.length() == 0)
     187                        value = null;
     188                if(!((oldvalue == null && value == null) || (value != null
     189                && oldvalue != null && oldvalue.equals(value))))
     190                {
     191                        if (value == null)
     192                                properties.remove(key);
     193                        else
     194                                properties.put(key, value);
     195                        save();
     196                        firePreferenceChanged(key, value);
     197                }
    191198        }
    192199
    193200        synchronized public void put(final String key, final boolean value) {
    194                 properties.put(key, Boolean.toString(value));
    195                 save();
    196                 firePreferenceChanged(key, Boolean.toString(value));
     201                put(key, Boolean.toString(value));
    197202        }
    198203
     
    210215                        final PrintWriter out = new PrintWriter(new FileWriter(getPreferencesDir() + "preferences"), false);
    211216                        for (final Entry<String, String> e : properties.entrySet()) {
    212                                 if (!e.getValue().equals(""))
    213                                         out.println(e.getKey() + "=" + e.getValue());
     217                                out.println(e.getKey() + "=" + e.getValue());
    214218                        }
    215219                        out.close();
  • trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java

    r795 r930  
    7171                defaults = Main.pref.getDefaults();
    7272                orig.remove("osm-server.password");
     73                defaults.remove("osm-server.password");
    7374                TreeSet<String> ts = new TreeSet<String>(orig.keySet());
    7475                for (String s : defaults.keySet())
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r906 r930  
    5353         * @author imi
    5454         */
    55         public static class PluginDescription {
     55        public static class PluginDescription implements Comparable {
    5656                // Note: All the following need to be public instance variables of
    5757                // type String.  (Plugin description XMLs from the server are parsed
     
    6868                }
    6969                public PluginDescription() {
     70                }
     71                public int compareTo(Object n) {
     72                        if(n instanceof PluginDescription)
     73                                return name.compareToIgnoreCase(((PluginDescription)n).name);
     74                        else
     75                                return -1;
    7076                }
    7177        }
     
    328334
    329335                String plugins = "";
    330                 for (Entry<PluginDescription, Boolean> entry : pluginMap.entrySet())
    331                         if (entry.getValue())
    332                                 plugins += entry.getKey().name + ",";
    333                 if (plugins.endsWith(","))
     336                Object pd[] = pluginMap.keySet().toArray();
     337                Arrays.sort(pd);
     338                for(Object d : pd)
     339                {
     340                        if(pluginMap.get(d))
     341                                plugins += ((PluginDescription)d).name + ",";
     342                }
     343                if(plugins.endsWith(","))
    334344                        plugins = plugins.substring(0, plugins.length()-1);
     345                if(plugins.length() == 0)
     346                        plugins = null;
    335347
    336348                String oldPlugins = Main.pref.get("plugins");
Note: See TracChangeset for help on using the changeset viewer.