Changeset 14461 in josm
- Timestamp:
- 2018-11-28T08:26:29+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r14302 r14461 472 472 final String base = ((GeneralSelector) selRightmost).getBase(); 473 473 switch (base) { 474 case "node":474 case Selector.BASE_NODE: 475 475 nodeRules.add(optRule); 476 476 break; 477 case "way":477 case Selector.BASE_WAY: 478 478 wayNoAreaRules.add(optRule); 479 479 wayRules.add(optRule); 480 480 break; 481 case "area":481 case Selector.BASE_AREA: 482 482 wayRules.add(optRule); 483 483 multipolygonRules.add(optRule); 484 484 break; 485 case "relation":485 case Selector.BASE_RELATION: 486 486 relationRules.add(optRule); 487 487 multipolygonRules.add(optRule); 488 488 break; 489 case "*":489 case Selector.BASE_ANY: 490 490 nodeRules.add(optRule); 491 491 wayRules.add(optRule); … … 494 494 multipolygonRules.add(optRule); 495 495 break; 496 case "canvas":496 case Selector.BASE_CANVAS: 497 497 canvasRules.add(r); 498 498 break; 499 case "meta":500 case "setting":499 case Selector.BASE_META: 500 case Selector.BASE_SETTING: 501 501 break; 502 502 default: … … 557 557 */ 558 558 private void loadMeta() { 559 Cascade c = constructSpecial( "meta");559 Cascade c = constructSpecial(Selector.BASE_META); 560 560 String pTitle = c.get("title", null, String.class); 561 561 if (title == null) { … … 569 569 570 570 private void loadCanvas() { 571 Cascade c = constructSpecial( "canvas");571 Cascade c = constructSpecial(Selector.BASE_CANVAS); 572 572 backgroundColorOverride = c.get("fill-color", null, Color.class); 573 573 } … … 586 586 if (r.selector instanceof GeneralSelector) { 587 587 GeneralSelector gs = (GeneralSelector) r.selector; 588 if ( "setting".equals(gs.getBase())) {588 if (Selector.BASE_SETTING.equals(gs.getBase())) { 589 589 if (!gs.matchesConditions(env)) { 590 590 continue; … … 738 738 if (x.selector instanceof GeneralSelector) { 739 739 GeneralSelector gs = (GeneralSelector) x.selector; 740 if ( "meta".equals(gs.base)) {740 if (Selector.BASE_META.equals(gs.base)) { 741 741 it.remove(); 742 742 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r14214 r14461 51 51 public interface Selector { 52 52 53 /** selector base that matches anything. */ 54 String BASE_ANY = "*"; 55 56 /** selector base that matches on OSM object node. */ 57 String BASE_NODE = "node"; 58 59 /** selector base that matches on OSM object way. */ 60 String BASE_WAY = "way"; 61 62 /** selector base that matches on OSM object relation. */ 63 String BASE_RELATION = "relation"; 64 65 /** selector base that matches with any area regardless of whether the area border is only modelled with a single way or with a set of ways glued together with a relation.*/ 66 String BASE_AREA = "area"; 67 68 /** selector base for special rules containing meta information. */ 69 String BASE_META = "meta"; 70 71 /** selector base for style information not specific to nodes, ways or relations. */ 72 String BASE_CANVAS = "canvas"; 73 74 /** selector base for artificial bases created to use preferences. */ 75 String BASE_SETTING = "setting"; 76 53 77 /** 54 78 * Apply the selector to the primitive and check if it matches. … … 576 600 public OptimizedGeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, Subpart subpart) { 577 601 super(conds); 578 this.base = base;602 this.base = checkBase(base); 579 603 if (zoom != null) { 580 604 int a = zoom.a == null ? 0 : zoom.a; … … 593 617 public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, Subpart subpart) { 594 618 super(conds); 595 this.base = base;619 this.base = checkBase(base); 596 620 this.range = range; 597 621 this.subpart = subpart != null ? subpart : Subpart.DEFAULT_SUBPART; … … 612 636 } 613 637 638 /** 639 * Check if this is a known base and return the corresponding string constant. 640 * @param base 641 * @return the matching String constant 642 */ 643 private static String checkBase(String base) { 644 switch(base) { 645 case "*": return BASE_ANY; 646 case "node": return BASE_NODE; 647 case "way": return BASE_WAY; 648 case "relation": return BASE_RELATION; 649 case "area": return BASE_AREA; 650 case "meta": return BASE_META; 651 case "canvas": return BASE_CANVAS; 652 case "setting": return BASE_SETTING; 653 default: 654 throw new IllegalArgumentException("unknown selector " + base); 655 } 656 } 657 614 658 public String getBase() { 615 659 return base; … … 617 661 618 662 public boolean matchesBase(OsmPrimitiveType type) { 619 if ( "*".equals(base)) {663 if (BASE_ANY.equals(base)) { 620 664 return true; 621 665 } else if (OsmPrimitiveType.NODE == type) { 622 return "node".equals(base);666 return BASE_NODE.equals(base); 623 667 } else if (OsmPrimitiveType.WAY == type) { 624 return "way".equals(base) || "area".equals(base);668 return BASE_WAY.equals(base) || BASE_AREA.equals(base); 625 669 } else if (OsmPrimitiveType.RELATION == type) { 626 return "area".equals(base) || "relation".equals(base) || "canvas".equals(base);670 return BASE_AREA.equals(base) || BASE_RELATION.equals(base) || BASE_CANVAS.equals(base); 627 671 } 628 672 return false; … … 634 678 } else { 635 679 if (p instanceof IRelation) { 636 if ( "area".equals(base)) {680 if (BASE_AREA.equals(base)) { 637 681 return ((IRelation<?>) p).isMultipolygon(); 638 } else if ( "canvas".equals(base)) {682 } else if (BASE_CANVAS.equals(base)) { 639 683 return p.get("#canvas") != null; 640 684 }
Note:
See TracChangeset
for help on using the changeset viewer.