Ticket #10391: 10391_not_working.patch

File 10391_not_working.patch, 5.4 KB (added by Don-vip, 11 years ago)
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

     
    179179|   < CARET: "^" >
    180180|   < FULLSTOP: "." >
    181181|   < ELEMENT_OF: "∈" >
     182|   < NOT_ELEMENT_OF: "∉" >
    182183|   < CROSSING: "⧉" >
    183184|   < COMMENT_START: "/*" > : COMMENT
    184185|   < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from
     
    534535            |
    535536                <ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.ELEMENT_OF; }
    536537            |
     538                <NOT_ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.NOT_ELEMENT_OF; }
     539            |
    537540                <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; }
    538541            )
    539542            w()
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

     
    2525
    2626/**
    2727 * MapCSS selector.
    28  * 
     28 *
    2929 * A rule has two parts, a selector and a declaration block
    3030 * e.g.
    3131 * <pre>
    32  * way[highway=residential]   
    33  * { width: 10; color: blue; } 
     32 * way[highway=residential]
     33 * { width: 10; color: blue; }
    3434 * </pre>
    35  * 
     35 *
    3636 * The selector decides, if the declaration block gets applied or not.
    37  * 
     37 *
    3838 * All implementing classes of Selector are immutable.
    3939 */
    4040public interface Selector {
     
    4848     * @return true, if the selector applies
    4949     */
    5050    boolean matches(Environment env);
    51    
     51
    5252    String getSubpart();
    5353
    5454    Range getRange();
    55    
     55
    5656    /**
    5757     * Create an "optimized" copy of this selector that omits the base check.
    58      * 
     58     *
    5959     * For the style source, the list of rules is preprocessed, such that
    6060     * there is a separate list of rules for nodes, ways, ...
    61      * 
     61     *
    6262     * This means that the base check does not have to be performed
    6363     * for each rule, but only once for each primitive.
    64      * 
     64     *
    6565     * @return a selector that is identical to this object, except the base of the
    6666     * "rightmost" selector is not checked
    6767     */
    6868    Selector optimizedBaseCheck();
    6969
    7070    public static enum ChildOrParentSelectorType {
    71         CHILD, PARENT, ELEMENT_OF, CROSSING, SIBLING
     71        CHILD,
     72        PARENT,
     73        ELEMENT_OF,
     74        NOT_ELEMENT_OF,
     75        CROSSING,
     76        SIBLING
    7277    }
    7378
    7479    /**
     
    265270            if (!right.matches(e))
    266271                return false;
    267272
    268             if (ChildOrParentSelectorType.ELEMENT_OF.equals(type)) {
     273            boolean elementOf = ChildOrParentSelectorType.ELEMENT_OF.equals(type);
     274            boolean notElementOf = ChildOrParentSelectorType.NOT_ELEMENT_OF.equals(type);
    269275
     276            if (elementOf || notElementOf) {
     277
    270278                if (e.osm instanceof Node || e.osm.getDataSet() == null) {
    271279                    // nodes cannot contain elements
    272280                    return false;
     
    308316                    containsFinder.visit(e.osm.getDataSet().allPrimitives());
    309317                }
    310318
    311                 return e.child != null;
     319                return elementOf ? e.child != null : e.child == null;
    312320
    313321            } else if (ChildOrParentSelectorType.CROSSING.equals(type) && e.osm instanceof Way) {
    314322                e.parent = e.osm;
     
    379387        public Range getRange() {
    380388            return right.getRange();
    381389        }
    382        
     390
    383391        @Override
    384392        public Selector optimizedBaseCheck() {
    385393            return new ChildOrParentSelector(left, link, right.optimizedBaseCheck(), type);
     
    472480        public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, String subpart) {
    473481            super(base, zoom, conds, subpart);
    474482        }
    475        
     483
    476484        public boolean matchesConditions(Environment e) {
    477485            return super.matches(e);
    478486        }
     
    487495            return matchesBase(e) && super.matches(e);
    488496        }
    489497    }
    490    
     498
    491499    public static class OptimizedGeneralSelector extends AbstractSelector {
    492500        public final String base;
    493501        public final Range range;
     
    509517            }
    510518            this.subpart = subpart;
    511519        }
    512        
     520
    513521        public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, String subpart) {
    514522            super(conds);
    515523            this.base = base;
    516524            this.range = range;
    517525            this.subpart = subpart;
    518526        }
    519        
     527
    520528        public OptimizedGeneralSelector(GeneralSelector s) {
    521529            this(s.base, s.range, s.conds, s.subpart);
    522530        }
     
    571579        public Selector optimizedBaseCheck() {
    572580            throw new UnsupportedOperationException();
    573581        }
    574        
     582
    575583        public static Range fromLevel(int a, int b) {
    576584            if (a > b)
    577585                throw new AssertionError();
     
    595603            // or similar level are displayed at the given scale
    596604            return 2.0 * Math.PI * R / Math.pow(2.0, lvl) / 2.56;
    597605        }
    598        
     606
    599607        public static int scale2level(double scale) {
    600608            if (scale < 0)
    601609                throw new IllegalArgumentException();