Changeset 6740 in josm
- Timestamp:
- 2014-01-19T20:30:57+01:00 (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r6534 r6740 13 13 import org.openstreetmap.josm.Main; 14 14 import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors; 15 import org.openstreetmap.josm.tools.ColorHelper; 15 16 import org.openstreetmap.josm.tools.Utils; 16 17 … … 171 172 return c; 172 173 if (HEX_COLOR_PATTERN.matcher((String) o).matches()) { 173 return Utils.hexToColor((String) o);174 return ColorHelper.html2color((String) o); 174 175 } 175 176 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6686 r6740 26 26 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 27 27 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector; 28 import org.openstreetmap.josm.tools.ColorHelper; 28 29 import org.openstreetmap.josm.tools.Pair; 29 30 import org.openstreetmap.josm.tools.Utils; … … 585 586 { 586 587 String val; 587 Token t; 588 Token t, t2; 588 589 float f; 589 590 } 590 591 { 592 LOOKAHEAD(2) 593 t2=<IDENT> t=<HEXCOLOR> 594 { return Main.pref.getColor("mappaint." + (sheet == null ? "MapCSS" : sheet.title) + "." + t2.image, ColorHelper.html2color(t.image)); } 595 | 591 596 t=<IDENT> { return new Keyword(t.image); } 592 597 | … … 597 602 f=ufloat() { return f; } 598 603 | 599 t=<HEXCOLOR> { return Utils.hexToColor(t.image); }604 t=<HEXCOLOR> { return ColorHelper.html2color(t.image); } 600 605 } 601 606 -
trunk/src/org/openstreetmap/josm/tools/ColorHelper.java
r6655 r6740 21 21 if (html.length() > 0 && html.charAt(0) == '#') 22 22 html = html.substring(1); 23 if (html.length() == 3) { 24 return html2color(new String( 25 new char[]{html.charAt(0), html.charAt(0), html.charAt(1), html.charAt(1), html.charAt(2), html.charAt(2)})); 26 } 23 27 if (html.length() != 6 && html.length() != 8) 24 28 return null; -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6717 r6740 630 630 631 631 /** 632 * Convert Hex String to Color.633 * @param s Must be of the form "#34a300" or "#3f2", otherwise throws Exception.634 * Upper/lower case does not matter.635 * @return The corresponding color.636 */637 static public Color hexToColor(String s) {638 String clr = s.substring(1);639 if (clr.length() == 3) {640 clr = new String(new char[] {641 clr.charAt(0), clr.charAt(0), clr.charAt(1), clr.charAt(1), clr.charAt(2), clr.charAt(2)642 });643 }644 if (clr.length() != 6)645 throw new IllegalArgumentException();646 return new Color(Integer.parseInt(clr, 16));647 }648 649 /**650 632 * Opens a HTTP connection to the given URL and sets the User-Agent property to JOSM's one. 651 633 * @param httpURL The HTTP url to open (must use http:// or https://) -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy
r6737 r6740 11 11 import org.openstreetmap.josm.gui.mappaint.MultiCascade 12 12 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser 13 import org.openstreetmap.josm.tools.ColorHelper 13 14 import org.openstreetmap.josm.tools.Utils 14 15 … … 81 82 def mc3 = new MultiCascade() 82 83 css.apply(mc3, getPrimitive("highway", "footway"), 1, null, false); 83 assert Utils.hexToColor("#FF6644").equals(mc3.getCascade("default").get("color", null, Color.class))84 assert ColorHelper.html2color("#FF6644").equals(mc3.getCascade("default").get("color", null, Color.class)) 84 85 } 85 86 … … 217 218 assert mc.getCascade(Environment.DEFAULT_LAYER).get("text") == "15 - 1.5 - Foo" 218 219 } 220 221 @Test 222 public void testColorNameTicket9191() throws Exception { 223 def e = new Environment(null, new MultiCascade(), Environment.DEFAULT_LAYER, null) 224 getParser("{color: testcolour1#88DD22}").declaration().get(0).execute(e) 225 def expected = new Color(0x88DD22) 226 assert e.getCascade(Environment.DEFAULT_LAYER).get("color") == expected 227 assert Main.pref.getDefaultColor("MapCSS.testcolour1") == expected 228 } 219 229 }
Note:
See TracChangeset
for help on using the changeset viewer.