Changeset 1222 in josm for trunk/src


Ignore:
Timestamp:
2009-01-09T11:34:51+01:00 (16 years ago)
Author:
stoecker
Message:

some cleanup in preferences handling

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/audio/AudioBackAction.java

    r1181 r1222  
    2020        super(tr("Back"), "audio-back", tr("Jump back."),
    2121        Shortcut.registerShortcut("audio:back", tr("Audio: {0}", tr("Back")), KeyEvent.VK_F6, Shortcut.GROUP_DIRECT), true);
    22         amount = -Main.pref.getDouble("audio.forwardbackamount",10.0);
     22        amount = -Main.pref.getDouble("audio.forwardbackamount","10.0");
    2323        this.putValue("help", "Action/Back");
    2424    }
  • trunk/src/org/openstreetmap/josm/actions/audio/AudioFwdAction.java

    r1181 r1222  
    2020        super(tr("Forward"), "audio-fwd", tr("Jump forward"),
    2121        Shortcut.registerShortcut("audio:forward", tr("Audio: {0}", tr("Forward")), KeyEvent.VK_F7, Shortcut.GROUP_DIRECT), true);
    22         amount = Main.pref.getDouble("audio.forwardbackamount",10.0);
     22        amount = Main.pref.getDouble("audio.forwardbackamount","10.0");
    2323    }
    2424
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1221 r1222  
    2323
    2424import org.openstreetmap.josm.Main;
     25import org.openstreetmap.josm.actions.AboutAction;
    2526import org.openstreetmap.josm.gui.preferences.ProxyPreferences;
    2627import org.openstreetmap.josm.tools.ColorHelper;
     
    236237            else
    237238                properties.put(key, value);
    238             save();
     239            String s = defaults.get(key);
     240            if(s == null || !s.equals(value))
     241                save();
    239242            firePreferenceChanged(key, value);
    240243            return true;
     
    265268     */
    266269    public void save() {
     270        /* currently unused, but may help to fix configuration issues in future */
     271        properties.put("josm.version", AboutAction.getVersionString());
    267272        try {
    268273            setSystemProperties();
    269274            final PrintWriter out = new PrintWriter(new FileWriter(getPreferencesDir() + "preferences"), false);
    270275            for (final Entry<String, String> e : properties.entrySet()) {
    271                 out.println(e.getKey() + "=" + e.getValue());
     276                String s = defaults.get(e.getKey());
     277                /* don't save default values */
     278                if(s == null || !s.equals(e.getValue()))
     279                    out.println(e.getKey() + "=" + e.getValue());
    272280            }
    273281            out.close();
     
    300308    public final void resetToDefault() {
    301309        properties.clear();
    302         properties.put("projection", "org.openstreetmap.josm.data.projection.Epsg4326");
    303         properties.put("draw.segment.direction", "true");
    304         properties.put("draw.wireframe", "false");
    305         properties.put("layerlist.visible", "true");
    306         properties.put("propertiesdialog.visible", "true");
    307         properties.put("selectionlist.visible", "true");
    308         properties.put("commandstack.visible", "true");
    309         properties.put("osm-server.url", "http://www.openstreetmap.org/api");
     310        put("layerlist.visible", true);
     311        put("propertiesdialog.visible", true);
     312        put("selectionlist.visible", true);
     313        put("commandstack.visible", true);
     314        put("osm-server.url", "http://www.openstreetmap.org/api");
    310315        if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") == -1) {
    311             properties.put("laf", "javax.swing.plaf.metal.MetalLookAndFeel");
     316            put("laf", "javax.swing.plaf.metal.MetalLookAndFeel");
    312317        } else {
    313             properties.put("laf", "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
     318            put("laf", "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    314319        }
    315320        save();
     
    425430        }
    426431        return def;
     432    }
     433
     434    synchronized public double getDouble(String key, String def) {
     435        putDefault(key, def);
     436        String v = get(key);
     437        try {
     438            return Double.parseDouble(v == null ? def : v);
     439        } catch(NumberFormatException e) {
     440            // fall out
     441        }
     442        return 0.0;
    427443    }
    428444
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r1221 r1222  
    9898
    9999    protected void getSettings(Boolean virtual) {
    100         showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
     100        showDirectionArrow = Main.pref.getBoolean("draw.segment.direction", true);
    101101        showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only", true);
    102         showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");
     102        showOrderNumber = Main.pref.getBoolean("draw.segment.order_number", false);
    103103        selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2;
    104104        selectedNodeSize = selectedNodeRadius * 2;
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r1219 r1222  
    246246        add(presetsMenu, KeyEvent.VK_P, "presets");
    247247
    248         if (!Main.pref.getBoolean("audio.menuinvisible")) {
     248        if (!Main.pref.getBoolean("audio.menuinvisible", false)) {
    249249            add(audioMenu, audioPlayPause);
    250250            add(audioMenu, audioNext);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java

    r1169 r1222  
    4949    {
    5050        int i = colString.indexOf("#");
    51         String colorString;
     51        Color ret;
    5252        if(i < 0) // name only
    53             colorString = Main.pref.get("color.mappaint."+styleName+"."+colString);
     53            ret = Main.pref.getColor("mappaint."+styleName+"."+colString, Color.red);
    5454        else if(i == 0) // value only
    55             colorString = colString;
     55            ret = ColorHelper.html2color(colString);
    5656        else // value and name
    57             colorString = Main.pref.get("color.mappaint."+styleName+"."+colString.substring(0,i), colString.substring(i));
    58         return ColorHelper.html2color(colorString);
     57            ret = Main.pref.getColor("mappaint."+styleName+"."+colString.substring(0,i),
     58            ColorHelper.html2color(colString.substring(i)));
     59        return ret;
    5960    }
    6061
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r1216 r1222  
    126126        });
    127127        directionHint.setToolTipText(tr("Draw direction hints for way segments."));
    128         directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction"));
     128        directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction", true));
    129129        panel.add(directionHint, GBC.eop().insets(20,0,0,0));
    130130
     
    137137        // segment order number
    138138        segmentOrderNumber.setToolTipText(tr("Draw the order numbers of all segments within their way."));
    139         segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number"));
     139        segmentOrderNumber.setSelected(Main.pref.getBoolean("draw.segment.order_number", false));
    140140        panel.add(segmentOrderNumber, GBC.eop().insets(20,0,0,0));
    141141
    142142        // antialiasing
    143143        useAntialiasing.setToolTipText(tr("Apply antialiasing to the map view resulting in a smoother appearance."));
    144         useAntialiasing.setSelected(Main.pref.getBoolean("mappaint.use-antialiasing"));
     144        useAntialiasing.setSelected(Main.pref.getBoolean("mappaint.use-antialiasing", false));
    145145        panel.add(useAntialiasing, GBC.eop().insets(20,0,0,0));
    146146
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r1169 r1222  
    5151        }
    5252
    53         if (Boolean.parseBoolean(Main.pref.get("osm-server.use-compression", "true")))
     53        if (Main.pref.getBoolean("osm-server.use-compression", true))
    5454            activeConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
    5555
Note: See TracChangeset for help on using the changeset viewer.