Changeset 16590 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r15719 r16590 21 21 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 22 22 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 23 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 23 24 import org.openstreetmap.josm.gui.MainApplication; 24 25 import org.openstreetmap.josm.gui.NavigatableComponent; … … 40 41 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; 41 42 import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener; 43 import org.openstreetmap.josm.tools.ColorHelper; 42 44 import org.openstreetmap.josm.tools.Pair; 43 45 … … 604 606 * each primitive can be slow during rendering. 605 607 * 608 * If the default value can be {@linkplain Cascade#convertTo converted} to a {@link Color}, 609 * the {@link NamedColorProperty} is retrieved as string. 610 * 611 * @param source style source 606 612 * @param key preference key 607 613 * @param def default value … … 609 615 * @see org.openstreetmap.josm.data.Preferences#get(String, String) 610 616 */ 611 public String getPreferenceCached(String key, String def) { 617 public String getPreferenceCached(StyleSource source, String key, String def) { 612 618 String res; 613 619 if (preferenceCache.containsKey(key)) { 614 620 res = preferenceCache.get(key); 615 621 } else { 616 res = Config.getPref().get(key, null); 622 Color realDef = Cascade.convertTo(def, Color.class); 623 if (realDef != null) { 624 String prefName = source != null ? source.getFileNamePart() : "unknown"; 625 NamedColorProperty property = new NamedColorProperty(NamedColorProperty.COLOR_CATEGORY_MAPPAINT, prefName, key, realDef); 626 res = ColorHelper.color2html(property.get()); 627 } else { 628 res = Config.getPref().get(key, null); 629 } 617 630 preferenceCache.put(key, res); 618 631 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
r16553 r16590 28 28 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 29 29 import org.openstreetmap.josm.data.osm.search.SearchParseError; 30 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 30 31 import org.openstreetmap.josm.gui.MainApplication; 31 32 import org.openstreetmap.josm.gui.mappaint.Cascade; … … 768 769 * Obtains the JOSM'key {@link org.openstreetmap.josm.data.Preferences} string for key {@code key}, 769 770 * and defaults to {@code def} if that is null. 771 * 772 * If the default value can be {@linkplain Cascade#convertTo converted} to a {@link Color}, 773 * the {@link NamedColorProperty} is retrieved as string. 774 * 770 775 * @param env the environment 771 776 * @param key Key in JOSM preference … … 774 779 */ 775 780 public static String JOSM_pref(Environment env, String key, String def) { // NO_UCD (unused code) 776 return MapPaintStyles.getStyles().getPreferenceCached(key, def); 781 return MapPaintStyles.getStyles().getPreferenceCached(env != null ? env.source : null, key, def); 777 782 } 778 783 -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/FunctionsTest.java
r16583 r16590 6 6 import static org.openstreetmap.josm.data.osm.OsmPrimitiveType.NODE; 7 7 8 import java.util.Collections; 9 8 10 import org.junit.Rule; 9 11 import org.junit.Test; … … 12 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 13 15 import org.openstreetmap.josm.data.osm.User; 16 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 14 17 import org.openstreetmap.josm.gui.mappaint.Environment; 15 18 import org.openstreetmap.josm.gui.util.GuiHelper; … … 113 116 public void testPref() { 114 117 String key = "Functions.JOSM_pref"; 118 Config.getPref().put(key, null); 115 119 assertEquals("foobar", Functions.JOSM_pref(null, key, "foobar")); 116 120 Config.getPref().put(key, "baz"); … … 124 128 }); 125 129 assertEquals("foobar", Functions.JOSM_pref(null, key, "foobar")); 130 Config.getPref().put(key, null); 126 131 } 132 133 /** 134 * Unit test of {@link Functions#JOSM_pref}, color handling 135 */ 136 @Test 137 public void testPrefColor() { 138 String key = "Functions.JOSM_pref"; 139 String colorKey = NamedColorProperty.NAMED_COLOR_PREFIX + NamedColorProperty.COLOR_CATEGORY_MAPPAINT + ".unknown." + key; 140 Config.getPref().put(colorKey, null); 141 assertEquals("#000000", Functions.JOSM_pref(null, key, "#000000")); 142 Config.getPref().putList(colorKey, Collections.singletonList("#00FF00")); 143 GuiHelper.runInEDTAndWait(() -> { 144 // await org.openstreetmap.josm.gui.mappaint.ElemStyles.clearCached 145 }); 146 assertEquals("#00FF00", Functions.JOSM_pref(null, key, "#000000")); 147 Config.getPref().put(colorKey, null); 148 GuiHelper.runInEDTAndWait(() -> { 149 // await org.openstreetmap.josm.gui.mappaint.ElemStyles.clearCached 150 }); 151 assertEquals("#000000", Functions.JOSM_pref(null, key, "#000000")); 152 Config.getPref().put(colorKey, null); 153 } 154 127 155 }
Note:
See TracChangeset
for help on using the changeset viewer.