Changeset 5577 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-11-12T21:38:11+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r3967 r5577 9 9 import java.util.List; 10 10 import java.util.Map; 11 import java.util.regex.Pattern; 11 12 12 13 import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors; 14 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 13 15 import org.openstreetmap.josm.tools.Utils; 14 16 … … 22 24 protected Map<String, Object> prop = new HashMap<String, Object>(); 23 25 26 private final static Pattern HEX_COLOR_PATTERN = Pattern.compile("#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})"); 27 24 28 public <T> T get(String key, T def, Class<T> klass) { 25 29 return get(key, def, klass, false); … … 28 32 /** 29 33 * Get value for the given key 34 * @param <T> the expected type 30 35 * @param key the key 31 36 * @param def default value, can be null … … 165 170 if (o instanceof Keyword) 166 171 return CSSColors.get(((Keyword) o).val); 172 if (o instanceof String) { 173 Color c = CSSColors.get((String) o); 174 if (c != null) 175 return c; 176 if (HEX_COLOR_PATTERN.matcher((String) o).matches()) { 177 return Utils.hexToColor((String) o); 178 } 179 } 167 180 return null; 168 181 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r4280 r5577 26 26 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector; 27 27 import org.openstreetmap.josm.tools.Pair; 28 import org.openstreetmap.josm.tools.Utils; 28 29 29 30 public class MapCSSParser { … … 553 554 f=ufloat() { return f; } 554 555 | 555 t=<HEXCOLOR> 556 { 557 String clr = t.image.substring(1); 558 if (clr.length() == 3) { 559 clr = new String(new char[] {clr.charAt(0),clr.charAt(0),clr.charAt(1),clr.charAt(1),clr.charAt(2),clr.charAt(2)}); 560 } 561 if (clr.length() != 6) 562 throw new AssertionError(); 563 return new Color(Integer.parseInt(clr, 16)); 564 } 556 t=<HEXCOLOR> { return Utils.hexToColor(t.image); } 565 557 } 566 558 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r5221 r5577 546 546 }; 547 547 } 548 549 /** 550 * Convert Hex String to Color. 551 * @param s Must be of the form "#34a300" or "#3f2", otherwise throws Exception. 552 * Upper/lower case does not matter. 553 * @return The corresponding color. 554 */ 555 static public Color hexToColor(String s) { 556 String clr = s.substring(1); 557 if (clr.length() == 3) { 558 clr = new String(new char[] { 559 clr.charAt(0), clr.charAt(0), clr.charAt(1), clr.charAt(1), clr.charAt(2), clr.charAt(2) 560 }); 561 } 562 if (clr.length() != 6) 563 throw new IllegalArgumentException(); 564 return new Color(Integer.parseInt(clr, 16)); 565 } 566 548 567 }
Note:
See TracChangeset
for help on using the changeset viewer.