Changeset 8086 in josm
- Timestamp:
- 2015-02-19T11:52:05+01:00 (10 years ago)
- 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 12 12 import java.util.List; 13 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.gui.mappaint.Keyword; 15 16 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 16 17 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context; 17 18 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; 19 import org.openstreetmap.josm.gui.mappaint.mapcss.ExpressionFactory; 18 20 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; 21 import org.openstreetmap.josm.gui.mappaint.mapcss.LiteralExpression; 22 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException; 19 23 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule; 20 24 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule.Declaration; 21 25 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 22 26 import 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;26 27 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector; 27 28 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 28 29 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector; 30 import org.openstreetmap.josm.gui.mappaint.mapcss.Subpart; 29 31 import org.openstreetmap.josm.tools.ColorHelper; 30 32 import org.openstreetmap.josm.tools.Pair; 31 import org.openstreetmap.josm.Main;32 33 33 34 /** … … 553 554 Pair<Integer, Integer> r = null; 554 555 List<Condition> conditions = new ArrayList<Condition>(); 555 S tringsub = null;556 Subpart sub = null; 556 557 } 557 558 { … … 708 709 } 709 710 710 S tringsubpart() :711 Subpart subpart() : 711 712 { 712 713 String s; 714 Expression e; 713 715 } 714 716 { 715 717 <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 ) 717 725 } 718 726 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r7563 r8086 374 374 continue; 375 375 } 376 env.layer = gs.getSubpart(); 376 env.layer = null; 377 env.layer = gs.getSubpart().getId(env); 377 378 r.execute(env); 378 379 } … … 455 456 for (MapCSSRule r : matchingRuleIndex.getRuleCandidates(osm)) { 456 457 env.clearSelectorMatchingInformation(); 457 env.layer = r.selector.getSubpart(); 458 env.layer = null; 459 String sub = env.layer = r.selector.getSubpart().getId(env); 458 460 if (r.selector.matches(env)) { // as side effect env.parent will be set (if s is a child selector) 459 461 Selector s = r.selector; … … 467 469 if (r.declaration.idx == lastDeclUsed) continue; // don't apply one declaration more than once 468 470 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)) { 474 472 for (Entry<String, Cascade> entry : mc.getLayers()) { 475 473 env.layer = entry.getKey(); … … 487 485 488 486 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 } 502 507 } 503 508 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r7881 r8086 50 50 boolean matches(Environment env); 51 51 52 S tringgetSubpart();52 Subpart getSubpart(); 53 53 54 54 Range getRange(); … … 372 372 373 373 @Override 374 public S tringgetSubpart() {374 public Subpart getSubpart() { 375 375 return right.getSubpart(); 376 376 } … … 453 453 454 454 @Override 455 public S tringgetSubpart() {455 public Subpart getSubpart() { 456 456 throw new UnsupportedOperationException("Not supported yet."); 457 457 } … … 475 475 public static class GeneralSelector extends OptimizedGeneralSelector { 476 476 477 public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, S tringsubpart) {477 public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, Subpart subpart) { 478 478 super(base, zoom, conds, subpart); 479 479 } … … 497 497 public final String base; 498 498 public final Range range; 499 public final S tringsubpart;500 501 public OptimizedGeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, S tringsubpart) {499 public final Subpart subpart; 500 501 public OptimizedGeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, Subpart subpart) { 502 502 super(conds); 503 503 this.base = base; … … 513 513 range = Range.ZERO_TO_INFINITY; 514 514 } 515 this.subpart = subpart ;516 } 517 518 public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, S tringsubpart) {515 this.subpart = subpart != null ? subpart : Subpart.DEFAULT_SUBPART; 516 } 517 518 public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, Subpart subpart) { 519 519 super(conds); 520 520 this.base = base; 521 521 this.range = range; 522 this.subpart = subpart ;522 this.subpart = subpart != null ? subpart : Subpart.DEFAULT_SUBPART; 523 523 } 524 524 … … 528 528 529 529 @Override 530 public S tringgetSubpart() {530 public Subpart getSubpart() { 531 531 return subpart; 532 532 }
Note:
See TracChangeset
for help on using the changeset viewer.