Changeset 9114 in josm


Ignore:
Timestamp:
2015-12-13T20:28:00+01:00 (5 years ago)
Author:
bastiK
Message:

mapcss: make partial fill threshold an advanced preference option (see #12104)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r9078 r9114  
    66import java.util.Collection;
    77import java.util.Collections;
     8import java.util.HashMap;
    89import java.util.List;
     10import java.util.Map;
    911import java.util.Map.Entry;
    1012
    1113import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
     15import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    1216import org.openstreetmap.josm.data.osm.Node;
    1317import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2327import org.openstreetmap.josm.tools.Utils;
    2428
    25 public class ElemStyles {
     29public class ElemStyles implements PreferenceChangedListener {
    2630    private final List<StyleSource> styleSources;
    2731    private boolean drawMultipolygon;
     
    3236    private int defaultNodesIdx, defaultLinesIdx;
    3337
     38    private final Map<String, String> preferenceCache = new HashMap<>();
     39
    3440    /**
    3541     * Constructs a new {@code ElemStyles}.
     
    3743    public ElemStyles() {
    3844        styleSources = new ArrayList<>();
     45        Main.pref.addPreferenceChangeListener(this);
    3946    }
    4047
     
    4855            public void run() {
    4956                cacheIdx++;
     57                preferenceCache.clear();
    5058            }
    5159        });
     
    487495        }
    488496    }
     497
     498    /**
     499     * Looks up a preference value and ensures the style cache is invalidated
     500     * as soon as this preference value is changed by the user.
     501     *
     502     * In addition, it adds an intermediate cache for the preference values,
     503     * as frequent preference lookup (using <code>Main.pref.get()</code>) for
     504     * each primitive can be slow during rendering.
     505     *
     506     * @param key preference key
     507     * @param def default value
     508     * @return the corresponding preference value
     509     * @see org.openstreetmap.josm.data.Preferences#get(String, String)
     510     */
     511    public String getPreferenceCached(String key, String def) {
     512        String res;
     513        if (preferenceCache.containsKey(key)) {
     514            res = preferenceCache.get(key);
     515        } else {
     516            res = Main.pref.get(key, null);
     517            preferenceCache.put(key, res);
     518        }
     519        return res != null ? res : def;
     520    }
     521
     522    @Override
     523    public void preferenceChanged(PreferenceChangeEvent e) {
     524        if (preferenceCache.containsKey(e.getKey())) {
     525            clearCached();
     526        }
     527    }
    489528}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r9078 r9114  
    3030import org.openstreetmap.josm.gui.mappaint.Cascade;
    3131import org.openstreetmap.josm.gui.mappaint.Environment;
     32import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    3233import org.openstreetmap.josm.gui.util.RotationAngle;
    3334import org.openstreetmap.josm.io.XmlWriter;
     
    678679         * @param def Default value
    679680         * @return value for key, or default value if not found
    680          * @see org.openstreetmap.josm.data.Preferences#get(String, String)
    681          */
    682         public static String JOSM_pref(String key, String def) {
    683             String res = Main.pref.get(key, null);
    684             return res != null ? res : def;
     681         */
     682        public static String JOSM_pref(Environment env, String key, String def) {
     683            return MapPaintStyles.getStyles().getPreferenceCached(key, def);
    685684        }
    686685
  • trunk/styles/standard/elemstyles.mapcss

    r9103 r9114  
    48764876   so only do this at low zoom. */
    48774877area|z-13[setting("partial_fill")] {
    4878     fill-extent-threshold: 100%;
     4878    fill-extent-threshold: 1.0;
    48794879}
    48804880
    48814881/* Larger extent for closed areas.
    4882    Turn partial fill off, when it covers more than about 70% of the area. This is avoids
     4882   Turn partial fill off, when it covers more than about 50% of the area. This is avoids
    48834883   areas with small unfilled patches in the center. */
    48844884area[setting("partial_fill")]:closed2 {
    48854885    fill-extent: 25;
    4886     fill-extent-threshold: 50%;
    4887 }
    4888 
     4886    fill-extent-threshold: JOSM_pref("draw.area.extent_threshold", 0.5);
     4887}
     4888
Note: See TracChangeset for help on using the changeset viewer.