Changeset 1814 in josm for trunk/src/org/openstreetmap/josm/actions/search
- Timestamp:
- 2009-07-19T19:04:49+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/search
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r1808 r1814 164 164 } 165 165 try { 166 Collection<OsmPrimitive> sel = Main. ds.getSelected();166 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 167 167 SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive, regexSearch); 168 168 int foundMatches = 0; 169 for (OsmPrimitive osm : Main. ds.allNonDeletedCompletePrimitives()) {169 for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedCompletePrimitives()) { 170 170 if (mode == SearchMode.replace) { 171 171 if (matcher.match(osm)) { … … 183 183 } 184 184 } 185 Main. ds.setSelected(sel);185 Main.main.getCurrentDataSet().setSelected(sel); 186 186 if (foundMatches == 0) { 187 187 String msg = null; … … 241 241 */ 242 242 protected void refreshEnabled() { 243 setEnabled(Main.map != null 244 && Main.map.mapView !=null 245 && Main.map.mapView.getEditLayer() != null 246 ); 243 setEnabled(getEditLayer() != null); 247 244 } 248 245 -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r1786 r1814 133 133 String value = null; 134 134 135 if (key.equals("timestamp")) 135 if (key.equals("timestamp")) { 136 136 value = DateUtils.fromDate(osm.getTimestamp()); 137 else137 } else { 138 138 value = osm.get(key); 139 } 139 140 140 141 if (value == null) … … 169 170 170 171 public ExactKeyValue(boolean regexp, String key, String value) throws ParseError { 171 if (key == "") {172 if (key == "") 172 173 throw new ParseError(tr("Key cannot be empty when tag operator is used. Sample use: key=value")); 173 }174 174 this.key = key; 175 175 this.value = value; … … 223 223 public boolean match(OsmPrimitive osm) throws ParseError { 224 224 225 if (osm.keys == null || osm.keys.isEmpty()) {225 if (osm.keys == null || osm.keys.isEmpty()) 226 226 return mode == Mode.NONE; 227 }228 227 229 228 switch (mode) { … … 238 237 case ANY_KEY: 239 238 for (String v:osm.keys.values()) { 240 if (v.equals(value)) {239 if (v.equals(value)) 241 240 return true; 242 }243 241 } 244 242 return false; … … 247 245 case ANY_KEY_REGEXP: 248 246 for (String v:osm.keys.values()) { 249 if (valuePattern.matcher(v).matches()) {247 if (valuePattern.matcher(v).matches()) 250 248 return true; 251 }252 249 } 253 250 return false; … … 257 254 if (keyPattern.matcher(entry.getKey()).matches()) { 258 255 if (mode == Mode.ANY_VALUE_REGEXP 259 || valuePattern.matcher(entry.getValue()).matches()) {256 || valuePattern.matcher(entry.getValue()).matches()) 260 257 return true; 261 }262 258 } 263 259 } … … 265 261 case MISSING_KEY_REGEXP: 266 262 for (String k:osm.keys.keySet()) { 267 if (keyPattern.matcher(k).matches()) {263 if (keyPattern.matcher(k).matches()) 268 264 return false; 269 }270 265 } 271 266 return true; … … 337 332 // is not Java 1.5 338 333 //String name = java.text.Normalizer.normalize(name, java.text.Normalizer.Form.NFC); 339 if (!caseSensitive) 334 if (!caseSensitive) { 340 335 name = name.toLowerCase(); 336 } 341 337 if (name.indexOf(search) != -1) 342 338 return true; … … 356 352 } else if ("relation".equals(type)) { 357 353 this.type = Relation.class; 358 } else {354 } else 359 355 throw new ParseError(tr("Unknown primitive type: {0}. Allowed values are node, way or relation", 360 356 type)); 361 }362 357 } 363 358 @Override public boolean match(OsmPrimitive osm) { … … 441 436 // "parent" (null) should mean the same as "parent()" 442 437 // (Always). I.e. match everything 443 if (child == null) 438 if (child == null) { 444 439 child = new Always(); 440 } 445 441 446 442 if (osm instanceof Way) { 447 for (Node n : ((Way)osm).nodes) 443 for (Node n : ((Way)osm).nodes) { 448 444 isParent |= child.match(n); 445 } 449 446 } else if (osm instanceof Relation) { 450 447 for (RelationMember member : ((Relation)osm).members) { 451 if (member.member != null) 448 if (member.member != null) { 452 449 isParent |= child.match(member.member); 450 } 453 451 } 454 452 } … … 464 462 // "child" (null) should mean the same as "child()" 465 463 // (Always). I.e. match everything 466 if (parent == null) 464 if (parent == null) { 467 465 parent = new Always(); 466 } 468 467 469 468 boolean isChild = false; 470 CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main. ds);469 CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet()); 471 470 osm.visit(backRefs); 472 471 for (OsmPrimitive p : backRefs.data) { … … 485 484 486 485 public static Match compile(String searchStr, boolean caseSensitive, boolean regexSearch) 487 486 throws ParseError { 488 487 return new SearchCompiler(caseSensitive, regexSearch, 489 488 new PushbackTokenizer( 490 new PushbackReader(new StringReader(searchStr))))491 489 new PushbackReader(new StringReader(searchStr)))) 490 .parse(); 492 491 } 493 492 494 493 public Match parse() throws ParseError { 495 494 Match m = parseJuxta(); 496 if (!tokenizer.readIfEqual(null)) {495 if (!tokenizer.readIfEqual(null)) 497 496 throw new ParseError(tr("Unexpected token: {0}", tokenizer.nextToken())); 498 }499 497 return m; 500 498 } … … 515 513 if (tokenizer.readIfEqual("|")) { 516 514 Match b = parseNot(); 517 if (a == null || b == null) {515 if (a == null || b == null) 518 516 throw new ParseError(tr("Missing arguments for or.")); 519 }520 517 return new Or(a, b); 521 518 } … … 526 523 if (tokenizer.readIfEqual("-")) { 527 524 Match m = parseParens(); 528 if (m == null) {525 if (m == null) 529 526 throw new ParseError(tr("Missing argument for not.")); 530 }531 527 return new Not(m); 532 528 } … … 537 533 if (tokenizer.readIfEqual("(")) { 538 534 Match m = parseJuxta(); 539 if (!tokenizer.readIfEqual(")")) {535 if (!tokenizer.readIfEqual(")")) 540 536 throw new ParseError(tr("Expected closing parenthesis.")); 541 }542 537 return m; 543 538 } … … 550 545 if (tokenizer.readIfEqual(":")) { 551 546 String tok2 = tokenizer.readText(); 552 if (tok == null) tok = ""; 553 if (tok2 == null) tok2 = ""; 547 if (tok == null) { 548 tok = ""; 549 } 550 if (tok2 == null) { 551 tok2 = ""; 552 } 554 553 return parseKV(tok, tok2); 555 554 } … … 557 556 if (tokenizer.readIfEqual("=")) { 558 557 String tok2 = tokenizer.readText(); 559 if (tok == null) tok = ""; 560 if (tok2 == null) tok2 = ""; 558 if (tok == null) { 559 tok = ""; 560 } 561 if (tok2 == null) { 562 tok2 = ""; 563 } 561 564 return new ExactKeyValue(regexSearch, tok, tok2); 562 565 } 563 566 564 if (tok == null) {567 if (tok == null) 565 568 return null; 566 } else if (tok.equals("modified")) {569 else if (tok.equals("modified")) 567 570 return new Modified(); 568 } else if (tok.equals("incomplete")) {571 else if (tok.equals("incomplete")) 569 572 return new Incomplete(); 570 } else if (tok.equals("untagged")) {573 else if (tok.equals("untagged")) 571 574 return new Untagged(); 572 } else if (tok.equals("selected")) {575 else if (tok.equals("selected")) 573 576 return new Selected(); 574 } else if (tok.equals("child")) {577 else if (tok.equals("child")) 575 578 return new Child(parseParens()); 576 } else if (tok.equals("parent")) {579 else if (tok.equals("parent")) 577 580 return new Parent(parseParens()); 578 } else {581 else 579 582 return new Any(tok); 580 }581 583 } 582 584 583 585 private Match parseKV(String key, String value) throws ParseError { 584 if (key.equals("type")) {586 if (key.equals("type")) 585 587 return new ExactType(value); 586 } else if (key.equals("user")) {588 else if (key.equals("user")) 587 589 return new UserMatch(value); 588 }else if (key.equals("nodes")) {590 else if (key.equals("nodes")) { 589 591 try { 590 592 String[] range = value.split("-"); 591 if (range.length == 1) {593 if (range.length == 1) 592 594 return new NodeCount(Integer.parseInt(value)); 593 } else if (range.length == 2) {595 else if (range.length == 2) 594 596 return new NodeCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1])); 595 } else {597 else 596 598 throw new ParseError(tr("Wrong number of parameters for nodes operator.")); 597 }598 599 } catch (NumberFormatException e) { 599 600 throw new ParseError(tr("Incorrect value of nodes operator: {0}. Nodes operator expects number of nodes or range, for example nodes:10-20", value)); … … 606 607 throw new ParseError(tr("Incorrect value of id operator: {0}. Number is expected.", value)); 607 608 } 608 } else {609 } else 609 610 return new KeyValue(key, value); 610 }611 611 } 612 612 … … 627 627 // insensitively, but the OSM data is in Unicode. With 628 628 // UNICODE_CASE casefolding is made Unicode-aware. 629 if (!caseSensitive) 629 if (!caseSensitive) { 630 630 searchFlags |= (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); 631 } 631 632 632 633 return searchFlags; -
trunk/src/org/openstreetmap/josm/actions/search/SelectionWebsiteLoader.java
r1811 r1814 40 40 @Override protected void realRun() { 41 41 progressMonitor.setTicksCount(2); 42 sel = mode != SearchAction.SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main. ds.allNonDeletedPrimitives();42 sel = mode != SearchAction.SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.main.getCurrentDataSet().allNonDeletedPrimitives(); 43 43 try { 44 44 URLConnection con = url.openConnection(); … … 47 47 progressMonitor.subTask(tr("Downloading...")); 48 48 Map<Long, String> ids = idReader.parseIds(in); 49 for (OsmPrimitive osm : Main. ds.allNonDeletedPrimitives()) {49 for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) { 50 50 if (ids.containsKey(osm.id) && osm.getClass().getName().toLowerCase().endsWith(ids.get(osm.id))) { 51 51 if (mode == SearchAction.SearchMode.remove) { … … 86 86 @Override protected void finish() { 87 87 if (sel != null) { 88 Main. ds.setSelected(sel);88 Main.main.getCurrentDataSet().setSelected(sel); 89 89 } 90 90 }
Note:
See TracChangeset
for help on using the changeset viewer.