Changeset 5578 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2012-11-13T14:19:52+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/search
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r5441 r5578 433 433 , GBC.eol()); 434 434 right.add(new SearchKeywordRow(hcbSearchString) 435 .addTitle(tr("relat ions"))435 .addTitle(tr("related objects")) 436 436 .addKeyword("child <i>expr</i>", "child ", tr("all children of objects matching the expression"), "child building") 437 437 .addKeyword("parent <i>expr</i>", "parent ", tr("all parents of objects matching the expression"), "parent bus_stop") 438 .addKeyword("nth:<i>7</i>", "nth: ", tr("n-th member of relation and/or n-th node of way"), "nth:5 (child type:relation)") 439 .addKeyword("nth%:<i>7</i>", "nth: ", tr("every n-th member of relation and/or every n-th node of way"), "nth%:100 (child waterway)") 438 440 , GBC.eol()); 439 441 right.add(new SearchKeywordRow(hcbSearchString) -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r5184 r5578 101 101 "changeset", "nodes", "tags", "areasize", "modified", "selected", 102 102 "incomplete", "untagged", "closed", "new", "indownloadarea", 103 "allindownloadarea", "inview", "allinview", "timestamp" );103 "allindownloadarea", "inview", "allinview", "timestamp", "nth", "nth%"); 104 104 105 105 @Override … … 138 138 else if ("areasize".equals(keyword)) 139 139 return new AreaSize(tokenizer); 140 else if ("nth".equals(keyword)) 141 return new Nth(tokenizer, false); 142 else if ("nth%".equals(keyword)) 143 return new Nth(tokenizer, true); 140 144 else if ("timestamp".equals(keyword)) { 141 145 String rangeS = " " + tokenizer.readTextOrNumber() + " "; // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""}) … … 785 789 @Override public String toString() { 786 790 return "role=" + role; 791 } 792 } 793 794 /** 795 * Matches the n-th object of a relation and/or the n-th node of a way. 796 */ 797 private static class Nth extends Match { 798 799 private final int nth; 800 private final boolean modulo; 801 802 public Nth(PushbackTokenizer tokenizer, boolean modulo) throws ParseError { 803 this((int) tokenizer.readNumber(tr("Primitive id expected")), modulo); 804 } 805 806 private Nth(int nth, boolean modulo) { 807 this.nth = nth; 808 this.modulo = modulo; 809 } 810 811 @Override 812 public boolean match(OsmPrimitive osm) { 813 for (OsmPrimitive p : osm.getReferrers()) { 814 Integer idx = null; 815 if (p instanceof Way) { 816 Way w = (Way) p; 817 idx = w.getNodes().indexOf(osm); 818 } else if (p instanceof Relation) { 819 Relation r = (Relation) p; 820 idx = r.getMemberPrimitivesList().indexOf(osm); 821 } 822 if (idx != null) { 823 if (idx.intValue() == nth || (modulo && idx.intValue() % nth == 0)) { 824 return true; 825 } 826 } 827 } 828 return false; 787 829 } 788 830 }
Note:
See TracChangeset
for help on using the changeset viewer.