Changeset 6561 in josm


Ignore:
Timestamp:
2013-12-29T12:43:55+01:00 (10 years ago)
Author:
simon04
Message:

see #9485 - MapCSS: add support for set .class_name instruction (with optional . before class), define Range.ZERO_TO_INFINITY

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java

    r5342 r6561  
    2121    public MultiCascade() {
    2222        layers = new HashMap<String, Cascade>();
    23         range = new Range();
     23        range = Range.ZERO_TO_INFINITY;
    2424    }
    2525
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Range.java

    r3836 r6561  
    1111    private double upper;
    1212
    13     public Range() {
    14         this.lower = 0;
    15         this.upper = Double.POSITIVE_INFINITY;
    16     }
     13    public static final Range ZERO_TO_INFINITY = new Range(0.0, Double.POSITIVE_INFINITY);
    1714
    1815    public Range(double lower, double upper) {
     
    7774        return String.format("|s%s-%s", lower, upper);
    7875    }
     76
     77    @Override
     78    public boolean equals(Object o) {
     79        if (this == o) return true;
     80        if (o == null || getClass() != o.getClass()) return false;
     81
     82        Range range = (Range) o;
     83
     84        if (Double.compare(range.lower, lower) != 0) return false;
     85        if (Double.compare(range.upper, upper) != 0) return false;
     86
     87        return true;
     88    }
     89
     90    @Override
     91    public int hashCode() {
     92        int result;
     93        long temp;
     94        temp = Double.doubleToLongBits(lower);
     95        result = (int) (temp ^ (temp >>> 32));
     96        temp = Double.doubleToLongBits(upper);
     97        result = 31 * result + (int) (temp ^ (temp >>> 32));
     98        return result;
     99    }
    79100}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r6560 r6561  
    463463    (
    464464        (
    465         <SET> w() key=<IDENT> w()
    466         ( <EQUAL> val=expression() )?
    467         { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val)); }
    468         ( <RBRACE> { return ins; } | <SEMICOLON> w() )
     465            <SET> w()
     466            (<FULLSTOP>)? // specification allows "set .class" to set "class". we also support "set class"
     467            key=<IDENT> w()
     468            ( <EQUAL> val=expression() )?
     469            { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val)); }
     470            ( <RBRACE> { return ins; } | <SEMICOLON> w() )
    469471        )
    470         |
     472    |
    471473        key=<IDENT> w() <COLON> w()
    472474        (
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r6538 r6561  
    267267
    268268    public static class GeneralSelector extends AbstractSelector {
    269         private String base;
    270         public Range range;
    271         private String subpart;
     269        public final String base;
     270        public final Range range;
     271        public final String subpart;
    272272
    273273        public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, String subpart) {
     
    279279                if (a <= b) {
    280280                    range = fromLevel(a, b);
    281                 }
    282             }
    283             if (range == null) {
    284                 range = new Range();
     281                } else {
     282                    range = Range.ZERO_TO_INFINITY;
     283                }
     284            } else {
     285                range = Range.ZERO_TO_INFINITY;
    285286            }
    286287            this.subpart = subpart;
     
    348349        @Override
    349350        public String toString() {
    350             return base + (range == null ? "" : range) + Utils.join("", conds) + (subpart != null ? ("::" + subpart) : "");
     351            return base + (Range.ZERO_TO_INFINITY.equals(range) ? "" : range) + Utils.join("", conds) + (subpart != null ? ("::" + subpart) : "");
    351352        }
    352353    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/AreaPrototype.java

    r3836 r6561  
    2323    {
    2424        priority = 0;
    25         range = new Range();
     25        range = Range.ZERO_TO_INFINITY;
    2626        closed = false;
    2727        color = null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/IconPrototype.java

    r6070 r6561  
    2222    public void init() {
    2323        priority = 0;
    24         range = new Range();
     24        range = Range.ZERO_TO_INFINITY;
    2525        icon = null;
    2626        annotate = null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/LinePrototype.java

    r6248 r6561  
    3535    {
    3636        priority = 0;
    37         range = new Range();
     37        range = Range.ZERO_TO_INFINITY;
    3838        width = -1;
    3939        realWidth = null;
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy

    r6560 r6561  
    1010import org.openstreetmap.josm.gui.mappaint.MultiCascade
    1111import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
     12import org.openstreetmap.josm.tools.Utils
     13
     14import java.awt.Color
    1215
    1316class MapCSSParserTest {
     
    6063        def css = new MapCSSStyleSource("")
    6164        getParser("" +
    62                 "way[highway=footway] { set path; color: #FF6644; width: 2; }\n" +
     65                "way[highway=footway] { set .path; color: #FF6644; width: 2; }\n" +
    6366                "way[highway=path]    { set path; color: brown; width: 2; }\n" +
    6467                "way[\"set\"=escape]  {  }\n" +
     
    7578        assert "orange".equals(mc2.getCascade("default").get("color", null, String.class))
    7679        assert mc2.getCascade("default").get("text-color", null, String.class) == null
     80        def mc3 = new MultiCascade()
     81        css.apply(mc3, getPrimitive("highway", "footway"), 1, null, false);
     82        assert Utils.hexToColor("#FF6644").equals(mc3.getCascade("default").get("color", null, Color.class))
    7783    }
    7884
Note: See TracChangeset for help on using the changeset viewer.