Changeset 9114 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint
- Timestamp:
- 2015-12-13T20:28:00+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r9078 r9114 6 6 import java.util.Collection; 7 7 import java.util.Collections; 8 import java.util.HashMap; 8 9 import java.util.List; 10 import java.util.Map; 9 11 import java.util.Map.Entry; 10 12 11 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 15 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 12 16 import org.openstreetmap.josm.data.osm.Node; 13 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 23 27 import org.openstreetmap.josm.tools.Utils; 24 28 25 public class ElemStyles { 29 public class ElemStyles implements PreferenceChangedListener { 26 30 private final List<StyleSource> styleSources; 27 31 private boolean drawMultipolygon; … … 32 36 private int defaultNodesIdx, defaultLinesIdx; 33 37 38 private final Map<String, String> preferenceCache = new HashMap<>(); 39 34 40 /** 35 41 * Constructs a new {@code ElemStyles}. … … 37 43 public ElemStyles() { 38 44 styleSources = new ArrayList<>(); 45 Main.pref.addPreferenceChangeListener(this); 39 46 } 40 47 … … 48 55 public void run() { 49 56 cacheIdx++; 57 preferenceCache.clear(); 50 58 } 51 59 }); … … 487 495 } 488 496 } 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 } 489 528 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r9078 r9114 30 30 import org.openstreetmap.josm.gui.mappaint.Cascade; 31 31 import org.openstreetmap.josm.gui.mappaint.Environment; 32 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 32 33 import org.openstreetmap.josm.gui.util.RotationAngle; 33 34 import org.openstreetmap.josm.io.XmlWriter; … … 678 679 * @param def Default value 679 680 * @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); 685 684 } 686 685
Note:
See TracChangeset
for help on using the changeset viewer.