Changeset 6774 in josm for trunk


Ignore:
Timestamp:
2014-01-29T22:15:06+01:00 (11 years ago)
Author:
simon04
Message:

fix #9633 - MapCSS: allow (named) colours with alpha

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r6671 r6774  
    877877        String colStr = specName != null ? get("color."+specName) : "";
    878878        if (colStr.isEmpty()) {
    879             colStr = get("color." + colKey, ColorHelper.color2html(def));
     879            colStr = get("color." + colKey, ColorHelper.color2html(def, true));
    880880        }
    881881        if (colStr != null && !colStr.isEmpty()) {
     
    893893
    894894    synchronized public boolean putColor(String colKey, Color val) {
    895         return put("color."+colKey, val != null ? ColorHelper.color2html(val) : null);
     895        return put("color."+colKey, val != null ? ColorHelper.color2html(val, true) : null);
    896896    }
    897897
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r6740 r6774  
    5252|   < REGEX: "/" <REGEX_CHAR_WITHOUT_STAR> ( <REGEX_CHAR_WITHOUT_STAR> | "*" )*  "/" >
    5353|   < #H: ["0"-"9","a"-"f","A"-"F"] >
    54 |   < HEXCOLOR: "#" ( <H><H><H><H><H><H> | <H><H><H> ) >
     54|   < HEXCOLOR: "#" ( <H><H><H><H><H><H><H><H> | <H><H><H><H><H><H> | <H><H><H> ) >
    5555|   < S: ( " " | "\t" | "\n" | "\r" | "\f" )+ >
    5656|   < STAR: "*" >
  • trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy

    r6671 r6774  
    22
    33import org.openstreetmap.josm.Main
     4
     5import java.awt.Color
    46
    57class PreferencesTest extends GroovyTestCase {
     
    1012
    1113    void testColorName() {
    12         Main.pref.getColorName("color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx") == "{5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx"
     14        assert Main.pref.getColorName("color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx") == "color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx"
     15    }
     16
     17    void testColorAlpha() {
     18        assert Main.pref.getColor("foo", new Color(0x12345678, true)).alpha == 0x12
     19        assert Main.pref.putColor("bar", new Color(0x12345678, true))
     20        assert Main.pref.getColor("bar", null).alpha == 0x12
     21    }
     22
     23    void testColorNameAlpha() {
     24        assert Main.pref.getColor("foo", "bar", new Color(0x12345678, true)).alpha == 0x12
     25        assert Main.pref.getDefaultColor("foo") == new Color(0x34, 0x56, 0x78, 0x12)
     26        assert Main.pref.getDefaultColor("foo").alpha == 0x12
    1327    }
    1428}
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy

    r6740 r6774  
    225225        def expected = new Color(0x88DD22)
    226226        assert e.getCascade(Environment.DEFAULT_LAYER).get("color") == expected
    227         assert Main.pref.getDefaultColor("MapCSS.testcolour1") == expected
     227        assert Main.pref.getDefaultColor("mappaint.mapcss.testcolour1") == expected
     228    }
     229
     230    @Test
     231    public void testColorNameTicket9191Alpha() throws Exception {
     232        def e = new Environment(null, new MultiCascade(), Environment.DEFAULT_LAYER, null)
     233        getParser("{color: testcolour2#12345678}").declaration().get(0).execute(e)
     234        def expected = new Color(0x12, 0x34, 0x56, 0x78)
     235        assert e.getCascade(Environment.DEFAULT_LAYER).get("color") == expected
     236        assert Main.pref.getDefaultColor("mappaint.mapcss.testcolour2") == expected
     237    }
     238
     239    @Test
     240    public void testColorParsing() throws Exception {
     241        assert ColorHelper.html2color("#12345678") == new Color(0x12, 0x34, 0x56, 0x78)
    228242    }
    229243}
Note: See TracChangeset for help on using the changeset viewer.