Changeset 8086 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2015-02-19T11:52:05+01:00 (9 years ago)
Author:
bastiK
Message:

MapCSS: add support for dynamic subparts

This feature is not useful on its own (aimed at loops & jumps).
Will keep this undocumented for now.

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r7761 r8086  
    1212import java.util.List;
    1313
     14import org.openstreetmap.josm.Main;
    1415import org.openstreetmap.josm.gui.mappaint.Keyword;
    1516import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
    1617import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
    1718import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
     19import org.openstreetmap.josm.gui.mappaint.mapcss.ExpressionFactory;
    1820import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
     21import org.openstreetmap.josm.gui.mappaint.mapcss.LiteralExpression;
     22import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException;
    1923import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
    2024import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule.Declaration;
    2125import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    2226import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
    23 import org.openstreetmap.josm.gui.mappaint.mapcss.ExpressionFactory;
    24 import org.openstreetmap.josm.gui.mappaint.mapcss.LiteralExpression;
    25 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException;
    2627import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
    2728import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
    2829import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector;
     30import org.openstreetmap.josm.gui.mappaint.mapcss.Subpart;
    2931import org.openstreetmap.josm.tools.ColorHelper;
    3032import org.openstreetmap.josm.tools.Pair;
    31 import org.openstreetmap.josm.Main;
    3233
    3334/**
     
    553554    Pair<Integer, Integer> r = null;
    554555    List<Condition> conditions = new ArrayList<Condition>();
    555     String sub = null;
     556    Subpart sub = null;
    556557}
    557558{
     
    708709}
    709710
    710 String subpart() :
     711Subpart subpart() :
    711712{
    712713    String s;
     714    Expression e;
    713715}
    714716{
    715717    <DCOLON>
    716     ( s=ident() { return s; } | <STAR> { return "*"; } )
     718    (
     719        s=ident() { return new Subpart.StringSubpart(s); }
     720    |
     721        <STAR> { return new Subpart.StringSubpart("*"); }
     722    |
     723        <LPAR> e=expression() <RPAR> { return new Subpart.ExpressionSubpart(e); }
     724    )
    717725}
    718726
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r7563 r8086  
    374374                        continue;
    375375                    }
    376                     env.layer = gs.getSubpart();
     376                    env.layer = null;
     377                    env.layer = gs.getSubpart().getId(env);
    377378                    r.execute(env);
    378379                }
     
    455456        for (MapCSSRule r : matchingRuleIndex.getRuleCandidates(osm)) {
    456457            env.clearSelectorMatchingInformation();
    457             env.layer = r.selector.getSubpart();
     458            env.layer = null;
     459            String sub = env.layer = r.selector.getSubpart().getId(env);
    458460            if (r.selector.matches(env)) { // as side effect env.parent will be set (if s is a child selector)
    459461                Selector s = r.selector;
     
    467469                if (r.declaration.idx == lastDeclUsed) continue; // don't apply one declaration more than once
    468470                lastDeclUsed = r.declaration.idx;
    469                 String sub = s.getSubpart();
    470                 if (sub == null) {
    471                     sub = "default";
    472                 }
    473                 else if ("*".equals(sub)) {
     471                if ("*".equals(sub)) {
    474472                    for (Entry<String, Cascade> entry : mc.getLayers()) {
    475473                        env.layer = entry.getKey();
     
    487485
    488486    public boolean evalMediaExpression(String feature, Object val) {
    489         if ("user-agent".equals(feature)) {
    490             String s = Cascade.convertTo(val, String.class);
    491             if ("josm".equals(s)) return true;
    492         }
    493         if ("min-josm-version".equals(feature)) {
    494             Float v = Cascade.convertTo(val, Float.class);
    495             if (v != null) return Math.round(v) <= Version.getInstance().getVersion();
    496         }
    497         if ("max-josm-version".equals(feature)) {
    498             Float v = Cascade.convertTo(val, Float.class);
    499             if (v != null) return Math.round(v) >= Version.getInstance().getVersion();
    500         }
    501         return false;
     487        if (feature == null) return false;
     488        switch (feature) {
     489            case "user-agent":
     490            {
     491                String s = Cascade.convertTo(val, String.class);
     492                return "josm".equals(s);
     493            }
     494            case "min-josm-version":
     495            {
     496                Float v = Cascade.convertTo(val, Float.class);
     497                return v != null && Math.round(v) <= Version.getInstance().getVersion();
     498            }
     499            case "max-josm-version":
     500            {
     501                Float v = Cascade.convertTo(val, Float.class);
     502                return v != null && Math.round(v) >= Version.getInstance().getVersion();
     503            }
     504            default:
     505                return false;
     506        }
    502507    }
    503508
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r7881 r8086  
    5050    boolean matches(Environment env);
    5151
    52     String getSubpart();
     52    Subpart getSubpart();
    5353
    5454    Range getRange();
     
    372372
    373373        @Override
    374         public String getSubpart() {
     374        public Subpart getSubpart() {
    375375            return right.getSubpart();
    376376        }
     
    453453
    454454        @Override
    455         public String getSubpart() {
     455        public Subpart getSubpart() {
    456456            throw new UnsupportedOperationException("Not supported yet.");
    457457        }
     
    475475    public static class GeneralSelector extends OptimizedGeneralSelector {
    476476
    477         public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, String subpart) {
     477        public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, Subpart subpart) {
    478478            super(base, zoom, conds, subpart);
    479479        }
     
    497497        public final String base;
    498498        public final Range range;
    499         public final String subpart;
    500 
    501         public OptimizedGeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, String subpart) {
     499        public final Subpart subpart;
     500
     501        public OptimizedGeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, Subpart subpart) {
    502502            super(conds);
    503503            this.base = base;
     
    513513                range = Range.ZERO_TO_INFINITY;
    514514            }
    515             this.subpart = subpart;
    516         }
    517 
    518         public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, String subpart) {
     515            this.subpart = subpart != null ? subpart : Subpart.DEFAULT_SUBPART;
     516        }
     517
     518        public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, Subpart subpart) {
    519519            super(conds);
    520520            this.base = base;
    521521            this.range = range;
    522             this.subpart = subpart;
     522            this.subpart = subpart != null ? subpart : Subpart.DEFAULT_SUBPART;
    523523        }
    524524
     
    528528
    529529        @Override
    530         public String getSubpart() {
     530        public Subpart getSubpart() {
    531531            return subpart;
    532532        }
Note: See TracChangeset for help on using the changeset viewer.