Changeset 30348 in osm
- Timestamp:
- 2014-03-24T21:51:44+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/FixAddresses
- Files:
-
- 1 deleted
- 47 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressEditContainer.java
r29967 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 14 15 /* File created on 24.10.2010 */ 1 // License: GPL. For details, see LICENSE file. 16 2 package org.openstreetmap.josm.plugins.fixAddresses; 17 3 … … 57 43 * 58 44 */ 59 60 45 public class AddressEditContainer implements Visitor, DataSetListener, IAddressEditContainerListener, IProblemVisitor, IAllKnowingTrashHeap { 61 46 62 private Collection<? extends OsmPrimitive> workingSet; 63 /** The street dictionary collecting all streets to a set of unique street names. */ 64 private HashMap<String, OSMStreet> streetDict = new HashMap<String, OSMStreet>(100); 65 66 /** The unresolved (addresses without valid street name) addresses list. */ 67 private List<OSMAddress> unresolvedAddresses = new ArrayList<OSMAddress>(100); 68 69 /** The incomplete addresses list. */ 70 private List<OSMAddress> incompleteAddresses = new ArrayList<OSMAddress>(100); 71 72 /** The shadow copy to assemble the street dict during update. */ 73 private HashMap<String, OSMStreet> shadowStreetDict = new HashMap<String, OSMStreet>(100); 74 /** The shadow copy to assemble the unresolved addresses during update. */ 75 private List<OSMAddress> shadowUnresolvedAddresses = new ArrayList<OSMAddress>(100); 76 /** The shadow copy to assemble the incomplete addresses during update. */ 77 private List<OSMAddress> shadowIncompleteAddresses = new ArrayList<OSMAddress>(100); 78 79 /** The visited nodes cache to increase iteration speed. */ 80 private HashSet<Node> visitedNodes = new HashSet<Node>(); 81 /** The visited ways cache to increase iteration speed. */ 82 private HashSet<Way> visitedWays = new HashSet<Way>(); 83 /** The tag list used within the data area. */ 84 private HashSet<String> tags = new HashSet<String>(); 85 /** The tag list used within the data area. */ 86 private HashMap<String, String> values = new HashMap<String, String>(); 87 88 /** The list containing the problems */ 89 private List<IProblem> problems = new ArrayList<IProblem>(); 90 91 /** The change listeners. */ 92 private List<IAddressEditContainerListener> listeners = new ArrayList<IAddressEditContainerListener>(); 93 94 /** 95 * Creates an empty container. 96 */ 97 public AddressEditContainer() { 98 OSMEntityBase.addChangedListener(this); 99 } 100 101 /** 102 * Gets the working set used by the container. This can by either the complete or just 103 * a subset of the current data layer. 104 * 105 * @return the workingSet 106 */ 107 protected Collection<? extends OsmPrimitive> getWorkingSet() { 108 return workingSet; 109 } 110 111 /** 112 * Adds a change listener. 113 * @param listener 114 */ 115 public void addChangedListener(IAddressEditContainerListener listener) { 116 listeners.add(listener); 117 } 118 119 /** 120 * Removes a change listener. 121 * @param listener 122 */ 123 public void removeChangedListener(IAddressEditContainerListener listener) { 124 listeners.remove(listener); 125 } 126 127 /** 128 * Notifies clients that the address container changed. 129 */ 130 protected void fireContainerChanged() { 131 List<IAddressEditContainerListener> shadowListeners = 132 new ArrayList<IAddressEditContainerListener>(listeners); 133 134 for (IAddressEditContainerListener listener : shadowListeners) { 135 listener.containerChanged(this); 136 } 137 } 138 139 /** 140 * Notifies clients that an entity within the address container changed. 141 */ 142 protected void fireEntityChanged(IOSMEntity entity) { 143 if (entity == null) throw new RuntimeException("Entity must not be null"); 144 145 List<IAddressEditContainerListener> shadowListeners = 146 new ArrayList<IAddressEditContainerListener>(listeners); 147 148 for (IAddressEditContainerListener listener : shadowListeners) { 149 listener.entityChanged(entity); 150 } 151 } 152 153 /** 154 * Marks an OSM node as visited. 155 * 156 * @param n the node to mark. 157 */ 158 private void markNodeAsVisited(Node n) { 159 visitedNodes.add(n); 160 } 161 162 /** 163 * Checks a node for been visited. 164 * 165 * @param n the n 166 * @return true, if node has been visited 167 */ 168 private boolean hasBeenVisited(Node n) { 169 return visitedNodes.contains(n); 170 } 171 172 /** 173 * Marks a way as visited. 174 * 175 * @param w the way to mark 176 */ 177 private void markWayAsVisited(Way w) { 178 visitedWays.add(w); 179 } 180 181 /** 182 * Checks a way for been visited. 183 * 184 * @param w the w to check 185 * @return true, if way has been visited 186 */ 187 private boolean hasBeenVisited(Way w) { 188 return visitedWays.contains(w); 189 } 190 191 /* (non-Javadoc) 192 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Node) 193 */ 194 @Override 195 public void visit(Node n) { 196 if (hasBeenVisited(n)) { 197 return; 198 } 199 200 OSMAddress aNode = null; 201 // Address nodes are recycled in order to keep instance variables like guessed names 202 aNode = OsmFactory.createNode(n); 203 204 if (aNode != null) { 205 addAndClassifyAddress(aNode); 206 aNode.visit(this, this); 207 } 208 markNodeAsVisited(n); 209 } 210 211 /* (non-Javadoc) 212 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Way) 213 */ 214 @Override 215 public void visit(Way w) { 216 // This doesn't matter, we just need the street name 217 //if (w.isIncomplete()) return; 218 219 if (hasBeenVisited(w)) { 220 return; 221 } 222 223 createNodeFromWay(w); 224 markWayAsVisited(w); 225 } 226 227 /** 228 * Adds and classify an address node according to completeness. 229 * 230 * @param aNode the address node to add and check 231 */ 232 private void addAndClassifyAddress(OSMAddress aNode) { 233 if (!assignAddressToStreet(aNode)) { 234 // Assignment failed: Street is not known (yet) -> add to 'unresolved' list 235 shadowUnresolvedAddresses.add(aNode); 236 } 237 238 if (!aNode.isComplete()) { 239 shadowIncompleteAddresses.add(aNode); 240 } 241 } 242 243 /** 244 * Creates the node from an OSM way instance. 245 * 246 * @param w the way to create the entity from 247 */ 248 private void createNodeFromWay(Way w) { 249 IOSMEntity ne = OsmFactory.createNodeFromWay(w); 250 251 if (!processNode(ne, w)) { 252 // Look also into nodes for addresses (unlikely, but at least they 253 // get marked as visited). 254 for (Node n : w.getNodes()) { 255 visit(n); 256 } 257 258 for (String key : w.keySet()) { 259 if (!tags.contains(key)) { 260 tags.add(key); 261 } 262 263 String v = w.get(key); 264 if (!values.containsKey(v)) { 265 values.put(v, key); 266 } 267 } 268 } // else: node has been processed, no need to look deeper 269 } 270 271 /** 272 * Process an entity node depending on the type. A street segment is added as a child to the 273 * corresponding street dictionary while an address is added to the incomplete/unresolved list 274 * depending of it's properties. 275 * 276 * @param ne the entity node. 277 * @param w the corresponding OSM way 278 * @return true, if node has been processed 279 */ 280 private boolean processNode(IOSMEntity ne, Way w) { 281 if (ne != null) { 282 // Node is a street (segment) 283 if (ne instanceof OSMStreetSegment) { 284 OSMStreetSegment newSegment = (OSMStreetSegment) ne; 285 286 if (newSegment != null) { 287 String name = newSegment.getName(); 288 if (StringUtils.isNullOrEmpty(name)) return false; 289 290 OSMStreet sNode = null; 291 if (shadowStreetDict.containsKey(name)) { // street exists? 292 sNode = shadowStreetDict.get(name); 293 } else { // new street name -> add to dict 294 sNode = new OSMStreet(w); 295 shadowStreetDict.put(name, sNode); 296 } 297 298 if (sNode != null) { 299 // TODO: Check if segment really belongs to the street, even if the 300 // names are the same. Then the streets should be split up... 301 sNode.addStreetSegment(newSegment); 302 return true; 303 } else { 304 throw new RuntimeException("Street node is null!"); 305 } 306 } 307 } 308 309 // Node is an address 310 if (ne instanceof OSMAddress) { 311 OSMAddress aNode = (OSMAddress) ne; 312 addAndClassifyAddress(aNode); 313 return true; 314 } 315 } 316 return false; 317 } 318 319 /* (non-Javadoc) 320 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Relation) 321 */ 322 @Override 323 public void visit(Relation e) { 324 } 325 326 /* (non-Javadoc) 327 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Changeset) 328 */ 329 @Override 330 public void visit(Changeset cs) { 331 } 332 333 /** 334 * Gets the dictionary contains the collected streets. 335 * @return 336 */ 337 public HashMap<String, OSMStreet> getStreetDict() { 338 return streetDict; 339 } 340 341 /** 342 * Gets the unresolved (addresses without valid street name) addresses. 343 * 344 * @return the unresolved addresses 345 */ 346 public List<OSMAddress> getUnresolvedAddresses() { 347 return unresolvedAddresses; 348 } 349 350 /** 351 * Gets the list with incomplete addresses. 352 * 353 * @return the incomplete addresses 354 */ 355 public List<OSMAddress> getIncompleteAddresses() { 356 return incompleteAddresses; 357 } 358 359 /** 360 * Gets the street list. 361 * 362 * @return the street list 363 */ 364 public List<OSMStreet> getStreetList() { 365 ArrayList<OSMStreet> sortedList = new ArrayList<OSMStreet>(streetDict.values()); 366 Collections.sort(sortedList); 367 return sortedList; 368 } 369 370 /** 371 * Gets all addresses without valid street. 372 * @return 373 */ 374 public List<OSMAddress> getUnresolvedItems() { 375 return unresolvedAddresses; 376 } 377 378 /** 379 * Gets the tags used in the data layer. 380 * @return 381 */ 382 public HashSet<String> getTags() { 383 return tags; 384 } 385 386 /** 387 * @return the values 388 */ 389 protected HashMap<String, String> getValues() { 390 return values; 391 } 392 393 /** 394 * Gets the number of streets in the container. 395 * @return 396 */ 397 public int getNumberOfStreets() { 398 return streetDict != null ? streetDict.size() : 0; 399 } 400 401 /** 402 * Get the number of incomplete addresses. 403 * @return 404 */ 405 public int getNumberOfIncompleteAddresses() { 406 return incompleteAddresses != null ? incompleteAddresses.size() : 0; 407 } 408 409 /** 410 * Gets the number of unresolved addresses. 411 * @return 412 */ 413 public int getNumberOfUnresolvedAddresses() { 414 return unresolvedAddresses != null ? unresolvedAddresses.size() : 0; 415 } 416 417 /** 418 * Gets the number of invalid (unresolved and/or incomplete) addresses. 419 * 420 * @return the number of invalid addresses 421 */ 422 public int getNumberOfInvalidAddresses() { 423 return getNumberOfIncompleteAddresses() + getNumberOfUnresolvedAddresses(); 424 } 425 426 /** 427 * Gets the number of guessed tags. 428 * @return 429 */ 430 public int getNumberOfGuesses() { 431 int sum = 0; 432 433 for (OSMAddress aNode : getAllAddressesToFix()) { 434 if (aNode.hasGuesses()) { 435 sum++; 436 } 437 } 438 return sum; 439 } 440 441 /** 442 * Gets all (incomplete and/or unresolved) address nodes to fix. 443 * @return 444 */ 445 public List<OSMAddress> getAllAddressesToFix() { 446 List<OSMAddress> all = new ArrayList<OSMAddress>(incompleteAddresses); 447 448 for (OSMAddress aNode : unresolvedAddresses) { 449 if (!all.contains(aNode)) { 450 all.add(aNode); 451 } 452 } 453 454 return all; 455 } 456 457 /** 458 * @return the problems 459 */ 460 protected List<IProblem> getProblems() { 461 return problems; 462 } 463 464 /** 465 * Clears the problem list. 466 */ 467 protected void clearProblems() { 468 problems.clear(); 469 } 470 471 /** 472 * Tries to assign an address to a street. 473 * @param aNode 474 */ 475 private boolean assignAddressToStreet(OSMAddress aNode) { 476 String streetName = aNode.getStreetName(); 477 478 // street name via relation -> implicitly resolved (see TRAC #8336) 479 if (aNode.isPartOfRelation()) { 480 return true; 481 } 482 483 if (streetName != null && shadowStreetDict.containsKey(streetName)) { 484 OSMStreet sNode = shadowStreetDict.get(streetName); 485 sNode.addAddress(aNode); 486 return true; 487 } 488 489 return false; 490 } 491 492 /** 493 * Walks through the list of unassigned addresses and tries to assign them to streets. 494 */ 495 public void resolveAddresses() { 496 List<OSMAddress> resolvedAddresses = new ArrayList<OSMAddress>(); 497 for (OSMAddress node : shadowUnresolvedAddresses) { 498 if (assignAddressToStreet(node)) { 499 resolvedAddresses.add(node); 500 } 501 } 502 503 /* Remove all resolves nodes from unresolved list */ 504 for (OSMAddress resolved : resolvedAddresses) { 505 shadowUnresolvedAddresses.remove(resolved); 506 } 507 } 508 509 /** 510 * Rebuilds the street and address lists using the data set given 511 * in {@link AddressEditContainer#attachToDataSet(Collection)} or the 512 * full data set of the current data layer {@link Main#getCurrentDataSet()}. 513 */ 514 public void invalidate() { 515 if (workingSet != null) { 516 invalidate(workingSet); 517 } else { 518 if (Main.main.getCurrentDataSet() != null) { 519 invalidate(Main.main.getCurrentDataSet().allPrimitives()); 520 } 521 } 522 } 523 524 /** 525 * Invalidate using the given data collection. 526 * 527 * @param osmData the collection containing the osm data to work on. 528 */ 529 public void invalidate(final Collection<? extends OsmPrimitive> osmData) { 530 if (osmData == null || osmData.isEmpty()) 531 return; 532 533 synchronized (this) { 534 clearData(); 535 clearProblems(); 536 // visit data set for problems... 537 for (OsmPrimitive osmPrimitive : osmData) { 538 if (osmPrimitive.isUsable()) { 539 osmPrimitive.accept(this); 540 } 541 } 542 543 // match streets with addresses... 544 resolveAddresses(); 545 // sort problem lists 546 Collections.sort(shadowIncompleteAddresses); 547 Collections.sort(shadowUnresolvedAddresses); 548 549 // put results from shadow copy into real lists 550 incompleteAddresses = new ArrayList<OSMAddress>(shadowIncompleteAddresses); 551 unresolvedAddresses = new ArrayList<OSMAddress>(shadowUnresolvedAddresses); 552 streetDict = new HashMap<String, OSMStreet>(shadowStreetDict); 553 // remove temp data 554 shadowStreetDict.clear(); 555 shadowUnresolvedAddresses.clear(); 556 shadowIncompleteAddresses.clear(); 557 558 // update clients 559 fireContainerChanged(); 560 } 561 } 562 563 /** 564 * Clears the shadowed lists data and resets the 'visited' flag for every OSM object. 565 */ 566 private void clearData() { 567 shadowStreetDict.clear(); 568 shadowUnresolvedAddresses.clear(); 569 shadowIncompleteAddresses.clear(); 570 visitedNodes.clear(); 571 visitedWays.clear(); 572 } 573 574 /** 575 * Connects the listener to the given data set and revisits the data. This method should 576 * be called immediately after an edit session finished. 577 * 578 * If the given data set is not null, calls of {@link AddressEditContainer#invalidate()} will 579 * only consider the data given within this set. This can be useful to keep out unimportant 580 * areas. However, a side-effect could be that some streets are not included and leads to 581 * false alarms regarding unresolved addresses. 582 * 583 * Calling {@link AddressEditContainer#detachFromDataSet()} drops the explicit data set and uses 584 * the full data set on subsequent updates.<p> 585 * 586 * <b>Example</b><br> 587 * <code> 588 * attachToDataSet(osmDataSetToWorkOn); // osmDataSetToWorkOn = selected items<br> 589 * //... launch dialog or whatever<br> 590 * detachFromDataSet(); 591 * </code> 592 * 593 * @param osmDataToWorkOn the data to examine 594 */ 595 public void attachToDataSet(Collection<? extends OsmPrimitive> osmDataToWorkOn) { 596 if (osmDataToWorkOn != null && !osmDataToWorkOn.isEmpty()) { 597 workingSet = new ArrayList<OsmPrimitive>(osmDataToWorkOn); 598 } else { 599 detachFromDataSet(); // drop old stuff, if present 600 } 601 invalidate(); // start our investigation... 602 } 603 604 /** 605 * Disconnects the listener from the data set. This method should 606 * be called immediately before an edit session started in order to 607 * prevent updates caused by e. g. a selection change within the map view. 608 */ 609 public void detachFromDataSet() { 610 //Main.main.getCurrentDataSet().removeDataSetListener(this); 611 if (workingSet != null) { 612 workingSet.clear(); 613 workingSet = null; 614 } 615 } 616 617 /* (non-Javadoc) 618 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#dataChanged(org.openstreetmap.josm.data.osm.event.DataChangedEvent) 619 */ 620 @Override 621 public void dataChanged(DataChangedEvent event) { 622 } 623 624 /* (non-Javadoc) 625 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#nodeMoved(org.openstreetmap.josm.data.osm.event.NodeMovedEvent) 626 */ 627 @Override 628 public void nodeMoved(NodeMovedEvent event) { 629 630 } 631 632 /* (non-Javadoc) 633 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#otherDatasetChange(org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent) 634 */ 635 @Override 636 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 637 } 638 639 /* (non-Javadoc) 640 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesAdded(org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent) 641 */ 47 private Collection<? extends OsmPrimitive> workingSet; 48 /** The street dictionary collecting all streets to a set of unique street names. */ 49 private HashMap<String, OSMStreet> streetDict = new HashMap<String, OSMStreet>(100); 50 51 /** The unresolved (addresses without valid street name) addresses list. */ 52 private List<OSMAddress> unresolvedAddresses = new ArrayList<OSMAddress>(100); 53 54 /** The incomplete addresses list. */ 55 private List<OSMAddress> incompleteAddresses = new ArrayList<OSMAddress>(100); 56 57 /** The shadow copy to assemble the street dict during update. */ 58 private HashMap<String, OSMStreet> shadowStreetDict = new HashMap<String, OSMStreet>(100); 59 /** The shadow copy to assemble the unresolved addresses during update. */ 60 private List<OSMAddress> shadowUnresolvedAddresses = new ArrayList<OSMAddress>(100); 61 /** The shadow copy to assemble the incomplete addresses during update. */ 62 private List<OSMAddress> shadowIncompleteAddresses = new ArrayList<OSMAddress>(100); 63 64 /** The visited nodes cache to increase iteration speed. */ 65 private HashSet<Node> visitedNodes = new HashSet<Node>(); 66 /** The visited ways cache to increase iteration speed. */ 67 private HashSet<Way> visitedWays = new HashSet<Way>(); 68 /** The tag list used within the data area. */ 69 private HashSet<String> tags = new HashSet<String>(); 70 /** The tag list used within the data area. */ 71 private HashMap<String, String> values = new HashMap<String, String>(); 72 73 /** The list containing the problems */ 74 private List<IProblem> problems = new ArrayList<IProblem>(); 75 76 /** The change listeners. */ 77 private List<IAddressEditContainerListener> listeners = new ArrayList<IAddressEditContainerListener>(); 78 79 /** 80 * Creates an empty container. 81 */ 82 public AddressEditContainer() { 83 OSMEntityBase.addChangedListener(this); 84 } 85 86 /** 87 * Gets the working set used by the container. This can by either the complete or just 88 * a subset of the current data layer. 89 * 90 * @return the workingSet 91 */ 92 protected Collection<? extends OsmPrimitive> getWorkingSet() { 93 return workingSet; 94 } 95 96 /** 97 * Adds a change listener. 98 * @param listener 99 */ 100 public void addChangedListener(IAddressEditContainerListener listener) { 101 listeners.add(listener); 102 } 103 104 /** 105 * Removes a change listener. 106 * @param listener 107 */ 108 public void removeChangedListener(IAddressEditContainerListener listener) { 109 listeners.remove(listener); 110 } 111 112 /** 113 * Notifies clients that the address container changed. 114 */ 115 protected void fireContainerChanged() { 116 List<IAddressEditContainerListener> shadowListeners = 117 new ArrayList<IAddressEditContainerListener>(listeners); 118 119 for (IAddressEditContainerListener listener : shadowListeners) { 120 listener.containerChanged(this); 121 } 122 } 123 124 /** 125 * Notifies clients that an entity within the address container changed. 126 */ 127 protected void fireEntityChanged(IOSMEntity entity) { 128 if (entity == null) throw new RuntimeException("Entity must not be null"); 129 130 List<IAddressEditContainerListener> shadowListeners = 131 new ArrayList<IAddressEditContainerListener>(listeners); 132 133 for (IAddressEditContainerListener listener : shadowListeners) { 134 listener.entityChanged(entity); 135 } 136 } 137 138 /** 139 * Marks an OSM node as visited. 140 * 141 * @param n the node to mark. 142 */ 143 private void markNodeAsVisited(Node n) { 144 visitedNodes.add(n); 145 } 146 147 /** 148 * Checks a node for been visited. 149 * 150 * @param n the n 151 * @return true, if node has been visited 152 */ 153 private boolean hasBeenVisited(Node n) { 154 return visitedNodes.contains(n); 155 } 156 157 /** 158 * Marks a way as visited. 159 * 160 * @param w the way to mark 161 */ 162 private void markWayAsVisited(Way w) { 163 visitedWays.add(w); 164 } 165 166 /** 167 * Checks a way for been visited. 168 * 169 * @param w the w to check 170 * @return true, if way has been visited 171 */ 172 private boolean hasBeenVisited(Way w) { 173 return visitedWays.contains(w); 174 } 175 176 @Override 177 public void visit(Node n) { 178 if (hasBeenVisited(n)) { 179 return; 180 } 181 182 OSMAddress aNode = null; 183 // Address nodes are recycled in order to keep instance variables like guessed names 184 aNode = OsmFactory.createNode(n); 185 186 if (aNode != null) { 187 addAndClassifyAddress(aNode); 188 aNode.visit(this, this); 189 } 190 markNodeAsVisited(n); 191 } 192 193 @Override 194 public void visit(Way w) { 195 // This doesn't matter, we just need the street name 196 //if (w.isIncomplete()) return; 197 198 if (hasBeenVisited(w)) { 199 return; 200 } 201 202 createNodeFromWay(w); 203 markWayAsVisited(w); 204 } 205 206 /** 207 * Adds and classify an address node according to completeness. 208 * 209 * @param aNode the address node to add and check 210 */ 211 private void addAndClassifyAddress(OSMAddress aNode) { 212 if (!assignAddressToStreet(aNode)) { 213 // Assignment failed: Street is not known (yet) -> add to 'unresolved' list 214 shadowUnresolvedAddresses.add(aNode); 215 } 216 217 if (!aNode.isComplete()) { 218 shadowIncompleteAddresses.add(aNode); 219 } 220 } 221 222 /** 223 * Creates the node from an OSM way instance. 224 * 225 * @param w the way to create the entity from 226 */ 227 private void createNodeFromWay(Way w) { 228 IOSMEntity ne = OsmFactory.createNodeFromWay(w); 229 230 if (!processNode(ne, w)) { 231 // Look also into nodes for addresses (unlikely, but at least they 232 // get marked as visited). 233 for (Node n : w.getNodes()) { 234 visit(n); 235 } 236 237 for (String key : w.keySet()) { 238 if (!tags.contains(key)) { 239 tags.add(key); 240 } 241 242 String v = w.get(key); 243 if (!values.containsKey(v)) { 244 values.put(v, key); 245 } 246 } 247 } // else: node has been processed, no need to look deeper 248 } 249 250 /** 251 * Process an entity node depending on the type. A street segment is added as a child to the 252 * corresponding street dictionary while an address is added to the incomplete/unresolved list 253 * depending of it's properties. 254 * 255 * @param ne the entity node. 256 * @param w the corresponding OSM way 257 * @return true, if node has been processed 258 */ 259 private boolean processNode(IOSMEntity ne, Way w) { 260 if (ne != null) { 261 // Node is a street (segment) 262 if (ne instanceof OSMStreetSegment) { 263 OSMStreetSegment newSegment = (OSMStreetSegment) ne; 264 265 if (newSegment != null) { 266 String name = newSegment.getName(); 267 if (StringUtils.isNullOrEmpty(name)) return false; 268 269 OSMStreet sNode = null; 270 if (shadowStreetDict.containsKey(name)) { // street exists? 271 sNode = shadowStreetDict.get(name); 272 } else { // new street name -> add to dict 273 sNode = new OSMStreet(w); 274 shadowStreetDict.put(name, sNode); 275 } 276 277 if (sNode != null) { 278 // TODO: Check if segment really belongs to the street, even if the 279 // names are the same. Then the streets should be split up... 280 sNode.addStreetSegment(newSegment); 281 return true; 282 } else { 283 throw new RuntimeException("Street node is null!"); 284 } 285 } 286 } 287 288 // Node is an address 289 if (ne instanceof OSMAddress) { 290 OSMAddress aNode = (OSMAddress) ne; 291 addAndClassifyAddress(aNode); 292 return true; 293 } 294 } 295 return false; 296 } 297 298 @Override 299 public void visit(Relation e) { 300 } 301 302 @Override 303 public void visit(Changeset cs) { 304 } 305 306 /** 307 * Gets the dictionary contains the collected streets. 308 * @return 309 */ 310 public HashMap<String, OSMStreet> getStreetDict() { 311 return streetDict; 312 } 313 314 /** 315 * Gets the unresolved (addresses without valid street name) addresses. 316 * 317 * @return the unresolved addresses 318 */ 319 public List<OSMAddress> getUnresolvedAddresses() { 320 return unresolvedAddresses; 321 } 322 323 /** 324 * Gets the list with incomplete addresses. 325 * 326 * @return the incomplete addresses 327 */ 328 public List<OSMAddress> getIncompleteAddresses() { 329 return incompleteAddresses; 330 } 331 332 /** 333 * Gets the street list. 334 * 335 * @return the street list 336 */ 337 public List<OSMStreet> getStreetList() { 338 ArrayList<OSMStreet> sortedList = new ArrayList<OSMStreet>(streetDict.values()); 339 Collections.sort(sortedList); 340 return sortedList; 341 } 342 343 /** 344 * Gets all addresses without valid street. 345 * @return 346 */ 347 public List<OSMAddress> getUnresolvedItems() { 348 return unresolvedAddresses; 349 } 350 351 /** 352 * Gets the tags used in the data layer. 353 * @return 354 */ 355 public HashSet<String> getTags() { 356 return tags; 357 } 358 359 /** 360 * @return the values 361 */ 362 protected HashMap<String, String> getValues() { 363 return values; 364 } 365 366 /** 367 * Gets the number of streets in the container. 368 * @return 369 */ 370 public int getNumberOfStreets() { 371 return streetDict != null ? streetDict.size() : 0; 372 } 373 374 /** 375 * Get the number of incomplete addresses. 376 * @return 377 */ 378 public int getNumberOfIncompleteAddresses() { 379 return incompleteAddresses != null ? incompleteAddresses.size() : 0; 380 } 381 382 /** 383 * Gets the number of unresolved addresses. 384 * @return 385 */ 386 public int getNumberOfUnresolvedAddresses() { 387 return unresolvedAddresses != null ? unresolvedAddresses.size() : 0; 388 } 389 390 /** 391 * Gets the number of invalid (unresolved and/or incomplete) addresses. 392 * 393 * @return the number of invalid addresses 394 */ 395 public int getNumberOfInvalidAddresses() { 396 return getNumberOfIncompleteAddresses() + getNumberOfUnresolvedAddresses(); 397 } 398 399 /** 400 * Gets the number of guessed tags. 401 * @return 402 */ 403 public int getNumberOfGuesses() { 404 int sum = 0; 405 406 for (OSMAddress aNode : getAllAddressesToFix()) { 407 if (aNode.hasGuesses()) { 408 sum++; 409 } 410 } 411 return sum; 412 } 413 414 /** 415 * Gets all (incomplete and/or unresolved) address nodes to fix. 416 * @return 417 */ 418 public List<OSMAddress> getAllAddressesToFix() { 419 List<OSMAddress> all = new ArrayList<OSMAddress>(incompleteAddresses); 420 421 for (OSMAddress aNode : unresolvedAddresses) { 422 if (!all.contains(aNode)) { 423 all.add(aNode); 424 } 425 } 426 427 return all; 428 } 429 430 /** 431 * @return the problems 432 */ 433 protected List<IProblem> getProblems() { 434 return problems; 435 } 436 437 /** 438 * Clears the problem list. 439 */ 440 protected void clearProblems() { 441 problems.clear(); 442 } 443 444 /** 445 * Tries to assign an address to a street. 446 * @param aNode 447 */ 448 private boolean assignAddressToStreet(OSMAddress aNode) { 449 String streetName = aNode.getStreetName(); 450 451 // street name via relation -> implicitly resolved (see TRAC #8336) 452 if (aNode.isPartOfRelation()) { 453 return true; 454 } 455 456 if (streetName != null && shadowStreetDict.containsKey(streetName)) { 457 OSMStreet sNode = shadowStreetDict.get(streetName); 458 sNode.addAddress(aNode); 459 return true; 460 } 461 462 return false; 463 } 464 465 /** 466 * Walks through the list of unassigned addresses and tries to assign them to streets. 467 */ 468 public void resolveAddresses() { 469 List<OSMAddress> resolvedAddresses = new ArrayList<OSMAddress>(); 470 for (OSMAddress node : shadowUnresolvedAddresses) { 471 if (assignAddressToStreet(node)) { 472 resolvedAddresses.add(node); 473 } 474 } 475 476 /* Remove all resolves nodes from unresolved list */ 477 for (OSMAddress resolved : resolvedAddresses) { 478 shadowUnresolvedAddresses.remove(resolved); 479 } 480 } 481 482 /** 483 * Rebuilds the street and address lists using the data set given 484 * in {@link AddressEditContainer#attachToDataSet(Collection)} or the 485 * full data set of the current data layer {@link Main#getCurrentDataSet()}. 486 */ 487 public void invalidate() { 488 if (workingSet != null) { 489 invalidate(workingSet); 490 } else { 491 if (Main.main.getCurrentDataSet() != null) { 492 invalidate(Main.main.getCurrentDataSet().allPrimitives()); 493 } 494 } 495 } 496 497 /** 498 * Invalidate using the given data collection. 499 * 500 * @param osmData the collection containing the osm data to work on. 501 */ 502 public void invalidate(final Collection<? extends OsmPrimitive> osmData) { 503 if (osmData == null || osmData.isEmpty()) 504 return; 505 506 synchronized (this) { 507 clearData(); 508 clearProblems(); 509 // visit data set for problems... 510 for (OsmPrimitive osmPrimitive : osmData) { 511 if (osmPrimitive.isUsable()) { 512 osmPrimitive.accept(this); 513 } 514 } 515 516 // match streets with addresses... 517 resolveAddresses(); 518 // sort problem lists 519 Collections.sort(shadowIncompleteAddresses); 520 Collections.sort(shadowUnresolvedAddresses); 521 522 // put results from shadow copy into real lists 523 incompleteAddresses = new ArrayList<OSMAddress>(shadowIncompleteAddresses); 524 unresolvedAddresses = new ArrayList<OSMAddress>(shadowUnresolvedAddresses); 525 streetDict = new HashMap<String, OSMStreet>(shadowStreetDict); 526 // remove temp data 527 shadowStreetDict.clear(); 528 shadowUnresolvedAddresses.clear(); 529 shadowIncompleteAddresses.clear(); 530 531 // update clients 532 fireContainerChanged(); 533 } 534 } 535 536 /** 537 * Clears the shadowed lists data and resets the 'visited' flag for every OSM object. 538 */ 539 private void clearData() { 540 shadowStreetDict.clear(); 541 shadowUnresolvedAddresses.clear(); 542 shadowIncompleteAddresses.clear(); 543 visitedNodes.clear(); 544 visitedWays.clear(); 545 } 546 547 /** 548 * Connects the listener to the given data set and revisits the data. This method should 549 * be called immediately after an edit session finished. 550 * 551 * If the given data set is not null, calls of {@link AddressEditContainer#invalidate()} will 552 * only consider the data given within this set. This can be useful to keep out unimportant 553 * areas. However, a side-effect could be that some streets are not included and leads to 554 * false alarms regarding unresolved addresses. 555 * 556 * Calling {@link AddressEditContainer#detachFromDataSet()} drops the explicit data set and uses 557 * the full data set on subsequent updates.<p> 558 * 559 * <b>Example</b><br> 560 * <code> 561 * attachToDataSet(osmDataSetToWorkOn); // osmDataSetToWorkOn = selected items<br> 562 * //... launch dialog or whatever<br> 563 * detachFromDataSet(); 564 * </code> 565 * 566 * @param osmDataToWorkOn the data to examine 567 */ 568 public void attachToDataSet(Collection<? extends OsmPrimitive> osmDataToWorkOn) { 569 if (osmDataToWorkOn != null && !osmDataToWorkOn.isEmpty()) { 570 workingSet = new ArrayList<OsmPrimitive>(osmDataToWorkOn); 571 } else { 572 detachFromDataSet(); // drop old stuff, if present 573 } 574 invalidate(); // start our investigation... 575 } 576 577 /** 578 * Disconnects the listener from the data set. This method should 579 * be called immediately before an edit session started in order to 580 * prevent updates caused by e. g. a selection change within the map view. 581 */ 582 public void detachFromDataSet() { 583 //Main.main.getCurrentDataSet().removeDataSetListener(this); 584 if (workingSet != null) { 585 workingSet.clear(); 586 workingSet = null; 587 } 588 } 589 590 @Override 591 public void dataChanged(DataChangedEvent event) { 592 } 593 594 @Override 595 public void nodeMoved(NodeMovedEvent event) { 596 597 } 598 599 @Override 600 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 601 } 602 603 @Override 604 public void primitivesAdded(PrimitivesAddedEvent event) { 605 invalidate(); 606 } 607 608 @Override 609 public void primitivesRemoved(PrimitivesRemovedEvent event) { 610 invalidate(); 611 } 612 613 @Override 614 public void relationMembersChanged(RelationMembersChangedEvent event) { 615 } 616 617 @Override 618 public void tagsChanged(TagsChangedEvent event) { 619 invalidate(); 620 } 621 622 @Override 623 public void wayNodesChanged(WayNodesChangedEvent event) { 624 } 625 626 @Override 627 public void containerChanged(AddressEditContainer container) { 628 invalidate(); 629 } 630 631 @Override 632 public void entityChanged(IOSMEntity entity) { 633 fireEntityChanged(entity); 634 } 635 636 @Override 637 public void addProblem(IProblem problem) { 638 problems.add(problem); 639 } 640 641 @Override 642 public void removeProblemsOfSource(IOSMEntity entity) { 643 CheckParameterUtil.ensureParameterNotNull(entity, "entity"); 644 645 List<IProblem> problemsToRemove = new ArrayList<IProblem>(); 646 for (IProblem problem : problems) { 647 if (problem.getSource() == entity) { 648 problemsToRemove.add(problem); 649 } 650 } 651 652 for (IProblem iProblem : problemsToRemove) { 653 problems.remove(iProblem); 654 } 655 } 656 657 @Override 658 public String getClosestStreetName(String name) { 659 List<String> matches = getClosestStreetNames(name, 1); 660 661 if (matches != null && matches.size() > 0) { 662 return matches.get(0); 663 } 664 665 return null; 666 } 667 668 @Override 669 public List<String> getClosestStreetNames(String name, int maxEntries) { 670 CheckParameterUtil.ensureParameterNotNull(name, "name"); 671 672 // ensure right number of entries 673 if (maxEntries < 1) maxEntries = 1; 674 675 List<StreetScore> scores = new ArrayList<StreetScore>(); 676 List<String> matches = new ArrayList<String>(); 677 678 // Find the longest common sub string 679 for (String streetName : streetDict.keySet()) { 680 int score = StringUtils.lcsLength(name, streetName); 681 682 if (score > 3) { // reasonable value? 683 StreetScore sc = new StreetScore(streetName, score); 684 scores.add(sc); 685 } 686 } 687 688 // sort by score 689 Collections.sort(scores); 690 691 // populate result list 692 int n = Math.min(maxEntries, scores.size()); 693 for (int i = 0; i < n; i++) { 694 matches.add(scores.get(i).getName()); 695 } 696 697 return matches; 698 } 699 700 @Override 701 public boolean isValidStreetName(String name) { 702 if (streetDict == null) return false; 703 704 return streetDict.containsKey(name); 705 } 706 707 /** 708 * Internal class to handle results of {@link AddressEditContainer#getClosestStreetNames(String, int)}. 709 */ 710 private class StreetScore implements Comparable<StreetScore> { 711 private String name; 712 private int score; 713 714 /** 715 * @param name Name of the street. 716 * @param score Score of the street (length of longest common substring) 717 */ 718 public StreetScore(String name, int score) { 719 super(); 720 this.name = name; 721 this.score = score; 722 } 723 724 /** 725 * @return the name of the street. 726 */ 727 protected String getName() { 728 return name; 729 } 730 731 /** 732 * @return the score of the street. 733 */ 734 @SuppressWarnings("unused") 735 // TODO: Implement properly 736 protected int getScore() { 737 return score; 738 } 739 642 740 @Override 643 public void primitivesAdded(PrimitivesAddedEvent event) { 644 invalidate(); 645 } 646 647 /* (non-Javadoc) 648 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesRemoved(org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent) 649 */ 650 @Override 651 public void primitivesRemoved(PrimitivesRemovedEvent event) { 652 invalidate(); 653 } 654 655 /* (non-Javadoc) 656 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#relationMembersChanged(org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent) 657 */ 658 @Override 659 public void relationMembersChanged(RelationMembersChangedEvent event) { 660 } 661 662 /* (non-Javadoc) 663 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#tagsChanged(org.openstreetmap.josm.data.osm.event.TagsChangedEvent) 664 */ 665 @Override 666 public void tagsChanged(TagsChangedEvent event) { 667 invalidate(); 668 } 669 670 /* (non-Javadoc) 671 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#wayNodesChanged(org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent) 672 */ 673 @Override 674 public void wayNodesChanged(WayNodesChangedEvent event) { 675 } 676 677 /* (non-Javadoc) 678 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 679 */ 680 @Override 681 public void containerChanged(AddressEditContainer container) { 682 invalidate(); 683 } 684 685 /* (non-Javadoc) 686 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity) 687 */ 688 @Override 689 public void entityChanged(IOSMEntity entity) { 690 fireEntityChanged(entity); 691 } 692 693 /* (non-Javadoc) 694 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblemVisitor#addProblem(org.openstreetmap.josm.plugins.fixAddresses.IProblem) 695 */ 696 @Override 697 public void addProblem(IProblem problem) { 698 problems.add(problem); 699 } 700 701 /* (non-Javadoc) 702 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblemVisitor#removeProblemsOfSource(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity) 703 */ 704 @Override 705 public void removeProblemsOfSource(IOSMEntity entity) { 706 CheckParameterUtil.ensureParameterNotNull(entity, "entity"); 707 708 List<IProblem> problemsToRemove = new ArrayList<IProblem>(); 709 for (IProblem problem : problems) { 710 if (problem.getSource() == entity) { 711 problemsToRemove.add(problem); 712 } 713 } 714 715 for (IProblem iProblem : problemsToRemove) { 716 problems.remove(iProblem); 717 } 718 } 719 720 /* (non-Javadoc) 721 * @see org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap#getClosestStreetName(java.lang.String) 722 */ 723 @Override 724 public String getClosestStreetName(String name) { 725 List<String> matches = getClosestStreetNames(name, 1); 726 727 if (matches != null && matches.size() > 0) { 728 return matches.get(0); 729 } 730 731 return null; 732 } 733 734 /* (non-Javadoc) 735 * @see org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap#getClosestStreetNames(java.lang.String, int) 736 */ 737 @Override 738 public List<String> getClosestStreetNames(String name, int maxEntries) { 739 CheckParameterUtil.ensureParameterNotNull(name, "name"); 740 741 // ensure right number of entries 742 if (maxEntries < 1) maxEntries = 1; 743 744 List<StreetScore> scores = new ArrayList<StreetScore>(); 745 List<String> matches = new ArrayList<String>(); 746 747 // Find the longest common sub string 748 for (String streetName : streetDict.keySet()) { 749 int score = StringUtils.lcsLength(name, streetName); 750 751 if (score > 3) { // reasonable value? 752 StreetScore sc = new StreetScore(streetName, score); 753 scores.add(sc); 754 } 755 } 756 757 // sort by score 758 Collections.sort(scores); 759 760 // populate result list 761 int n = Math.min(maxEntries, scores.size()); 762 for (int i = 0; i < n; i++) { 763 matches.add(scores.get(i).getName()); 764 } 765 766 return matches; 767 } 768 769 /* (non-Javadoc) 770 * @see org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap#isValidStreetName(java.lang.String) 771 */ 772 @Override 773 public boolean isValidStreetName(String name) { 774 if (streetDict == null) return false; 775 776 return streetDict.containsKey(name); 777 } 778 779 /** 780 * Internal class to handle results of {@link AddressEditContainer#getClosestStreetNames(String, int)}. 781 */ 782 private class StreetScore implements Comparable<StreetScore> { 783 private String name; 784 private int score; 785 786 /** 787 * @param name Name of the street. 788 * @param score Score of the street (length of longest common substring) 789 */ 790 public StreetScore(String name, int score) { 791 super(); 792 this.name = name; 793 this.score = score; 794 } 795 796 /** 797 * @return the name of the street. 798 */ 799 protected String getName() { 800 return name; 801 } 802 803 /** 804 * @return the score of the street. 805 */ 806 @SuppressWarnings("unused") 807 // TODO: Implement properly 808 protected int getScore() { 809 return score; 810 } 811 812 @Override 813 public int compareTo(StreetScore arg0) { 814 if (arg0 == null) return 1; 815 816 return new Integer(score).compareTo(new Integer(arg0.score)); 817 } 818 } 741 public int compareTo(StreetScore arg0) { 742 if (arg0 == null) return 1; 743 744 return new Integer(score).compareTo(new Integer(arg0.score)); 745 } 746 } 819 747 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressProblem.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 20 8 21 9 public class AddressProblem implements IProblem { 22 23 24 25 10 private List<ISolution> solutions = null; 11 private String description; 12 private ProblemType type; 13 private IOSMEntity source; 26 14 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 15 /** 16 * Instantiates a new problem. 17 * 18 * @param source the source 19 * @param description The problem description. 20 * @param solutions This list of solutions. 21 * @param type the type 22 */ 23 public AddressProblem(IOSMEntity source, String description, 24 List<ISolution> solutions, ProblemType type) { 25 super(); 26 this.source = source; 27 this.description = description; 28 this.solutions = solutions; 29 this.type = type; 30 } 43 31 44 45 46 47 48 49 50 51 52 53 32 /** 33 * Instantiates a new problem with type 'warning'. 34 * 35 * @param source the source 36 * @param description The problem description. 37 * @param solutions This list of solutions. 38 */ 39 public AddressProblem(IOSMEntity source, String description, List<ISolution> solutions) { 40 this(source, description, solutions, ProblemType.Warning); 41 } 54 42 55 56 57 58 59 60 61 62 63 43 /** 44 * Instantiates a new problem with type 'warning' and without solutions. 45 * 46 * @param source the source 47 * @param description The problem description. 48 */ 49 public AddressProblem(IOSMEntity source, String description) { 50 this(source, description, null, ProblemType.Warning); 51 } 64 52 65 66 67 68 69 70 71 72 53 /** 54 * Creates the solution list, if necessary. 55 */ 56 private void lazyCreateSolutions() { 57 if (solutions == null) { 58 solutions = new ArrayList<ISolution>(); 59 } 60 } 73 61 74 /* (non-Javadoc) 75 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#addSolution(org.openstreetmap.josm.plugins.fixAddresses.ISolution) 76 */ 77 @Override 78 public void addSolution(ISolution solution) { 79 CheckParameterUtil.ensureParameterNotNull(solution, "solution"); 62 @Override 63 public void addSolution(ISolution solution) { 64 CheckParameterUtil.ensureParameterNotNull(solution, "solution"); 80 65 81 82 83 66 lazyCreateSolutions(); 67 solutions.add(solution); 68 } 84 69 85 /* (non-Javadoc) 86 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#applySolution(org.openstreetmap.josm.plugins.fixAddresses.ISolution) 87 */ 88 @Override 89 public void applySolution(ISolution solution) { 90 CheckParameterUtil.ensureParameterNotNull(solution, "solution"); 70 @Override 71 public void applySolution(ISolution solution) { 72 CheckParameterUtil.ensureParameterNotNull(solution, "solution"); 91 73 92 93 74 solution.solve(); 75 } 94 76 95 /* (non-Javadoc) 96 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#clearSolutions() 97 */ 98 @Override 99 public void clearSolutions() { 100 if (solutions == null) return; 77 @Override 78 public void clearSolutions() { 79 if (solutions == null) return; 101 80 102 103 81 solutions.clear(); 82 } 104 83 105 /* (non-Javadoc) 106 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getDescription() 107 */ 108 @Override 109 public String getDescription() { 110 return description; 111 } 84 @Override 85 public String getDescription() { 86 return description; 87 } 112 88 113 /* (non-Javadoc) 114 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getSolutions() 115 */ 116 @Override 117 public List<ISolution> getSolutions() { 118 return solutions; 119 } 89 @Override 90 public List<ISolution> getSolutions() { 91 return solutions; 92 } 120 93 121 /* (non-Javadoc) 122 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getType() 123 */ 124 @Override 125 public ProblemType getType() { 126 return type; 127 } 94 @Override 95 public ProblemType getType() { 96 return type; 97 } 128 98 129 /* (non-Javadoc) 130 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#removeSolution(org.openstreetmap.josm.plugins.fixAddresses.ISolution) 131 */ 132 @Override 133 public void removeSolution(ISolution solution) { 134 if (solutions == null ) throw new RuntimeException("Solution list is null"); 135 if (solutions.size() == 0) throw new RuntimeException("Solution list is empty"); 99 @Override 100 public void removeSolution(ISolution solution) { 101 if (solutions == null ) throw new RuntimeException("Solution list is null"); 102 if (solutions.size() == 0) throw new RuntimeException("Solution list is empty"); 136 103 137 138 139 104 CheckParameterUtil.ensureParameterNotNull(solution, "solution"); 105 solutions.remove(solution); 106 } 140 107 141 /* (non-Javadoc) 142 * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getSource() 143 */ 144 @Override 145 public IOSMEntity getSource() { 146 return source; 147 } 108 @Override 109 public IOSMEntity getSource() { 110 return source; 111 } 148 112 149 113 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressSolution.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 20 8 */ 21 9 public class AddressSolution implements ISolution { 22 23 24 10 private JosmAction action; 11 private String description; 12 private SolutionType type; 25 13 26 27 28 29 30 31 32 33 34 35 36 37 14 /** 15 * @param description The solution description. 16 * @param action The action to execute to solve the problem. 17 * @param type The solution type. 18 */ 19 public AddressSolution(String description, JosmAction action, 20 SolutionType type) { 21 super(); 22 this.description = description; 23 this.action = action; 24 this.type = type; 25 } 38 26 39 40 41 42 27 @Override 28 public JosmAction getAction() { 29 return action; 30 } 43 31 44 45 46 47 32 @Override 33 public String getDescription() { 34 return description; 35 } 48 36 49 50 51 52 37 @Override 38 public SolutionType getType() { 39 return type; 40 } 53 41 54 55 56 57 42 @Override 43 public void solve() { 44 // TODO: Remove?? 45 } 58 46 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixAddressesMapMode.java
r26509 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 21 9 import org.openstreetmap.josm.gui.MapFrame; 22 10 23 24 11 @SuppressWarnings("serial") 25 12 public class FixAddressesMapMode extends MapMode { 26 13 27 public FixAddressesMapMode(MapFrame mapFrame) { 28 super(tr("Fix addresses"), "incompleteaddress_24", 29 tr("Show dialog with incomplete addresses"), 30 mapFrame, 31 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 32 } 33 34 14 public FixAddressesMapMode(MapFrame mapFrame) { 15 super(tr("Fix addresses"), "incompleteaddress_24", 16 tr("Show dialog with incomplete addresses"), 17 mapFrame, 18 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 19 } 35 20 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixAddressesPlugin.java
r29869 r30348 1 /** 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 28 16 */ 29 17 public class FixAddressesPlugin extends Plugin { 30 18 private static FixAddressesPreferences preferences; 31 19 32 33 34 35 36 37 20 /** 21 * Constructor for the AddressEdit plugin. Called by JOSM when loading the plugin. 22 * @param info Context information of the plugin. 23 */ 24 public FixAddressesPlugin(PluginInformation info) { 25 super(info); 38 26 39 40 41 27 // Create actions... 28 FixUnresolvedStreetsAction action = new FixUnresolvedStreetsAction(); 29 SelectIncompleteAddressesAction incAddrAction = new SelectIncompleteAddressesAction(); 42 30 43 31 // ... and add them to the tools menu in main 44 32 MainMenu.add(Main.main.menu.toolsMenu, action, false, 0); 45 33 MainMenu.add(Main.main.menu.toolsMenu, incAddrAction); 46 34 47 48 49 35 // create preferences instance 36 preferences = (FixAddressesPreferences) new FixAddressesPreferences.Factory().createPreferenceSetting(); 37 } 50 38 51 /* (non-Javadoc) 52 * @see org.openstreetmap.josm.plugins.Plugin#mapFrameInitialized(org.openstreetmap.josm.gui.MapFrame, org.openstreetmap.josm.gui.MapFrame) 53 */ 54 @Override 55 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 56 if (newFrame != null) { 57 FixAddressesMapMode faMode = new FixAddressesMapMode(Main.map); 58 IconToggleButton faModeButton = new IconToggleButton(faMode); 59 faModeButton.setVisible(true); 60 newFrame.addToggleDialog(new IncompleteAddressesDialog()); 61 } 62 } 39 @Override 40 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 41 if (newFrame != null) { 42 FixAddressesMapMode faMode = new FixAddressesMapMode(Main.map); 43 IconToggleButton faModeButton = new IconToggleButton(faMode); 44 faModeButton.setVisible(true); 45 newFrame.addToggleDialog(new IncompleteAddressesDialog()); 46 } 47 } 63 48 64 65 66 67 49 @Override 50 public PreferenceSetting getPreferenceSetting() { 51 return getPreferences(); 52 } 68 53 69 70 71 72 73 74 75 76 54 /** 55 * Gets the preferences instance for this plugin. 56 * 57 * @return the preferences 58 */ 59 public static FixAddressesPreferences getPreferences() { 60 return preferences; 61 } 77 62 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixAddressesPreferences.java
r29500 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 26 14 27 15 public class FixAddressesPreferences extends DefaultTabPreferenceSetting { 28 29 30 31 32 16 private static final String FIX_ADDRESSES_IGNORE_POST_CODE_KEY = "fixAddresses.ignorePostCode"; 17 private static final String FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY = "fixAddresses.selectGuessedObjects"; 18 19 private JCheckBox cbSelectGuessedObjects = new JCheckBox(tr("Include objects used for guesses")); 20 private JCheckBox cbIgnorePostCode = new JCheckBox(); 33 21 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 22 /** 23 * Internal factory class. Call <code>FixAddressesPreferences.Factory().createPreferenceSetting()</code> to 24 * create the preference setting instance. 25 */ 26 public static class Factory implements PreferenceSettingFactory { 27 public PreferenceSetting createPreferenceSetting() { 28 return new FixAddressesPreferences(); 29 } 30 } 31 32 /** 33 * Internal constructor. 34 */ 35 private FixAddressesPreferences() { 36 loadFromPrefs(); 37 } 38 39 /** 40 * Loads the (initial) preference settings. 41 */ 42 private void loadFromPrefs() { 43 setSelectGuessedObjects(Main.pref.getBoolean(FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY, false)); 44 setIgnorePostCode(Main.pref.getBoolean(FIX_ADDRESSES_IGNORE_POST_CODE_KEY, false)); 45 } 46 47 /** 48 * Save the preference settings. 49 */ 50 private void saveToPrefs() { 51 Main.pref.put(FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY, isSelectGuessedObjects()); 52 Main.pref.put(FIX_ADDRESSES_IGNORE_POST_CODE_KEY, isIgnorePostCode()); 53 } 66 54 67 /* (non-Javadoc) 68 * @see org.openstreetmap.josm.gui.preferences.PreferenceSetting#addGui(org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane) 69 */ 70 @Override 71 public void addGui(PreferenceTabbedPane gui) { 72 // Import settings 55 @Override 56 public void addGui(PreferenceTabbedPane gui) { 57 // Import settings 73 58 ButtonGroup fixAddrOptions = new ButtonGroup(); 74 59 fixAddrOptions.add(cbSelectGuessedObjects); 75 60 fixAddrOptions.add(cbIgnorePostCode); 76 61 } 77 62 78 /* (non-Javadoc) 79 * @see org.openstreetmap.josm.gui.preferences.PreferenceSetting#ok() 80 */ 81 @Override 82 public boolean ok() { 83 saveToPrefs(); 84 loadFromPrefs(); 85 return false; 86 } 63 @Override 64 public boolean ok() { 65 saveToPrefs(); 66 loadFromPrefs(); 67 return false; 68 } 87 69 88 89 90 91 92 93 94 95 96 97 70 /** 71 * Checks if option "select guessed objects" is set. If yes, every selection 72 * includes also the objects used for guessing the address tags. 73 * Otherwise only the address itself is selected. 74 * 75 * @return the selectGuessedObjects 76 */ 77 public boolean isSelectGuessedObjects() { 78 return cbSelectGuessedObjects.isSelected(); 79 } 98 80 99 100 101 102 103 104 105 106 81 /** 82 * Sets the select guessed objects. 83 * 84 * @param selectGuessedObjects the selectGuessedObjects to set 85 */ 86 void setSelectGuessedObjects(boolean selectGuessedObjects) { 87 cbSelectGuessedObjects.setSelected(selectGuessedObjects); 88 } 107 89 108 109 110 111 112 113 114 115 90 /** 91 * Checks if invalid post codes should be ignored. If yes, post codes are neither 92 * checked for existence nor for correctness. 93 * @return 94 */ 95 public boolean isIgnorePostCode() { 96 return cbIgnorePostCode.isSelected(); 97 } 116 98 117 118 119 99 public void setIgnorePostCode(boolean ignorePostCode) { 100 cbIgnorePostCode.setSelected(ignorePostCode); 101 } 120 102 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixUnresolvedStreetsAction.java
r29500 r30348 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.fixAddresses; 2 3 … … 20 21 * @author Oliver Wieland <oliver.wieland@online.de> 21 22 */ 22 23 23 @SuppressWarnings("serial") 24 24 public class FixUnresolvedStreetsAction extends JosmAction implements SelectionChangedListener { 25 26 25 private AddressEditContainer addressEditContainer; 26 private Collection<? extends OsmPrimitive> newSelection; 27 27 28 29 30 31 32 28 public FixUnresolvedStreetsAction() { 29 super(tr("Fix street addresses"), "fixstreets_24", 30 tr("Find and fix addresses without (valid) streets."), 31 Shortcut.registerShortcut("tools:AddressEdit", tr("Tool: {0}", 32 tr("Address Edit")), KeyEvent.VK_X, Shortcut.CTRL_SHIFT), false); 33 33 34 35 36 37 34 setEnabled(false); 35 addressEditContainer = new AddressEditContainer(); 36 DataSet.addSelectionListener(this); 37 } 38 38 39 /* (non-Javadoc) 40 * @see org.openstreetmap.josm.data.SelectionChangedListener#selectionChanged(java.util.Collection) 41 */ 42 @Override 43 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 44 /* remember new selection for actionPerformed */ 45 this.newSelection = newSelection; 46 } 39 @Override 40 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 41 /* remember new selection for actionPerformed */ 42 this.newSelection = newSelection; 43 } 47 44 48 /* (non-Javadoc) 49 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 50 */ 51 @Override 52 public void actionPerformed(ActionEvent arg0) { 53 if (addressEditContainer != null) { 54 addressEditContainer.attachToDataSet(newSelection); 55 try { 56 //generateTagCode(addressEditContainer); 57 AddressEditDialog dlg = new AddressEditDialog(addressEditContainer); 58 dlg.setVisible(true); 59 } finally { 60 addressEditContainer.detachFromDataSet(); 61 } 62 } 63 } 45 @Override 46 public void actionPerformed(ActionEvent arg0) { 47 if (addressEditContainer != null) { 48 addressEditContainer.attachToDataSet(newSelection); 49 try { 50 //generateTagCode(addressEditContainer); 51 AddressEditDialog dlg = new AddressEditDialog(addressEditContainer); 52 dlg.setVisible(true); 53 } finally { 54 addressEditContainer.detachFromDataSet(); 55 } 56 } 57 } 64 58 59 @Override 60 protected void updateEnabledState() { 61 setEnabled(getCurrentDataSet() != null); 62 } 65 63 66 /* (non-Javadoc) 67 * @see org.openstreetmap.josm.actions.JosmAction#updateEnabledState() 68 */ 69 @Override 70 protected void updateEnabledState() { 71 setEnabled(getCurrentDataSet() != null);72 64 @Override 65 protected void updateEnabledState( 66 Collection<? extends OsmPrimitive> selection) { 67 // Enable button if there is either a selection or at least a data set 68 setEnabled( selection != null && !selection.isEmpty() || 69 (getCurrentDataSet() != null)); 70 } 73 71 74 @Override 75 protected void updateEnabledState( 76 Collection<? extends OsmPrimitive> selection) { 77 // Enable button if there is either a selection or at least a data set 78 setEnabled( selection != null && !selection.isEmpty() || 79 (getCurrentDataSet() != null)); 80 } 72 /* This code is abused to generate tag utility code */ 81 73 82 /* This code is abused to generate tag utility code */ 74 @SuppressWarnings("unused") 75 private void generateTagCode(AddressEditContainer addrVisitor) { 83 76 84 @SuppressWarnings("unused") 85 private void generateTagCode(AddressEditContainer addrVisitor) { 77 for (String tag : addrVisitor.getTags()) { 78 String methodName = createMethodName(tag); 79 System.out 80 .println(String 81 .format( 82 "/** Check if OSM primitive has a tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static boolean has%sTag(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.hasKey(%s_TAG) : false;\n}\n", 83 tag, methodName, tag.toUpperCase() 84 .replaceAll(":", "_"))); 85 System.out 86 .println(String 87 .format( 88 "/** Gets the value of tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static String get%sValue(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.get(%s_TAG) : null;\n}\n", 89 tag, methodName, tag.toUpperCase() 90 .replaceAll(":", "_"))); 91 } 86 92 87 for (String tag : addrVisitor.getTags()) { 88 String methodName = createMethodName(tag); 89 System.out 90 .println(String 91 .format( 92 "/** Check if OSM primitive has a tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static boolean has%sTag(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.hasKey(%s_TAG) : false;\n}\n", 93 tag, methodName, tag.toUpperCase() 94 .replaceAll(":", "_"))); 95 System.out 96 .println(String 97 .format( 98 "/** Gets the value of tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static String get%sValue(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.get(%s_TAG) : null;\n}\n", 99 tag, methodName, tag.toUpperCase() 100 .replaceAll(":", "_"))); 101 } 93 for (String tag : addrVisitor.getTags()) { 94 System.out.println(String.format( 95 "public static final String %s_TAG = \"%s\";", tag 96 .toUpperCase().replaceAll(":", "_"), tag)); 97 } 102 98 103 for (String tag : addrVisitor.getTags()) { 104 System.out.println(String.format( 105 "public static final String %s_TAG = \"%s\";", tag 106 .toUpperCase().replaceAll(":", "_"), tag)); 107 } 99 for (String value : addrVisitor.getValues().keySet()) { 100 String tag = addrVisitor.getValues().get(value); 108 101 109 for (String value : addrVisitor.getValues().keySet()) { 110 String tag = addrVisitor.getValues().get(value); 102 String tags = tag.toUpperCase().replaceAll(":", "_"); 103 String values = value.toUpperCase().replaceAll(":", "_"); 104 System.out.println(String.format( 105 "public static final String %s_%s_VALUE = \"%s\";", tags, values 106 , value)); 107 } 108 } 111 109 112 String tags = tag.toUpperCase().replaceAll(":", "_"); 113 String values = value.toUpperCase().replaceAll(":", "_"); 114 System.out.println(String.format( 115 "public static final String %s_%s_VALUE = \"%s\";", tags, values 116 , value)); 117 } 118 } 110 private String createMethodName(String osmName) { 111 StringBuffer result = new StringBuffer(osmName.length()); 112 boolean nextUp = false; 113 for (int i = 0; i < osmName.length(); i++) { 114 char c = osmName.charAt(i); 115 if (i == 0) { 116 result.append(Character.toUpperCase(c)); 117 continue; 118 } 119 if (c == '_' || c == ':') { 120 nextUp = true; 121 } else { 122 if (nextUp) { 123 result.append(Character.toUpperCase(c)); 124 nextUp = false; 125 } else { 126 result.append(c); 127 } 128 } 129 } 119 130 120 private String createMethodName(String osmName) { 121 StringBuffer result = new StringBuffer(osmName.length()); 122 boolean nextUp = false; 123 for (int i = 0; i < osmName.length(); i++) { 124 char c = osmName.charAt(i); 125 if (i == 0) { 126 result.append(Character.toUpperCase(c)); 127 continue; 128 } 129 if (c == '_' || c == ':') { 130 nextUp = true; 131 } else { 132 if (nextUp) { 133 result.append(Character.toUpperCase(c)); 134 nextUp = false; 135 } else { 136 result.append(c); 137 } 138 } 139 } 140 141 return result.toString(); 142 } 131 return result.toString(); 132 } 143 133 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/GuessAddressRunnable.java
r29870 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 36 24 */ 37 25 public class GuessAddressRunnable extends PleaseWaitRunnable { 38 private List<OSMAddress> addressesToGuess; 39 private List<IProgressMonitorFinishedListener> finishListeners = new ArrayList<IProgressMonitorFinishedListener>(); 40 private boolean isRunning = false; 41 private boolean canceled; 42 43 private GuessedValueHandler[] wayGuessers = new GuessedValueHandler[]{new GuessStreetValueHandler(TagUtils.ADDR_STREET_TAG)}; 44 private GuessedValueHandler[] nodeGuessers = new GuessedValueHandler[]{ 45 new GuessedValueHandler(TagUtils.ADDR_POSTCODE_TAG, 500.0), 46 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 5000.0), 47 new GuessedValueHandler(TagUtils.ADDR_STATE_TAG, 5000.0), 48 new GuessedValueHandler(TagUtils.ADDR_COUNTRY_TAG, 5000.0), 49 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 2000.0) 50 }; 51 52 /** 53 * Instantiates a new guess address runnable. 54 * 55 * @param addresses the addresses to guess the values for 56 * @param title the title of progress monitor 57 */ 58 public GuessAddressRunnable(List<OSMAddress> addresses, String title) { 59 super(title != null ? title : tr("Searching")); 60 setAddressEditContainer(addresses); 61 } 62 63 /** 64 * Sets the address edit container. 65 * 66 * @param nodes the new address edit container 67 */ 68 public void setAddressEditContainer(List<OSMAddress> nodes) { 69 if (isRunning) { 70 throw new ConcurrentModificationException(); 71 } 72 this.addressesToGuess = nodes; 73 } 74 75 /** 76 * Gets the addresses to guess. 77 * 78 * @return the addresses to guess 79 */ 80 public List<OSMAddress> getAddressesToGuess() { 81 return addressesToGuess; 82 } 83 /** 84 * @return the isRunning 85 */ 86 public boolean isRunning() { 87 return isRunning; 88 } 89 90 /** 91 * Adds a finish listener. 92 * 93 * @param l the listener to add 94 */ 95 public void addFinishListener(IProgressMonitorFinishedListener l) { 96 finishListeners.add(l); 97 } 98 99 /** 100 * Removes a finish listener. 101 * 102 * @param l the listener to remove 103 */ 104 public void removeFinishListener(IProgressMonitorFinishedListener l) { 105 finishListeners.remove(l); 106 } 107 108 /** 109 * Fires the 'finished' event after the thread has done his work. 110 */ 111 protected void fireFinished() { 112 for (IProgressMonitorFinishedListener l : finishListeners) { 113 l.finished(); 114 } 115 // this event is fired only once, then we disconnect all listeners 116 finishListeners.clear(); 117 } 118 119 /* (non-Javadoc) 120 * @see org.openstreetmap.josm.gui.PleaseWaitRunnable#cancel() 121 */ 122 @Override 123 protected void cancel() { 124 canceled = true; 125 } 126 127 /* (non-Javadoc) 128 * @see org.openstreetmap.josm.gui.PleaseWaitRunnable#finish() 129 */ 130 @Override 131 protected void finish() { 132 // nothing to do yet 133 } 134 135 /* (non-Javadoc) 136 * @see org.openstreetmap.josm.gui.PleaseWaitRunnable#realRun() 137 */ 138 @Override 139 protected void realRun() throws SAXException, IOException, 140 OsmTransferException { 141 142 if (Main.main.getCurrentDataSet() == null || addressesToGuess == null) return; 143 144 isRunning = true; 145 canceled = false; 146 147 // Start progress monitor to guess address values 148 progressMonitor.subTask(tr("Searching") + "..."); 149 150 try { 151 progressMonitor.setTicksCount(addressesToGuess.size()); 152 153 List<OSMAddress> shadowCopy = new ArrayList<OSMAddress>(addressesToGuess); 154 for (OSMAddress aNode : shadowCopy) { 155 if (!aNode.needsGuess()) { // nothing to do 156 progressMonitor.worked(1); 157 continue; 158 } 159 160 // check for cancel 161 if (canceled) { 162 break; 163 } 164 165 // Update progress monitor 166 progressMonitor.subTask(tr("Guess values for ") + aNode); 167 168 // Run way-related guessers 169 for (int i = 0; i < wayGuessers.length; i++) { 170 GuessedValueHandler guesser = wayGuessers[i]; 171 172 guesser.setAddressNode(aNode); 173 174 // visit osm data 175 for (Way way : Main.main.getCurrentDataSet().getWays()) { 176 if (canceled) { 177 break; 178 } 179 way.accept(guesser); 180 } 181 182 String guessedVal = guesser.getCurrentValue(); 183 if (guessedVal != null) { 184 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode()); 185 } 186 } 187 188 // Run node-related guessers 189 for (int i = 0; i < nodeGuessers.length; i++) { 190 GuessedValueHandler guesser = nodeGuessers[i]; 191 192 guesser.setAddressNode(aNode); 193 194 // visit osm data 195 for (Node node : Main.main.getCurrentDataSet().getNodes()) { 196 if (canceled) { 197 break; 198 } 199 node.accept(guesser); 200 } 201 202 String guessedVal = guesser.getCurrentValue(); 203 if (guessedVal != null) { 204 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode()); 205 } 206 } 207 208 // report progress 209 progressMonitor.worked(1); 210 } 211 } finally { 212 isRunning = false; 213 fireFinished(); 214 } 215 } 216 217 // TODO: Put in separate file 218 private class GuessStreetValueHandler extends GuessedValueHandler { 219 public GuessStreetValueHandler(String tag) { 220 this(tag, null); 221 } 222 223 public GuessStreetValueHandler(String tag, OSMAddress aNode) { 224 super(tag, aNode, 200.0); 225 } 226 227 /* (non-Javadoc) 228 * @see org.openstreetmap.josm.plugins.fixAddresses.GuessedValueHandler#visit(org.openstreetmap.josm.data.osm.Node) 229 */ 230 @Override 231 public void visit(Node n) { 232 // do nothing 233 } 234 235 /* (non-Javadoc) 236 * @see org.openstreetmap.josm.plugins.fixAddresses.GuessedValueHandler#visit(org.openstreetmap.josm.data.osm.Way) 237 */ 238 @Override 239 public void visit(Way w) { 240 if (TagUtils.isStreetSupportingHousenumbers(w)) { 241 OSMAddress aNode = getAddressNode(); 242 String newVal = TagUtils.getNameValue(w); 243 244 if (newVal != null) { 245 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); 246 247 if (dist < minDist && dist < getMaxDistance()) { 248 minDist = dist; 249 currentValue = newVal; 250 srcNode = w; 251 //aNode.setGuessedValue(getTag(), currentValue, w); 252 } else { 253 //System.out.println(String.format("Skipped %s: %4.2f m", TagUtils.getNameValue(w), dist)); 254 } 255 } 256 } 257 } 258 } 26 private List<OSMAddress> addressesToGuess; 27 private List<IProgressMonitorFinishedListener> finishListeners = new ArrayList<IProgressMonitorFinishedListener>(); 28 private boolean isRunning = false; 29 private boolean canceled; 30 31 private GuessedValueHandler[] wayGuessers = new GuessedValueHandler[]{new GuessStreetValueHandler(TagUtils.ADDR_STREET_TAG)}; 32 private GuessedValueHandler[] nodeGuessers = new GuessedValueHandler[]{ 33 new GuessedValueHandler(TagUtils.ADDR_POSTCODE_TAG, 500.0), 34 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 5000.0), 35 new GuessedValueHandler(TagUtils.ADDR_STATE_TAG, 5000.0), 36 new GuessedValueHandler(TagUtils.ADDR_COUNTRY_TAG, 5000.0), 37 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 2000.0) 38 }; 39 40 /** 41 * Instantiates a new guess address runnable. 42 * 43 * @param addresses the addresses to guess the values for 44 * @param title the title of progress monitor 45 */ 46 public GuessAddressRunnable(List<OSMAddress> addresses, String title) { 47 super(title != null ? title : tr("Searching")); 48 setAddressEditContainer(addresses); 49 } 50 51 /** 52 * Sets the address edit container. 53 * 54 * @param nodes the new address edit container 55 */ 56 public void setAddressEditContainer(List<OSMAddress> nodes) { 57 if (isRunning) { 58 throw new ConcurrentModificationException(); 59 } 60 this.addressesToGuess = nodes; 61 } 62 63 /** 64 * Gets the addresses to guess. 65 * 66 * @return the addresses to guess 67 */ 68 public List<OSMAddress> getAddressesToGuess() { 69 return addressesToGuess; 70 } 71 /** 72 * @return the isRunning 73 */ 74 public boolean isRunning() { 75 return isRunning; 76 } 77 78 /** 79 * Adds a finish listener. 80 * 81 * @param l the listener to add 82 */ 83 public void addFinishListener(IProgressMonitorFinishedListener l) { 84 finishListeners.add(l); 85 } 86 87 /** 88 * Removes a finish listener. 89 * 90 * @param l the listener to remove 91 */ 92 public void removeFinishListener(IProgressMonitorFinishedListener l) { 93 finishListeners.remove(l); 94 } 95 96 /** 97 * Fires the 'finished' event after the thread has done his work. 98 */ 99 protected void fireFinished() { 100 for (IProgressMonitorFinishedListener l : finishListeners) { 101 l.finished(); 102 } 103 // this event is fired only once, then we disconnect all listeners 104 finishListeners.clear(); 105 } 106 107 @Override 108 protected void cancel() { 109 canceled = true; 110 } 111 112 @Override 113 protected void finish() { 114 // nothing to do yet 115 } 116 117 @Override 118 protected void realRun() throws SAXException, IOException, 119 OsmTransferException { 120 121 if (Main.main.getCurrentDataSet() == null || addressesToGuess == null) return; 122 123 isRunning = true; 124 canceled = false; 125 126 // Start progress monitor to guess address values 127 progressMonitor.subTask(tr("Searching") + "..."); 128 129 try { 130 progressMonitor.setTicksCount(addressesToGuess.size()); 131 132 List<OSMAddress> shadowCopy = new ArrayList<OSMAddress>(addressesToGuess); 133 for (OSMAddress aNode : shadowCopy) { 134 if (!aNode.needsGuess()) { // nothing to do 135 progressMonitor.worked(1); 136 continue; 137 } 138 139 // check for cancel 140 if (canceled) { 141 break; 142 } 143 144 // Update progress monitor 145 progressMonitor.subTask(tr("Guess values for ") + aNode); 146 147 // Run way-related guessers 148 for (int i = 0; i < wayGuessers.length; i++) { 149 GuessedValueHandler guesser = wayGuessers[i]; 150 151 guesser.setAddressNode(aNode); 152 153 // visit osm data 154 for (Way way : Main.main.getCurrentDataSet().getWays()) { 155 if (canceled) { 156 break; 157 } 158 way.accept(guesser); 159 } 160 161 String guessedVal = guesser.getCurrentValue(); 162 if (guessedVal != null) { 163 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode()); 164 } 165 } 166 167 // Run node-related guessers 168 for (int i = 0; i < nodeGuessers.length; i++) { 169 GuessedValueHandler guesser = nodeGuessers[i]; 170 171 guesser.setAddressNode(aNode); 172 173 // visit osm data 174 for (Node node : Main.main.getCurrentDataSet().getNodes()) { 175 if (canceled) { 176 break; 177 } 178 node.accept(guesser); 179 } 180 181 String guessedVal = guesser.getCurrentValue(); 182 if (guessedVal != null) { 183 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode()); 184 } 185 } 186 187 // report progress 188 progressMonitor.worked(1); 189 } 190 } finally { 191 isRunning = false; 192 fireFinished(); 193 } 194 } 195 196 // TODO: Put in separate file 197 private class GuessStreetValueHandler extends GuessedValueHandler { 198 public GuessStreetValueHandler(String tag) { 199 this(tag, null); 200 } 201 202 public GuessStreetValueHandler(String tag, OSMAddress aNode) { 203 super(tag, aNode, 200.0); 204 } 205 206 @Override 207 public void visit(Node n) { 208 // do nothing 209 } 210 211 @Override 212 public void visit(Way w) { 213 if (TagUtils.isStreetSupportingHousenumbers(w)) { 214 OSMAddress aNode = getAddressNode(); 215 String newVal = TagUtils.getNameValue(w); 216 217 if (newVal != null) { 218 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); 219 220 if (dist < minDist && dist < getMaxDistance()) { 221 minDist = dist; 222 currentValue = newVal; 223 srcNode = w; 224 //aNode.setGuessedValue(getTag(), currentValue, w); 225 } else { 226 //System.out.println(String.format("Skipped %s: %4.2f m", TagUtils.getNameValue(w), dist)); 227 } 228 } 229 } 230 } 231 } 259 232 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/GuessedValueHandler.java
r27326 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 30 18 public class GuessedValueHandler implements Visitor { 31 19 32 33 20 /** Default maximum distance (100m) */ 21 private static final double DEFAULT_MAX_DIST = 100.0; 34 22 35 36 37 38 39 40 23 private String tag; 24 protected double minDist; 25 protected String currentValue; 26 private OSMAddress aNode; 27 private double maxDist = DEFAULT_MAX_DIST; 28 protected OsmPrimitive srcNode; 41 29 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 30 /** 31 * Instantiates a new guessed value handler without node and default maximum distance. 32 * 33 * @param tag the tag to find the guessed value for. 34 */ 35 public GuessedValueHandler(String tag) { 36 this(tag, null, DEFAULT_MAX_DIST); 37 } 38 39 /** 40 * Instantiates a new guessed value handler without node. 41 * 42 * @param tag the tag to find the guessed value for. 43 * @param maxDist the maximum distance for a node/way to be considered as guessed value. 44 */ 45 public GuessedValueHandler(String tag, double maxDist) { 46 this(tag, null, maxDist); 47 } 48 49 /** 50 * Instantiates a new guessed value handler. 51 * 52 * @param tag the tag to find the guessed value for. 53 * @param aNode the address node to guess the values for. 54 * @param maxDist the maximum distance for a node/way to be considered as guessed value. 55 */ 56 public GuessedValueHandler(String tag, OSMAddress aNode) { 57 this(tag, aNode, DEFAULT_MAX_DIST); 58 } 71 59 72 73 74 75 76 77 78 79 80 60 /** 61 * Instantiates a new guessed value handler. 62 * 63 * @param tag the tag to find the guessed value for. 64 * @param aNode the address node to guess the values for. 65 * @param maxDist the maximum distance for a node/way to be considered as guessed value. 66 */ 67 public GuessedValueHandler(String tag, OSMAddress aNode, double maxDist) { 68 super(); 81 69 82 83 84 70 if (StringUtils.isNullOrEmpty(tag)) { 71 throw new RuntimeException("Tag must not be empty or null!"); 72 } 85 73 86 87 88 89 90 91 92 setAddressNode(aNode); 93 74 if (maxDist < 1.0) { // clip value 75 maxDist = 1.0; 76 } 77 78 this.tag = tag; 79 this.maxDist = maxDist; 80 setAddressNode(aNode); 81 } 94 82 95 96 97 98 99 100 101 102 103 83 /** 84 * Gets the address node to make the guess for. 85 * 86 * @return the aNode 87 */ 88 protected OSMAddress getAddressNode() { 89 return aNode; 90 } 91 104 92 105 106 107 108 109 public void setAddressNode(OSMAddress aNode) { 110 111 112 113 114 currentValue = null; 115 93 /** 94 * Sets the address node to make the guess for. 95 * @param aNode 96 */ 97 public void setAddressNode(OSMAddress aNode) { 98 this.aNode = aNode; 99 // reset search results 100 minDist = Double.MAX_VALUE; 101 srcNode = null; 102 currentValue = null; 103 } 116 104 117 118 119 120 121 122 123 124 125 126 105 /** 106 * Gets the max distance allowed to consider a node as guess. 107 * If the distance of the node is greater than maxDist, the 108 * node/way will be ignored. 109 * 110 * @return the maxDist 111 */ 112 protected double getMaxDistance() { 113 return maxDist; 114 } 127 115 128 129 130 131 132 133 134 135 116 /** 117 * Gets the tag name to use as guess. 118 * 119 * @return the tag 120 */ 121 protected String getTag() { 122 return tag; 123 } 136 124 137 138 139 140 141 142 143 144 125 /** 126 * Gets the distance of the node/way which has been used for the guessed value. 127 * 128 * @return the minDist 129 */ 130 protected double getMinimumDist() { 131 return minDist; 132 } 145 133 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 134 /** 135 * Gets the current guessed value or null, if no guess has been possible (so far). 136 * 137 * @return the currentValue 138 */ 139 public String getCurrentValue() { 140 return currentValue; 141 } 142 143 144 /** 145 * Gets the node/way which has been selected for the guess. 146 * @return The source node or null; if no appropriate source primitive has been found 147 */ 148 public OsmPrimitive getSourceNode() { 149 return srcNode; 150 } 163 151 164 165 166 167 168 169 170 171 152 /** 153 * Check if we need to visit the OSM data 154 * 155 * @return true, if successful 156 */ 157 public boolean needsGuess() { 158 return aNode.needsGuessedValue(tag); 159 } 172 160 173 /* (non-Javadoc) 174 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Node) 175 */ 176 @Override 177 public void visit(Node n) { 178 assert aNode != null; 179 180 if (n.hasKey(tag)) { 181 double dist = n.getCoor().greatCircleDistance(aNode.getCoor()); 182 if (dist < minDist && dist < maxDist) { 183 minDist = dist; 184 currentValue = n.get(tag); 185 srcNode = n; 186 } 187 } 188 } 161 @Override 162 public void visit(Node n) { 163 assert aNode != null; 164 165 if (n.hasKey(tag)) { 166 double dist = n.getCoor().greatCircleDistance(aNode.getCoor()); 167 if (dist < minDist && dist < maxDist) { 168 minDist = dist; 169 currentValue = n.get(tag); 170 srcNode = n; 171 } 172 } 173 } 189 174 190 /* (non-Javadoc) 191 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Way) 192 */ 193 @Override 194 public void visit(Way w) { 195 assert aNode != null; 196 197 if (w.hasKey(tag)) { 198 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); 199 if (dist < minDist && dist < maxDist) { 200 minDist = dist; 201 currentValue = w.get(tag); 202 srcNode = w; 203 } 204 } 205 } 175 @Override 176 public void visit(Way w) { 177 assert aNode != null; 178 179 if (w.hasKey(tag)) { 180 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); 181 if (dist < minDist && dist < maxDist) { 182 minDist = dist; 183 currentValue = w.get(tag); 184 srcNode = w; 185 } 186 } 187 } 206 188 207 /* (non-Javadoc) 208 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Relation) 209 */ 210 @Override 211 public void visit(Relation e) { 212 // nothing to do (yet) 213 } 189 @Override 190 public void visit(Relation e) { 191 // nothing to do (yet) 192 } 214 193 215 /* (non-Javadoc) 216 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Changeset) 217 */ 218 @Override 219 public void visit(Changeset cs) { 220 // nothing to do (yet) 221 } 194 @Override 195 public void visit(Changeset cs) { 196 // nothing to do (yet) 197 } 222 198 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IAddressEditContainerListener.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 4 public interface IAddressEditContainerListener { 5 /** 6 * Notifies clients that the container has been changed. 7 * @param container 8 */ 9 public void containerChanged(AddressEditContainer container); 16 10 17 public interface IAddressEditContainerListener { 18 /** 19 * Notifies clients that the container has been changed. 20 * @param container 21 */ 22 public void containerChanged(AddressEditContainer container); 23 24 /** 25 * Notifies clients that an entity has been changed. 26 */ 27 public void entityChanged(IOSMEntity node); 11 /** 12 * Notifies clients that an entity has been changed. 13 */ 14 public void entityChanged(IOSMEntity node); 28 15 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IAllKnowingTrashHeap.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 18 6 public interface IAllKnowingTrashHeap { 19 7 20 21 22 23 24 25 26 27 8 /** 9 * Gets the list containing the best matching (closest) street names. 10 * 11 * @param name the name of the street to find the matches for. 12 * @param maxEntries the maximum number of matches. 13 * @return the closest street names 14 */ 15 public List<String> getClosestStreetNames(String name, int maxEntries); 28 16 29 30 31 32 33 34 35 17 /** 18 * Gets the closest street name to the given name. 19 * 20 * @param name the name of the street to find a match for. 21 * @return the closest street name 22 */ 23 public String getClosestStreetName(String name); 36 24 37 38 39 40 41 42 43 25 /** 26 * Checks if the given street name is valid. 27 * 28 * @param name the name of the street to check. 29 * @return true, if street name is valid; otherwise false. 30 */ 31 public boolean isValidStreetName(String name); 44 32 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/ICommandListener.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 17 5 18 6 public interface ICommandListener { 19 20 21 22 23 24 25 7 /** 8 * Called by a node entity if a command has been created. Clients may collect 9 * these commands to define a sequence command. 10 * @param entity The entity which created/used the command. 11 * @param command The command instance to process by the enclosing command listener. 12 */ 13 public void commandIssued(IOSMEntity entity, Command command); 26 14 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IOSMEntity.java
r29869 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 25 13 * 26 14 */ 15 public interface IOSMEntity extends Comparable<IOSMEntity> { 16 /** 17 * Gets the underlying OSM object. 18 * @return 19 */ 20 public OsmPrimitive getOsmObject(); 27 21 28 public interface IOSMEntity extends Comparable<IOSMEntity> { 29 /** 30 * Gets the underlying OSM object. 31 * @return 32 */ 33 public OsmPrimitive getOsmObject(); 22 /** 23 * Checks if underlying OSM object has a name. 24 * @return 25 */ 26 public boolean hasName(); 34 27 35 36 * Checks if underlying OSM object has a name.37 38 39 public boolean hasName();28 /** 29 * Gets the name of the entity node. 30 * @return 31 */ 32 public String getName(); 40 33 41 42 * Gets the nameof the entity node.43 44 45 public String getName();34 /** 35 * Gets the children of the entity node. 36 * @return 37 */ 38 public List<IOSMEntity> getChildren(); 46 39 47 /** 48 * Gets the children of the entity node. 49 * @return 50 */ 51 public List<IOSMEntity> getChildren(); 40 /** 41 * Gets the coordinate of the node. If the underlying object is a 42 * node, it just returns the node coordinate. For ways and areas, this 43 * method returns the coordinate of the center (balance point). 44 * @return 45 */ 46 public LatLon getCoor(); 52 47 53 /** 54 * Gets the coordinate of the node. If the underlying object is a 55 * node, it just returns the node coordinate. For ways and areas, this 56 * method returns the coordinate of the center (balance point). 57 * @return 58 */ 59 public LatLon getCoor(); 48 /** 49 * Adds a command listener. 50 * @param listener 51 */ 52 public void addCommandListener(ICommandListener listener); 60 53 61 62 * Adds a command listener.63 64 65 public void addCommandListener(ICommandListener listener);54 /** 55 * Removes a command listener. 56 * @param listener 57 */ 58 public void removeCommandListener(ICommandListener listener); 66 59 67 /** 68 * Removes a command listener. 69 * @param listener 70 */ 71 public void removeCommandListener(ICommandListener listener); 60 /** 61 * Collects problems and possible solutions. 62 * 63 * @param trashHeap the trash heap to ask for possible solutions 64 * @param visitor the problem visitor 65 */ 66 public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor); 72 67 73 /** 74 * Collects problems and possible solutions. 75 * 76 * @param trashHeap the trash heap to ask for possible solutions 77 * @param visitor the problem visitor 78 */ 79 public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor); 80 81 int compareTo(IOSMEntity o); 68 int compareTo(IOSMEntity o); 82 69 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IProblem.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 18 6 public interface IProblem { 19 7 20 21 22 23 24 25 8 /** 9 * Gets the OSM entity which causes the problem. 10 * 11 * @return the source 12 */ 13 public IOSMEntity getSource(); 26 14 27 28 29 30 31 32 15 /** 16 * Gets the problem description. 17 * 18 * @return the description 19 */ 20 public String getDescription(); 33 21 34 35 36 37 38 39 22 /** 23 * Gets the problem type. 24 * 25 * @return the type 26 */ 27 public ProblemType getType(); 40 28 41 42 43 44 45 46 29 /** 30 * Gets the available solutions for this problem. 31 * 32 * @return the solutions 33 */ 34 public List<ISolution> getSolutions(); 47 35 48 49 50 51 52 53 36 /** 37 * Adds a possible solution to the problem. 38 * 39 * @param solution the solution 40 */ 41 public void addSolution(ISolution solution); 54 42 55 56 57 58 59 60 43 /** 44 * Removes a solution from this problem. 45 * 46 * @param solution the solution 47 */ 48 public void removeSolution(ISolution solution); 61 49 62 63 64 65 50 /** 51 * Removes all solutions from this problem. 52 */ 53 public void clearSolutions(); 66 54 67 68 69 70 71 72 55 /** 56 * Applies a {@link ISolution} instance on the problem. 57 * 58 * @param solution the solution 59 */ 60 public void applySolution(ISolution solution); 73 61 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IProblemVisitor.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 4 public interface IProblemVisitor { 5 /** 6 * Adds a problem without solution. 7 * 8 * @param problem the problem to add 9 */ 10 public void addProblem(IProblem problem); 16 11 17 public interface IProblemVisitor { 18 /** 19 * Adds a problem without solution. 20 * 21 * @param problem the problem to add 22 */ 23 public void addProblem(IProblem problem); 24 25 /** 26 * Removes the problems of the given source. 27 */ 28 public void removeProblemsOfSource(IOSMEntity entity); 12 /** 13 * Removes the problems of the given source. 14 */ 15 public void removeProblemsOfSource(IOSMEntity entity); 29 16 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IProgressMonitorFinishedListener.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 16 4 public interface IProgressMonitorFinishedListener { 17 5 public void finished(); 18 6 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/ISolution.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 18 6 public interface ISolution { 19 7 20 21 22 23 24 25 8 /** 9 * Gets the description of the solution. 10 * 11 * @return the description 12 */ 13 public String getDescription(); 26 14 27 28 29 30 31 32 15 /** 16 * Gets the action to execute for solving the problem. 17 * 18 * @return the action 19 */ 20 public JosmAction getAction(); 33 21 34 35 36 37 38 39 22 /** 23 * Gets the solution type. 24 * 25 * @return the type 26 */ 27 public SolutionType getType(); 40 28 41 42 43 44 29 /** 30 * Executes one or more actions to solve a problem. 31 */ 32 public void solve(); 45 33 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMAddress.java
r29967 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 46 34 47 35 public OSMAddress(OsmPrimitive osmObject) { 48 super(osmObject); 49 } 50 51 /* 52 * (non-Javadoc) 53 * 54 * @see 55 * org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#setOsmObject 56 * (org.openstreetmap.josm.data.osm.OsmPrimitive) 57 */ 36 super(osmObject); 37 } 38 58 39 @Override 59 40 public void setOsmObject(OsmPrimitive osmObject) { 60 61 62 63 64 41 super.setOsmObject(osmObject); 42 43 isPartOfInterpolation = OsmUtils 44 .getValuesFromAddressInterpolation(this); 45 isPartOfAssocStreetRel = OsmUtils.getValuesFromRelation(this); 65 46 } 66 47 … … 72 53 */ 73 54 public boolean isComplete() { 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 55 boolean isComplete = hasCity() && hasHouseNumber() && hasCity() 56 && hasStreetName(); 57 58 // Check, if "addr:state" is required (US and AU) 59 if (TagUtils.isStateRequired()) { 60 isComplete = isComplete && hasState(); 61 } 62 63 // Check, if user checked "ignore post code" 64 if (!FixAddressesPlugin.getPreferences().isIgnorePostCode()) { 65 isComplete = isComplete && hasPostalCode() 66 && PostalCodeChecker.hasValidPostalCode(this); 67 } 68 69 return isComplete; 89 70 } 90 71 … … 95 76 */ 96 77 public String getStreetName() { 97 78 return getTagValueWithGuess(TagUtils.ADDR_STREET_TAG); 98 79 } 99 80 … … 108 89 */ 109 90 private String getTagValueWithGuess(String tag) { 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 91 if (StringUtils.isNullOrEmpty(tag)) 92 return MISSING_TAG; 93 if (osmObject == null) 94 return MISSING_TAG; 95 96 if (!osmObject.hasKey(tag) 97 || StringUtils.isNullOrEmpty(osmObject.get(tag))) { 98 if (!hasDerivedValue(tag)) { 99 // object does not have this tag -> check for guess 100 if (hasGuessedValue(tag)) { 101 return "*" + getGuessedValue(tag); 102 } else { 103 // give up 104 return MISSING_TAG; 105 } 106 } else { // ok, use derived value known via associated relation or 107 // way 108 return getDerivedValue(tag); 109 } 110 } else { // get existing tag value 111 return osmObject.get(tag); 112 } 132 113 } 133 114 … … 138 119 */ 139 120 public boolean hasStreetName() { 140 121 return hasTag(TagUtils.ADDR_STREET_TAG) || isPartOfRelation(); 141 122 } 142 123 … … 147 128 */ 148 129 public String getGuessedStreetName() { 149 130 return getGuessedValue(TagUtils.ADDR_STREET_TAG); 150 131 } 151 132 … … 159 140 */ 160 141 public void setGuessedStreetName(String guessedStreetName, 161 162 142 OsmPrimitive srcObj) { 143 setGuessedValue(TagUtils.ADDR_STREET_TAG, guessedStreetName, srcObj); 163 144 } 164 145 … … 169 150 */ 170 151 public boolean hasGuessedStreetName() { 171 152 return hasGuessedValue(TagUtils.ADDR_STREET_TAG); 172 153 } 173 154 … … 176 157 */ 177 158 public String getGuessedPostalCode() { 178 159 return getGuessedValue(TagUtils.ADDR_POSTCODE_TAG); 179 160 } 180 161 … … 188 169 */ 189 170 public void setGuessedPostalCode(String guessedPostCode, OsmPrimitive srcObj) { 190 171 setGuessedValue(TagUtils.ADDR_POSTCODE_TAG, guessedPostCode, srcObj); 191 172 } 192 173 … … 197 178 */ 198 179 public boolean hasGuessedPostalCode() { 199 180 return hasGuessedValue(TagUtils.ADDR_POSTCODE_TAG); 200 181 } 201 182 … … 204 185 */ 205 186 public String getGuessedCity() { 206 187 return getGuessedValue(TagUtils.ADDR_CITY_TAG); 207 188 } 208 189 … … 216 197 */ 217 198 public void setGuessedCity(String guessedCity, OsmPrimitive srcObj) { 218 199 setGuessedValue(TagUtils.ADDR_CITY_TAG, guessedCity, srcObj); 219 200 } 220 201 … … 225 206 */ 226 207 public boolean hasGuessedCity() { 227 208 return hasGuessedValue(TagUtils.ADDR_CITY_TAG); 228 209 } 229 210 … … 234 215 */ 235 216 public boolean hasGuesses() { 236 217 return guessedValues.size() > 0; 237 218 } 238 219 … … 241 222 */ 242 223 public void applyAllGuesses() { 243 244 245 246 247 248 249 224 for (String tag : guessedValues.keySet()) { 225 applyGuessForTag(tag); 226 } 227 228 // Clear all guesses 229 guessedValues.clear(); 230 guessedObjects.clear(); 250 231 } 251 232 … … 257 238 */ 258 239 public void applyGuessForTag(String tag) { 259 260 261 262 263 264 240 if (guessedValues.containsKey(tag)) { 241 String val = guessedValues.get(tag); 242 if (!StringUtils.isNullOrEmpty(val)) { 243 setOSMTag(tag, val); 244 } 245 } 265 246 } 266 247 … … 271 252 */ 272 253 public String getPostalCode() { 273 274 275 276 277 278 279 254 String pc = getTagValueWithGuess(TagUtils.ADDR_POSTCODE_TAG); 255 256 if (!MISSING_TAG.equals(pc) 257 && !PostalCodeChecker.hasValidPostalCode(getCountry(), pc)) { 258 pc = "(!)" + pc; 259 } 260 return pc; 280 261 } 281 262 … … 286 267 */ 287 268 public boolean hasValidPostalCode() { 288 269 return PostalCodeChecker.hasValidPostalCode(this); 289 270 } 290 271 … … 295 276 */ 296 277 public boolean hasPostalCode() { 297 278 return hasTag(TagUtils.ADDR_POSTCODE_TAG); 298 279 } 299 280 … … 304 285 */ 305 286 public String getHouseNumber() { 306 307 308 309 310 311 312 313 287 if (!TagUtils.hasAddrHousenumberTag(osmObject)) { 288 if (!isPartOfInterpolation) { 289 return MISSING_TAG; 290 } else { 291 return INTERPOLATION_TAG; 292 } 293 } 294 return TagUtils.getAddrHousenumberValue(osmObject); 314 295 } 315 296 … … 320 301 */ 321 302 public boolean hasHouseNumber() { 322 return TagUtils.hasAddrHousenumberTag(osmObject) 323 || isPartOfInterpolation; 324 } 325 326 /* 327 * (non-Javadoc) 328 * 329 * @see org.openstreetmap.josm.plugins.fixAddresses.OSMEntityBase#getName() 330 */ 303 return TagUtils.hasAddrHousenumberTag(osmObject) 304 || isPartOfInterpolation; 305 } 306 331 307 public String getName() { 332 333 334 335 336 337 308 String name = TagUtils.getNameValue(osmObject); 309 if (!StringUtils.isNullOrEmpty(name)) { 310 return TagUtils.getAddrHousenameValue(osmObject); 311 } 312 313 return ""; 338 314 } 339 315 … … 344 320 */ 345 321 protected boolean isPartOfInterpolation() { 346 322 return isPartOfInterpolation; 347 323 } 348 324 … … 353 329 */ 354 330 protected boolean isPartOfRelation() { 355 331 return isPartOfAssocStreetRel; 356 332 } 357 333 … … 362 338 */ 363 339 public String getCity() { 364 340 return getTagValueWithGuess(TagUtils.ADDR_CITY_TAG); 365 341 } 366 342 … … 371 347 */ 372 348 public boolean hasCity() { 373 349 return hasTag(TagUtils.ADDR_CITY_TAG); 374 350 } 375 351 … … 380 356 */ 381 357 public String getState() { 382 358 return getTagValueWithGuess(TagUtils.ADDR_STATE_TAG); 383 359 } 384 360 … … 389 365 */ 390 366 public boolean hasState() { 391 367 return hasTag(TagUtils.ADDR_STATE_TAG); 392 368 } 393 369 … … 398 374 */ 399 375 public String getCountry() { 400 376 return getTagValueWithGuess(TagUtils.ADDR_COUNTRY_TAG); 401 377 } 402 378 … … 407 383 */ 408 384 public boolean hasCountry() { 409 385 return hasTag(TagUtils.ADDR_COUNTRY_TAG); 410 386 } 411 387 … … 414 390 */ 415 391 public void removeAllAddressTags() { 416 417 418 419 420 421 392 removeOSMTag(TagUtils.ADDR_CITY_TAG); 393 removeOSMTag(TagUtils.ADDR_COUNTRY_TAG); 394 removeOSMTag(TagUtils.ADDR_POSTCODE_TAG); 395 removeOSMTag(TagUtils.ADDR_HOUSENUMBER_TAG); 396 removeOSMTag(TagUtils.ADDR_STATE_TAG); 397 removeOSMTag(TagUtils.ADDR_STREET_TAG); 422 398 } 423 399 … … 431 407 */ 432 408 public boolean hasTag(String tag) { 433 if (StringUtils.isNullOrEmpty(tag)) 434 return false; 435 436 return TagUtils.hasTag(osmObject, tag) || hasDerivedValue(tag); 437 } 438 439 /* 440 * (non-Javadoc) 441 * 442 * @see 443 * org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#compareTo(org 444 * .openstreetmap.josm.plugins.addressEdit.INodeEntity) 445 */ 409 if (StringUtils.isNullOrEmpty(tag)) 410 return false; 411 412 return TagUtils.hasTag(osmObject, tag) || hasDerivedValue(tag); 413 } 414 446 415 @Override 447 416 public int compareTo(IOSMEntity o) { 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 String gsm =this.getGuessedStreetName();469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 417 if (o == null || !(o instanceof OSMAddress)) { 418 return -1; 419 } 420 OSMAddress other = (OSMAddress) o; 421 422 if (this.equals(other)) 423 return 0; 424 425 int cc = 0; 426 cc = this.getCountry().compareTo(other.getCountry()); 427 if (cc == 0) { 428 cc = this.getState().compareTo(other.getState()); 429 if (cc == 0) { 430 cc = this.getCity().compareTo(other.getCity()); 431 if (cc == 0) { 432 cc = this.getStreetName().compareTo(other.getStreetName()); 433 if (cc == 0) { 434 if (hasGuessedStreetName()) { 435 if (other.hasStreetName()) { 436 // Compare guessed name with the real name 437 /*String gsm =*/ this.getGuessedStreetName(); 438 cc = this.getGuessedStreetName().compareTo( 439 other.getStreetName()); 440 if (cc == 0) { 441 cc = this.getHouseNumber().compareTo( 442 other.getHouseNumber()); 443 } 444 } else if (other.hasGuessedStreetName()) { 445 // Compare guessed name with the guessed name 446 cc = this.getGuessedStreetName().compareTo( 447 other.getGuessedStreetName()); 448 if (cc == 0) { 449 cc = this.getHouseNumber().compareTo( 450 other.getHouseNumber()); 451 } 452 } // else: give up 453 // No guessed name at all -> just compare the 454 // number 455 } else { 456 cc = this.getHouseNumber().compareTo( 457 other.getHouseNumber()); 458 } 459 } 460 } 461 } 462 } 463 464 return cc; 496 465 } 497 466 … … 502 471 */ 503 472 public void assignStreet(OSMStreet node) { 504 505 506 507 508 509 510 511 473 if (node == null || !node.hasName()) 474 return; 475 476 if (!node.getName().equals(getStreetName())) { 477 setStreetName(node.getName()); 478 node.addAddress(this); 479 fireEntityChanged(this); 480 } 512 481 } 513 482 … … 520 489 */ 521 490 public String getGuessedValue(String tag) { 522 523 524 525 526 527 491 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 492 493 if (!hasGuessedValue(tag)) { 494 return null; 495 } 496 return guessedValues.get(tag); 528 497 } 529 498 … … 536 505 */ 537 506 public OsmPrimitive getGuessedObject(String tag) { 538 539 540 541 542 543 507 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 508 509 if (guessedObjects.containsKey(tag)) { 510 return guessedObjects.get(tag); 511 } 512 return null; 544 513 } 545 514 … … 551 520 */ 552 521 public Collection<OsmPrimitive> getGuessedObjects() { 553 554 555 556 522 if (guessedObjects == null) 523 return null; 524 525 return guessedObjects.values(); 557 526 } 558 527 … … 564 533 */ 565 534 public boolean needsGuess() { 566 567 568 569 570 535 return needsGuessedValue(TagUtils.ADDR_CITY_TAG) 536 || needsGuessedValue(TagUtils.ADDR_POSTCODE_TAG) 537 || needsGuessedValue(TagUtils.ADDR_COUNTRY_TAG) || 538 // needsGuessedValue(TagUtils.ADDR_STATE_TAG) || 539 needsGuessedValue(TagUtils.ADDR_STREET_TAG); 571 540 } 572 541 … … 577 546 */ 578 547 public boolean needsGuessedValue(String tag) { 579 548 return MISSING_TAG.equals(getTagValueWithGuess(tag)); 580 549 } 581 550 … … 584 553 */ 585 554 public void clearAllGuesses() { 586 555 guessedValues.clear(); 587 556 } 588 557 … … 596 565 */ 597 566 private boolean hasGuessedValue(String tag) { 598 599 600 601 567 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 568 569 return guessedValues.containsKey(tag) 570 && !StringUtils.isNullOrEmpty(guessedValues.get(tag)); 602 571 } 603 572 … … 613 582 */ 614 583 public void setGuessedValue(String tag, String value, OsmPrimitive osm) { 615 616 617 618 619 620 621 622 623 584 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 585 586 if (value != null && osm != null) { 587 guessedValues.put(tag, value); 588 if (osm != null) { 589 guessedObjects.put(tag, osm); 590 } 591 fireEntityChanged(this); 592 } 624 593 } 625 594 … … 633 602 */ 634 603 private boolean hasDerivedValue(String tag) { 635 636 637 638 604 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 605 606 return derivedValues.containsKey(tag) 607 && !StringUtils.isNullOrEmpty(derivedValues.get(tag)); 639 608 } 640 609 … … 645 614 */ 646 615 public boolean hasDerivedValues() { 647 616 return derivedValues.size() > 0; 648 617 } 649 618 … … 656 625 */ 657 626 public String getDerivedValue(String tag) { 658 659 660 661 627 if (!hasDerivedValue(tag)) { 628 return null; 629 } 630 return derivedValues.get(tag); 662 631 } 663 632 … … 671 640 */ 672 641 public void setDerivedValue(String tag, String value) { 673 642 derivedValues.put(tag, value); 674 643 } 675 644 … … 680 649 */ 681 650 public void setStreetName(String streetName) { 682 683 684 685 651 if (streetName != null && streetName.length() == 0) 652 return; 653 654 setOSMTag(TagUtils.ADDR_STREET_TAG, streetName); 686 655 } 687 656 … … 692 661 */ 693 662 public void setState(String state) { 694 695 696 697 663 if (state != null && state.length() == 0) 664 return; 665 666 setOSMTag(TagUtils.ADDR_STATE_TAG, state); 698 667 } 699 668 … … 704 673 */ 705 674 public void setCountry(String country) { 706 707 708 709 675 if (country != null && country.length() == 0) 676 return; 677 678 setOSMTag(TagUtils.ADDR_COUNTRY_TAG, country); 710 679 } 711 680 … … 716 685 */ 717 686 public void setPostCode(String postCode) { 718 if (postCode != null && postCode.length() == 0) 719 return; 720 721 setOSMTag(TagUtils.ADDR_POSTCODE_TAG, postCode); 722 } 723 724 /* 725 * (non-Javadoc) 726 * 727 * @see org.openstreetmap.josm.plugins.fixAddresses.OSMEntityBase#visit(org. 728 * openstreetmap.josm.plugins.fixAddresses.IProblemVisitor) 729 */ 687 if (postCode != null && postCode.length() == 0) 688 return; 689 690 setOSMTag(TagUtils.ADDR_POSTCODE_TAG, postCode); 691 } 692 730 693 @Override 731 694 public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor) { 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 695 CheckParameterUtil.ensureParameterNotNull(visitor, "visitor"); 696 697 // Check for street 698 if (!hasStreetName()) { 699 AddressProblem p = new AddressProblem(this, 700 tr("Address has no street")); 701 if (hasGuessedStreetName()) { // guess exists -> add solution entry 702 String tag = TagUtils.ADDR_STREET_TAG; 703 addGuessValueSolution(p, tag); 704 } 705 addRemoveAddressTagsSolution(p); 706 visitor.addProblem(p); 707 // Street name exists, but is invalid -> ask the all knowing trash 708 // heap 709 } else if (!trashHeap.isValidStreetName(getStreetName())) { 710 AddressProblem p = new AddressProblem(this, 711 tr("Address has no valid street")); 712 String match = trashHeap.getClosestStreetName(getStreetName()); 713 714 if (!StringUtils.isNullOrEmpty(match)) { 715 setGuessedStreetName(match, null); 716 addGuessValueSolution(p, TagUtils.ADDR_STREET_TAG); 717 } 718 visitor.addProblem(p); 719 } 720 721 // Check for postal code 722 if (!hasPostalCode()) { 723 AddressProblem p = new AddressProblem(this, 724 tr("Address has no post code")); 725 if (hasGuessedStreetName()) { 726 String tag = TagUtils.ADDR_POSTCODE_TAG; 727 addGuessValueSolution(p, tag); 728 } 729 addRemoveAddressTagsSolution(p); 730 visitor.addProblem(p); 731 } 732 733 // Check for city 734 if (!hasCity()) { 735 AddressProblem p = new AddressProblem(this, 736 tr("Address has no city")); 737 if (hasGuessedStreetName()) { 738 String tag = TagUtils.ADDR_CITY_TAG; 739 addGuessValueSolution(p, tag); 740 } 741 addRemoveAddressTagsSolution(p); 742 visitor.addProblem(p); 743 } 744 745 // Check for country 746 if (!hasCountry()) { 747 // TODO: Add guess for country 748 AddressProblem p = new AddressProblem(this, 749 tr("Address has no country")); 750 addRemoveAddressTagsSolution(p); 751 visitor.addProblem(p); 752 } 790 753 } 791 754 … … 799 762 */ 800 763 private void addGuessValueSolution(AddressProblem p, String tag) { 801 802 803 804 805 764 AddressSolution s = new AddressSolution(String.format("%s '%s'", 765 tr("Assign to"), getGuessedValue(tag)), 766 AddressActions.getApplyGuessesAction(), SolutionType.Change); 767 768 p.addSolution(s); 806 769 } 807 770 … … 813 776 */ 814 777 private void addRemoveAddressTagsSolution(IProblem problem) { 815 CheckParameterUtil.ensureParameterNotNull(problem, "problem"); 816 817 AddressSolution s = new AddressSolution(tr("Remove all address tags"), 818 AddressActions.getRemoveTagsAction(), SolutionType.Remove); 819 problem.addSolution(s); 820 } 821 822 /* 823 * (non-Javadoc) 824 * 825 * @see org.openstreetmap.josm.plugins.fixAddresses.OSMEntityBase#toString() 826 */ 778 CheckParameterUtil.ensureParameterNotNull(problem, "problem"); 779 780 AddressSolution s = new AddressSolution(tr("Remove all address tags"), 781 AddressActions.getRemoveTagsAction(), SolutionType.Remove); 782 problem.addSolution(s); 783 } 784 827 785 @Override 828 786 public String toString() { 829 787 return OSMAddress.getFormatString(this); 830 788 } 831 789 … … 838 796 */ 839 797 public static String getFormatString(OSMAddress node) { 840 841 842 843 844 845 846 847 848 849 850 798 // TODO: Add further countries here 799 // DE 800 String guessed = node.getGuessedStreetName(); 801 String sName = node.getStreetName(); 802 if (!StringUtils.isNullOrEmpty(guessed) && MISSING_TAG.equals(sName)) { 803 sName = String.format("(%s)", guessed); 804 } 805 806 return String.format("%s %s, %s-%s %s (%s) ", sName, 807 node.getHouseNumber(), node.getCountry(), node.getPostalCode(), 808 node.getCity(), node.getState()); 851 809 } 852 810 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMEntityBase.java
r29971 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 39 27 */ 40 28 public class OSMEntityBase implements IOSMEntity, Comparable<IOSMEntity> { 41 public static final String ANONYMOUS = tr("No name"); 42 private static List<IAddressEditContainerListener> containerListeners = new ArrayList<IAddressEditContainerListener>(); 43 private List<ICommandListener> cmdListeners = new ArrayList<ICommandListener>(); 44 45 protected OsmPrimitive osmObject; 46 47 /** 48 * @param osmObject 49 */ 50 public OSMEntityBase(OsmPrimitive osmObject) { 51 super(); 52 this.osmObject = osmObject; 53 } 54 55 /** 56 * @param osmObject the osmObject to set 57 */ 58 protected void setOsmObject(OsmPrimitive osmObject) { 59 CheckParameterUtil.ensureParameterNotNull(osmObject, "osmObject"); 60 this.osmObject = osmObject; 61 } 62 63 /** 64 * Adds a change listener. 65 * @param listener 66 */ 67 public static void addChangedListener(IAddressEditContainerListener listener) { 68 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 69 containerListeners.add(listener); 70 } 71 72 /** 73 * Removes a change listener. 74 * @param listener 75 */ 76 public static void removeChangedListener(IAddressEditContainerListener listener) { 77 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 78 containerListeners.remove(listener); 79 } 80 81 /** 82 * Notifies clients that the address container changed. 83 */ 84 protected static void fireEntityChanged(IOSMEntity entity) { 85 CheckParameterUtil.ensureParameterNotNull(entity, "entity"); 86 for (IAddressEditContainerListener listener : containerListeners) { 87 listener.entityChanged(entity); 88 } 89 } 90 91 /** 92 * Adds a command listener. 93 * @param listener 94 */ 95 public void addCommandListener(ICommandListener listener) { 96 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 97 cmdListeners.add(listener); 98 } 99 100 /** 101 * Removes a command listener. 102 * @param listener 103 */ 104 public void removeCommandListener(ICommandListener listener) { 105 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 106 cmdListeners.remove(listener); 107 } 108 109 /** 110 * Notifies clients that an entity has issued a command. 111 * 112 * @param source the entity that issued the command. 113 * @param command the command to execute. 114 */ 115 protected void fireCommandIssued(Command command) { 116 CheckParameterUtil.ensureParameterNotNull(command, "command"); 117 if (cmdListeners.size() == 0) { 118 throw new RuntimeException("Object has no TX context: " + this); 119 } 120 121 for (ICommandListener l : cmdListeners) { 122 l.commandIssued(this, command); 123 } 124 } 125 126 public OsmPrimitive getOsmObject() { 127 return osmObject; 128 } 129 130 @Override 131 public List<IOSMEntity> getChildren() { 132 return null; 133 } 134 135 @Override 136 /** 137 * Gets the name of the street or ANONYMOUS, if street has no name. 138 * @return 139 */ 140 public String getName() { 141 if (TagUtils.hasNameTag(osmObject)) { 142 return TagUtils.getNameValue(osmObject); 143 } 144 return ""; 145 } 146 147 /* (non-Javadoc) 148 * @see org.openstreetmap.josm.plugins.addressEdit.INodeEntity#hasName() 149 */ 150 @Override 151 public boolean hasName() { 152 return TagUtils.hasNameTag(osmObject); 153 } 154 155 /** 156 * Internal helper method which changes the given property and 157 * puts the appropriate command {@link src.org.openstreetmap.josm.command.Command} 158 * into the undo/redo queue. 159 * @param tag The tag to change. 160 * @param newValue The new value for the tag. 161 * @param cmd The surrounding command sequence 162 */ 163 protected void setOSMTag(String tag, String newValue) { 164 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 165 166 167 if (osmObject != null) { 168 String existingValue = osmObject.get(tag); 169 // Bugfix #9047: Keep existing values 170 if (!StringUtils.isNullOrEmpty(existingValue)) { 171 return; 172 } 173 174 if ((osmObject.hasKey(tag) && newValue == null) || newValue != null) { 175 fireCommandIssued(new ChangePropertyCommand(osmObject, tag, newValue)); 176 fireEntityChanged(this); 177 } 178 } 179 } 180 181 /** 182 * Removes the given tag from the OSM object. 183 * 184 * @param tag the tag 185 */ 186 protected void removeOSMTag(String tag) { 187 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 188 setOSMTag(tag, null); // a value of null removes the tag 189 } 190 191 /* (non-Javadoc) 192 * @see java.lang.Object#toString() 193 */ 194 @Override 195 public String toString() { 196 if (hasName()) { 197 return this.getClass().getName() + ": " + getName(); 198 } 199 return this.getClass().getName() + ": " + ANONYMOUS; 200 } 201 202 /* (non-Javadoc) 203 * @see java.lang.Comparable#compareTo(java.lang.Object) 204 */ 205 @Override 206 public int compareTo(IOSMEntity o) { 207 if (o == null || !(o instanceof OSMEntityBase)) return -1; 208 return this.getName().compareTo(o.getName()); 209 } 210 211 /* (non-Javadoc) 212 * @see org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity#visit(org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap, org.openstreetmap.josm.plugins.fixAddresses.IProblemVisitor) 213 */ 214 @Override 215 public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor) { 216 // do nothing 217 } 218 219 /* (non-Javadoc) 220 * @see org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity#getCoor() 221 */ 222 @Override 223 public LatLon getCoor() { 224 OsmPrimitive osm = getOsmObject(); 225 if (osm == null) return null; 226 227 if (osm instanceof Node) { 228 return ((Node)osm).getCoor(); 229 // way: return center 230 } else if (osm instanceof Way) { 231 Way w = (Way) osm; 232 BBox bb = w.getBBox(); 233 return bb.getBottomRight().getCenter(bb.getTopLeft()); 234 } 235 // relations?? 236 return null; 237 } 29 public static final String ANONYMOUS = tr("No name"); 30 private static List<IAddressEditContainerListener> containerListeners = new ArrayList<IAddressEditContainerListener>(); 31 private List<ICommandListener> cmdListeners = new ArrayList<ICommandListener>(); 32 33 protected OsmPrimitive osmObject; 34 35 /** 36 * @param osmObject 37 */ 38 public OSMEntityBase(OsmPrimitive osmObject) { 39 super(); 40 this.osmObject = osmObject; 41 } 42 43 /** 44 * @param osmObject the osmObject to set 45 */ 46 protected void setOsmObject(OsmPrimitive osmObject) { 47 CheckParameterUtil.ensureParameterNotNull(osmObject, "osmObject"); 48 this.osmObject = osmObject; 49 } 50 51 /** 52 * Adds a change listener. 53 * @param listener 54 */ 55 public static void addChangedListener(IAddressEditContainerListener listener) { 56 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 57 containerListeners.add(listener); 58 } 59 60 /** 61 * Removes a change listener. 62 * @param listener 63 */ 64 public static void removeChangedListener(IAddressEditContainerListener listener) { 65 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 66 containerListeners.remove(listener); 67 } 68 69 /** 70 * Notifies clients that the address container changed. 71 */ 72 protected static void fireEntityChanged(IOSMEntity entity) { 73 CheckParameterUtil.ensureParameterNotNull(entity, "entity"); 74 for (IAddressEditContainerListener listener : containerListeners) { 75 listener.entityChanged(entity); 76 } 77 } 78 79 /** 80 * Adds a command listener. 81 * @param listener 82 */ 83 public void addCommandListener(ICommandListener listener) { 84 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 85 cmdListeners.add(listener); 86 } 87 88 /** 89 * Removes a command listener. 90 * @param listener 91 */ 92 public void removeCommandListener(ICommandListener listener) { 93 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 94 cmdListeners.remove(listener); 95 } 96 97 /** 98 * Notifies clients that an entity has issued a command. 99 * 100 * @param source the entity that issued the command. 101 * @param command the command to execute. 102 */ 103 protected void fireCommandIssued(Command command) { 104 CheckParameterUtil.ensureParameterNotNull(command, "command"); 105 if (cmdListeners.size() == 0) { 106 throw new RuntimeException("Object has no TX context: " + this); 107 } 108 109 for (ICommandListener l : cmdListeners) { 110 l.commandIssued(this, command); 111 } 112 } 113 114 public OsmPrimitive getOsmObject() { 115 return osmObject; 116 } 117 118 @Override 119 public List<IOSMEntity> getChildren() { 120 return null; 121 } 122 123 @Override 124 /** 125 * Gets the name of the street or ANONYMOUS, if street has no name. 126 * @return 127 */ 128 public String getName() { 129 if (TagUtils.hasNameTag(osmObject)) { 130 return TagUtils.getNameValue(osmObject); 131 } 132 return ""; 133 } 134 135 @Override 136 public boolean hasName() { 137 return TagUtils.hasNameTag(osmObject); 138 } 139 140 /** 141 * Internal helper method which changes the given property and 142 * puts the appropriate command {@link src.org.openstreetmap.josm.command.Command} 143 * into the undo/redo queue. 144 * @param tag The tag to change. 145 * @param newValue The new value for the tag. 146 * @param cmd The surrounding command sequence 147 */ 148 protected void setOSMTag(String tag, String newValue) { 149 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 150 151 152 if (osmObject != null) { 153 String existingValue = osmObject.get(tag); 154 // Bugfix #9047: Keep existing values 155 if (!StringUtils.isNullOrEmpty(existingValue)) { 156 return; 157 } 158 159 if ((osmObject.hasKey(tag) && newValue == null) || newValue != null) { 160 fireCommandIssued(new ChangePropertyCommand(osmObject, tag, newValue)); 161 fireEntityChanged(this); 162 } 163 } 164 } 165 166 /** 167 * Removes the given tag from the OSM object. 168 * 169 * @param tag the tag 170 */ 171 protected void removeOSMTag(String tag) { 172 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 173 setOSMTag(tag, null); // a value of null removes the tag 174 } 175 176 @Override 177 public String toString() { 178 if (hasName()) { 179 return this.getClass().getName() + ": " + getName(); 180 } 181 return this.getClass().getName() + ": " + ANONYMOUS; 182 } 183 184 @Override 185 public int compareTo(IOSMEntity o) { 186 if (o == null || !(o instanceof OSMEntityBase)) return -1; 187 return this.getName().compareTo(o.getName()); 188 } 189 190 @Override 191 public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor) { 192 // do nothing 193 } 194 195 @Override 196 public LatLon getCoor() { 197 OsmPrimitive osm = getOsmObject(); 198 if (osm == null) return null; 199 200 if (osm instanceof Node) { 201 return ((Node)osm).getCoor(); 202 // way: return center 203 } else if (osm instanceof Way) { 204 Way w = (Way) osm; 205 BBox bb = w.getBBox(); 206 return bb.getBottomRight().getCenter(bb.getTopLeft()); 207 } 208 // relations?? 209 return null; 210 } 238 211 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMStreet.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 28 16 */ 29 17 public class OSMStreet extends OSMEntityBase { 30 31 18 private List<IOSMEntity> children; 19 private List<OSMAddress> addresses; 32 20 33 34 35 36 37 38 21 /** 22 * @param osmPrimitive 23 */ 24 public OSMStreet(OsmPrimitive osmPrimitive) { 25 super(osmPrimitive); 26 } 39 27 40 41 42 28 public List<IOSMEntity> getChildren() { 29 return children; 30 } 43 31 44 45 46 47 48 49 32 /** 33 * Adds a street segment to the street node. 34 * @param segment 35 */ 36 public void addStreetSegment(OSMStreetSegment segment) { 37 lazyCreateChildren(); 50 38 51 52 53 39 children.add(segment); 40 Collections.sort(children); 41 } 54 42 55 56 57 58 59 60 61 62 43 /** 44 * Lazy creation of children list. 45 */ 46 private void lazyCreateChildren() { 47 if (children == null) { 48 children = new ArrayList<IOSMEntity>(); 49 } 50 } 63 51 64 65 66 67 68 69 70 71 72 52 /** 53 * Adds an associated address to the street. 54 * 55 * @param aNode the address node to add 56 */ 57 public void addAddress(OSMAddress aNode) { 58 lazyCreateAddresses(); 59 addresses.add(aNode); 60 } 73 61 74 75 76 77 78 79 80 81 62 /** 63 * Lazy creation of address list. 64 */ 65 private void lazyCreateAddresses() { 66 if (addresses == null) { 67 addresses = new ArrayList<OSMAddress>(); 68 } 69 } 82 70 83 84 85 86 87 88 89 90 71 /** 72 * Checks for addresses. 73 * 74 * @return true, if street has one or more associated addresses. 75 */ 76 public boolean hasAddresses() { 77 return addresses != null && addresses.size() > 0; 78 } 91 79 92 93 94 80 public List<OSMAddress> getAddresses() { 81 return addresses; 82 } 95 83 96 97 98 84 public void setAddresses(List<OSMAddress> addresses) { 85 this.addresses = addresses; 86 } 99 87 100 101 102 103 104 105 88 /** 89 * Gets the number of addresses associated with this street. 90 * @return 91 */ 92 public int getNumberOfAddresses() { 93 if (addresses == null) return 0; 106 94 107 108 95 return addresses.size(); 96 } 109 97 110 111 112 113 114 115 98 /** 99 * Gets the number of street segments of this street. 100 * @return 101 */ 102 public int getNumberOfSegments() { 103 if (children == null) return 0; 116 104 117 118 119 120 121 122 123 124 105 int sc = 0; 106 for (IOSMEntity node : children) { 107 if (node instanceof OSMStreetSegment) { 108 sc++; 109 } 110 } 111 return sc; 112 } 125 113 126 127 128 129 130 131 132 114 /** 115 * Gets the road type(s) of this street. If the street has different types, 116 * they are separated by comma. 117 * @return 118 */ 119 public String getType() { 120 List<String> types = new ArrayList<String>(); 133 121 134 135 136 137 138 139 140 141 142 122 for (IOSMEntity seg : getChildren()) { 123 OsmPrimitive osmPrim = seg.getOsmObject(); 124 if (TagUtils.hasHighwayTag(osmPrim)) { 125 String val = osmPrim.get(TagUtils.HIGHWAY_TAG); 126 if (!types.contains(val)) { 127 types.add(val); 128 } 129 } 130 } 143 131 144 145 146 147 148 149 132 StringBuffer sb = new StringBuffer(20); 133 for (String string : types) { 134 if (sb.length() > 0) { 135 sb.append(", "); 136 } 137 sb.append(string); 150 138 151 152 153 139 } 140 return sb.toString(); 141 } 154 142 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 143 /** 144 * Checks if the attached way has an associated street relation. 145 * 146 * @return true, if this street has an "associatedStreet" relation. 147 */ 148 public boolean hasAssociatedStreetRelation() { 149 OsmPrimitive osm = getOsmObject(); 150 for (OsmPrimitive refs : osm.getReferrers()) { 151 if (refs instanceof Relation) { 152 Relation rel = (Relation) refs; 153 if (TagUtils.isAssociatedStreetRelation(rel)) { 154 return true; 155 } 156 } 157 } 158 return false; 159 } 172 160 173 /* (non-Javadoc) 174 * @see org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#toString() 175 */ 176 @Override 177 public String toString() { 178 StringBuffer sb = new StringBuffer(getName()); 161 @Override 162 public String toString() { 163 StringBuffer sb = new StringBuffer(getName()); 179 164 180 181 182 165 if (children != null) { 166 sb.append(String.format(", %d segments", children.size())); 167 } 183 168 184 185 186 169 if (addresses != null) { 170 sb.append(String.format(", %d address entries", addresses.size())); 171 } 187 172 188 return sb.toString(); 189 } 190 173 return sb.toString(); 174 } 191 175 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMStreetSegment.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 25 13 * 26 14 */ 27 28 15 public class OSMStreetSegment extends OSMEntityBase { 29 16 30 31 32 17 public OSMStreetSegment(OsmPrimitive osmObject) { 18 super(osmObject); 19 } 33 20 34 @Override 35 public List<IOSMEntity> getChildren() { 36 return null; 37 } 38 21 @Override 22 public List<IOSMEntity> getChildren() { 23 return null; 24 } 39 25 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OsmFactory.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 20 8 21 9 public class OsmFactory { 22 10 private static HashMap<String, OSMAddress> addressCache = new HashMap<String, OSMAddress>(); 23 11 24 25 26 27 28 29 30 31 12 /** 13 * Creates an address node from an OSM node, if possible. 14 * @param node 15 * @return 16 */ 17 public static OSMAddress createNode(Node node) { 18 if (TagUtils.isAddress(node)) { 19 String aid = "" + node.getId(); 32 20 33 34 35 36 37 38 39 40 41 21 OSMAddress aNode = lookup(aid); 22 if (aNode == null) { 23 aNode = new OSMAddress(node); 24 addressCache.put(aid, aNode); 25 } else { 26 aNode.setOsmObject(node); 27 } 28 return aNode; 29 } 42 30 43 44 31 return null; 32 } 45 33 46 47 48 49 50 51 52 53 54 34 /** 35 * Creates an node entity from an OSM way, if possible. 36 * @param way 37 * @return The new node instance or null; if given way is inappropriate. 38 */ 39 public static IOSMEntity createNodeFromWay(Way way) { 40 if (TagUtils.hasHighwayTag(way)) { 41 return new OSMStreetSegment(way); 42 } 55 43 56 57 58 44 // Check for building with address 45 if (way.isClosed() && TagUtils.hasBuildingTag(way) && TagUtils.isAddress(way)) { 46 String aid = "" + way.getId(); 59 47 60 61 62 63 64 65 66 48 OSMAddress aNode = lookup(aid); 49 if (aNode == null) { 50 aNode = new OSMAddress(way); 51 addressCache.put(aid, aNode); 52 } else { 53 aNode.setOsmObject(way); 54 } 67 55 68 69 70 71 56 return aNode; 57 } 58 return null; 59 } 72 60 73 74 75 76 77 78 61 private static OSMAddress lookup(String aid) { 62 if (addressCache.containsKey(aid)) { 63 return addressCache.get(aid); 64 } 65 return null; 66 } 79 67 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OsmUtils.java
r29967 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 35 23 public class OsmUtils { 36 24 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 25 /** 26 * Instantiates a new osm utils. 27 */ 28 private OsmUtils() {} 29 30 /** The cached locale. */ 31 private static String cachedLocale = null; 32 33 /** 34 * Gets the minimum distance of single coordinate to a way. 35 * 36 * @param coor the coordinate to get the minimum distance for. 37 * @param w the w the way to compare against 38 * @return the minimum distance between the given coordinate and the way 39 */ 40 public static double getMinimumDistanceToWay(LatLon coor, Way w) { 41 if (coor == null || w == null) return Double.POSITIVE_INFINITY; 42 43 double minDist = Double.MAX_VALUE; 44 List<Pair<Node,Node>> x = w.getNodePairs(true); 45 46 for (Pair<Node, Node> pair : x) { 47 LatLon ap = pair.a.getCoor(); 48 LatLon bp = pair.b.getCoor(); 49 50 double dist = findMinimum(ap, bp, coor); 51 if (dist < minDist) { 52 minDist = dist; 53 } 54 } 55 return minDist; 56 } 57 58 /** 59 * Find the minimum distance between a point and two way coordinates recursively. 60 * 61 * @param a the a the first way point coordinate 62 * @param b the b the second way point coordinate 63 * @param c the c the node coordinate 64 * @return the double the minimum distance in m of the way and the node 65 */ 66 private static double findMinimum(LatLon a, LatLon b, LatLon c) { 67 CheckParameterUtil.ensureParameterNotNull(c, "c"); 68 CheckParameterUtil.ensureParameterNotNull(b, "b"); 69 CheckParameterUtil.ensureParameterNotNull(a, "a"); 70 71 LatLon mid = new LatLon((a.lat() + b.lat()) / 2, (a.lon() + b.lon()) / 2); 72 73 double ac = a.greatCircleDistance(c); 74 double bc = b.greatCircleDistance(c); 75 double mc = mid.greatCircleDistance(c); 76 77 double min = Math.min(Math.min(ac, mc), bc); 78 79 80 if (min < 5.0) { // close enough? 81 return min; 82 } 83 84 if (mc < ac && mc < bc) { 85 // mid point has lower distance than a and b 86 if (ac > bc) { // recurse 87 return findMinimum(b, mid, c); 88 } else { 89 return findMinimum(a, mid, c); 90 } 91 } else { // mid point is not closer than a or b 92 return Math.min(ac, bc); 93 } 94 } 95 96 /** 97 * Checks, if the given address has a relation hosting the address values. This method looks 98 * for a relation of type 'associatedStreet' and checks the members for address values, if present. 99 * If the member has address values, this methods sets the derived properties of the address 100 * node accordingly. 101 * 102 * @param address The address to check. 103 * @return true, if an associated relation has been found. 104 */ 105 public static boolean getValuesFromRelation(OSMAddress address) { 106 if (address == null) { 107 return false; 108 } 109 110 boolean hasValuesFromRel = false; /* true, if we applied some address props from the relation */ 111 OsmPrimitive addrNode = address.getOsmObject(); 112 113 // check all referrers of the node 114 for (OsmPrimitive osm : addrNode.getReferrers()) { 115 if (osm instanceof Relation) { 116 Relation r = (Relation) osm; 117 // Relation has the right type? 118 if (!TagUtils.isAssociatedStreetRelation(r)) continue; 119 120 // check for 'street' members 121 for (RelationMember rm : r.getMembers()) { 122 if (TagUtils.isStreetMember(rm)) { 123 OsmPrimitive street = rm.getMember(); 124 if (TagUtils.hasHighwayTag(street)) { 125 String streetName = TagUtils.getNameValue(street); 126 if (!StringUtils.isNullOrEmpty(streetName)) { 127 // street name found -> set property 128 address.setDerivedValue(TagUtils.ADDR_STREET_TAG, streetName); 129 hasValuesFromRel = true; 130 break; 131 } // else: Street has no name: Ooops 132 } // else: Street member, but no highway tag: Ooops 133 } 134 } 135 136 // Check for other address properties 137 if (TagUtils.hasAddrCityTag(r)) { // city 138 address.setDerivedValue(TagUtils.ADDR_CITY_TAG, TagUtils.getAddrCityValue(r)); 139 hasValuesFromRel = true; 140 } 141 if (TagUtils.hasAddrCountryTag(r)) { // country 142 address.setDerivedValue(TagUtils.ADDR_COUNTRY_TAG, TagUtils.getAddrCountryValue(r)); 143 hasValuesFromRel = true; 144 } 145 if (TagUtils.hasAddrPostcodeTag(r)) { // postcode 146 address.setDerivedValue(TagUtils.ADDR_POSTCODE_TAG, TagUtils.getAddrPostcodeValue(r)); 147 hasValuesFromRel = true; 148 } 149 } 150 } 151 return hasValuesFromRel; 152 } 153 154 /** 155 * Gets the tag values from an address interpolation ref, if present. 156 * 157 * @param address The address 158 * @return true, if house numbers are given via address interpolation; otherwise false. 159 */ 160 public static boolean getValuesFromAddressInterpolation(OSMAddress address) { 161 if (address == null) return false; 162 163 OsmPrimitive osmAddr = address.getOsmObject(); 164 165 for (OsmPrimitive osm : osmAddr.getReferrers()) { 166 if (osm instanceof Way) { 167 Way w = (Way) osm; 168 if (TagUtils.hasAddrInterpolationTag(w)) { 169 applyDerivedValue(address, w, TagUtils.ADDR_POSTCODE_TAG); 170 applyDerivedValue(address, w, TagUtils.ADDR_CITY_TAG); 171 applyDerivedValue(address, w, TagUtils.ADDR_COUNTRY_TAG); 172 applyDerivedValue(address, w, TagUtils.ADDR_STREET_TAG); 173 applyDerivedValue(address, w, TagUtils.ADDR_STATE_TAG); 174 return true; 175 } 176 } 177 } 178 179 return false; 180 } 181 182 /** 183 * Gets the local code as string. 184 * 185 * @return the string representation of the local. 186 */ 187 public static String getLocale() { 188 // Check if user could prefer imperial system 189 if (cachedLocale == null) { 190 Locale l = Locale.getDefault(); 191 cachedLocale = l.toString(); 192 } 193 return cachedLocale; 194 } 195 196 /** 197 * Zooms to the given addresses. 198 * 199 * @param addressList the address list 200 */ 201 public static void zoomAddresses(List<OSMAddress> addressList) { 202 CheckParameterUtil.ensureParameterNotNull(addressList, "addressList"); 203 204 if (Main.map == null && Main.map.mapView == null) return; // nothing to do 205 if (addressList.size() == 0) return; // dto. 206 207 // compute bounding box 208 BoundingXYVisitor bbox = new BoundingXYVisitor(); 209 for (OSMAddress source : addressList) { 210 OsmPrimitive osm = source.getOsmObject(); 211 Bounds b = new Bounds(osm.getBBox().getTopLeft(), osm.getBBox().getBottomRight()); 212 bbox.visit(b); 213 } 214 215 if (bbox.getBounds() != null) { 216 // zoom to calculated bounding box 217 Main.map.mapView.zoomTo(bbox.getBounds()); 218 } 219 } 220 221 /** 222 * Helper method to set a derived value of an address node. 223 * 224 * @param address The address to change 225 * @param w the way containing the tag for the derived value. 226 * @param tag the tag to set as applied value. 227 */ 228 private static void applyDerivedValue(OSMAddress address, Way w, String tag) { 229 CheckParameterUtil.ensureParameterNotNull(address, "address"); 230 CheckParameterUtil.ensureParameterNotNull(w, "way"); 231 232 if (!address.hasTag(tag) && TagUtils.hasTag(w, tag)) { 233 address.setDerivedValue(tag, w.get(tag)); 234 } 235 } 248 236 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/PostalCodeChecker.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 23 11 */ 24 12 public class PostalCodeChecker { 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 13 private static HashMap<String, String> postalCodePatternMap = new HashMap<String, String>(); 14 15 static { 16 fillMap(); 17 } 18 19 /** 20 * Checks if given address has a valid postal code. 21 * 22 * @param address the address to check the postal code for 23 * @return true, if postal code is valid (this implies 24 * also that a country is NOT supported); otherwise false. 25 */ 26 public static boolean hasValidPostalCode(OSMAddress address) { 27 CheckParameterUtil.ensureParameterNotNull(address, "address"); 28 29 if (!address.hasPostalCode()) { 30 return false; // no postal code available 31 } 32 33 String ctry = getCountry(address); 34 String postalCode = address.getPostalCode(); 35 36 return hasValidPostalCode(ctry, postalCode); 37 } 38 39 /** 40 * Checks if postal code is valid for the country reported by the Java VM. 41 * 42 * @param postalCode the postal code 43 * @return true, if successful 44 */ 45 public static boolean hasValidPostalCode(String postalCode) { 46 return hasValidPostalCode(getCountry(), postalCode); 47 } 48 49 /** 50 * Checks if given postal code if valid for the specified country. 51 * 52 * @param country the country 53 * @param postalCode the postal code 54 * @return true, if successful 55 */ 56 public static boolean hasValidPostalCode(String country, String postalCode) { 57 // Get country-specific pattern for postal code 58 if (postalCodePatternMap.containsKey(country)) { 59 String pattern = postalCodePatternMap.get(country); 60 // Check if postal code matches pattern 61 return postalCode.matches(pattern); 62 } else { 63 // we cannot validate; assume postal code as valid until we know better 64 return true; 65 } 66 } 67 68 /** 69 * Checks if validation for the given country is supported. 70 * 71 * @param country 2-letter ISO-Code (e. g. "GB", "US", "IT") of the country to check. 72 * @return true, if is validation supported; otherwise false 73 */ 74 public static boolean isValidationSupported(String country) { 75 CheckParameterUtil.ensureParameterNotNull(country, "country"); 76 return postalCodePatternMap.containsKey(country.toUpperCase()); 77 } 78 79 /** 80 * Checks if validation for the given address is supported. 81 * 82 * @param address the address to check postal code validation support for. 83 * @return true, if is validation supported; otherwise false 84 */ 85 public static boolean isValidationSupported(OSMAddress address) { 86 CheckParameterUtil.ensureParameterNotNull(address, "address"); 87 88 String ctry = getCountry(address); 89 return postalCodePatternMap.containsKey(ctry); 90 } 91 92 /** 93 * Gets the current country. 94 * 95 * @return the country of the Java VM. 96 */ 97 public static String getCountry() { 98 return getCountry(null); 99 } 100 101 /** 102 * Gets the country of the given address. 103 * 104 * @param address the address to get the country for 105 * @return the country of the address. If the given address has no postal code, 106 * the default country of the Java VM is returned instead. 107 */ 108 private static String getCountry(OSMAddress address) { 109 String ctry = Locale.getDefault().getCountry(); 110 if (address != null && address.hasCountry()) { 111 // If address has a country, use this one (e. g. a dutch edits UK data) 112 ctry = address.getCountry().toUpperCase(); 113 } 114 return ctry; 115 } 116 117 /** 118 * Fills the country-postal code pattern map. 119 */ 120 private static void fillMap() { 121 /* 122 String[] countries = Locale.getISOCountries(); 123 124 for (int i = 0; i < countries.length; i++) { 125 System.out.println("//postalCodePatternMap.put(\"" + countries[i] + "\", \"[0-9]{5}\");"); 126 } 127 128 String x = "A9999AAA"; 129 130 if (x.matches("[A-Z]{1}[0-9]{4}[A-Z]{3}")) { 131 System.out.println("YES"); 132 } 133 134 String xx = "99999-999"; 135 // "[0-9]{5}\-[0-9]{3}"); // 136 if (xx.matches("[0-9]{5}-[0-9]{3}")) { 137 System.out.println("YES"); 138 } 139 140 141 String[] xxx = new String[]{"A9 9AA", "A99 9AA", "A9A 9AA", "AA9 9AA", "AA99 9AA", "AA9A 9AA"}; 142 for (int i = 0; i < xxx.length; i++) { 143 if (!xxx[i].matches("[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1}[A-Z]{2}")) { 144 System.err.println(xxx[i]); 145 } 146 }*/ 147 // see http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html for country codes 148 // 149 150 //postalCodePatternMap.put("AD", "[0-9]{5}"); 151 //postalCodePatternMap.put("AE", "[0-9]{5}"); 152 //postalCodePatternMap.put("AF", "[0-9]{5}"); 153 //postalCodePatternMap.put("AG", "[0-9]{5}"); 154 //postalCodePatternMap.put("AI", "[0-9]{5}"); 155 postalCodePatternMap.put("AL", "[0-9]{5}"); 156 postalCodePatternMap.put("AM", "[0-9]{4}"); 157 //postalCodePatternMap.put("AN", "[0-9]{5}"); 158 //postalCodePatternMap.put("AO", "[0-9]{5}"); 159 //postalCodePatternMap.put("AQ", "[0-9]{5}"); 160 postalCodePatternMap.put("AR", "[A-Z]{1}[0-9]{4}[A-Z]{3}"); // Argentina 161 //postalCodePatternMap.put("AS", "[0-9]{5}"); 162 postalCodePatternMap.put("AT", "[0-9]{4}"); // Austria 163 postalCodePatternMap.put("AU", "[0-9]{4}"); // Australia 164 //postalCodePatternMap.put("AW", "[0-9]{5}"); 165 //postalCodePatternMap.put("AX", "[0-9]{5}"); 166 //postalCodePatternMap.put("AZ", "[0-9]{5}"); 167 //postalCodePatternMap.put("BA", "[0-9]{5}"); 168 //postalCodePatternMap.put("BB", "[0-9]{5}"); 169 //postalCodePatternMap.put("BD", "[0-9]{5}"); 170 //postalCodePatternMap.put("BE", "[0-9]{5}"); 171 //postalCodePatternMap.put("BF", "[0-9]{5}"); 172 //postalCodePatternMap.put("BG", "[0-9]{5}"); 173 //postalCodePatternMap.put("BH", "[0-9]{5}"); 174 //postalCodePatternMap.put("BI", "[0-9]{5}"); 175 //postalCodePatternMap.put("BJ", "[0-9]{5}"); 176 //postalCodePatternMap.put("BL", "[0-9]{5}"); 177 //postalCodePatternMap.put("BM", "[0-9]{5}"); 178 //postalCodePatternMap.put("BN", "[0-9]{5}"); 179 //postalCodePatternMap.put("BO", "[0-9]{5}"); 180 postalCodePatternMap.put("BR", "[0-9]{5}-[0-9]{3}"); // 99999-999 181 //postalCodePatternMap.put("BS", "[0-9]{5}"); 182 //postalCodePatternMap.put("BT", "[0-9]{5}"); 183 //postalCodePatternMap.put("BV", "[0-9]{5}"); 184 //postalCodePatternMap.put("BW", "[0-9]{5}"); 185 //postalCodePatternMap.put("BY", "[0-9]{5}"); 186 //postalCodePatternMap.put("BZ", "[0-9]{5}"); 187 postalCodePatternMap.put("CA", "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"); // Canada A9A 9A9 188 //postalCodePatternMap.put("CC", "[0-9]{5}"); 189 //postalCodePatternMap.put("CD", "[0-9]{5}"); 190 //postalCodePatternMap.put("CF", "[0-9]{5}"); 191 //postalCodePatternMap.put("CG", "[0-9]{5}"); 192 postalCodePatternMap.put("CH", "[0-9]{4}"); // Switzerland 193 //postalCodePatternMap.put("CI", "[0-9]{5}"); 194 //postalCodePatternMap.put("CK", "[0-9]{5}"); 195 //postalCodePatternMap.put("CL", "[0-9]{5}"); 196 //postalCodePatternMap.put("CM", "[0-9]{5}"); 197 postalCodePatternMap.put("CN", "[0-9]{6}"); // China 198 //postalCodePatternMap.put("CO", "[0-9]{5}"); 199 //postalCodePatternMap.put("CR", "[0-9]{5}"); 200 //postalCodePatternMap.put("CS", "[0-9]{5}"); 201 //postalCodePatternMap.put("CU", "[0-9]{5}"); 202 //postalCodePatternMap.put("CV", "[0-9]{5}"); 203 //postalCodePatternMap.put("CX", "[0-9]{5}"); 204 //postalCodePatternMap.put("CY", "[0-9]{5}"); 205 postalCodePatternMap.put("CZ", "[0-9]{3} [0-9]{2}"); // Czech: 999-99 206 postalCodePatternMap.put("DE", "[0-9]{5}"); // Germany 207 //postalCodePatternMap.put("DJ", "[0-9]{5}"); 208 postalCodePatternMap.put("DK", "[0-9]{4}"); // Denmark 209 //postalCodePatternMap.put("DM", "[0-9]{5}"); 210 //postalCodePatternMap.put("DO", "[0-9]{5}"); 211 //postalCodePatternMap.put("DZ", "[0-9]{5}"); 212 //postalCodePatternMap.put("EC", "[0-9]{5}"); 213 postalCodePatternMap.put("EE", "[0-9]{5}"); // Estonia 214 //postalCodePatternMap.put("EG", "[0-9]{5}"); 215 //postalCodePatternMap.put("EH", "[0-9]{5}"); 216 //postalCodePatternMap.put("ER", "[0-9]{5}"); 217 postalCodePatternMap.put("ES", "[0-9]{5}"); 218 //postalCodePatternMap.put("ET", "[0-9]{5}"); 219 postalCodePatternMap.put("FI", "[0-9]{5}"); 220 //postalCodePatternMap.put("FJ", "[0-9]{5}"); 221 //postalCodePatternMap.put("FK", "[0-9]{5}"); 222 //postalCodePatternMap.put("FM", "[0-9]{5}"); 223 //postalCodePatternMap.put("FO", "[0-9]{5}"); 224 postalCodePatternMap.put("FR", "[0-9]{5}"); // France 225 //postalCodePatternMap.put("GA", "[0-9]{5}"); 226 postalCodePatternMap.put("GB", "[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1}[A-Z]{2}"); // UK 227 //postalCodePatternMap.put("GD", "[0-9]{5}"); 228 //postalCodePatternMap.put("GE", "[0-9]{5}"); 229 //postalCodePatternMap.put("GF", "[0-9]{5}"); 230 //postalCodePatternMap.put("GG", "[0-9]{5}"); 231 //postalCodePatternMap.put("GH", "[0-9]{5}"); 232 //postalCodePatternMap.put("GI", "[0-9]{5}"); 233 //postalCodePatternMap.put("GL", "[0-9]{5}"); 234 //postalCodePatternMap.put("GM", "[0-9]{5}"); 235 //postalCodePatternMap.put("GN", "[0-9]{5}"); 236 //postalCodePatternMap.put("GP", "[0-9]{5}"); 237 //postalCodePatternMap.put("GQ", "[0-9]{5}"); 238 postalCodePatternMap.put("GR", "[0-9]{5}"); // Greece 239 //postalCodePatternMap.put("GS", "[0-9]{5}"); 240 //postalCodePatternMap.put("GT", "[0-9]{5}"); 241 //postalCodePatternMap.put("GU", "[0-9]{5}"); 242 //postalCodePatternMap.put("GW", "[0-9]{5}"); 243 //postalCodePatternMap.put("GY", "[0-9]{5}"); 244 //postalCodePatternMap.put("HK", "[0-9]{5}"); 245 //postalCodePatternMap.put("HM", "[0-9]{5}"); 246 //postalCodePatternMap.put("HN", "[0-9]{5}"); 247 postalCodePatternMap.put("HR", "[0-9]{5}"); // Croatia (Hrvatska) 248 //postalCodePatternMap.put("HT", "[0-9]{5}"); 249 postalCodePatternMap.put("HU", "[0-9]{4}"); // Hungary 250 //postalCodePatternMap.put("ID", "[0-9]{5}"); 251 //postalCodePatternMap.put("IE", "[0-9]{5}"); 252 postalCodePatternMap.put("IL", "[0-9]{5}"); 253 //postalCodePatternMap.put("IM", "[0-9]{5}"); 254 //postalCodePatternMap.put("IN", "[0-9]{5}"); 255 //postalCodePatternMap.put("IO", "[0-9]{5}"); 256 //postalCodePatternMap.put("IQ", "[0-9]{5}"); 257 //postalCodePatternMap.put("IR", "[0-9]{5}"); 258 postalCodePatternMap.put("IS", "[0-9]{3}"); // Iceland 259 postalCodePatternMap.put("IT", "[0-9]{5}"); // Italy 260 //postalCodePatternMap.put("JE", "[0-9]{5}"); 261 //postalCodePatternMap.put("JM", "[0-9]{5}"); 262 //postalCodePatternMap.put("JO", "[0-9]{5}"); 263 postalCodePatternMap.put("JP", "[0-9]{3}-[0-9]{4}"); // Japan: 999-9999 264 //postalCodePatternMap.put("KE", "[0-9]{5}"); 265 //postalCodePatternMap.put("KG", "[0-9]{5}"); 266 //postalCodePatternMap.put("KH", "[0-9]{5}"); 267 //postalCodePatternMap.put("KI", "[0-9]{5}"); 268 //postalCodePatternMap.put("KM", "[0-9]{5}"); 269 //postalCodePatternMap.put("KN", "[0-9]{5}"); 270 //postalCodePatternMap.put("KP", "[0-9]{5}"); 271 //postalCodePatternMap.put("KR", "[0-9]{5}"); 272 //postalCodePatternMap.put("KW", "[0-9]{5}"); 273 //postalCodePatternMap.put("KY", "[0-9]{5}"); 274 //postalCodePatternMap.put("KZ", "[0-9]{5}"); 275 postalCodePatternMap.put("LA", "[0-9]{5}"); 276 //postalCodePatternMap.put("LB", "[0-9]{5}"); 277 //postalCodePatternMap.put("LC", "[0-9]{5}"); 278 postalCodePatternMap.put("LI", "[0-9]{4}"); 279 //postalCodePatternMap.put("LK", "[0-9]{5}"); 280 //postalCodePatternMap.put("LR", "[0-9]{5}"); 281 //postalCodePatternMap.put("LS", "[0-9]{5}"); 282 postalCodePatternMap.put("LT", "[0-9]{5}"); 283 postalCodePatternMap.put("LU", "[0-9]{4}"); 284 postalCodePatternMap.put("LV", "[0-9]{4}"); // Latvia 285 //postalCodePatternMap.put("LY", "[0-9]{5}"); 286 //postalCodePatternMap.put("MA", "[0-9]{5}"); 287 //postalCodePatternMap.put("MC", "[0-9]{5}"); 288 //postalCodePatternMap.put("MD", "[0-9]{5}"); 289 postalCodePatternMap.put("ME", "[0-9]{5}"); // Montenegro 290 //postalCodePatternMap.put("MF", "[0-9]{5}"); 291 //postalCodePatternMap.put("MG", "[0-9]{5}"); 292 //postalCodePatternMap.put("MH", "[0-9]{5}"); 293 //postalCodePatternMap.put("MK", "[0-9]{5}"); 294 //postalCodePatternMap.put("ML", "[0-9]{5}"); 295 //postalCodePatternMap.put("MM", "[0-9]{5}"); 296 //postalCodePatternMap.put("MN", "[0-9]{5}"); 297 //postalCodePatternMap.put("MO", "[0-9]{5}"); 298 //postalCodePatternMap.put("MP", "[0-9]{5}"); 299 //postalCodePatternMap.put("MQ", "[0-9]{5}"); 300 //postalCodePatternMap.put("MR", "[0-9]{5}"); 301 //postalCodePatternMap.put("MS", "[0-9]{5}"); 302 //postalCodePatternMap.put("MT", "[0-9]{5}"); 303 //postalCodePatternMap.put("MU", "[0-9]{5}"); 304 //postalCodePatternMap.put("MV", "[0-9]{5}"); 305 //postalCodePatternMap.put("MW", "[0-9]{5}"); 306 postalCodePatternMap.put("MX", "[0-9]{5}"); // Mexico 307 //postalCodePatternMap.put("MY", "[0-9]{5}"); 308 //postalCodePatternMap.put("MZ", "[0-9]{5}"); 309 //postalCodePatternMap.put("NA", "[0-9]{5}"); 310 //postalCodePatternMap.put("NC", "[0-9]{5}"); 311 //postalCodePatternMap.put("NE", "[0-9]{5}"); 312 //postalCodePatternMap.put("NF", "[0-9]{5}"); 313 //postalCodePatternMap.put("NG", "[0-9]{5}"); 314 //postalCodePatternMap.put("NI", "[0-9]{5}"); 315 postalCodePatternMap.put("NL", "[0-9]{4} [A-Z]{2}"); // Dutch 316 postalCodePatternMap.put("NO", "[0-9]{4}"); // Norway 317 //postalCodePatternMap.put("NP", "[0-9]{5}"); 318 //postalCodePatternMap.put("NR", "[0-9]{5}"); 319 //postalCodePatternMap.put("NU", "[0-9]{5}"); 320 //postalCodePatternMap.put("NZ", "[0-9]{5}"); 321 //postalCodePatternMap.put("OM", "[0-9]{5}"); 322 //postalCodePatternMap.put("PA", "[0-9]{5}"); 323 //postalCodePatternMap.put("PE", "[0-9]{5}"); 324 //postalCodePatternMap.put("PF", "[0-9]{5}"); 325 //postalCodePatternMap.put("PG", "[0-9]{5}"); 326 //postalCodePatternMap.put("PH", "[0-9]{5}"); 327 //postalCodePatternMap.put("PK", "[0-9]{5}"); 328 postalCodePatternMap.put("PL", "[0-9]{2}-[0-9]{3}"); // Poland 329 //postalCodePatternMap.put("PM", "[0-9]{5}"); 330 //postalCodePatternMap.put("PN", "[0-9]{5}"); 331 //postalCodePatternMap.put("PR", "[0-9]{5}"); 332 //postalCodePatternMap.put("PS", "[0-9]{5}"); 333 postalCodePatternMap.put("PT", "[0-9]{4}-[0-9]{3}"); // Portugal 334 //postalCodePatternMap.put("PW", "[0-9]{5}"); 335 //postalCodePatternMap.put("PY", "[0-9]{5}"); 336 //postalCodePatternMap.put("QA", "[0-9]{5}"); 337 //postalCodePatternMap.put("RE", "[0-9]{5}"); 338 postalCodePatternMap.put("RO", "[0-9]{6}"); // Romania 339 //postalCodePatternMap.put("RS", "[0-9]{5}"); 340 postalCodePatternMap.put("RU", "[0-9]{6}"); // Russia 341 //postalCodePatternMap.put("RW", "[0-9]{5}"); 342 //postalCodePatternMap.put("SA", "[0-9]{5}"); 343 //postalCodePatternMap.put("SB", "[0-9]{5}"); 344 //postalCodePatternMap.put("SC", "[0-9]{5}"); 345 //postalCodePatternMap.put("SD", "[0-9]{5}"); 346 postalCodePatternMap.put("SE", "[0-9]{3} [0-9]{2}"); // Sweden: 999-99 347 //postalCodePatternMap.put("SG", "[0-9]{5}"); 348 //postalCodePatternMap.put("SH", "[0-9]{5}"); 349 postalCodePatternMap.put("SI", "[0-9]{4}"); 350 //postalCodePatternMap.put("SJ", "[0-9]{5}"); 351 postalCodePatternMap.put("SK", "[0-9]{3} [0-9]{2}"); // Slovakia: 999-99 352 postalCodePatternMap.put("SL", "[0-9]{4}"); // Slowenia 353 postalCodePatternMap.put("SM", "[0-9]{5}"); // san marino -> Italy 354 //postalCodePatternMap.put("SN", "[0-9]{5}"); 355 //postalCodePatternMap.put("SO", "[0-9]{5}"); 356 //postalCodePatternMap.put("SR", "[0-9]{5}"); 357 //postalCodePatternMap.put("ST", "[0-9]{5}"); 358 //postalCodePatternMap.put("SV", "[0-9]{5}"); 359 //postalCodePatternMap.put("SY", "[0-9]{5}"); 360 //postalCodePatternMap.put("SZ", "[0-9]{5}"); 361 //postalCodePatternMap.put("TC", "[0-9]{5}"); 362 //postalCodePatternMap.put("TD", "[0-9]{5}"); 363 //postalCodePatternMap.put("TF", "[0-9]{5}"); 364 //postalCodePatternMap.put("TG", "[0-9]{5}"); 365 //postalCodePatternMap.put("TH", "[0-9]{5}"); 366 //postalCodePatternMap.put("TJ", "[0-9]{5}"); 367 //postalCodePatternMap.put("TK", "[0-9]{5}"); 368 //postalCodePatternMap.put("TL", "[0-9]{5}"); 369 //postalCodePatternMap.put("TM", "[0-9]{5}"); 370 //postalCodePatternMap.put("TN", "[0-9]{5}"); 371 //postalCodePatternMap.put("TO", "[0-9]{5}"); 372 postalCodePatternMap.put("TR", "[0-9]{5}"); // turkye 373 //postalCodePatternMap.put("TT", "[0-9]{5}"); 374 //postalCodePatternMap.put("TV", "[0-9]{5}"); 375 //postalCodePatternMap.put("TW", "[0-9]{5}"); 376 //postalCodePatternMap.put("TZ", "[0-9]{5}"); 377 postalCodePatternMap.put("UA", "[0-9]{5}"); // Ukraine 378 //postalCodePatternMap.put("UG", "[0-9]{5}"); 379 //postalCodePatternMap.put("UM", "[0-9]{5}"); 380 postalCodePatternMap.put("US", "([A-Z]{2} )?[0-9]{5}"); // USA: support "99999" and "IL 99999" 381 //postalCodePatternMap.put("UY", "[0-9]{5}"); 382 //postalCodePatternMap.put("UZ", "[0-9]{5}"); 383 //postalCodePatternMap.put("VA", "[0-9]{5}"); 384 //postalCodePatternMap.put("VC", "[0-9]{5}"); 385 //postalCodePatternMap.put("VE", "[0-9]{5}"); 386 //postalCodePatternMap.put("VG", "[0-9]{5}"); 387 //postalCodePatternMap.put("VI", "[0-9]{5}"); 388 //postalCodePatternMap.put("VN", "[0-9]{5}"); 389 //postalCodePatternMap.put("VU", "[0-9]{5}"); 390 //postalCodePatternMap.put("WF", "[0-9]{5}"); 391 //postalCodePatternMap.put("WS", "[0-9]{5}"); 392 //postalCodePatternMap.put("YE", "[0-9]{5}"); 393 //postalCodePatternMap.put("YT", "[0-9]{5}"); 394 //postalCodePatternMap.put("ZA", "[0-9]{5}"); 395 //postalCodePatternMap.put("ZM", "[0-9]{5}"); 396 //postalCodePatternMap.put("ZW", "[0-9]{5}"); 397 } 410 398 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/ProblemType.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 16 4 public enum ProblemType { 17 18 5 Warning, 6 Error, 19 7 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/SolutionType.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 19 7 */ 20 8 public enum SolutionType { 21 22 23 9 Remove, 10 Change, 11 Add 24 12 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/StringUtils.java
r26509 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 17 5 18 6 public class StringUtils { 19 20 21 22 23 24 25 26 27 28 7 /** 8 * Checks, if a string is either null or empty. 9 * 10 * @param txt 11 * Text to check 12 * @return True, if string is null or empty; otherwise false 13 */ 14 public static boolean isNullOrEmpty(String txt) { 15 return txt == null || txt.length() == 0; 16 } 29 17 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 18 /** 19 * Gets the length of the longest common substring of a and b 20 * 21 * @param a 22 * First string 23 * @param b 24 * Second string 25 * @return The length of the longest common substring or 0, if no common 26 * sequence exists or one of the arguments are invalid. For 27 * algorithm details please refer to {@link http 28 * ://www.ics.uci.edu/~eppstein/161/960229.html} 29 */ 30 public static int lcsLength(String a, String b) { 31 if (StringUtils.isNullOrEmpty(a)) 32 return 0; 33 if (StringUtils.isNullOrEmpty(b)) 34 return 0; 47 35 48 49 50 36 int[][] L = createLCSTable(a, b); 37 return L[0][0]; 38 } 51 39 52 53 54 55 56 57 58 59 40 /** 41 * Internal use only 42 */ 43 private static int[][] createLCSTable(String a, String b) { 44 if (StringUtils.isNullOrEmpty(a)) 45 return null; 46 if (StringUtils.isNullOrEmpty(b)) 47 return null; 60 48 61 62 63 64 65 66 49 int m = a.length(); 50 int n = b.length(); 51 int[][] l = new int[m + 1][n + 1]; 52 for (int i = 0; i < l.length; i++) { 53 l[i] = new int[n + 1]; 54 } 67 55 68 69 70 71 72 73 74 75 76 77 78 79 80 81 56 int i, j; 57 for (i = m - 1; i >= 0; i--) { 58 for (j = n - 1; j >= 0; j--) { 59 /* 60 * if (i >= m || j >= n) { l[i][j] = 0; } else 61 */if (a.charAt(i) == b.charAt(j)) { 62 l[i][j] = 1 + l[i + 1][j + 1]; 63 } else { 64 l[i][j] = Math.max(l[i + 1][j], l[i][j + 1]); 65 } 66 } 67 } 68 return l; 69 } 82 70 83 84 85 86 87 88 89 90 91 92 93 94 71 /** 72 * Gets the longest common substring of a and b. 73 * 74 * @param a The first string. 75 * @param b The second string. 76 * @return 77 */ 78 public static String getLongestCommonSubstring(String a, String b) { 79 if (StringUtils.isNullOrEmpty(a)) 80 return null; 81 if (StringUtils.isNullOrEmpty(b)) 82 return null; 95 83 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 84 StringBuffer sb = new StringBuffer(); 85 int[][] l = createLCSTable(a, b); 86 int m = a.length(); 87 int n = b.length(); 88 int i = 0; 89 int j = 0; 90 while (i < m && j < n) { 91 char aa = a.charAt(i); 92 char bb = b.charAt(j); 93 if (aa == bb) { 94 sb.append(aa); 95 i++; 96 j++; 97 } else if (l[i + 1][j] >= l[i][j + 1]) { 98 i++; 99 } else { 100 j++; 101 } 102 } 115 103 116 117 118 104 l = null; 105 return sb.toString(); 106 } 119 107 120 121 122 123 124 125 126 127 128 108 /** 109 * @param needle The string to find the best match for. 110 * @param haystack The list of strings to pick the best match from. 111 * @return The string of the list with the longest common substring to needle or 112 * <tt>null</tt>, if either <tt>needle</tt> or <tt>haystack</tt> is empty or null. 113 */ 114 public static String findBestMatch(String needle, List<String> haystack) { 115 String bestMatch = null; 116 double maxRatio = Double.MIN_VALUE; 129 117 130 131 132 133 134 135 118 if (StringUtils.isNullOrEmpty(needle)) { 119 return null; 120 } 121 if (haystack == null || haystack.size() == 0) { 122 return null; 123 } 136 124 137 138 139 140 141 142 143 144 125 int lNeedle = needle.length(); 126 for (String curString : haystack) { 127 int ll = lcsLength(needle, curString); 128 double ratio = ll / (double)lNeedle; 129 if (ratio > maxRatio) { 130 maxRatio = ratio; 131 bestMatch = curString; 132 } 145 133 146 134 } 147 135 148 149 136 return bestMatch; 137 } 150 138 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/TagUtils.java
r27338 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses; 15 3 … … 27 15 */ 28 16 public final class TagUtils { 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 17 private static String COUNTRIES_REQUIRE_STATE[] = { 18 "en_US", /* USA */ 19 "en_AU" /* Australia */ 20 }; 21 22 /** 23 * Checks if the given OSM object has a (non-empty) value for the given tag. 24 * 25 * @param osm the osm object to inspect. 26 * @param tag the tag to look for. 27 * @return true, if osm object has a non-empty value for this tag 28 */ 29 public static boolean hasTag(OsmPrimitive osm, String tag) { 30 return osm != null && !StringUtils.isNullOrEmpty(osm.get(tag)); 31 } 32 33 /** 34 * Checks if the given OSM primitive is an address node. 35 * @return 36 */ 37 public static boolean isAddress(OsmPrimitive osmObject) { 38 return TagUtils.hasAddrCityTag(osmObject) || TagUtils.hasAddrCountryTag(osmObject) || 39 TagUtils.hasAddrHousenumberTag(osmObject) || TagUtils.hasAddrPostcodeTag(osmObject) || 40 TagUtils.hasAddrStateTag(osmObject) || TagUtils.hasAddrStreetTag(osmObject); 41 } 42 43 /** 44 * Check if OSM primitive has a tag 'parking'. 45 * 46 * @param osmPrimitive 47 * The OSM entity to check. 48 */ 49 public static boolean hasParkingTag(OsmPrimitive osmPrimitive) { 50 return osmPrimitive != null ? osmPrimitive.hasKey(PARKING_TAG) : false; 51 } 52 53 /** 54 * Gets the value of tag 'parking'. 55 * 56 * @param osmPrimitive 57 * The OSM entity to check. 58 */ 59 public static String getParkingValue(OsmPrimitive osmPrimitive) { 60 return osmPrimitive != null ? osmPrimitive.get(PARKING_TAG) : null; 61 } 62 63 /** 64 * Check if OSM primitive has a tag 'shop'. 65 * 66 * @param osmPrimitive 67 * The OSM entity to check. 68 */ 69 public static boolean hasShopTag(OsmPrimitive osmPrimitive) { 70 return osmPrimitive != null ? osmPrimitive.hasKey(SHOP_TAG) : false; 71 } 72 73 /** 74 * Gets the value of tag 'shop'. 75 * 76 * @param osmPrimitive 77 * The OSM entity to check. 78 */ 79 public static String getShopValue(OsmPrimitive osmPrimitive) { 80 return osmPrimitive != null ? osmPrimitive.get(SHOP_TAG) : null; 81 } 82 83 /** 84 * Check if OSM primitive has a tag 'craft'. 85 * 86 * @param osmPrimitive 87 * The OSM entity to check. 88 */ 89 public static boolean hasCraftTag(OsmPrimitive osmPrimitive) { 90 return osmPrimitive != null ? osmPrimitive.hasKey(CRAFT_TAG) : false; 91 } 92 93 /** 94 * Gets the value of tag 'craft'. 95 * 96 * @param osmPrimitive 97 * The OSM entity to check. 98 */ 99 public static String getCraftValue(OsmPrimitive osmPrimitive) { 100 return osmPrimitive != null ? osmPrimitive.get(CRAFT_TAG) : null; 101 } 102 103 /** 104 * Check if OSM primitive has a tag 'surface'. 105 * 106 * @param osmPrimitive 107 * The OSM entity to check. 108 */ 109 public static boolean hasSurfaceTag(OsmPrimitive osmPrimitive) { 110 return osmPrimitive != null ? osmPrimitive.hasKey(SURFACE_TAG) : false; 111 } 112 113 /** 114 * Gets the value of tag 'surface'. 115 * 116 * @param osmPrimitive 117 * The OSM entity to check. 118 */ 119 public static String getSurfaceValue(OsmPrimitive osmPrimitive) { 120 return osmPrimitive != null ? osmPrimitive.get(SURFACE_TAG) : null; 121 } 122 123 /** 124 * Check if OSM primitive has a tag 'cuisine'. 125 * 126 * @param osmPrimitive 127 * The OSM entity to check. 128 */ 129 public static boolean hasCuisineTag(OsmPrimitive osmPrimitive) { 130 return osmPrimitive != null ? osmPrimitive.hasKey(CUISINE_TAG) : false; 131 } 132 133 /** 134 * Gets the value of tag 'cuisine'. 135 * 136 * @param osmPrimitive 137 * The OSM entity to check. 138 */ 139 public static String getCuisineValue(OsmPrimitive osmPrimitive) { 140 return osmPrimitive != null ? osmPrimitive.get(CUISINE_TAG) : null; 141 } 142 143 /** 144 * Check if OSM primitive has a tag 'wood'. 145 * 146 * @param osmPrimitive 147 * The OSM entity to check. 148 */ 149 public static boolean hasWoodTag(OsmPrimitive osmPrimitive) { 150 return osmPrimitive != null ? osmPrimitive.hasKey(WOOD_TAG) : false; 151 } 152 153 /** 154 * Gets the value of tag 'wood'. 155 * 156 * @param osmPrimitive 157 * The OSM entity to check. 158 */ 159 public static String getWoodValue(OsmPrimitive osmPrimitive) { 160 return osmPrimitive != null ? osmPrimitive.get(WOOD_TAG) : null; 161 } 162 163 /** 164 * Check if OSM primitive has a tag 'foot'. 165 * 166 * @param osmPrimitive 167 * The OSM entity to check. 168 */ 169 public static boolean hasFootTag(OsmPrimitive osmPrimitive) { 170 return osmPrimitive != null ? osmPrimitive.hasKey(FOOT_TAG) : false; 171 } 172 173 /** 174 * Gets the value of tag 'foot'. 175 * 176 * @param osmPrimitive 177 * The OSM entity to check. 178 */ 179 public static String getFootValue(OsmPrimitive osmPrimitive) { 180 return osmPrimitive != null ? osmPrimitive.get(FOOT_TAG) : null; 181 } 182 183 /** 184 * Check if OSM primitive has a tag 'name:de'. 185 * 186 * @param osmPrimitive 187 * The OSM entity to check. 188 */ 189 public static boolean hasNameDeTag(OsmPrimitive osmPrimitive) { 190 return osmPrimitive != null ? osmPrimitive.hasKey(NAME_DE_TAG) : false; 191 } 192 193 /** 194 * Gets the value of tag 'name:de'. 195 * 196 * @param osmPrimitive 197 * The OSM entity to check. 198 */ 199 public static String getNameDeValue(OsmPrimitive osmPrimitive) { 200 return osmPrimitive != null ? osmPrimitive.get(NAME_DE_TAG) : null; 201 } 202 203 /** 204 * Check if OSM primitive has a tag 'nat_ref'. 205 * 206 * @param osmPrimitive 207 * The OSM entity to check. 208 */ 209 public static boolean hasNatRefTag(OsmPrimitive osmPrimitive) { 210 return osmPrimitive != null ? osmPrimitive.hasKey(NAT_REF_TAG) : false; 211 } 212 213 /** 214 * Gets the value of tag 'nat_ref'. 215 * 216 * @param osmPrimitive 217 * The OSM entity to check. 218 */ 219 public static String getNatRefValue(OsmPrimitive osmPrimitive) { 220 return osmPrimitive != null ? osmPrimitive.get(NAT_REF_TAG) : null; 221 } 222 223 /** 224 * Check if OSM primitive has a tag 'note:de'. 225 * 226 * @param osmPrimitive 227 * The OSM entity to check. 228 */ 229 public static boolean hasNoteDeTag(OsmPrimitive osmPrimitive) { 230 return osmPrimitive != null ? osmPrimitive.hasKey(NOTE_DE_TAG) : false; 231 } 232 233 /** 234 * Gets the value of tag 'note:de'. 235 * 236 * @param osmPrimitive 237 * The OSM entity to check. 238 */ 239 public static String getNoteDeValue(OsmPrimitive osmPrimitive) { 240 return osmPrimitive != null ? osmPrimitive.get(NOTE_DE_TAG) : null; 241 } 242 243 /** 244 * Check if OSM primitive has a tag 'addr:street'. 245 * 246 * @param osmPrimitive 247 * The OSM entity to check. 248 */ 249 public static boolean hasAddrStreetTag(OsmPrimitive osmPrimitive) { 250 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_STREET_TAG) 251 : false; 252 } 253 254 /** 255 * Gets the value of tag 'addr:street'. 256 * 257 * @param osmPrimitive 258 * The OSM entity to check. 259 */ 260 public static String getAddrStreetValue(OsmPrimitive osmPrimitive) { 261 return osmPrimitive != null ? osmPrimitive.get(ADDR_STREET_TAG) : null; 262 } 263 264 /** 265 * Check if OSM primitive has a tag 'type'. 266 * 267 * @param osmPrimitive 268 * The OSM entity to check. 269 */ 270 public static boolean hasTypeTag(OsmPrimitive osmPrimitive) { 271 return osmPrimitive != null ? osmPrimitive.hasKey(TYPE_TAG) : false; 272 } 273 274 /** 275 * Gets the value of tag 'type'. 276 * 277 * @param osmPrimitive 278 * The OSM entity to check. 279 */ 280 public static String getTypeValue(OsmPrimitive osmPrimitive) { 281 return osmPrimitive != null ? osmPrimitive.get(TYPE_TAG) : null; 282 } 283 284 /** 285 * Check if OSM primitive has a tag 'addr:city'. 286 * 287 * @param osmPrimitive 288 * The OSM entity to check. 289 */ 290 public static boolean hasAddrCityTag(OsmPrimitive osmPrimitive) { 291 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_CITY_TAG) 292 : false; 293 } 294 295 /** 296 * Gets the value of tag 'addr:city'. 297 * 298 * @param osmPrimitive 299 * The OSM entity to check. 300 */ 301 public static String getAddrCityValue(OsmPrimitive osmPrimitive) { 302 return osmPrimitive != null ? osmPrimitive.get(ADDR_CITY_TAG) : null; 303 } 304 305 /** 306 * Check if OSM primitive has a tag 'boundary'. 307 * 308 * @param osmPrimitive 309 * The OSM entity to check. 310 */ 311 public static boolean hasBoundaryTag(OsmPrimitive osmPrimitive) { 312 return osmPrimitive != null ? osmPrimitive.hasKey(BOUNDARY_TAG) : false; 313 } 314 315 /** 316 * Gets the value of tag 'boundary'. 317 * 318 * @param osmPrimitive 319 * The OSM entity to check. 320 */ 321 public static String getBoundaryValue(OsmPrimitive osmPrimitive) { 322 return osmPrimitive != null ? osmPrimitive.get(BOUNDARY_TAG) : null; 323 } 324 325 /** 326 * Check if OSM primitive has a tag 'smoothness'. 327 * 328 * @param osmPrimitive 329 * The OSM entity to check. 330 */ 331 public static boolean hasSmoothnessTag(OsmPrimitive osmPrimitive) { 332 return osmPrimitive != null ? osmPrimitive.hasKey(SMOOTHNESS_TAG) 333 : false; 334 } 335 336 /** 337 * Gets the value of tag 'smoothness'. 338 * 339 * @param osmPrimitive 340 * The OSM entity to check. 341 */ 342 public static String getSmoothnessValue(OsmPrimitive osmPrimitive) { 343 return osmPrimitive != null ? osmPrimitive.get(SMOOTHNESS_TAG) : null; 344 } 345 346 /** 347 * Check if OSM primitive has a tag 'opening_hours'. 348 * 349 * @param osmPrimitive 350 * The OSM entity to check. 351 */ 352 public static boolean hasOpeningHoursTag(OsmPrimitive osmPrimitive) { 353 return osmPrimitive != null ? osmPrimitive.hasKey(OPENING_HOURS_TAG) 354 : false; 355 } 356 357 /** 358 * Gets the value of tag 'opening_hours'. 359 * 360 * @param osmPrimitive 361 * The OSM entity to check. 362 */ 363 public static String getOpeningHoursValue(OsmPrimitive osmPrimitive) { 364 return osmPrimitive != null ? osmPrimitive.get(OPENING_HOURS_TAG) 365 : null; 366 } 367 368 /** 369 * Check if OSM primitive has a tag 'bicycle'. 370 * 371 * @param osmPrimitive 372 * The OSM entity to check. 373 */ 374 public static boolean hasBicycleTag(OsmPrimitive osmPrimitive) { 375 return osmPrimitive != null ? osmPrimitive.hasKey(BICYCLE_TAG) : false; 376 } 377 378 /** 379 * Gets the value of tag 'bicycle'. 380 * 381 * @param osmPrimitive 382 * The OSM entity to check. 383 */ 384 public static String getBicycleValue(OsmPrimitive osmPrimitive) { 385 return osmPrimitive != null ? osmPrimitive.get(BICYCLE_TAG) : null; 386 } 387 388 /** 389 * Check if OSM primitive has a tag 'religion'. 390 * 391 * @param osmPrimitive 392 * The OSM entity to check. 393 */ 394 public static boolean hasReligionTag(OsmPrimitive osmPrimitive) { 395 return osmPrimitive != null ? osmPrimitive.hasKey(RELIGION_TAG) : false; 396 } 397 398 /** 399 * Gets the value of tag 'religion'. 400 * 401 * @param osmPrimitive 402 * The OSM entity to check. 403 */ 404 public static String getReligionValue(OsmPrimitive osmPrimitive) { 405 return osmPrimitive != null ? osmPrimitive.get(RELIGION_TAG) : null; 406 } 407 408 /** 409 * Check if OSM primitive has a tag 'barrier'. 410 * 411 * @param osmPrimitive 412 * The OSM entity to check. 413 */ 414 public static boolean hasBarrierTag(OsmPrimitive osmPrimitive) { 415 return osmPrimitive != null ? osmPrimitive.hasKey(BARRIER_TAG) : false; 416 } 417 418 /** 419 * Gets the value of tag 'barrier'. 420 * 421 * @param osmPrimitive 422 * The OSM entity to check. 423 */ 424 public static String getBarrierValue(OsmPrimitive osmPrimitive) { 425 return osmPrimitive != null ? osmPrimitive.get(BARRIER_TAG) : null; 426 } 427 428 /** 429 * Check if OSM primitive has a tag 'power'. 430 * 431 * @param osmPrimitive 432 * The OSM entity to check. 433 */ 434 public static boolean hasPowerTag(OsmPrimitive osmPrimitive) { 435 return osmPrimitive != null ? osmPrimitive.hasKey(POWER_TAG) : false; 436 } 437 438 /** 439 * Gets the value of tag 'power'. 440 * 441 * @param osmPrimitive 442 * The OSM entity to check. 443 */ 444 public static String getPowerValue(OsmPrimitive osmPrimitive) { 445 return osmPrimitive != null ? osmPrimitive.get(POWER_TAG) : null; 446 } 447 448 /** 449 * Check if OSM primitive has a tag 'landuse'. 450 * 451 * @param osmPrimitive 452 * The OSM entity to check. 453 */ 454 public static boolean hasLanduseTag(OsmPrimitive osmPrimitive) { 455 return osmPrimitive != null ? osmPrimitive.hasKey(LANDUSE_TAG) : false; 456 } 457 458 /** 459 * Gets the value of tag 'landuse'. 460 * 461 * @param osmPrimitive 462 * The OSM entity to check. 463 */ 464 public static String getLanduseValue(OsmPrimitive osmPrimitive) { 465 return osmPrimitive != null ? osmPrimitive.get(LANDUSE_TAG) : null; 466 } 467 468 /** 469 * Check if OSM primitive has a tag 'fireplace'. 470 * 471 * @param osmPrimitive 472 * The OSM entity to check. 473 */ 474 public static boolean hasFireplaceTag(OsmPrimitive osmPrimitive) { 475 return osmPrimitive != null ? osmPrimitive.hasKey(FIREPLACE_TAG) 476 : false; 477 } 478 479 /** 480 * Gets the value of tag 'fireplace'. 481 * 482 * @param osmPrimitive 483 * The OSM entity to check. 484 */ 485 public static String getFireplaceValue(OsmPrimitive osmPrimitive) { 486 return osmPrimitive != null ? osmPrimitive.get(FIREPLACE_TAG) : null; 487 } 488 489 /** 490 * Check if OSM primitive has a tag 'int_ref'. 491 * 492 * @param osmPrimitive 493 * The OSM entity to check. 494 */ 495 public static boolean hasIntRefTag(OsmPrimitive osmPrimitive) { 496 return osmPrimitive != null ? osmPrimitive.hasKey(INT_REF_TAG) : false; 497 } 498 499 /** 500 * Gets the value of tag 'int_ref'. 501 * 502 * @param osmPrimitive 503 * The OSM entity to check. 504 */ 505 public static String getIntRefValue(OsmPrimitive osmPrimitive) { 506 return osmPrimitive != null ? osmPrimitive.get(INT_REF_TAG) : null; 507 } 508 509 /** 510 * Check if OSM primitive has a tag 'whitewater:section_grade'. 511 * 512 * @param osmPrimitive 513 * The OSM entity to check. 514 */ 515 public static boolean hasWhitewaterSectionGradeTag(OsmPrimitive osmPrimitive) { 516 return osmPrimitive != null ? osmPrimitive 517 .hasKey(WHITEWATER_SECTION_GRADE_TAG) : false; 518 } 519 520 /** 521 * Gets the value of tag 'whitewater:section_grade'. 522 * 523 * @param osmPrimitive 524 * The OSM entity to check. 525 */ 526 public static String getWhitewaterSectionGradeValue( 527 OsmPrimitive osmPrimitive) { 528 return osmPrimitive != null ? osmPrimitive 529 .get(WHITEWATER_SECTION_GRADE_TAG) : null; 530 } 531 532 /** 533 * Check if OSM primitive has a tag 'denomination'. 534 * 535 * @param osmPrimitive 536 * The OSM entity to check. 537 */ 538 public static boolean hasDenominationTag(OsmPrimitive osmPrimitive) { 539 return osmPrimitive != null ? osmPrimitive.hasKey(DENOMINATION_TAG) 540 : false; 541 } 542 543 /** 544 * Gets the value of tag 'denomination'. 545 * 546 * @param osmPrimitive 547 * The OSM entity to check. 548 */ 549 public static String getDenominationValue(OsmPrimitive osmPrimitive) { 550 return osmPrimitive != null ? osmPrimitive.get(DENOMINATION_TAG) : null; 551 } 552 553 /** 554 * Check if OSM primitive has a tag 'addr:postcode'. 555 * 556 * @param osmPrimitive 557 * The OSM entity to check. 558 */ 559 public static boolean hasAddrPostcodeTag(OsmPrimitive osmPrimitive) { 560 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_POSTCODE_TAG) 561 : false; 562 } 563 564 /** 565 * Gets the value of tag 'addr:postcode'. 566 * 567 * @param osmPrimitive 568 * The OSM entity to check. 569 */ 570 public static String getAddrPostcodeValue(OsmPrimitive osmPrimitive) { 571 return osmPrimitive != null ? osmPrimitive.get(ADDR_POSTCODE_TAG) 572 : null; 573 } 574 575 /** 576 * Check if OSM primitive has a tag 'wires'. 577 * 578 * @param osmPrimitive 579 * The OSM entity to check. 580 */ 581 public static boolean hasWiresTag(OsmPrimitive osmPrimitive) { 582 return osmPrimitive != null ? osmPrimitive.hasKey(WIRES_TAG) : false; 583 } 584 585 /** 586 * Gets the value of tag 'wires'. 587 * 588 * @param osmPrimitive 589 * The OSM entity to check. 590 */ 591 public static String getWiresValue(OsmPrimitive osmPrimitive) { 592 return osmPrimitive != null ? osmPrimitive.get(WIRES_TAG) : null; 593 } 594 595 /** 596 * Check if OSM primitive has a tag 'loc_ref'. 597 * 598 * @param osmPrimitive 599 * The OSM entity to check. 600 */ 601 public static boolean hasLocRefTag(OsmPrimitive osmPrimitive) { 602 return osmPrimitive != null ? osmPrimitive.hasKey(LOC_REF_TAG) : false; 603 } 604 605 /** 606 * Gets the value of tag 'loc_ref'. 607 * 608 * @param osmPrimitive 609 * The OSM entity to check. 610 */ 611 public static String getLocRefValue(OsmPrimitive osmPrimitive) { 612 return osmPrimitive != null ? osmPrimitive.get(LOC_REF_TAG) : null; 613 } 614 615 /** 616 * Check if OSM primitive has a tag 'width'. 617 * 618 * @param osmPrimitive 619 * The OSM entity to check. 620 */ 621 public static boolean hasWidthTag(OsmPrimitive osmPrimitive) { 622 return osmPrimitive != null ? osmPrimitive.hasKey(WIDTH_TAG) : false; 623 } 624 625 /** 626 * Gets the value of tag 'width'. 627 * 628 * @param osmPrimitive 629 * The OSM entity to check. 630 */ 631 public static String getWidthValue(OsmPrimitive osmPrimitive) { 632 return osmPrimitive != null ? osmPrimitive.get(WIDTH_TAG) : null; 633 } 634 635 /** 636 * Check if OSM primitive has a tag 'tourism'. 637 * 638 * @param osmPrimitive 639 * The OSM entity to check. 640 */ 641 public static boolean hasTourismTag(OsmPrimitive osmPrimitive) { 642 return osmPrimitive != null ? osmPrimitive.hasKey(TOURISM_TAG) : false; 643 } 644 645 /** 646 * Gets the value of tag 'tourism'. 647 * 648 * @param osmPrimitive 649 * The OSM entity to check. 650 */ 651 public static String getTourismValue(OsmPrimitive osmPrimitive) { 652 return osmPrimitive != null ? osmPrimitive.get(TOURISM_TAG) : null; 653 } 654 655 /** 656 * Check if OSM primitive has a tag 'leisure'. 657 * 658 * @param osmPrimitive 659 * The OSM entity to check. 660 */ 661 public static boolean hasLeisureTag(OsmPrimitive osmPrimitive) { 662 return osmPrimitive != null ? osmPrimitive.hasKey(LEISURE_TAG) : false; 663 } 664 665 /** 666 * Gets the value of tag 'leisure'. 667 * 668 * @param osmPrimitive 669 * The OSM entity to check. 670 */ 671 public static String getLeisureValue(OsmPrimitive osmPrimitive) { 672 return osmPrimitive != null ? osmPrimitive.get(LEISURE_TAG) : null; 673 } 674 675 /** 676 * Check if OSM primitive has a tag 'electrified'. 677 * 678 * @param osmPrimitive 679 * The OSM entity to check. 680 */ 681 public static boolean hasElectrifiedTag(OsmPrimitive osmPrimitive) { 682 return osmPrimitive != null ? osmPrimitive.hasKey(ELECTRIFIED_TAG) 683 : false; 684 } 685 686 /** 687 * Gets the value of tag 'electrified'. 688 * 689 * @param osmPrimitive 690 * The OSM entity to check. 691 */ 692 public static String getElectrifiedValue(OsmPrimitive osmPrimitive) { 693 return osmPrimitive != null ? osmPrimitive.get(ELECTRIFIED_TAG) : null; 694 } 695 696 /** 697 * Check if OSM primitive has a tag 'junction'. 698 * 699 * @param osmPrimitive 700 * The OSM entity to check. 701 */ 702 public static boolean hasJunctionTag(OsmPrimitive osmPrimitive) { 703 return osmPrimitive != null ? osmPrimitive.hasKey(JUNCTION_TAG) : false; 704 } 705 706 /** 707 * Gets the value of tag 'junction'. 708 * 709 * @param osmPrimitive 710 * The OSM entity to check. 711 */ 712 public static String getJunctionValue(OsmPrimitive osmPrimitive) { 713 return osmPrimitive != null ? osmPrimitive.get(JUNCTION_TAG) : null; 714 } 715 716 /** 717 * Check if OSM primitive has a tag 'railway'. 718 * 719 * @param osmPrimitive 720 * The OSM entity to check. 721 */ 722 public static boolean hasRailwayTag(OsmPrimitive osmPrimitive) { 723 return osmPrimitive != null ? osmPrimitive.hasKey(RAILWAY_TAG) : false; 724 } 725 726 /** 727 * Gets the value of tag 'railway'. 728 * 729 * @param osmPrimitive 730 * The OSM entity to check. 731 */ 732 public static String getRailwayValue(OsmPrimitive osmPrimitive) { 733 return osmPrimitive != null ? osmPrimitive.get(RAILWAY_TAG) : null; 734 } 735 736 /** 737 * Check if OSM primitive has a tag 'voltage'. 738 * 739 * @param osmPrimitive 740 * The OSM entity to check. 741 */ 742 public static boolean hasVoltageTag(OsmPrimitive osmPrimitive) { 743 return osmPrimitive != null ? osmPrimitive.hasKey(VOLTAGE_TAG) : false; 744 } 745 746 /** 747 * Gets the value of tag 'voltage'. 748 * 749 * @param osmPrimitive 750 * The OSM entity to check. 751 */ 752 public static String getVoltageValue(OsmPrimitive osmPrimitive) { 753 return osmPrimitive != null ? osmPrimitive.get(VOLTAGE_TAG) : null; 754 } 755 756 /** 757 * Check if OSM primitive has a tag 'bridge'. 758 * 759 * @param osmPrimitive 760 * The OSM entity to check. 761 */ 762 public static boolean hasBridgeTag(OsmPrimitive osmPrimitive) { 763 return osmPrimitive != null ? osmPrimitive.hasKey(BRIDGE_TAG) : false; 764 } 765 766 /** 767 * Gets the value of tag 'bridge'. 768 * 769 * @param osmPrimitive 770 * The OSM entity to check. 771 */ 772 public static String getBridgeValue(OsmPrimitive osmPrimitive) { 773 return osmPrimitive != null ? osmPrimitive.get(BRIDGE_TAG) : null; 774 } 775 776 /** 777 * Check if OSM primitive has a tag 'motor_vehicle'. 778 * 779 * @param osmPrimitive 780 * The OSM entity to check. 781 */ 782 public static boolean hasMotorVehicleTag(OsmPrimitive osmPrimitive) { 783 return osmPrimitive != null ? osmPrimitive.hasKey(MOTOR_VEHICLE_TAG) 784 : false; 785 } 786 787 /** 788 * Gets the value of tag 'motor_vehicle'. 789 * 790 * @param osmPrimitive 791 * The OSM entity to check. 792 */ 793 public static String getMotorVehicleValue(OsmPrimitive osmPrimitive) { 794 return osmPrimitive != null ? osmPrimitive.get(MOTOR_VEHICLE_TAG) 795 : null; 796 } 797 798 /** 799 * Check if OSM primitive has a tag 'comment'. 800 * 801 * @param osmPrimitive 802 * The OSM entity to check. 803 */ 804 public static boolean hasCommentTag(OsmPrimitive osmPrimitive) { 805 return osmPrimitive != null ? osmPrimitive.hasKey(COMMENT_TAG) : false; 806 } 807 808 /** 809 * Gets the value of tag 'comment'. 810 * 811 * @param osmPrimitive 812 * The OSM entity to check. 813 */ 814 public static String getCommentValue(OsmPrimitive osmPrimitive) { 815 return osmPrimitive != null ? osmPrimitive.get(COMMENT_TAG) : null; 816 } 817 818 /** 819 * Check if OSM primitive has a tag 'maxspeed'. 820 * 821 * @param osmPrimitive 822 * The OSM entity to check. 823 */ 824 public static boolean hasMaxspeedTag(OsmPrimitive osmPrimitive) { 825 return osmPrimitive != null ? osmPrimitive.hasKey(MAXSPEED_TAG) : false; 826 } 827 828 /** 829 * Gets the value of tag 'maxspeed'. 830 * 831 * @param osmPrimitive 832 * The OSM entity to check. 833 */ 834 public static String getMaxspeedValue(OsmPrimitive osmPrimitive) { 835 return osmPrimitive != null ? osmPrimitive.get(MAXSPEED_TAG) : null; 836 } 837 838 /** 839 * Check if OSM primitive has a tag 'natural'. 840 * 841 * @param osmPrimitive 842 * The OSM entity to check. 843 */ 844 public static boolean hasNaturalTag(OsmPrimitive osmPrimitive) { 845 return osmPrimitive != null ? osmPrimitive.hasKey(NATURAL_TAG) : false; 846 } 847 848 /** 849 * Gets the value of tag 'natural'. 850 * 851 * @param osmPrimitive 852 * The OSM entity to check. 853 */ 854 public static String getNaturalValue(OsmPrimitive osmPrimitive) { 855 return osmPrimitive != null ? osmPrimitive.get(NATURAL_TAG) : null; 856 } 857 858 /** 859 * Check if OSM primitive has a tag 'sac_scale'. 860 * 861 * @param osmPrimitive 862 * The OSM entity to check. 863 */ 864 public static boolean hasSacScaleTag(OsmPrimitive osmPrimitive) { 865 return osmPrimitive != null ? osmPrimitive.hasKey(SAC_SCALE_TAG) 866 : false; 867 } 868 869 /** 870 * Gets the value of tag 'sac_scale'. 871 * 872 * @param osmPrimitive 873 * The OSM entity to check. 874 */ 875 public static String getSacScaleValue(OsmPrimitive osmPrimitive) { 876 return osmPrimitive != null ? osmPrimitive.get(SAC_SCALE_TAG) : null; 877 } 878 879 /** 880 * Check if OSM primitive has a tag 'tunnel'. 881 * 882 * @param osmPrimitive 883 * The OSM entity to check. 884 */ 885 public static boolean hasTunnelTag(OsmPrimitive osmPrimitive) { 886 return osmPrimitive != null ? osmPrimitive.hasKey(TUNNEL_TAG) : false; 887 } 888 889 /** 890 * Gets the value of tag 'tunnel'. 891 * 892 * @param osmPrimitive 893 * The OSM entity to check. 894 */ 895 public static String getTunnelValue(OsmPrimitive osmPrimitive) { 896 return osmPrimitive != null ? osmPrimitive.get(TUNNEL_TAG) : null; 897 } 898 899 /** 900 * Check if OSM primitive has a tag 'waterway'. 901 * 902 * @param osmPrimitive 903 * The OSM entity to check. 904 */ 905 public static boolean hasWaterwayTag(OsmPrimitive osmPrimitive) { 906 return osmPrimitive != null ? osmPrimitive.hasKey(WATERWAY_TAG) : false; 907 } 908 909 /** 910 * Gets the value of tag 'waterway'. 911 * 912 * @param osmPrimitive 913 * The OSM entity to check. 914 */ 915 public static String getWaterwayValue(OsmPrimitive osmPrimitive) { 916 return osmPrimitive != null ? osmPrimitive.get(WATERWAY_TAG) : null; 917 } 918 919 /** 920 * Check if OSM primitive has a tag 'trail_visibility'. 921 * 922 * @param osmPrimitive 923 * The OSM entity to check. 924 */ 925 public static boolean hasTrailVisibilityTag(OsmPrimitive osmPrimitive) { 926 return osmPrimitive != null ? osmPrimitive.hasKey(TRAIL_VISIBILITY_TAG) 927 : false; 928 } 929 930 /** 931 * Gets the value of tag 'trail_visibility'. 932 * 933 * @param osmPrimitive 934 * The OSM entity to check. 935 */ 936 public static String getTrailVisibilityValue(OsmPrimitive osmPrimitive) { 937 return osmPrimitive != null ? osmPrimitive.get(TRAIL_VISIBILITY_TAG) 938 : null; 939 } 940 941 /** 942 * Check if OSM primitive has a tag 'highway'. 943 * 944 * @param osmPrimitive 945 * The OSM entity to check. 946 */ 947 public static boolean hasHighwayTag(OsmPrimitive osmPrimitive) { 948 return osmPrimitive != null ? osmPrimitive.hasKey(HIGHWAY_TAG) : false; 949 } 950 951 /** 952 * Gets the value of tag 'highway'. 953 * 954 * @param osmPrimitive 955 * The OSM entity to check. 956 */ 957 public static String getHighwayValue(OsmPrimitive osmPrimitive) { 958 return osmPrimitive != null ? osmPrimitive.get(HIGHWAY_TAG) : null; 959 } 960 961 /** 962 * Check if OSM primitive has a tag 'vehicle'. 963 * 964 * @param osmPrimitive 965 * The OSM entity to check. 966 */ 967 public static boolean hasVehicleTag(OsmPrimitive osmPrimitive) { 968 return osmPrimitive != null ? osmPrimitive.hasKey(VEHICLE_TAG) : false; 969 } 970 971 /** 972 * Gets the value of tag 'vehicle'. 973 * 974 * @param osmPrimitive 975 * The OSM entity to check. 976 */ 977 public static String getVehicleValue(OsmPrimitive osmPrimitive) { 978 return osmPrimitive != null ? osmPrimitive.get(VEHICLE_TAG) : null; 979 } 980 981 /** 982 * Check if OSM primitive has a tag 'horse'. 983 * 984 * @param osmPrimitive 985 * The OSM entity to check. 986 */ 987 public static boolean hasHorseTag(OsmPrimitive osmPrimitive) { 988 return osmPrimitive != null ? osmPrimitive.hasKey(HORSE_TAG) : false; 989 } 990 991 /** 992 * Gets the value of tag 'horse'. 993 * 994 * @param osmPrimitive 995 * The OSM entity to check. 996 */ 997 public static String getHorseValue(OsmPrimitive osmPrimitive) { 998 return osmPrimitive != null ? osmPrimitive.get(HORSE_TAG) : null; 999 } 1000 1001 /** 1002 * Check if OSM primitive has a tag 'goods'. 1003 * 1004 * @param osmPrimitive 1005 * The OSM entity to check. 1006 */ 1007 public static boolean hasGoodsTag(OsmPrimitive osmPrimitive) { 1008 return osmPrimitive != null ? osmPrimitive.hasKey(GOODS_TAG) : false; 1009 } 1010 1011 /** 1012 * Gets the value of tag 'goods'. 1013 * 1014 * @param osmPrimitive 1015 * The OSM entity to check. 1016 */ 1017 public static String getGoodsValue(OsmPrimitive osmPrimitive) { 1018 return osmPrimitive != null ? osmPrimitive.get(GOODS_TAG) : null; 1019 } 1020 1021 /** 1022 * Check if OSM primitive has a tag 'frequency'. 1023 * 1024 * @param osmPrimitive 1025 * The OSM entity to check. 1026 */ 1027 public static boolean hasFrequencyTag(OsmPrimitive osmPrimitive) { 1028 return osmPrimitive != null ? osmPrimitive.hasKey(FREQUENCY_TAG) 1029 : false; 1030 } 1031 1032 /** 1033 * Gets the value of tag 'frequency'. 1034 * 1035 * @param osmPrimitive 1036 * The OSM entity to check. 1037 */ 1038 public static String getFrequencyValue(OsmPrimitive osmPrimitive) { 1039 return osmPrimitive != null ? osmPrimitive.get(FREQUENCY_TAG) : null; 1040 } 1041 1042 /** 1043 * Check if OSM primitive has a tag 'man_made'. 1044 * 1045 * @param osmPrimitive 1046 * The OSM entity to check. 1047 */ 1048 public static boolean hasManMadeTag(OsmPrimitive osmPrimitive) { 1049 return osmPrimitive != null ? osmPrimitive.hasKey(MAN_MADE_TAG) : false; 1050 } 1051 1052 /** 1053 * Gets the value of tag 'man_made'. 1054 * 1055 * @param osmPrimitive 1056 * The OSM entity to check. 1057 */ 1058 public static String getManMadeValue(OsmPrimitive osmPrimitive) { 1059 return osmPrimitive != null ? osmPrimitive.get(MAN_MADE_TAG) : null; 1060 } 1061 1062 /** 1063 * Check if OSM primitive has a tag 'addr:housenumber'. 1064 * 1065 * @param osmPrimitive 1066 * The OSM entity to check. 1067 */ 1068 public static boolean hasAddrHousenumberTag(OsmPrimitive osmPrimitive) { 1069 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_HOUSENUMBER_TAG) 1070 : false; 1071 } 1072 1073 /** 1074 * Gets the value of tag 'addr:housenumber'. 1075 * 1076 * @param osmPrimitive 1077 * The OSM entity to check. 1078 */ 1079 public static String getAddrHousenumberValue(OsmPrimitive osmPrimitive) { 1080 return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENUMBER_TAG) 1081 : null; 1082 } 1083 1084 /** 1085 * Check if OSM primitive has a tag 'addr:housename'. 1086 * 1087 * @param osmPrimitive 1088 * The OSM entity to check. 1089 */ 1090 public static boolean hasAddrHousenameTag(OsmPrimitive osmPrimitive) { 1091 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_HOUSENAME_TAG) 1092 : false; 1093 } 1094 1095 /** 1096 * Gets the value of tag 'addr:housename'. 1097 * 1098 * @param osmPrimitive 1099 * The OSM entity to check. 1100 */ 1101 public static String getAddrHousenameValue(OsmPrimitive osmPrimitive) { 1102 return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENAME_TAG) 1103 : null; 1104 } 1105 1106 /** 1107 * Check if OSM primitive has a tag 'area'. 1108 * 1109 * @param osmPrimitive 1110 * The OSM entity to check. 1111 */ 1112 public static boolean hasAreaTag(OsmPrimitive osmPrimitive) { 1113 return osmPrimitive != null ? osmPrimitive.hasKey(AREA_TAG) : false; 1114 } 1115 1116 /** 1117 * Gets the value of tag 'area'. 1118 * 1119 * @param osmPrimitive 1120 * The OSM entity to check. 1121 */ 1122 public static String getAreaValue(OsmPrimitive osmPrimitive) { 1123 return osmPrimitive != null ? osmPrimitive.get(AREA_TAG) : null; 1124 } 1125 1126 /** 1127 * Check if OSM primitive has a tag 'building:levels'. 1128 * 1129 * @param osmPrimitive 1130 * The OSM entity to check. 1131 */ 1132 public static boolean hasBuildingLevelsTag(OsmPrimitive osmPrimitive) { 1133 return osmPrimitive != null ? osmPrimitive.hasKey(BUILDING_LEVELS_TAG) 1134 : false; 1135 } 1136 1137 /** 1138 * Gets the value of tag 'building:levels'. 1139 * 1140 * @param osmPrimitive 1141 * The OSM entity to check. 1142 */ 1143 public static String getBuildingLevelsValue(OsmPrimitive osmPrimitive) { 1144 return osmPrimitive != null ? osmPrimitive.get(BUILDING_LEVELS_TAG) 1145 : null; 1146 } 1147 1148 /** 1149 * Check if OSM primitive has a tag 'wheelchair'. 1150 * 1151 * @param osmPrimitive 1152 * The OSM entity to check. 1153 */ 1154 public static boolean hasWheelchairTag(OsmPrimitive osmPrimitive) { 1155 return osmPrimitive != null ? osmPrimitive.hasKey(WHEELCHAIR_TAG) 1156 : false; 1157 } 1158 1159 /** 1160 * Gets the value of tag 'wheelchair'. 1161 * 1162 * @param osmPrimitive 1163 * The OSM entity to check. 1164 */ 1165 public static String getWheelchairValue(OsmPrimitive osmPrimitive) { 1166 return osmPrimitive != null ? osmPrimitive.get(WHEELCHAIR_TAG) : null; 1167 } 1168 1169 /** 1170 * Check if OSM primitive has a tag 'name'. 1171 * 1172 * @param osmPrimitive 1173 * The OSM entity to check. 1174 */ 1175 public static boolean hasNameTag(OsmPrimitive osmPrimitive) { 1176 return osmPrimitive != null ? osmPrimitive.hasKey(NAME_TAG) : false; 1177 } 1178 1179 /** 1180 * Gets the value of tag 'name'. 1181 * 1182 * @param osmPrimitive 1183 * The OSM entity to check. 1184 */ 1185 public static String getNameValue(OsmPrimitive osmPrimitive) { 1186 return osmPrimitive != null ? osmPrimitive.get(NAME_TAG) : null; 1187 } 1188 1189 /** 1190 * Check if OSM primitive has a tag 'oneway'. 1191 * 1192 * @param osmPrimitive 1193 * The OSM entity to check. 1194 */ 1195 public static boolean hasOnewayTag(OsmPrimitive osmPrimitive) { 1196 return osmPrimitive != null ? osmPrimitive.hasKey(ONEWAY_TAG) : false; 1197 } 1198 1199 /** 1200 * Gets the value of tag 'oneway'. 1201 * 1202 * @param osmPrimitive 1203 * The OSM entity to check. 1204 */ 1205 public static String getOnewayValue(OsmPrimitive osmPrimitive) { 1206 return osmPrimitive != null ? osmPrimitive.get(ONEWAY_TAG) : null; 1207 } 1208 1209 /** 1210 * Check if OSM primitive has a tag 'FIXME'. 1211 * 1212 * @param osmPrimitive 1213 * The OSM entity to check. 1214 */ 1215 public static boolean hasFIXMETag(OsmPrimitive osmPrimitive) { 1216 return osmPrimitive != null ? osmPrimitive.hasKey(FIXME_TAG) : false; 1217 } 1218 1219 /** 1220 * Gets the value of tag 'FIXME'. 1221 * 1222 * @param osmPrimitive 1223 * The OSM entity to check. 1224 */ 1225 public static String getFIXMEValue(OsmPrimitive osmPrimitive) { 1226 return osmPrimitive != null ? osmPrimitive.get(FIXME_TAG) : null; 1227 } 1228 1229 /** 1230 * Check if OSM primitive has a tag 'capacity'. 1231 * 1232 * @param osmPrimitive 1233 * The OSM entity to check. 1234 */ 1235 public static boolean hasCapacityTag(OsmPrimitive osmPrimitive) { 1236 return osmPrimitive != null ? osmPrimitive.hasKey(CAPACITY_TAG) : false; 1237 } 1238 1239 /** 1240 * Gets the value of tag 'capacity'. 1241 * 1242 * @param osmPrimitive 1243 * The OSM entity to check. 1244 */ 1245 public static String getCapacityValue(OsmPrimitive osmPrimitive) { 1246 return osmPrimitive != null ? osmPrimitive.get(CAPACITY_TAG) : null; 1247 } 1248 1249 /** 1250 * Check if OSM primitive has a tag 'motorcycle'. 1251 * 1252 * @param osmPrimitive 1253 * The OSM entity to check. 1254 */ 1255 public static boolean hasMotorcycleTag(OsmPrimitive osmPrimitive) { 1256 return osmPrimitive != null ? osmPrimitive.hasKey(MOTORCYCLE_TAG) 1257 : false; 1258 } 1259 1260 /** 1261 * Gets the value of tag 'motorcycle'. 1262 * 1263 * @param osmPrimitive 1264 * The OSM entity to check. 1265 */ 1266 public static String getMotorcycleValue(OsmPrimitive osmPrimitive) { 1267 return osmPrimitive != null ? osmPrimitive.get(MOTORCYCLE_TAG) : null; 1268 } 1269 1270 /** 1271 * Check if OSM primitive has a tag 'hgv'. 1272 * 1273 * @param osmPrimitive 1274 * The OSM entity to check. 1275 */ 1276 public static boolean hasHgvTag(OsmPrimitive osmPrimitive) { 1277 return osmPrimitive != null ? osmPrimitive.hasKey(HGV_TAG) : false; 1278 } 1279 1280 /** 1281 * Gets the value of tag 'hgv'. 1282 * 1283 * @param osmPrimitive 1284 * The OSM entity to check. 1285 */ 1286 public static String getHgvValue(OsmPrimitive osmPrimitive) { 1287 return osmPrimitive != null ? osmPrimitive.get(HGV_TAG) : null; 1288 } 1289 1290 /** 1291 * Check if OSM primitive has a tag 'construction'. 1292 * 1293 * @param osmPrimitive 1294 * The OSM entity to check. 1295 */ 1296 public static boolean hasConstructionTag(OsmPrimitive osmPrimitive) { 1297 return osmPrimitive != null ? osmPrimitive.hasKey(CONSTRUCTION_TAG) 1298 : false; 1299 } 1300 1301 /** 1302 * Gets the value of tag 'construction'. 1303 * 1304 * @param osmPrimitive 1305 * The OSM entity to check. 1306 */ 1307 public static String getConstructionValue(OsmPrimitive osmPrimitive) { 1308 return osmPrimitive != null ? osmPrimitive.get(CONSTRUCTION_TAG) : null; 1309 } 1310 1311 /** 1312 * Check if OSM primitive has a tag 'addr:state'. 1313 * 1314 * @param osmPrimitive 1315 * The OSM entity to check. 1316 */ 1317 public static boolean hasAddrStateTag(OsmPrimitive osmPrimitive) { 1318 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_STATE_TAG) 1319 : false; 1320 } 1321 1322 /** 1323 * Gets the value of tag 'addr:state'. 1324 * 1325 * @param osmPrimitive 1326 * The OSM entity to check. 1327 */ 1328 public static String getAddrStateValue(OsmPrimitive osmPrimitive) { 1329 return osmPrimitive != null ? osmPrimitive.get(ADDR_STATE_TAG) : null; 1330 } 1331 1332 /** 1333 * Check if OSM primitive has a tag 'lanes'. 1334 * 1335 * @param osmPrimitive 1336 * The OSM entity to check. 1337 */ 1338 public static boolean hasLanesTag(OsmPrimitive osmPrimitive) { 1339 return osmPrimitive != null ? osmPrimitive.hasKey(LANES_TAG) : false; 1340 } 1341 1342 /** 1343 * Gets the value of tag 'lanes'. 1344 * 1345 * @param osmPrimitive 1346 * The OSM entity to check. 1347 */ 1348 public static String getLanesValue(OsmPrimitive osmPrimitive) { 1349 return osmPrimitive != null ? osmPrimitive.get(LANES_TAG) : null; 1350 } 1351 1352 /** 1353 * Check if OSM primitive has a tag 'note'. 1354 * 1355 * @param osmPrimitive 1356 * The OSM entity to check. 1357 */ 1358 public static boolean hasNoteTag(OsmPrimitive osmPrimitive) { 1359 return osmPrimitive != null ? osmPrimitive.hasKey(NOTE_TAG) : false; 1360 } 1361 1362 /** 1363 * Gets the value of tag 'note'. 1364 * 1365 * @param osmPrimitive 1366 * The OSM entity to check. 1367 */ 1368 public static String getNoteValue(OsmPrimitive osmPrimitive) { 1369 return osmPrimitive != null ? osmPrimitive.get(NOTE_TAG) : null; 1370 } 1371 1372 /** 1373 * Check if OSM primitive has a tag 'lit'. 1374 * 1375 * @param osmPrimitive 1376 * The OSM entity to check. 1377 */ 1378 public static boolean hasLitTag(OsmPrimitive osmPrimitive) { 1379 return osmPrimitive != null ? osmPrimitive.hasKey(LIT_TAG) : false; 1380 } 1381 1382 /** 1383 * Gets the value of tag 'lit'. 1384 * 1385 * @param osmPrimitive 1386 * The OSM entity to check. 1387 */ 1388 public static String getLitValue(OsmPrimitive osmPrimitive) { 1389 return osmPrimitive != null ? osmPrimitive.get(LIT_TAG) : null; 1390 } 1391 1392 /** 1393 * Check if OSM primitive has a tag 'building'. 1394 * 1395 * @param osmPrimitive 1396 * The OSM entity to check. 1397 */ 1398 public static boolean hasBuildingTag(OsmPrimitive osmPrimitive) { 1399 return osmPrimitive != null ? osmPrimitive.hasKey(BUILDING_TAG) : false; 1400 } 1401 1402 /** 1403 * Gets the value of tag 'building'. 1404 * 1405 * @param osmPrimitive 1406 * The OSM entity to check. 1407 */ 1408 public static String getBuildingValue(OsmPrimitive osmPrimitive) { 1409 return osmPrimitive != null ? osmPrimitive.get(BUILDING_TAG) : null; 1410 } 1411 1412 /** 1413 * Check if OSM primitive has a tag 'segregated'. 1414 * 1415 * @param osmPrimitive 1416 * The OSM entity to check. 1417 */ 1418 public static boolean hasSegregatedTag(OsmPrimitive osmPrimitive) { 1419 return osmPrimitive != null ? osmPrimitive.hasKey(SEGREGATED_TAG) 1420 : false; 1421 } 1422 1423 /** 1424 * Gets the value of tag 'segregated'. 1425 * 1426 * @param osmPrimitive 1427 * The OSM entity to check. 1428 */ 1429 public static String getSegregatedValue(OsmPrimitive osmPrimitive) { 1430 return osmPrimitive != null ? osmPrimitive.get(SEGREGATED_TAG) : null; 1431 } 1432 1433 /** 1434 * Check if OSM primitive has a tag 'addr:inclusion'. 1435 * 1436 * @param osmPrimitive 1437 * The OSM entity to check. 1438 */ 1439 public static boolean hasAddrInclusionTag(OsmPrimitive osmPrimitive) { 1440 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_INCLUSION_TAG) 1441 : false; 1442 } 1443 1444 /** 1445 * Gets the value of tag 'addr:inclusion'. 1446 * 1447 * @param osmPrimitive 1448 * The OSM entity to check. 1449 */ 1450 public static String getAddrInclusionValue(OsmPrimitive osmPrimitive) { 1451 return osmPrimitive != null ? osmPrimitive.get(ADDR_INCLUSION_TAG) 1452 : null; 1453 } 1454 1455 /** 1456 * Check if OSM primitive has a tag 'layer'. 1457 * 1458 * @param osmPrimitive 1459 * The OSM entity to check. 1460 */ 1461 public static boolean hasLayerTag(OsmPrimitive osmPrimitive) { 1462 return osmPrimitive != null ? osmPrimitive.hasKey(LAYER_TAG) : false; 1463 } 1464 1465 /** 1466 * Gets the value of tag 'layer'. 1467 * 1468 * @param osmPrimitive 1469 * The OSM entity to check. 1470 */ 1471 public static String getLayerValue(OsmPrimitive osmPrimitive) { 1472 return osmPrimitive != null ? osmPrimitive.get(LAYER_TAG) : null; 1473 } 1474 1475 /** 1476 * Check if OSM primitive has a tag 'sport'. 1477 * 1478 * @param osmPrimitive 1479 * The OSM entity to check. 1480 */ 1481 public static boolean hasSportTag(OsmPrimitive osmPrimitive) { 1482 return osmPrimitive != null ? osmPrimitive.hasKey(SPORT_TAG) : false; 1483 } 1484 1485 /** 1486 * Gets the value of tag 'sport'. 1487 * 1488 * @param osmPrimitive 1489 * The OSM entity to check. 1490 */ 1491 public static String getSportValue(OsmPrimitive osmPrimitive) { 1492 return osmPrimitive != null ? osmPrimitive.get(SPORT_TAG) : null; 1493 } 1494 1495 /** 1496 * Check if OSM primitive has a tag 'addr:interpolation'. 1497 * 1498 * @param osmPrimitive 1499 * The OSM entity to check. 1500 */ 1501 public static boolean hasAddrInterpolationTag(OsmPrimitive osmPrimitive) { 1502 return osmPrimitive != null ? osmPrimitive 1503 .hasKey(ADDR_INTERPOLATION_TAG) : false; 1504 } 1505 1506 /** 1507 * Gets the value of tag 'addr:interpolation'. 1508 * 1509 * @param osmPrimitive 1510 * The OSM entity to check. 1511 */ 1512 public static String getAddrInterpolationValue(OsmPrimitive osmPrimitive) { 1513 return osmPrimitive != null ? osmPrimitive.get(ADDR_INTERPOLATION_TAG) 1514 : null; 1515 } 1516 1517 /** 1518 * Check if OSM primitive has a tag 'cutting'. 1519 * 1520 * @param osmPrimitive 1521 * The OSM entity to check. 1522 */ 1523 public static boolean hasCuttingTag(OsmPrimitive osmPrimitive) { 1524 return osmPrimitive != null ? osmPrimitive.hasKey(CUTTING_TAG) : false; 1525 } 1526 1527 /** 1528 * Gets the value of tag 'cutting'. 1529 * 1530 * @param osmPrimitive 1531 * The OSM entity to check. 1532 */ 1533 public static String getCuttingValue(OsmPrimitive osmPrimitive) { 1534 return osmPrimitive != null ? osmPrimitive.get(CUTTING_TAG) : null; 1535 } 1536 1537 /** 1538 * Check if OSM primitive has a tag 'amenity'. 1539 * 1540 * @param osmPrimitive 1541 * The OSM entity to check. 1542 */ 1543 public static boolean hasAmenityTag(OsmPrimitive osmPrimitive) { 1544 return osmPrimitive != null ? osmPrimitive.hasKey(AMENITY_TAG) : false; 1545 } 1546 1547 /** 1548 * Gets the value of tag 'amenity'. 1549 * 1550 * @param osmPrimitive 1551 * The OSM entity to check. 1552 */ 1553 public static String getAmenityValue(OsmPrimitive osmPrimitive) { 1554 return osmPrimitive != null ? osmPrimitive.get(AMENITY_TAG) : null; 1555 } 1556 1557 /** 1558 * Check if OSM primitive has a tag 'access'. 1559 * 1560 * @param osmPrimitive 1561 * The OSM entity to check. 1562 */ 1563 public static boolean hasAccessTag(OsmPrimitive osmPrimitive) { 1564 return osmPrimitive != null ? osmPrimitive.hasKey(ACCESS_TAG) : false; 1565 } 1566 1567 /** 1568 * Gets the value of tag 'access'. 1569 * 1570 * @param osmPrimitive 1571 * The OSM entity to check. 1572 */ 1573 public static String getAccessValue(OsmPrimitive osmPrimitive) { 1574 return osmPrimitive != null ? osmPrimitive.get(ACCESS_TAG) : null; 1575 } 1576 1577 /** 1578 * Check if OSM primitive has a tag 'agricultural'. 1579 * 1580 * @param osmPrimitive 1581 * The OSM entity to check. 1582 */ 1583 public static boolean hasAgriculturalTag(OsmPrimitive osmPrimitive) { 1584 return osmPrimitive != null ? osmPrimitive.hasKey(AGRICULTURAL_TAG) 1585 : false; 1586 } 1587 1588 /** 1589 * Gets the value of tag 'agricultural'. 1590 * 1591 * @param osmPrimitive 1592 * The OSM entity to check. 1593 */ 1594 public static String getAgriculturalValue(OsmPrimitive osmPrimitive) { 1595 return osmPrimitive != null ? osmPrimitive.get(AGRICULTURAL_TAG) : null; 1596 } 1597 1598 /** 1599 * Check if OSM primitive has a tag 'capacity:disabled'. 1600 * 1601 * @param osmPrimitive 1602 * The OSM entity to check. 1603 */ 1604 public static boolean hasCapacityDisabledTag(OsmPrimitive osmPrimitive) { 1605 return osmPrimitive != null ? osmPrimitive 1606 .hasKey(CAPACITY_DISABLED_TAG) : false; 1607 } 1608 1609 /** 1610 * Gets the value of tag 'capacity:disabled'. 1611 * 1612 * @param osmPrimitive 1613 * The OSM entity to check. 1614 */ 1615 public static String getCapacityDisabledValue(OsmPrimitive osmPrimitive) { 1616 return osmPrimitive != null ? osmPrimitive.get(CAPACITY_DISABLED_TAG) 1617 : null; 1618 } 1619 1620 /** 1621 * Check if OSM primitive has a tag 'operator'. 1622 * 1623 * @param osmPrimitive 1624 * The OSM entity to check. 1625 */ 1626 public static boolean hasOperatorTag(OsmPrimitive osmPrimitive) { 1627 return osmPrimitive != null ? osmPrimitive.hasKey(OPERATOR_TAG) : false; 1628 } 1629 1630 /** 1631 * Gets the value of tag 'operator'. 1632 * 1633 * @param osmPrimitive 1634 * The OSM entity to check. 1635 */ 1636 public static String getOperatorValue(OsmPrimitive osmPrimitive) { 1637 return osmPrimitive != null ? osmPrimitive.get(OPERATOR_TAG) : null; 1638 } 1639 1640 /** 1641 * Check if OSM primitive has a tag 'ref'. 1642 * 1643 * @param osmPrimitive 1644 * The OSM entity to check. 1645 */ 1646 public static boolean hasRefTag(OsmPrimitive osmPrimitive) { 1647 return osmPrimitive != null ? osmPrimitive.hasKey(REF_TAG) : false; 1648 } 1649 1650 /** 1651 * Gets the value of tag 'ref'. 1652 * 1653 * @param osmPrimitive 1654 * The OSM entity to check. 1655 */ 1656 public static String getRefValue(OsmPrimitive osmPrimitive) { 1657 return osmPrimitive != null ? osmPrimitive.get(REF_TAG) : null; 1658 } 1659 1660 /** 1661 * Check if OSM primitive has a tag 'noexit'. 1662 * 1663 * @param osmPrimitive 1664 * The OSM entity to check. 1665 */ 1666 public static boolean hasNoexitTag(OsmPrimitive osmPrimitive) { 1667 return osmPrimitive != null ? osmPrimitive.hasKey(NOEXIT_TAG) : false; 1668 } 1669 1670 /** 1671 * Gets the value of tag 'noexit'. 1672 * 1673 * @param osmPrimitive 1674 * The OSM entity to check. 1675 */ 1676 public static String getNoexitValue(OsmPrimitive osmPrimitive) { 1677 return osmPrimitive != null ? osmPrimitive.get(NOEXIT_TAG) : null; 1678 } 1679 1680 /** 1681 * Check if OSM primitive has a tag 'admin_level'. 1682 * 1683 * @param osmPrimitive 1684 * The OSM entity to check. 1685 */ 1686 public static boolean hasAdminLevelTag(OsmPrimitive osmPrimitive) { 1687 return osmPrimitive != null ? osmPrimitive.hasKey(ADMIN_LEVEL_TAG) 1688 : false; 1689 } 1690 1691 /** 1692 * Gets the value of tag 'admin_level'. 1693 * 1694 * @param osmPrimitive 1695 * The OSM entity to check. 1696 */ 1697 public static String getAdminLevelValue(OsmPrimitive osmPrimitive) { 1698 return osmPrimitive != null ? osmPrimitive.get(ADMIN_LEVEL_TAG) : null; 1699 } 1700 1701 /** 1702 * Check if OSM primitive has a tag 'source'. 1703 * 1704 * @param osmPrimitive 1705 * The OSM entity to check. 1706 */ 1707 public static boolean hasSourceTag(OsmPrimitive osmPrimitive) { 1708 return osmPrimitive != null ? osmPrimitive.hasKey(SOURCE_TAG) : false; 1709 } 1710 1711 /** 1712 * Gets the value of tag 'source'. 1713 * 1714 * @param osmPrimitive 1715 * The OSM entity to check. 1716 */ 1717 public static String getSourceValue(OsmPrimitive osmPrimitive) { 1718 return osmPrimitive != null ? osmPrimitive.get(SOURCE_TAG) : null; 1719 } 1720 1721 /** 1722 * Check if OSM primitive has a tag 'tracktype'. 1723 * 1724 * @param osmPrimitive 1725 * The OSM entity to check. 1726 */ 1727 public static boolean hasTracktypeTag(OsmPrimitive osmPrimitive) { 1728 return osmPrimitive != null ? osmPrimitive.hasKey(TRACKTYPE_TAG) 1729 : false; 1730 } 1731 1732 /** 1733 * Gets the value of tag 'tracktype'. 1734 * 1735 * @param osmPrimitive 1736 * The OSM entity to check. 1737 */ 1738 public static String getTracktypeValue(OsmPrimitive osmPrimitive) { 1739 return osmPrimitive != null ? osmPrimitive.get(TRACKTYPE_TAG) : null; 1740 } 1741 1742 /** 1743 * Check if OSM primitive has a tag 'addr:country'. 1744 * 1745 * @param osmPrimitive 1746 * The OSM entity to check. 1747 */ 1748 public static boolean hasAddrCountryTag(OsmPrimitive osmPrimitive) { 1749 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_COUNTRY_TAG) 1750 : false; 1751 } 1752 1753 /** 1754 * Gets the value of tag 'addr:country'. 1755 * 1756 * @param osmPrimitive 1757 * The OSM entity to check. 1758 */ 1759 public static String getAddrCountryValue(OsmPrimitive osmPrimitive) { 1760 return osmPrimitive != null ? osmPrimitive.get(ADDR_COUNTRY_TAG) : null; 1761 } 1762 1763 /** 1764 * Check if OSM primitive has a tag 'route'. 1765 * 1766 * @param osmPrimitive 1767 * The OSM entity to check. 1768 */ 1769 public static boolean hasRouteTag(OsmPrimitive osmPrimitive) { 1770 return osmPrimitive != null ? osmPrimitive.hasKey(ROUTE_TAG) : false; 1771 } 1772 1773 /** 1774 * Gets the value of tag 'route'. 1775 * 1776 * @param osmPrimitive 1777 * The OSM entity to check. 1778 */ 1779 public static String getRouteValue(OsmPrimitive osmPrimitive) { 1780 return osmPrimitive != null ? osmPrimitive.get(ROUTE_TAG) : null; 1781 } 1782 1783 /** 1784 * Check if OSM primitive has a tag 'cables'. 1785 * 1786 * @param osmPrimitive 1787 * The OSM entity to check. 1788 */ 1789 public static boolean hasCablesTag(OsmPrimitive osmPrimitive) { 1790 return osmPrimitive != null ? osmPrimitive.hasKey(CABLES_TAG) : false; 1791 } 1792 1793 /** 1794 * Gets the value of tag 'cables'. 1795 * 1796 * @param osmPrimitive 1797 * The OSM entity to check. 1798 */ 1799 public static String getCablesValue(OsmPrimitive osmPrimitive) { 1800 return osmPrimitive != null ? osmPrimitive.get(CABLES_TAG) : null; 1801 } 1802 1803 /** 1804 * Check if OSM primitive has a tag 'service'. 1805 * 1806 * @param osmPrimitive 1807 * The OSM entity to check. 1808 */ 1809 public static boolean hasServiceTag(OsmPrimitive osmPrimitive) { 1810 return osmPrimitive != null ? osmPrimitive.hasKey(SERVICE_TAG) : false; 1811 } 1812 1813 /** 1814 * Gets the value of tag 'service'. 1815 * 1816 * @param osmPrimitive 1817 * The OSM entity to check. 1818 */ 1819 public static String getServiceValue(OsmPrimitive osmPrimitive) { 1820 return osmPrimitive != null ? osmPrimitive.get(SERVICE_TAG) : null; 1821 } 1822 1823 /** 1824 * Check if OSM primitive has a tag 'motorcar'. 1825 * 1826 * @param osmPrimitive 1827 * The OSM entity to check. 1828 */ 1829 public static boolean hasMotorcarTag(OsmPrimitive osmPrimitive) { 1830 return osmPrimitive != null ? osmPrimitive.hasKey(MOTORCAR_TAG) : false; 1831 } 1832 1833 /** 1834 * Gets the value of tag 'motorcar'. 1835 * 1836 * @param osmPrimitive 1837 * The OSM entity to check. 1838 */ 1839 public static String getMotorcarValue(OsmPrimitive osmPrimitive) { 1840 return osmPrimitive != null ? osmPrimitive.get(MOTORCAR_TAG) : null; 1841 } 1842 1843 /** 1844 * Check if OSM primitive has a tag 'whitewater'. 1845 * 1846 * @param osmPrimitive 1847 * The OSM entity to check. 1848 */ 1849 public static boolean hasWhitewaterTag(OsmPrimitive osmPrimitive) { 1850 return osmPrimitive != null ? osmPrimitive.hasKey(WHITEWATER_TAG) 1851 : false; 1852 } 1853 1854 /** 1855 * Gets the value of tag 'whitewater'. 1856 * 1857 * @param osmPrimitive 1858 * The OSM entity to check. 1859 */ 1860 public static String getWhitewaterValue(OsmPrimitive osmPrimitive) { 1861 return osmPrimitive != null ? osmPrimitive.get(WHITEWATER_TAG) : null; 1862 } 1863 1864 /** 1865 * Check if OSM primitive has a tag 'embankment'. 1866 * 1867 * @param osmPrimitive 1868 * The OSM entity to check. 1869 */ 1870 public static boolean hasEmbankmentTag(OsmPrimitive osmPrimitive) { 1871 return osmPrimitive != null ? osmPrimitive.hasKey(EMBANKMENT_TAG) 1872 : false; 1873 } 1874 1875 /** 1876 * Gets the value of tag 'embankment'. 1877 * 1878 * @param osmPrimitive 1879 * The OSM entity to check. 1880 */ 1881 public static String getEmbankmentValue(OsmPrimitive osmPrimitive) { 1882 return osmPrimitive != null ? osmPrimitive.get(EMBANKMENT_TAG) : null; 1883 } 1884 1885 /** 1886 * Checks if the given street supporting housenumbers. Usually motor ways and primary roads have 1887 * no addresses, also no paths or tracks. 1888 * 1889 * @param w the w 1890 * @return true, if is street supporting housenumbers 1891 */ 1892 public static boolean isStreetSupportingHousenumbers(Way w) { 1893 if (w == null) return false; 1894 if (!hasHighwayTag(w)) { 1895 return false; 1896 } 1897 1898 // TODO: Should be configurable 1899 1900 /* Allow everything until this can be configured */ 1901 return true; 1902 /* 1903 String hwType = getHighwayValue(w); 1904 return !(TagUtils.HIGHWAY_MOTORWAY_LINK_VALUE.equals(hwType) || 1905 TagUtils.HIGHWAY_MOTORWAY_VALUE.equals(hwType) || 1906 TagUtils.HIGHWAY_FOOTWAY_VALUE.equals(hwType) || 1907 TagUtils.HIGHWAY_TRACK_VALUE.equals(hwType) 1908 );*/ 1909 } 1910 1911 // Relation support 1912 1913 /** 1914 * Check if OSM relation is a 'associatedStreet' relation. 1915 * 1916 * @param osmPrimitive 1917 * The OSM entity to check. 1918 */ 1919 public static boolean isAssociatedStreetRelation(Relation rel) { 1920 return rel != null && 1921 rel.hasKey(RELATION_TYPE) && 1922 ASSOCIATEDSTREET_RELATION_TYPE.equals(rel.get(RELATION_TYPE)); 1923 } 1924 1925 /** 1926 * Checks if given relation member has role "street". 1927 * 1928 * @param relMember the relation member 1929 * @return true, if is street member 1930 */ 1931 public static boolean isStreetMember(RelationMember relMember) { 1932 return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole()); 1933 } 1934 1935 /** 1936 * Checks if given relation member has role "house". 1937 * 1938 * @param relMember the relation member 1939 * @return true, if is street member 1940 */ 1941 public static boolean isHouseMember(RelationMember relMember) { 1942 return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole()); 1943 } 1944 1945 /** 1946 * Checks if "addr:state" tag is required. 1947 * 1948 * @return true, if is state required 1949 */ 1950 public static boolean isStateRequired() { 1951 String loc = OsmUtils.getLocale(); 1952 1953 for (int i = 0; i < COUNTRIES_REQUIRE_STATE.length; i++) { 1954 if (COUNTRIES_REQUIRE_STATE[i].equals(loc)) { 1955 return true; 1956 } 1957 } 1958 1959 return false; 1960 } 1961 1962 public static final String PARKING_TAG = "parking"; 1963 public static final String SHOP_TAG = "shop"; 1964 public static final String CRAFT_TAG = "craft"; 1965 public static final String SURFACE_TAG = "surface"; 1966 public static final String CUISINE_TAG = "cuisine"; 1967 public static final String WOOD_TAG = "wood"; 1968 public static final String FOOT_TAG = "foot"; 1969 public static final String NAME_DE_TAG = "name:de"; 1970 public static final String NAT_REF_TAG = "nat_ref"; 1971 public static final String NOTE_DE_TAG = "note:de"; 1972 public static final String ADDR_STREET_TAG = "addr:street"; 1973 public static final String TYPE_TAG = "type"; 1974 public static final String ADDR_CITY_TAG = "addr:city"; 1975 public static final String BOUNDARY_TAG = "boundary"; 1976 public static final String SMOOTHNESS_TAG = "smoothness"; 1977 public static final String OPENING_HOURS_TAG = "opening_hours"; 1978 public static final String BICYCLE_TAG = "bicycle"; 1979 public static final String RELIGION_TAG = "religion"; 1980 public static final String BARRIER_TAG = "barrier"; 1981 public static final String POWER_TAG = "power"; 1982 public static final String LANDUSE_TAG = "landuse"; 1983 public static final String FIREPLACE_TAG = "fireplace"; 1984 public static final String INT_REF_TAG = "int_ref"; 1985 public static final String WHITEWATER_SECTION_GRADE_TAG = "whitewater:section_grade"; 1986 public static final String DENOMINATION_TAG = "denomination"; 1987 public static final String ADDR_POSTCODE_TAG = "addr:postcode"; 1988 public static final String WIRES_TAG = "wires"; 1989 public static final String LOC_REF_TAG = "loc_ref"; 1990 public static final String WIDTH_TAG = "width"; 1991 public static final String TOURISM_TAG = "tourism"; 1992 public static final String LEISURE_TAG = "leisure"; 1993 public static final String ELECTRIFIED_TAG = "electrified"; 1994 public static final String JUNCTION_TAG = "junction"; 1995 public static final String RAILWAY_TAG = "railway"; 1996 public static final String VOLTAGE_TAG = "voltage"; 1997 public static final String BRIDGE_TAG = "bridge"; 1998 public static final String MOTOR_VEHICLE_TAG = "motor_vehicle"; 1999 public static final String COMMENT_TAG = "comment"; 2000 public static final String MAXSPEED_TAG = "maxspeed"; 2001 public static final String NATURAL_TAG = "natural"; 2002 public static final String BUILDING_HEIGHT_TAG = "building:height"; 2003 public static final String SAC_SCALE_TAG = "sac_scale"; 2004 public static final String TUNNEL_TAG = "tunnel"; 2005 public static final String WATERWAY_TAG = "waterway"; 2006 public static final String TRAIL_VISIBILITY_TAG = "trail_visibility"; 2007 public static final String HIGHWAY_TAG = "highway"; 2008 public static final String VEHICLE_TAG = "vehicle"; 2009 public static final String HORSE_TAG = "horse"; 2010 public static final String GOODS_TAG = "goods"; 2011 public static final String FREQUENCY_TAG = "frequency"; 2012 public static final String MAN_MADE_TAG = "man_made"; 2013 public static final String ADDR_HOUSENUMBER_TAG = "addr:housenumber"; 2014 public static final String AREA_TAG = "area"; 2015 public static final String BUILDING_LEVELS_TAG = "building:levels"; 2016 public static final String WHEELCHAIR_TAG = "wheelchair"; 2017 public static final String NAME_TAG = "name"; 2018 public static final String ONEWAY_TAG = "oneway"; 2019 public static final String FIXME_TAG = "FIXME"; 2020 public static final String CAPACITY_TAG = "capacity"; 2021 public static final String MOTORCYCLE_TAG = "motorcycle"; 2022 public static final String HGV_TAG = "hgv"; 2023 public static final String CONSTRUCTION_TAG = "construction"; 2024 public static final String ADDR_STATE_TAG = "addr:state"; 2025 public static final String LANES_TAG = "lanes"; 2026 public static final String NOTE_TAG = "note"; 2027 public static final String LIT_TAG = "lit"; 2028 public static final String BUILDING_TAG = "building"; 2029 public static final String SEGREGATED_TAG = "segregated"; 2030 public static final String ADDR_INCLUSION_TAG = "addr:inclusion"; 2031 public static final String LAYER_TAG = "layer"; 2032 public static final String SPORT_TAG = "sport"; 2033 public static final String ADDR_INTERPOLATION_TAG = "addr:interpolation"; 2034 public static final String CUTTING_TAG = "cutting"; 2035 public static final String AMENITY_TAG = "amenity"; 2036 public static final String ACCESS_TAG = "access"; 2037 public static final String AGRICULTURAL_TAG = "agricultural"; 2038 public static final String CAPACITY_DISABLED_TAG = "capacity:disabled"; 2039 public static final String OPERATOR_TAG = "operator"; 2040 public static final String REF_TAG = "ref"; 2041 public static final String NOEXIT_TAG = "noexit"; 2042 public static final String ADMIN_LEVEL_TAG = "admin_level"; 2043 public static final String SOURCE_TAG = "source"; 2044 public static final String TRACKTYPE_TAG = "tracktype"; 2045 public static final String ADDR_COUNTRY_TAG = "addr:country"; 2046 public static final String ROUTE_TAG = "route"; 2047 public static final String CABLES_TAG = "cables"; 2048 public static final String SERVICE_TAG = "service"; 2049 public static final String MOTORCAR_TAG = "motorcar"; 2050 public static final String WHITEWATER_TAG = "whitewater"; 2051 public static final String EMBANKMENT_TAG = "embankment"; 2052 public static final String ADDR_HOUSENAME_TAG = "addr:housename"; 2053 2054 /* Highway types */ 2055 public static final String HIGHWAY_CYCLEWAY_VALUE = "cycleway"; 2056 public static final String HIGHWAY_FOOTWAY_VALUE = "footway"; 2057 public static final String HIGHWAY_MOTORWAY_LINK_VALUE = "motorway_link"; 2058 public static final String HIGHWAY_MOTORWAY_VALUE = "motorway"; 2059 public static final String HIGHWAY_PATH_VALUE = "path"; 2060 public static final String HIGHWAY_RESIDENTIAL_VALUE = "residential"; 2061 public static final String HIGHWAY_LIVING_STREET_VALUE = "living_street"; 2062 public static final String HIGHWAY_ROAD_VALUE = "road"; 2063 public static final String HIGHWAY_SECONDARY_VALUE = "secondary"; 2064 public static final String HIGHWAY_SERVICE_VALUE = "service"; 2065 public static final String HIGHWAY_STEPS_VALUE = "steps"; 2066 public static final String HIGHWAY_TERTIARY_VALUE = "tertiary"; 2067 public static final String HIGHWAY_TRACK_VALUE = "track"; 2068 public static final String HIGHWAY_TRUNK_LINK_VALUE = "trunk_link"; 2069 public static final String HIGHWAY_TRUNK_VALUE = "trunk"; 2070 public static final String HIGHWAY_UNCLASSIFIED_VALUE = "unclassified"; 2071 2072 /* Relation keys */ 2073 2074 // Associated street: See http://wiki.openstreetmap.org/wiki/Proposed_features/De:Hausnummern 2075 public static final String RELATION_TYPE = "type"; 2076 public static final String ASSOCIATEDSTREET_RELATION_TYPE = "associatedStreet"; 2077 public static final String STREET_RELATION_ROLE = "street"; 2078 public static final String HOUSE_RELATION_ROLE = "house"; 2091 2079 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditDialog.java
r27322 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 62 50 @SuppressWarnings("serial") 63 51 public class AddressEditDialog extends JDialog implements ActionListener, ListSelectionListener, IAddressEditContainerListener { 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 52 private static final String UNRESOLVED_ADDRESS = tr("Unresolved Addresses"); 53 private static final String STREETS = tr("Streets"); 54 private static final String UNRESOLVED_HEADER_FMT = "%s (%d)"; 55 private static final String STREET_HEADER_FMT = "%s (%d)"; 56 private static final String OK_COMMAND = tr("Close"); 57 private static final String SELECT_AND_CLOSE = tr("Select and close"); 58 59 private AddressEditContainer editContainer; 60 private JTable unresolvedTable; 61 private JTable streetTable; 62 63 private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[] { 64 AddressActions.getResolveAction(), 65 AddressActions.getGuessAddressAction(), 66 AddressActions.getApplyGuessesAction(), 67 AddressActions.getSelectAction(), 68 AddressActions.getRemoveTagsAction(), 69 AddressActions.getConvertToRelationAction(), 70 AddressActions.getConvertAllToRelationAction() 71 }; 72 73 private JLabel streetLabel; 74 private JLabel unresolvedAddressesLabel; 75 private JMapViewer mapViewer; 76 77 78 /** 79 * @param arg0 80 * @throws HeadlessException 81 */ 82 public AddressEditDialog(AddressEditContainer addressEditContainer) throws HeadlessException { 83 super(JOptionPane.getFrameForComponent(Main.parent), tr("Fix unresolved addresses"), false); 84 85 this.editContainer = addressEditContainer; 86 this.editContainer.addChangedListener(this); 87 setLayout(new BorderLayout()); 88 setSize(1024,600); 89 setLocationRelativeTo(null); 90 91 if (addressEditContainer != null) { 92 /* Panel for street table */ 93 JPanel streetPanel = new JPanel(new BorderLayout()); 94 streetTable = new JTable(new StreetTableModel(editContainer)); 95 streetTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 96 streetTable.getSelectionModel().addListSelectionListener(this); 97 streetTable.addKeyListener(new JumpToEntryListener(1)); 98 99 JScrollPane scroll1 = new JScrollPane(streetTable); 100 streetPanel.add(scroll1, BorderLayout.CENTER); 101 102 streetLabel = createHeaderLabel(STREET_HEADER_FMT, 103 tr(STREETS), 104 editContainer.getNumberOfStreets()); 105 106 JPanel headerPanel = new JPanel(new GridLayout(1, 4)); 107 headerPanel.setMinimumSize(new Dimension(100, 30)); 108 headerPanel.add(streetLabel); 109 110 /* 111 JPanel streetButtonPanel = new JPanel(new GridLayout(1, 3)); 112 SideButton convertToRel = new SideButton(convertToRelationAction); 113 streetButtonPanel.add(convertToRel); 114 // SideButton convertAllToRel = new SideButton(convertAllToRelationAction); 115 // streetButtonPanel.add(convertAllToRel); 116 // add filler 117 streetButtonPanel.add(new JPanel()); 118 streetButtonPanel.add(new JPanel()); 119 120 121 streetPanel.add(streetButtonPanel, BorderLayout.SOUTH); 122 */ 123 streetPanel.add(headerPanel, BorderLayout.NORTH); 124 streetPanel.setMinimumSize(new Dimension(500, 200)); 125 126 /* Panel for unresolved addresses table */ 127 JPanel unresolvedPanel = new JPanel(new BorderLayout()); 128 UnresolvedAddressesTableModel uaModel = new UnresolvedAddressesTableModel(editContainer); 129 unresolvedTable = new JTable(uaModel); 130 unresolvedTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 131 unresolvedTable.getSelectionModel().addListSelectionListener(this); 132 unresolvedTable.getSelectionModel().addListSelectionListener(new IncompleteAddressListener()); 133 unresolvedTable.addMouseListener(AddressActions.getApplyGuessesAction()); 134 135 JTableHeader header = unresolvedTable.getTableHeader(); 136 header.addMouseListener(uaModel.new ColumnListener(unresolvedTable)); 137 138 JScrollPane scroll2 = new JScrollPane(unresolvedTable); 139 unresolvedPanel.add(scroll2, BorderLayout.CENTER); 140 unresolvedAddressesLabel = createHeaderLabel( 141 UNRESOLVED_HEADER_FMT, 142 tr(UNRESOLVED_ADDRESS), 143 editContainer.getNumberOfUnresolvedAddresses()); 144 145 JPanel headerPanel2 = new JPanel(new GridLayout(1, 4)); 146 headerPanel2.setMinimumSize(new Dimension(100, 30)); 147 headerPanel2.add(unresolvedAddressesLabel); 148 unresolvedPanel.add(headerPanel2 , BorderLayout.NORTH); 149 unresolvedPanel.setMinimumSize(new Dimension(500, 200)); 150 151 152 try { 153 JPanel unresolvedButtons = new JPanel(new GridLayout(2,5, 5, 5)); 154 SideButton assign = new SideButton(AddressActions.getResolveAction()); 155 unresolvedButtons.add(assign); 156 157 SideButton guess = new SideButton(AddressActions.getGuessAddressAction()); 158 unresolvedButtons.add(guess); 159 SideButton applyAllGuesses = new SideButton(AddressActions.getApplyGuessesAction()); 160 unresolvedButtons.add(applyAllGuesses); 161 162 SideButton removeAddressTags = new SideButton(AddressActions.getRemoveTagsAction()); 163 unresolvedButtons.add(removeAddressTags); 164 165 unresolvedButtons.add(new JPanel()); 166 167 SideButton selectInMap = new SideButton(AddressActions.getSelectAction()); 168 unresolvedButtons.add(selectInMap); 169 headerPanel2.setMinimumSize(new Dimension(100, 70)); 170 171 unresolvedPanel.add(unresolvedButtons, BorderLayout.SOUTH); 172 } catch (Exception e) { 173 e.printStackTrace(); 174 } 175 176 /* Map Panel */ 177 JPanel mapPanel = new JPanel(new BorderLayout()); 178 mapViewer = new JMapViewer(); 179 mapPanel.add(mapViewer, BorderLayout.CENTER); 180 mapPanel.setMinimumSize(new Dimension(200, 200)); 181 mapViewer.setVisible(false); 182 183 JPanel mapControl = new JPanel(new GridLayout(1, 4)); 184 JLabel mapL1 = new JLabel(tr("Complete Addresses")); 185 mapL1.setForeground(Color.BLUE); 186 mapControl.add(mapL1); 187 188 JLabel mapL2 = new JLabel(tr("Incomplete Addresses")); 189 mapL2.setForeground(Color.RED); 190 mapControl.add(mapL2); 191 192 JLabel mapL3 = new JLabel(tr("Selected Addresses")); 193 mapL3.setForeground(Color.ORANGE); 194 mapControl.add(mapL3); 195 196 JLabel mapL4 = new JLabel(tr("Selected Street")); 197 mapL4.setForeground(Color.GREEN); 198 mapControl.add(mapL4); 199 200 mapPanel.add(mapControl, BorderLayout.SOUTH); 201 202 /* Combine panels */ 203 JSplitPane unresSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, streetPanel, unresolvedPanel); 204 JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, unresSplitPane, mapPanel); 205 206 this.getContentPane().add(pane, BorderLayout.CENTER); 207 //this.getContentPane().add(mapPanel, BorderLayout.SOUTH); 208 } else { 209 this.getContentPane().add(new JLabel(tr("(No data)")), BorderLayout.CENTER); 210 } 211 212 for (int i = 0; i < actions.length; i++) { 213 actions[i].setContainer(addressEditContainer); 214 } 215 216 JPanel buttonPanel = new JPanel(new GridLayout(1,10)); 217 JButton ok = new JButton(OK_COMMAND, ImageProvider.getIfAvailable(null, "ok")); 218 ok.addActionListener(this); 219 JButton selectAndClose = new JButton(SELECT_AND_CLOSE); 220 selectAndClose.addActionListener(this); 221 222 // Murks 223 for (int i = 0; i < 8; i++) { 224 buttonPanel.add(new JSeparator()); 225 } 226 227 buttonPanel.add(ok); 228 229 230 this.getContentPane().add(buttonPanel, BorderLayout.SOUTH); 231 } 232 233 /** 234 * Creates a header label in the form "title (number)" with bold font. 235 * @param fmtString The format string having a string and a numeric placeholder. 236 * @param title The title of the header. 237 * @param n The number to show in the header. 238 * @return 239 */ 240 private JLabel createHeaderLabel(String fmtString, String title, int n) { 241 JLabel label = new JLabel(String.format(fmtString, title, n)); 242 label.setFont(label.getFont().deriveFont(Font.BOLD, label.getFont().getSize() + 2)); 243 label.setBorder(new EmptyBorder(5,2,4,5)); 244 return label; 245 } 246 247 /** 248 * Updates the list headings. 249 */ 250 private void updateHeaders() { 251 if (editContainer != null) { 252 streetLabel.setText(String.format( 253 STREET_HEADER_FMT, 254 STREETS, 255 editContainer.getNumberOfStreets())); 256 unresolvedAddressesLabel.setText( 257 String.format(UNRESOLVED_HEADER_FMT, 258 UNRESOLVED_ADDRESS, 259 editContainer.getNumberOfUnresolvedAddresses())); 260 } else { 261 streetLabel.setText(String.format(STREET_HEADER_FMT, 0)); 262 unresolvedAddressesLabel.setText(String.format(UNRESOLVED_HEADER_FMT, 0)); 263 } 264 } 265 266 @Override 267 public void actionPerformed(ActionEvent e) { 268 if (OK_COMMAND.equals(e.getActionCommand())) { 269 this.setVisible(false); 270 } 271 } 272 273 @Override 274 public void valueChanged(ListSelectionEvent e) { 275 276 AddressEditSelectionEvent ev = new AddressEditSelectionEvent(e.getSource(), 277 streetTable, unresolvedTable, null, editContainer); 278 279 for (AbstractAddressEditAction action : actions) { 280 action.setEvent(ev); 281 } 282 283 clearMapViewer(); 284 OSMStreet sNode = ev.getSelectedStreet(); 285 if (sNode != null) { 286 287 //mapViewer.addMapRectangle(new BBoxMapRectangle(bb)); 288 for (IOSMEntity seg : sNode.getChildren()) { 289 Way way = (Way) seg.getOsmObject(); 290 //BBox bb = way.getBBox(); 291 292 for (Node node : way.getNodes()) { 293 mapViewer.addMapMarker(new MapMarkerDot(Color.GREEN, node.getCoor().lat(), node.getCoor().lon())); 294 } 295 } 296 297 // show addresses as blue marker 298 if (sNode.hasAddresses()) { 299 for (OSMAddress aNode : sNode.getAddresses()) { 300 Color markerCol = Color.BLUE; 301 if (!aNode.isComplete()) { 302 markerCol = Color.RED; 303 } 304 mapViewer.addMapMarker(new MapMarkerDot(markerCol, aNode.getCoor().lat(), aNode.getCoor().lon())); 305 } 306 } 307 } 308 309 List<OSMAddress> unrAddresses = ev.getSelectedUnresolvedAddresses(); 310 if (unrAddresses != null) { 311 for (OSMAddress aNode : unrAddresses) { 312 mapViewer.addMapMarker(new MapMarkerDot(Color.ORANGE, aNode.getCoor().lat(), aNode.getCoor().lon())); 313 } 314 } 315 mapViewer.setDisplayToFitMapMarkers(); 316 mapViewer.setVisible(true); 317 } 318 319 /** 320 * Removes all markers and rectangles from the map viewer. 321 */ 322 private void clearMapViewer() { 323 mapViewer.setVisible(false); 324 // remove markers and rectangles from map viewer 325 mapViewer.getMapMarkerList().clear(); 326 mapViewer.getMapRectangleList().clear(); 327 } 328 329 @Override 330 public void containerChanged(AddressEditContainer container) { 331 updateHeaders(); 332 333 for (int i = 0; i < actions.length; i++) { 334 actions[i].setEvent(null); 335 actions[i].setContainer(container); 336 } 337 } 338 339 @Override 340 public void entityChanged(IOSMEntity entity) { 341 updateHeaders(); 342 } 343 344 /** 345 * Special listener to react on selection changes in the incomplete address list. 346 * It searches the street table for the streets which matches best matching to the 347 * street name given in the address. 348 * 349 * @author Oliver Wieland <oliver.wieland@online.de> 350 */ 351 class IncompleteAddressListener implements ListSelectionListener { 352 353 @Override 354 public void valueChanged(ListSelectionEvent e) { 355 if (unresolvedTable.getSelectedRowCount() == 1) { 356 String streetOfAddr = (String) unresolvedTable. 357 getModel().getValueAt(unresolvedTable.getSelectedRow(), 0); 358 359 int maxScore = 0, score = 0, row = -1; 360 for (int i = 0; i < streetTable.getRowCount(); i++) { 361 String streetName = (String) streetTable.getModel().getValueAt(i, 1); 362 363 score = StringUtils.lcsLength(streetOfAddr, streetName); 364 if (score > maxScore) { 365 maxScore = score; 366 row = i; 367 } 368 } 369 370 if (row > 0) { 371 streetTable.getSelectionModel().clearSelection(); 372 streetTable.getSelectionModel().addSelectionInterval(row, row); 373 streetTable.scrollRectToVisible(streetTable.getCellRect(row, 0, true)); 374 } 375 } 376 } 377 378 } 379 380 /** 381 * The listener interface for receiving key events of a table. 382 * The class that is interested in processing a jumpToEntry 383 * event implements this interface, and the object created 384 * with that class is registered with a component using the 385 * component's <code>addJumpToEntryListener<code> method. When 386 * the jumpToEntry event occurs, that object's appropriate 387 * method is invoked. 388 * 389 * @see JumpToEntryEvent 390 */ 391 class JumpToEntryListener implements KeyListener { 392 private int column; 393 394 /** 395 * Instantiates a new jump-to-entry listener. 396 * @param column the column of the table to use for the comparison 397 */ 398 public JumpToEntryListener(int column) { 399 super(); 400 this.column = column; 401 } 402 403 @Override 404 public void keyPressed(KeyEvent arg0) { 405 // TODO Auto-generated method stub 406 407 } 408 409 @Override 410 public void keyReleased(KeyEvent arg0) { 411 // TODO Auto-generated method stub 412 413 } 414 415 @Override 416 public void keyTyped(KeyEvent arg0) { 417 JTable table = (JTable) arg0.getSource(); 418 419 if (table == null) return; 420 421 TableModel model = table.getModel(); 422 423 if (model == null || model.getColumnCount() == 0) { 424 return; 425 } 426 // clip column 427 if (column < 0 || column >= model.getColumnCount()) { 428 column = 0; // use the first column 429 } 430 431 char firstChar = Character.toLowerCase(arg0.getKeyChar()); 432 433 // visit every row and find a matching entry 434 for (int i = 0; i < model.getRowCount(); i++) { 435 Object obj = model.getValueAt(i, column); 436 if (obj != null) { 437 String s = obj.toString(); 438 if (s.length() > 0 && firstChar == Character.toLowerCase(s.charAt(0))) { 439 // select entry and make it visible in the table 440 table.getSelectionModel().setSelectionInterval(i, i); 441 table.scrollRectToVisible(streetTable.getCellRect(i, 0, true)); 442 return; 443 } 444 } 445 } 446 } 447 } 460 448 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditModel.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 27 15 28 16 public class AddressEditModel { 29 30 31 32 33 34 17 private List<OSMStreet> streets; 18 private List<OSMAddress> unresolvedAddresses; 19 private List<OSMAddress> incompleteAddresses = new ArrayList<OSMAddress>(); 20 private DefaultMutableTreeNode streetRoot; 21 private DefaultMutableTreeNode unresolvedRoot; 22 private DefaultMutableTreeNode incompleteRoot; 35 23 36 37 38 39 40 41 42 43 44 45 24 /** 25 * @param streets 26 * @param unresolvedAddresses 27 */ 28 public AddressEditModel(List<OSMStreet> streets, 29 List<OSMAddress> unresolvedAddresses) { 30 super(); 31 this.streets = streets; 32 this.unresolvedAddresses = unresolvedAddresses; 33 } 46 34 47 48 35 public TreeNode getStreetsTree() { 36 if (streets == null) return new DefaultMutableTreeNode(tr("(No data)")); 49 37 50 51 52 53 38 if (streetRoot == null) { 39 streetRoot = new DefaultMutableTreeNode(); 40 for (OSMStreet sNode : streets) { 41 DefaultMutableTreeNode treeStreetNode = new DefaultMutableTreeNode(sNode); 54 42 55 56 43 DefaultMutableTreeNode segmentsNode = new DefaultMutableTreeNode(tr("Segments")); 44 treeStreetNode.add(segmentsNode); 57 45 58 59 60 61 46 // Add street segment(s) 47 for (IOSMEntity child : sNode.getChildren()) { 48 segmentsNode.add(new DefaultMutableTreeNode(child)); 49 } 62 50 63 64 65 66 51 if (sNode.hasAddresses()) { 52 // Add address nodes 53 DefaultMutableTreeNode addressNode = new DefaultMutableTreeNode(tr("Addresses")); 54 treeStreetNode.add(addressNode); 67 55 68 69 70 71 72 73 74 75 76 77 56 for (OSMAddress addr : sNode.getAddresses()) { 57 addressNode.add(new DefaultMutableTreeNode(addr)); 58 if (!addr.isComplete()) { 59 incompleteAddresses.add(addr); 60 } 61 } 62 } 63 streetRoot.add(treeStreetNode); 64 } 65 } 78 66 79 80 67 return streetRoot; 68 } 81 69 82 83 84 85 86 87 70 /** 71 * Gets the tree node containing all unresolved addresses. 72 * @return 73 */ 74 public TreeNode getUnresolvedAddressesTree() { 75 if (unresolvedAddresses == null) return new DefaultMutableTreeNode(tr("(No data)")); 88 76 89 90 77 if (unresolvedRoot == null) { 78 unresolvedRoot = new DefaultMutableTreeNode(); 91 79 92 93 94 95 96 80 for (OSMAddress addr : unresolvedAddresses) { 81 // Add address nodes 82 unresolvedRoot.add(new DefaultMutableTreeNode(addr)); 83 } 84 } 97 85 98 99 86 return unresolvedRoot; 87 } 100 88 101 102 103 104 105 106 89 /** 90 * Gets the tree node containing all incomplete addresses. 91 * @return 92 */ 93 public TreeNode getIncompleteAddressesTree() { 94 if (incompleteAddresses == null) return new DefaultMutableTreeNode(tr("(No data)")); 107 95 108 109 96 if (incompleteRoot == null) { 97 incompleteRoot = new DefaultMutableTreeNode(); 110 98 111 112 113 114 115 99 for (OSMAddress addr : incompleteAddresses) { 100 // Add address nodes 101 incompleteRoot.add(new DefaultMutableTreeNode(addr)); 102 } 103 } 116 104 117 118 105 return incompleteRoot; 106 } 119 107 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditSelectionEvent.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 25 13 26 14 public class AddressEditSelectionEvent extends ActionEvent { 27 28 29 30 31 32 33 34 15 /** 16 * 17 */ 18 private static final long serialVersionUID = -93034483427803409L; 19 private JTable streetTable; 20 private JTable unresolvedAddressTable; 21 private JTable incompleteAddressTable; 22 private AddressEditContainer addressContainer; 35 23 36 37 24 private List<OSMAddress> unresolvedCache; 25 private List<OSMAddress> incompleteCache; 38 26 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 27 /** 28 * Creates a new 'AddressEditSelectionEvent'. 29 * @param source The event source. 30 * @param selStreet The street table component. 31 * @param unresolvedAddresses The unresolved addresses table component. 32 * @param incomplete The incomplete addresses table component. 33 * @param container The address container instance holding the entities for streets and addresses. 34 */ 35 public AddressEditSelectionEvent(Object source, JTable selStreet, JTable unresolvedAddresses, JTable incompleteAddresses, AddressEditContainer container) { 36 super(source, -1, ""); 37 this.streetTable = selStreet; 38 this.unresolvedAddressTable = unresolvedAddresses; 39 this.incompleteAddressTable = incompleteAddresses; 40 this.addressContainer = container; 41 } 54 42 55 56 57 58 59 60 61 43 /** 44 * Gets the street table component. 45 * @return 46 */ 47 public JTable getStreetTable() { 48 return streetTable; 49 } 62 50 63 64 65 66 67 68 69 51 /** 52 * Gets the 'unresolved addresses' table component. 53 * @return 54 */ 55 public JTable getUnresolvedAddressTable() { 56 return unresolvedAddressTable; 57 } 70 58 71 72 73 74 75 76 59 /** 60 * @return the incompleteAddressTable 61 */ 62 protected JTable getIncompleteAddressTable() { 63 return incompleteAddressTable; 64 } 77 65 78 79 80 81 82 83 84 85 66 /** 67 * Gets the address container. 68 * 69 * @return the address container 70 */ 71 public AddressEditContainer getAddressContainer() { 72 return addressContainer; 73 } 86 74 87 88 89 90 91 92 93 75 /** 76 * Gets the selected street of the street table. 77 * @return 78 */ 79 public OSMStreet getSelectedStreet() { 80 if (streetTable != null && addressContainer != null && addressContainer.getStreetList() != null) { 81 int selRows = streetTable.getSelectedRow(); 94 82 95 96 97 83 if (selRows < 0 || selRows >= addressContainer.getNumberOfStreets()) { 84 return null; 85 } 98 86 99 100 101 102 87 return addressContainer.getStreetList().get(selRows); 88 } 89 return null; 90 } 103 91 104 105 106 107 108 109 110 111 92 /** 93 * Checks for addresses. 94 * 95 * @return true, if successful 96 */ 97 public boolean hasAddresses() { 98 return hasIncompleteAddresses() || hasUnresolvedAddresses(); 99 } 112 100 113 114 115 116 117 118 119 120 101 /** 102 * Checks for incomplete addresses. 103 * 104 * @return true, if successful 105 */ 106 public boolean hasIncompleteAddresses() { 107 return getSelectedIncompleteAddresses() != null; 108 } 121 109 122 123 124 125 126 127 128 129 110 /** 111 * Checks for unresolved addresses. 112 * 113 * @return true, if successful 114 */ 115 public boolean hasUnresolvedAddresses() { 116 return getSelectedUnresolvedAddresses() != null; 117 } 130 118 131 132 133 134 135 136 137 138 139 140 141 142 143 119 /** 120 * Checks for addresses with guesses. 121 * 122 * @return true, if successful 123 */ 124 public boolean hasAddressesWithGuesses() { 125 if (hasIncompleteAddresses()) { 126 for (OSMAddress addr : getSelectedIncompleteAddresses()) { 127 if (addr.hasGuesses()) { 128 return true; 129 } 130 } 131 } 144 132 145 146 147 148 149 150 151 133 if (hasUnresolvedAddresses()) { 134 for (OSMAddress addr : getSelectedUnresolvedAddresses()) { 135 if (addr.hasGuesses()) { 136 return true; 137 } 138 } 139 } 152 140 153 154 141 return false; 142 } 155 143 156 157 158 159 160 161 162 163 144 /** 145 * Gets the list containing the selected items of the 'unresolved addresses ' table. 146 * @return 147 */ 148 public List<OSMAddress> getSelectedUnresolvedAddresses() { 149 if (unresolvedAddressTable != null && 150 addressContainer != null && 151 unresolvedCache == null) { 164 152 165 153 int[] selRows = unresolvedAddressTable.getSelectedRows(); 166 154 167 168 169 170 171 172 173 174 175 176 177 155 unresolvedCache = new ArrayList<OSMAddress>(); 156 for (int i = 0; i < selRows.length; i++) { 157 if (selRows[i] >= 0 && selRows[i] < addressContainer.getNumberOfUnresolvedAddresses()) { 158 unresolvedCache.add(addressContainer.getUnresolvedAddresses().get(selRows[i])); 159 } 160 } 161 return unresolvedCache; 162 } else { 163 return unresolvedCache; 164 } 165 } 178 166 179 180 181 182 183 184 185 186 187 167 /** 168 * Gets the selected incomplete addresses. 169 * 170 * @return the selected incomplete addresses 171 */ 172 public List<OSMAddress> getSelectedIncompleteAddresses() { 173 if (incompleteAddressTable != null && 174 addressContainer != null && 175 incompleteCache == null) { 188 176 189 177 int[] selRows = incompleteAddressTable.getSelectedRows(); 190 178 191 192 193 194 195 196 197 198 199 200 201 179 incompleteCache = new ArrayList<OSMAddress>(); 180 for (int i = 0; i < selRows.length; i++) { 181 if (selRows[i] >= 0 && selRows[i] < addressContainer.getNumberOfIncompleteAddresses()) { 182 incompleteCache.add(addressContainer.getIncompleteAddresses().get(selRows[i])); 183 } 184 } 185 return incompleteCache; 186 } else { 187 return incompleteCache; // equals null, if no data is present 188 } 189 } 202 190 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditTableModel.java
r27326 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 31 19 @SuppressWarnings("serial") 32 20 public abstract class AddressEditTableModel extends DefaultTableModel implements 33 21 IAddressEditContainerListener { 34 22 35 36 37 23 protected AddressEditContainer addressContainer; 24 protected int sortCol = 0; 25 protected boolean isSortAsc = true; 38 26 39 40 41 42 43 27 public AddressEditTableModel(AddressEditContainer addressContainer) { 28 super(); 29 this.addressContainer = addressContainer; 30 addressContainer.addChangedListener(this); 31 } 44 32 45 46 47 48 49 50 51 52 53 54 fireTableDataChanged(); // update model 55 56 57 58 33 @Override 34 public void containerChanged(AddressEditContainer container) { 35 if (SwingUtilities.isEventDispatchThread()) { 36 fireTableDataChanged(); // update model 37 } else { 38 SwingUtilities.invokeLater(new Runnable() { 39 40 @Override 41 public void run() { 42 fireTableDataChanged(); // update model 43 } 44 }); 45 } 46 } 59 47 60 61 62 63 64 65 66 48 @Override 49 public void entityChanged(IOSMEntity entity) { 50 int row = getRowOfEntity(entity); 51 if (row != -1) { // valid row? -> update model 52 fireTableRowsUpdated(row, row); 53 } // else we don't do anything 54 } 67 55 68 69 70 71 72 73 74 75 76 56 /** 57 * Gets the node entity for the given row or null; if row contains no 58 * entity. 59 * 60 * @param row 61 * The row to get the entity object for. 62 * @return 63 */ 64 public abstract IOSMEntity getEntityOfRow(int row); 77 65 78 79 80 81 82 83 84 85 86 66 /** 67 * Gets the row for the given node entity or -1; if the model does not 68 * contain the entity. 69 * 70 * @param entity 71 * The entity to get the row for. 72 * @return 73 */ 74 public abstract int getRowOfEntity(IOSMEntity entity); 87 75 88 89 90 91 92 93 94 95 96 76 /** 77 * Sorts the model data by the given column. 78 * 79 * @param column 80 * the column 81 * @param ascending 82 * the ascending 83 */ 84 protected abstract void sortByColumn(int column, boolean ascending); 97 85 98 86 99 100 101 102 103 104 105 106 107 108 109 110 111 87 /** 88 * The listener interface for receiving column events. 89 * The class that is interested in processing a column 90 * event implements this interface, and the object created 91 * with that class is registered with a component using the 92 * component's <code>addColumnListener<code> method. When 93 * the column event occurs, that object's appropriate 94 * method is invoked. 95 * 96 * @see ColumnEvent 97 */ 98 class ColumnListener extends MouseAdapter { 99 protected JTable table; 112 100 113 114 115 116 117 118 119 120 101 /** 102 * Instantiates a new column listener. 103 * 104 * @param t the t 105 */ 106 public ColumnListener(JTable t) { 107 table = t; 108 } 121 109 122 /* (non-Javadoc) 123 * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) 124 */ 125 public void mouseClicked(MouseEvent e) { 126 TableColumnModel colModel = table.getColumnModel(); 127 int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); 128 int modelIndex = colModel.getColumn(columnModelIndex) 129 .getModelIndex(); 110 public void mouseClicked(MouseEvent e) { 111 TableColumnModel colModel = table.getColumnModel(); 112 int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); 113 int modelIndex = colModel.getColumn(columnModelIndex) 114 .getModelIndex(); 130 115 131 132 133 134 135 136 137 138 139 116 if (modelIndex < 0) { 117 return; 118 } 119 // Same column? If yes, flip order 120 if (sortCol == modelIndex) { 121 isSortAsc = !isSortAsc; 122 } else { 123 sortCol = modelIndex; 124 } 140 125 141 142 143 144 145 126 for (int i = 0; i < colModel.getColumnCount(); i++) { 127 TableColumn column = colModel.getColumn(i); 128 column.setHeaderValue(getColumnName(column.getModelIndex())); 129 } 130 table.getTableHeader().repaint(); 146 131 147 132 //Collections.sort(addressContainer, new MyComparator(isSortAsc)); 148 133 149 150 151 152 153 134 sortByColumn(sortCol, isSortAsc); 135 table.tableChanged(new TableModelEvent(AddressEditTableModel.this)); 136 table.repaint(); 137 } 138 } 154 139 155 156 157 158 159 160 140 /** 141 * Internal base class to sort items by different columns. 142 */ 143 protected abstract class ColumnSorter<E> implements Comparator<E> { 144 private int column; 145 private boolean ascending; 161 146 162 163 164 165 166 167 168 169 170 171 147 /** 148 * Instantiates a new address sorter. 149 * 150 * @param column the column to sort by 151 */ 152 public ColumnSorter(int column, boolean ascending) { 153 super(); 154 this.column = column; 155 this.ascending = ascending; 156 } 172 157 173 174 175 176 177 178 179 180 158 /** 159 * Gets the index of the column to sort. 160 * 161 * @return the column 162 */ 163 protected int getColumn() { 164 return column; 165 } 181 166 182 183 184 185 186 187 188 189 167 /** 168 * Checks if sort mode is ascending or not. 169 * 170 * @return true, if is ascending 171 */ 172 protected boolean isAscending() { 173 return ascending; 174 } 190 175 191 /* (non-Javadoc) 192 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 193 */ 194 @Override 195 public abstract int compare(E arg0, E arg1); 196 } 176 @Override 177 public abstract int compare(E arg0, E arg1); 178 } 197 179 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/BBoxMapRectangle.java
r29519 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 22 10 23 11 public class BBoxMapRectangle extends MapRectangleImpl { 24 12 private BBox bbox; 25 13 26 27 28 29 30 31 32 14 /** 15 * @param bbox 16 */ 17 public BBoxMapRectangle(BBox bbox) { 18 super(null, null); 19 this.bbox = bbox; 20 } 33 21 34 35 36 37 22 @Override 23 public Coordinate getBottomRight() { 24 return new Coordinate(bbox.getBottomRight().lat(), bbox.getBottomRight().lon()); 25 } 38 26 39 40 41 42 27 @Override 28 public Coordinate getTopLeft() { 29 return new Coordinate(bbox.getTopLeft().lat(), bbox.getTopLeft().lon()); 30 } 43 31 44 45 46 47 32 @Override 33 public void paint(Graphics g, Point topLeft, Point bottomRight) { 34 // do nothing here 35 } 48 36 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/IncompleteAddressesDialog.java
r27357 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 85 73 } 86 74 87 /* (non-Javadoc)88 * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#hideNotify()89 */90 75 @Override 91 76 public void hideNotify() { … … 94 79 } 95 80 96 /* (non-Javadoc)97 * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#showNotify()98 */99 81 @Override 100 82 public void showNotify() { … … 103 85 } 104 86 105 /* (non-Javadoc)106 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#dataChanged(org.openstreetmap.josm.data.osm.event.DataChangedEvent)107 */108 87 @Override 109 88 public void dataChanged(DataChangedEvent event) { … … 111 90 } 112 91 113 /* (non-Javadoc)114 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#nodeMoved(org.openstreetmap.josm.data.osm.event.NodeMovedEvent)115 */116 92 @Override 117 93 public void nodeMoved(NodeMovedEvent event) { … … 119 95 } 120 96 121 /* (non-Javadoc)122 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#otherDatasetChange(org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent)123 */124 97 @Override 125 98 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 126 99 // TODO Auto-generated method stub 127 128 100 } 129 101 130 /* (non-Javadoc) 131 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesAdded(org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent) 132 */ 133 @Override 102 @Override 134 103 public void primitivesAdded(PrimitivesAddedEvent event) { 135 104 container.invalidate(); 136 137 105 } 138 106 139 /* (non-Javadoc) 140 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesRemoved(org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent) 141 */ 142 @Override 107 @Override 143 108 public void primitivesRemoved(PrimitivesRemovedEvent event) { 144 109 container.invalidate(); 145 110 } 146 111 147 /* (non-Javadoc)148 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#relationMembersChanged(org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent)149 */150 112 @Override 151 113 public void relationMembersChanged(RelationMembersChangedEvent event) { … … 153 115 } 154 116 155 /* (non-Javadoc)156 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#tagsChanged(org.openstreetmap.josm.data.osm.event.TagsChangedEvent)157 */158 117 @Override 159 118 public void tagsChanged(TagsChangedEvent event) { 160 119 container.invalidate(); 161 162 120 } 163 121 164 /* (non-Javadoc)165 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#wayNodesChanged(org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent)166 */167 122 @Override 168 123 public void wayNodesChanged(WayNodesChangedEvent event) { … … 170 125 } 171 126 172 /* (non-Javadoc)173 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)174 */175 127 @Override 176 128 public void valueChanged(ListSelectionEvent e) { … … 184 136 } 185 137 186 /* (non-Javadoc)187 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)188 */189 138 @Override 190 139 public void containerChanged(AddressEditContainer container) { … … 198 147 } 199 148 200 /* (non-Javadoc)201 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity)202 */203 149 @Override 204 150 public void entityChanged(IOSMEntity node) { -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/IncompleteAddressesTableModel.java
r28977 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 24 12 25 13 public class IncompleteAddressesTableModel extends AddressEditTableModel { 26 27 28 29 14 /** 15 * 16 */ 17 private static final long serialVersionUID = -5951629033395186324L; 30 18 31 32 33 34 35 19 // TODO: Add "state" column, if required 20 private static final int NUMBER_OF_COLUMNS = 5; 21 private static final String[] COLUMN_NAMES = new String[]{tr("Country"), trc("address", "City" /* fix #8140 */), tr("Postcode"), tr("Street"), tr("Number")}; 22 private static final Class<?>[] COLUMN_CLASSES = new Class<?>[]{ 23 String.class, String.class, String.class, String.class, String.class, String.class}; 36 24 37 25 38 39 40 41 42 43 44 45 26 /** 27 * Instantiates a new incomplete addresses table model. 28 * 29 * @param addressContainer the address container used for display 30 */ 31 public IncompleteAddressesTableModel(AddressEditContainer addressContainer) { 32 super(addressContainer); 33 } 46 34 47 /* (non-Javadoc) 48 * @see javax.swing.table.DefaultTableModel#getColumnCount() 49 */ 50 @Override 51 public int getColumnCount() { 52 return NUMBER_OF_COLUMNS; 53 } 35 @Override 36 public int getColumnCount() { 37 return NUMBER_OF_COLUMNS; 38 } 54 39 55 /* (non-Javadoc) 56 * @see javax.swing.table.DefaultTableModel#getColumnName(int) 57 */ 58 @Override 59 public String getColumnName(int column) { 60 return COLUMN_NAMES[column]; 61 } 40 @Override 41 public String getColumnName(int column) { 42 return COLUMN_NAMES[column]; 43 } 62 44 63 /* (non-Javadoc) 64 * @see javax.swing.table.DefaultTableModel#getRowCount() 65 */ 66 @Override 67 public int getRowCount() { 68 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) { 69 return 0; 70 } 71 return addressContainer.getNumberOfIncompleteAddresses(); 72 } 45 @Override 46 public int getRowCount() { 47 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) { 48 return 0; 49 } 50 return addressContainer.getNumberOfIncompleteAddresses(); 51 } 73 52 74 /* (non-Javadoc) 75 * @see javax.swing.table.DefaultTableModel#getValueAt(int, int) 76 */ 77 @Override 78 public Object getValueAt(int row, int column) { 79 OSMAddress aNode = (OSMAddress) getEntityOfRow(row); 53 @Override 54 public Object getValueAt(int row, int column) { 55 OSMAddress aNode = (OSMAddress) getEntityOfRow(row); 80 56 81 82 83 57 if (aNode == null) { 58 return null; 59 } 84 60 85 86 87 88 89 90 91 92 93 94 95 96 97 98 61 switch (column) { 62 case 0: 63 return aNode.getCountry(); 64 case 1: 65 return aNode.getCity(); 66 case 2: 67 return aNode.getPostalCode(); 68 case 3: 69 return aNode.getStreetName(); 70 case 4: 71 return aNode.getHouseNumber(); 72 default: 73 throw new RuntimeException("Invalid column index: " + column); 74 } 99 75 100 76 } 101 77 102 /* (non-Javadoc) 103 * @see javax.swing.table.AbstractTableModel#getColumnClass(int) 104 */ 105 @Override 106 public Class<?> getColumnClass(int arg0) { 107 return COLUMN_CLASSES[arg0]; 108 } 78 @Override 79 public Class<?> getColumnClass(int arg0) { 80 return COLUMN_CLASSES[arg0]; 81 } 109 82 110 /* (non-Javadoc) 111 * @see javax.swing.table.DefaultTableModel#isCellEditable(int, int) 112 */ 113 @Override 114 public boolean isCellEditable(int row, int column) { 115 return false; 116 } 83 @Override 84 public boolean isCellEditable(int row, int column) { 85 return false; 86 } 117 87 118 /* (non-Javadoc) 119 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#getEntityOfRow(int) 120 */ 121 @Override 122 public IOSMEntity getEntityOfRow(int row) { 123 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) { 124 return null; 125 } 126 if (row < 0 || row >= addressContainer.getNumberOfIncompleteAddresses()) { 127 return null; 128 } 129 return addressContainer.getIncompleteAddresses().get(row); 130 } 88 @Override 89 public IOSMEntity getEntityOfRow(int row) { 90 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) { 91 return null; 92 } 93 if (row < 0 || row >= addressContainer.getNumberOfIncompleteAddresses()) { 94 return null; 95 } 96 return addressContainer.getIncompleteAddresses().get(row); 97 } 131 98 132 /* (non-Javadoc) 133 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#getRowOfEntity(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity) 134 */ 135 @Override 136 public int getRowOfEntity(IOSMEntity entity) { 137 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) { 138 return -1; 139 } 99 @Override 100 public int getRowOfEntity(IOSMEntity entity) { 101 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) { 102 return -1; 103 } 140 104 141 142 105 return addressContainer.getIncompleteAddresses().indexOf(entity); 106 } 143 107 108 @Override 109 protected void sortByColumn(int column, boolean ascending) { 110 if (addressContainer.getNumberOfIncompleteAddresses() == 0) return; 144 111 145 /* (non-Javadoc) 146 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#sortByColumn(int, boolean) 147 */ 148 @Override 149 protected void sortByColumn(int column, boolean ascending) { 150 if (addressContainer.getNumberOfIncompleteAddresses() == 0) return; 112 Collections.sort(addressContainer.getIncompleteAddresses(), 113 new IncompleteAddressModelSorter(column, ascending)); 114 } 151 115 152 Collections.sort(addressContainer.getIncompleteAddresses(), 153 new IncompleteAddressModelSorter(column, ascending)); 154 } 116 /** 117 * Internal class StreetModelSorter. 118 */ 119 class IncompleteAddressModelSorter extends ColumnSorter<OSMAddress> { 155 120 156 /** 157 * Internal class StreetModelSorter. 158 */ 159 class IncompleteAddressModelSorter extends ColumnSorter<OSMAddress> { 121 /** 122 * Instantiates a new incomplete address model sorter. 123 * 124 * @param column the column to sort 125 * @param asc sort ascending 126 */ 127 public IncompleteAddressModelSorter(int column, boolean asc) { 128 super(column, asc); 129 } 160 130 161 /** 162 * Instantiates a new incomplete address model sorter. 163 * 164 * @param column the column to sort 165 * @param asc sort ascending 166 */ 167 public IncompleteAddressModelSorter(int column, boolean asc) { 168 super(column, asc); 169 } 131 @Override 132 public int compare(OSMAddress arg0, OSMAddress arg1) { 133 int cc = 0; 170 134 171 /* (non-Javadoc) 172 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel.ColumnSorter#compare(java.lang.Object, java.lang.Object) 173 */ 174 @Override 175 public int compare(OSMAddress arg0, OSMAddress arg1) { 176 int cc = 0; 135 switch (getColumn()) { 136 case 0: 137 cc=arg0.getCountry().compareTo(arg1.getCountry()); 138 break; 139 case 1: 140 cc=arg0.getCity().compareTo(arg1.getCity()); 141 break; 142 case 2: 143 cc=arg0.getPostalCode().compareTo(arg1.getPostalCode()); 144 break; 145 case 3: 146 cc= arg0.getStreetName().compareTo(arg1.getStreetName()); 147 break; 148 case 4: 149 cc=arg0.getHouseNumber().compareTo(arg1.getHouseNumber()); 150 break; 151 default: 152 throw new RuntimeException("Invalid column index: " + getColumn()); 153 } 177 154 178 switch (getColumn()) { 179 case 0: 180 cc=arg0.getCountry().compareTo(arg1.getCountry()); 181 break; 182 case 1: 183 cc=arg0.getCity().compareTo(arg1.getCity()); 184 break; 185 case 2: 186 cc=arg0.getPostalCode().compareTo(arg1.getPostalCode()); 187 break; 188 case 3: 189 cc= arg0.getStreetName().compareTo(arg1.getStreetName()); 190 break; 191 case 4: 192 cc=arg0.getHouseNumber().compareTo(arg1.getHouseNumber()); 193 break; 194 default: 195 throw new RuntimeException("Invalid column index: " + getColumn()); 196 } 155 if (!isAscending()) { 156 cc = -cc; 157 } 197 158 198 if (!isAscending()) { 199 cc = -cc; 200 } 201 202 return cc; 203 } 204 } 159 return cc; 160 } 161 } 205 162 206 163 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/StreetTableModel.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 15 3 … … 24 12 @SuppressWarnings("serial") 25 13 public class StreetTableModel extends AddressEditTableModel { 26 27 28 29 30 31 32 33 34 14 private static final int NUMBER_OF_COLUMNS = 3; 15 private static final String[] COLUMN_NAMES = new String[]{tr("Type"), tr("Name"), tr("Addresses")}; 16 private static final Class<?>[] COLUMN_CLASSES = new Class<?>[]{String.class, String.class, Integer.class}; 17 /** 18 * @param addressContainer 19 */ 20 public StreetTableModel(AddressEditContainer addressContainer) { 21 super(addressContainer); 22 } 35 23 36 /* (non-Javadoc) 37 * @see javax.swing.table.DefaultTableModel#getColumnCount() 38 */ 39 @Override 40 public int getColumnCount() { 41 // TODO Auto-generated method stub 42 return NUMBER_OF_COLUMNS; 43 } 24 @Override 25 public int getColumnCount() { 26 // TODO Auto-generated method stub 27 return NUMBER_OF_COLUMNS; 28 } 44 29 45 /* (non-Javadoc) 46 * @see javax.swing.table.DefaultTableModel#getColumnName(int) 47 */ 48 @Override 49 public String getColumnName(int column) { 50 return COLUMN_NAMES[column]; 51 } 30 @Override 31 public String getColumnName(int column) { 32 return COLUMN_NAMES[column]; 33 } 52 34 53 /* (non-Javadoc) 54 * @see javax.swing.table.AbstractTableModel#getColumnClass(int) 55 */ 56 @Override 57 public Class<?> getColumnClass(int columnIndex) { 58 return COLUMN_CLASSES[columnIndex]; 59 } 35 @Override 36 public Class<?> getColumnClass(int columnIndex) { 37 return COLUMN_CLASSES[columnIndex]; 38 } 60 39 61 /* (non-Javadoc) 62 * @see javax.swing.table.DefaultTableModel#getRowCount() 63 */ 64 @Override 65 public int getRowCount() { 66 if (addressContainer == null || addressContainer.getStreetList() == null) { 67 return 0; 68 } 69 return addressContainer.getNumberOfStreets(); 70 } 40 @Override 41 public int getRowCount() { 42 if (addressContainer == null || addressContainer.getStreetList() == null) { 43 return 0; 44 } 45 return addressContainer.getNumberOfStreets(); 46 } 71 47 72 /* (non-Javadoc) 73 * @see javax.swing.table.DefaultTableModel#getValueAt(int, int) 74 */ 75 @Override 76 public Object getValueAt(int row, int column) { 77 OSMStreet sNode = (OSMStreet) getEntityOfRow(row); 48 @Override 49 public Object getValueAt(int row, int column) { 50 OSMStreet sNode = (OSMStreet) getEntityOfRow(row); 78 51 79 80 81 52 if (sNode == null) { 53 return null; 54 } 82 55 83 84 85 86 87 88 89 90 91 92 93 94 95 96 56 switch (column) { 57 case 0: 58 return sNode.getType(); 59 case 1: 60 return sNode.getName(); 61 case 2: 62 return sNode.getNumberOfSegments(); 63 case 3: 64 return sNode.getNumberOfAddresses(); 65 case 4: 66 return sNode.hasAssociatedStreetRelation(); 67 default: 68 throw new RuntimeException("Invalid column index: " + column); 69 } 97 70 98 71 } 99 72 100 101 102 103 104 73 @Override 74 public boolean isCellEditable(int row, int column) { 75 // TODO Auto-generated method stub 76 return false; 77 } 105 78 106 107 108 109 110 111 112 113 114 115 79 @Override 80 public IOSMEntity getEntityOfRow(int row) { 81 if (addressContainer == null || addressContainer.getStreetList() == null) { 82 return null; 83 } 84 if (row < 0 || row >= addressContainer.getNumberOfStreets()) { 85 return null; 86 } 87 return addressContainer.getStreetList().get(row); 88 } 116 89 117 118 119 120 121 90 @Override 91 public int getRowOfEntity(IOSMEntity entity) { 92 if (addressContainer == null || addressContainer.getStreetList() == null) { 93 return -1; 94 } 122 95 123 124 96 return addressContainer.getStreetList().indexOf(entity); 97 } 125 98 126 /* (non-Javadoc) 127 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#sortByColumn(int, boolean) 128 */ 129 @Override 130 protected void sortByColumn(int column, boolean ascending) { 131 Collections.sort(addressContainer.getStreetList(), new StreetModelSorter(column, ascending)); 132 } 99 @Override 100 protected void sortByColumn(int column, boolean ascending) { 101 Collections.sort(addressContainer.getStreetList(), new StreetModelSorter(column, ascending)); 102 } 133 103 134 135 136 137 104 /** 105 * Internal class StreetModelSorter. 106 */ 107 class StreetModelSorter extends ColumnSorter<OSMStreet> { 138 108 139 140 141 109 public StreetModelSorter(int column, boolean asc) { 110 super(column, asc); 111 } 142 112 143 144 113 public int compare(OSMStreet arg0, OSMStreet arg1) { 114 if (arg0 == null || arg1 == null) return 0; 145 115 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 116 switch (getColumn()) { 117 case 0: 118 if (arg0.getType() != null) { 119 return arg0.getType().compareTo(arg1.getType()); 120 } else { 121 return arg1.hasName() ? -1 : 0; 122 } 123 case 1: 124 if (arg0.hasName()) { 125 return arg0.getName().compareTo(arg1.getName()); 126 } else { 127 return arg1.hasName() ? -1 : 0; 128 } 129 case 2: 130 return new Integer(arg0.getNumberOfAddresses()). 131 compareTo(new Integer(arg1.getNumberOfAddresses())); 132 default: 133 } 134 return 0; 135 } 136 } 167 137 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/UnresolvedAddressesTableModel.java
r28977 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 14 /** 15 * This program is free software: you can redistribute it and/or modify it under 16 * the terms of the GNU General Public License as published by the 17 * Free Software Foundation, either version 3 of the License, or 18 * (at your option) any later version. 19 * 20 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 21 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 * See the GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License along with this program. 25 * If not, see <http://www.gnu.org/licenses/>. 26 */ 27 28 /* File created on 25.10.2010 */ 1 // License: GPL. For details, see LICENSE file. 29 2 package org.openstreetmap.josm.plugins.fixAddresses.gui; 30 3 … … 47 20 public class UnresolvedAddressesTableModel extends AddressEditTableModel { 48 21 49 50 51 22 private static final int NUMBER_OF_COLUMNS = 5; 23 private static final String[] COLUMN_NAMES = new String[] { tr("Street"), 24 tr("Number"), trc("address", "City" /* fix #8140 */), tr("Postcode"), tr("Name") }; 52 25 53 54 55 26 private static final Class<?>[] COLUMN_CLASSES = new Class<?>[] { 27 String.class, String.class, String.class, String.class, 28 String.class }; 56 29 57 58 59 60 30 /** 31 * 32 */ 33 private static final long serialVersionUID = 424009321818130586L; 61 34 62 63 64 65 66 67 35 /** 36 * @param addressContainer 37 */ 38 public UnresolvedAddressesTableModel(AddressEditContainer addressContainer) { 39 super(addressContainer); 40 } 68 41 69 /* 70 * (non-Javadoc) 71 * 72 * @see javax.swing.table.DefaultTableModel#getColumnCount() 73 */ 74 @Override 75 public int getColumnCount() { 76 return NUMBER_OF_COLUMNS; 77 } 42 @Override 43 public int getColumnCount() { 44 return NUMBER_OF_COLUMNS; 45 } 78 46 79 /* 80 * (non-Javadoc) 81 * 82 * @see javax.swing.table.DefaultTableModel#getColumnName(int) 83 */ 84 @Override 85 public String getColumnName(int column) { 86 return COLUMN_NAMES[column]; 87 } 47 @Override 48 public String getColumnName(int column) { 49 return COLUMN_NAMES[column]; 50 } 88 51 89 /* 90 * (non-Javadoc) 91 * 92 * @see javax.swing.table.DefaultTableModel#getRowCount() 93 */ 94 @Override 95 public int getRowCount() { 96 if (addressContainer == null 97 || addressContainer.getUnresolvedAddresses() == null) { 98 return 0; 99 } 100 return addressContainer.getNumberOfUnresolvedAddresses(); 101 } 52 @Override 53 public int getRowCount() { 54 if (addressContainer == null 55 || addressContainer.getUnresolvedAddresses() == null) { 56 return 0; 57 } 58 return addressContainer.getNumberOfUnresolvedAddresses(); 59 } 102 60 103 /* 104 * (non-Javadoc) 105 * 106 * @see javax.swing.table.DefaultTableModel#getValueAt(int, int) 107 */ 108 @Override 109 public Object getValueAt(int row, int column) { 110 OSMAddress aNode = (OSMAddress) getEntityOfRow(row); 61 @Override 62 public Object getValueAt(int row, int column) { 63 OSMAddress aNode = (OSMAddress) getEntityOfRow(row); 111 64 112 113 114 65 if (aNode == null) { 66 return null; 67 } 115 68 116 117 118 119 120 121 122 123 124 125 126 127 128 129 69 switch (column) { 70 case 0: 71 return aNode.getStreetName(); 72 case 1: 73 return aNode.getHouseNumber(); 74 case 2: 75 return aNode.getCity(); 76 case 3: 77 return aNode.getPostalCode(); 78 case 4: 79 return aNode.getName(); 80 default: 81 throw new RuntimeException("Invalid column index: " + column); 82 } 130 83 131 84 } 132 85 133 /* 134 * (non-Javadoc) 135 * 136 * @see javax.swing.table.AbstractTableModel#getColumnClass(int) 137 */ 138 @Override 139 public Class<?> getColumnClass(int arg0) { 140 return COLUMN_CLASSES[arg0]; 141 } 86 @Override 87 public Class<?> getColumnClass(int arg0) { 88 return COLUMN_CLASSES[arg0]; 89 } 142 90 143 /* 144 * (non-Javadoc) 145 * 146 * @see javax.swing.table.DefaultTableModel#isCellEditable(int, int) 147 */ 148 @Override 149 public boolean isCellEditable(int row, int column) { 150 return false; 151 } 91 @Override 92 public boolean isCellEditable(int row, int column) { 93 return false; 94 } 152 95 153 /* 154 * (non-Javadoc) 155 * 156 * @see 157 * org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel 158 * #getEntityOfRow(int) 159 */ 160 @Override 161 public IOSMEntity getEntityOfRow(int row) { 162 if (addressContainer == null 163 || addressContainer.getUnresolvedAddresses() == null) { 164 return null; 165 } 166 if (row < 0 || row >= addressContainer.getNumberOfUnresolvedAddresses()) { 167 return null; 168 } 169 return addressContainer.getUnresolvedAddresses().get(row); 170 } 96 @Override 97 public IOSMEntity getEntityOfRow(int row) { 98 if (addressContainer == null 99 || addressContainer.getUnresolvedAddresses() == null) { 100 return null; 101 } 102 if (row < 0 || row >= addressContainer.getNumberOfUnresolvedAddresses()) { 103 return null; 104 } 105 return addressContainer.getUnresolvedAddresses().get(row); 106 } 171 107 172 173 174 175 176 177 108 @Override 109 public int getRowOfEntity(IOSMEntity entity) { 110 if (addressContainer == null 111 || addressContainer.getUnresolvedAddresses() == null) { 112 return -1; 113 } 178 114 179 180 115 return addressContainer.getUnresolvedAddresses().indexOf(entity); 116 } 181 117 182 /* 183 * (non-Javadoc) 184 * 185 * @see 186 * org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel 187 * #sortByColumn(int, boolean) 188 */ 189 @Override 190 protected void sortByColumn(int column, boolean ascending) { 191 if (addressContainer.getNumberOfUnresolvedAddresses() == 0) 192 return; 118 @Override 119 protected void sortByColumn(int column, boolean ascending) { 120 if (addressContainer.getNumberOfUnresolvedAddresses() == 0) 121 return; 193 122 194 195 196 123 Collections.sort(addressContainer.getUnresolvedAddresses(), 124 new UnresolvedAddressModelSorter(column, ascending)); 125 } 197 126 198 199 200 201 127 /** 128 * Internal class StreetModelSorter. 129 */ 130 class UnresolvedAddressModelSorter extends ColumnSorter<OSMAddress> { 202 131 203 204 205 132 public UnresolvedAddressModelSorter(int column, boolean asc) { 133 super(column, asc); 134 } 206 135 207 /* 208 * (non-Javadoc) 209 * 210 * @see 211 * org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel 212 * .ColumnSorter#compare(java.lang.Object, java.lang.Object) 213 */ 214 @Override 215 public int compare(OSMAddress arg0, OSMAddress arg1) { 216 int cc = 0; 217 switch (getColumn()) { 218 case 0: 219 cc = arg0.getStreetName().compareTo(arg1.getStreetName()); 220 break; 221 case 1: 222 cc = arg0.getHouseNumber().compareTo(arg1.getHouseNumber()); 223 break; 224 case 2: 225 cc = arg0.getCity().compareTo(arg1.getCity()); 226 break; 227 case 3: 228 cc = arg0.getPostalCode().compareTo(arg1.getPostalCode()); 229 break; 230 case 4: 231 cc = arg0.getName().compareTo(arg1.getName()); 232 break; 233 default: 234 throw new RuntimeException("Invalid column index: " 235 + getColumn()); 236 } 136 @Override 137 public int compare(OSMAddress arg0, OSMAddress arg1) { 138 int cc = 0; 139 switch (getColumn()) { 140 case 0: 141 cc = arg0.getStreetName().compareTo(arg1.getStreetName()); 142 break; 143 case 1: 144 cc = arg0.getHouseNumber().compareTo(arg1.getHouseNumber()); 145 break; 146 case 2: 147 cc = arg0.getCity().compareTo(arg1.getCity()); 148 break; 149 case 3: 150 cc = arg0.getPostalCode().compareTo(arg1.getPostalCode()); 151 break; 152 case 4: 153 cc = arg0.getName().compareTo(arg1.getName()); 154 break; 155 default: 156 throw new RuntimeException("Invalid column index: " 157 + getColumn()); 158 } 237 159 238 239 240 160 if (!isAscending()) { 161 cc = -cc; 162 } 241 163 242 243 244 164 return cc; 165 } 166 } 245 167 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/AbstractAddressEditAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 43 31 @SuppressWarnings("serial") 44 32 public abstract class AbstractAddressEditAction extends JosmAction implements IAddressEditContainerListener, ICommandListener { 45 private AddressEditSelectionEvent event; 46 protected AddressEditContainer container; 47 protected List<Command> commands; 48 private String txName; 49 50 /** 51 * @param name 52 * @param icon 53 */ 54 public AbstractAddressEditAction(String name, String iconName, String tooltip, String toolbar) { 55 super(name, iconName, tooltip, null, true, toolbar, true); 56 57 setEnabled(false); 58 } 59 60 /** 61 * @param name 62 */ 63 public AbstractAddressEditAction(String name) { 64 this(name, null, "", null); 65 } 66 67 /** 68 * Gets the current address container. 69 * @return the container 70 */ 71 public AddressEditContainer getContainer() { 72 return container; 73 } 74 75 /** 76 * @param container the container to set 77 */ 78 public void setContainer(AddressEditContainer container) { 79 if (container != null) { // remove old listener first 80 container.removeChangedListener(this); 81 } 82 this.container = container; 83 updateEnabledState(); 84 if (container != null) { 85 container.addChangedListener(this); 86 } 87 } 88 89 /** 90 * @return the event 91 */ 92 protected AddressEditSelectionEvent getEvent() { 93 return event; 94 } 95 96 /** 97 * @param event the event to set 98 */ 99 public void setEvent(AddressEditSelectionEvent event) { 100 this.event = event; 101 updateEnabledState(); 102 } 103 104 /* (non-Javadoc) 105 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 106 */ 107 @Override 108 public void actionPerformed(ActionEvent arg0) { 109 if (event != null) { // use the event acquired previously. 110 addressEditActionPerformed(event); 111 event = null; // consume event 112 } else { 113 if (container != null) { 114 addressEditActionPerformed(container); 115 } else { 116 throw new RuntimeException("AbstractAddressEditAction has no container or event"); 117 } 118 } 119 } 120 121 /* (non-Javadoc) 122 * @see org.openstreetmap.josm.actions.JosmAction#updateEnabledState() 123 */ 124 @Override 125 protected void updateEnabledState() { 126 if (this.event != null) { 127 updateEnabledState(this.event); 128 } else { 129 if (container != null) { 130 updateEnabledState(container); 131 } else { 132 super.updateEnabledState(); 133 } 134 } 135 } 136 137 /** 138 * Updates 'enabled' state depending on the given address container object. 139 * @param container The address container (maybe null). 140 * @return 141 */ 142 protected abstract void updateEnabledState(AddressEditContainer container); 143 144 /** 145 * Updates 'enabled' state depending on the current selection. 146 * @param container The selection event. 147 * @return 148 */ 149 protected abstract void updateEnabledState(AddressEditSelectionEvent event); 150 151 /** 152 * Redirected action handler for doing actions on a address selection. 153 * @param ev 154 */ 155 public abstract void addressEditActionPerformed(AddressEditSelectionEvent ev); 156 157 /** 158 * Redirected action handler for doing actions on an address container. 159 * @param ev 160 */ 161 public abstract void addressEditActionPerformed(AddressEditContainer container); 162 163 164 /* (non-Javadoc) 165 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 166 */ 167 @Override 168 public void containerChanged(AddressEditContainer container) { 169 updateEnabledState(); 170 } 171 172 /* (non-Javadoc) 173 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity) 174 */ 175 @Override 176 public void entityChanged(IOSMEntity node) { 177 container.removeProblemsOfSource(node); // clear problems of changed node... 178 node.visit(container, container); // .. and revisit it. 179 updateEnabledState(); 180 } 181 182 /** 183 * Begins the transaction (command sequence). Must be called by every subclass before 184 * any modification on OSM objects starts. 185 * 186 * @param txName the name of the transaction (e. g. "change address tags"). 187 */ 188 public void beginTransaction(String txName) { 189 if (commands != null && commands.size() > 0) { 190 throw new RuntimeException("TX has not been closed (missing finishTransaction?)"); 191 } 192 193 commands = new ArrayList<Command>(); 194 if (StringUtils.isNullOrEmpty(txName)) { 195 throw new RuntimeException("Transaction must have a name"); 196 } 197 this.txName = txName; 198 } 199 200 /** 201 * Finishes the transaction and passes the command sequence to the framework. 202 */ 203 public void finishTransaction() { 204 if (commands == null) { 205 throw new RuntimeException("No command list available. Did you forget to call beginTransaction?"); 206 } 207 // execute the command 208 Main.main.undoRedo.add(new SequenceCommand(txName, commands)); 209 commands.clear(); 210 container.invalidate(); 211 } 212 213 /** 214 * Begins the transaction for a single object. 215 * 216 * @param entity the entity 217 */ 218 public void beginObjectTransaction(IOSMEntity entity) { 219 if (entity != null) { 220 entity.addCommandListener(this); 221 } else { 222 throw new RuntimeException("Entity must not be null"); 223 } 224 } 225 226 /** 227 * Finishes the transaction for a single object. 228 * 229 * @param entity the entity 230 */ 231 public void finishObjectTransaction(IOSMEntity entity) { 232 if (entity != null) { 233 entity.removeCommandListener(this); 234 } else { 235 throw new RuntimeException("Entity must not be null"); 236 } 237 } 238 239 /* (non-Javadoc) 240 * @see org.openstreetmap.josm.plugins.fixAddresses.ICommandListener#commandIssued(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity, org.openstreetmap.josm.command.Command) 241 */ 242 @Override 243 public void commandIssued(IOSMEntity entity, Command command) { 244 if (commands == null) { 245 throw new RuntimeException("No command list available. Did you forget to call beginTransaction?"); 246 } 247 commands.add(command); 248 } 33 private AddressEditSelectionEvent event; 34 protected AddressEditContainer container; 35 protected List<Command> commands; 36 private String txName; 37 38 /** 39 * @param name 40 * @param icon 41 */ 42 public AbstractAddressEditAction(String name, String iconName, String tooltip, String toolbar) { 43 super(name, iconName, tooltip, null, true, toolbar, true); 44 45 setEnabled(false); 46 } 47 48 /** 49 * @param name 50 */ 51 public AbstractAddressEditAction(String name) { 52 this(name, null, "", null); 53 } 54 55 /** 56 * Gets the current address container. 57 * @return the container 58 */ 59 public AddressEditContainer getContainer() { 60 return container; 61 } 62 63 /** 64 * @param container the container to set 65 */ 66 public void setContainer(AddressEditContainer container) { 67 if (container != null) { // remove old listener first 68 container.removeChangedListener(this); 69 } 70 this.container = container; 71 updateEnabledState(); 72 if (container != null) { 73 container.addChangedListener(this); 74 } 75 } 76 77 /** 78 * @return the event 79 */ 80 protected AddressEditSelectionEvent getEvent() { 81 return event; 82 } 83 84 /** 85 * @param event the event to set 86 */ 87 public void setEvent(AddressEditSelectionEvent event) { 88 this.event = event; 89 updateEnabledState(); 90 } 91 92 @Override 93 public void actionPerformed(ActionEvent arg0) { 94 if (event != null) { // use the event acquired previously. 95 addressEditActionPerformed(event); 96 event = null; // consume event 97 } else { 98 if (container != null) { 99 addressEditActionPerformed(container); 100 } else { 101 throw new RuntimeException("AbstractAddressEditAction has no container or event"); 102 } 103 } 104 } 105 106 @Override 107 protected void updateEnabledState() { 108 if (this.event != null) { 109 updateEnabledState(this.event); 110 } else { 111 if (container != null) { 112 updateEnabledState(container); 113 } else { 114 super.updateEnabledState(); 115 } 116 } 117 } 118 119 /** 120 * Updates 'enabled' state depending on the given address container object. 121 * @param container The address container (maybe null). 122 * @return 123 */ 124 protected abstract void updateEnabledState(AddressEditContainer container); 125 126 /** 127 * Updates 'enabled' state depending on the current selection. 128 * @param container The selection event. 129 * @return 130 */ 131 protected abstract void updateEnabledState(AddressEditSelectionEvent event); 132 133 /** 134 * Redirected action handler for doing actions on a address selection. 135 * @param ev 136 */ 137 public abstract void addressEditActionPerformed(AddressEditSelectionEvent ev); 138 139 /** 140 * Redirected action handler for doing actions on an address container. 141 * @param ev 142 */ 143 public abstract void addressEditActionPerformed(AddressEditContainer container); 144 145 @Override 146 public void containerChanged(AddressEditContainer container) { 147 updateEnabledState(); 148 } 149 150 @Override 151 public void entityChanged(IOSMEntity node) { 152 container.removeProblemsOfSource(node); // clear problems of changed node... 153 node.visit(container, container); // .. and revisit it. 154 updateEnabledState(); 155 } 156 157 /** 158 * Begins the transaction (command sequence). Must be called by every subclass before 159 * any modification on OSM objects starts. 160 * 161 * @param txName the name of the transaction (e. g. "change address tags"). 162 */ 163 public void beginTransaction(String txName) { 164 if (commands != null && commands.size() > 0) { 165 throw new RuntimeException("TX has not been closed (missing finishTransaction?)"); 166 } 167 168 commands = new ArrayList<Command>(); 169 if (StringUtils.isNullOrEmpty(txName)) { 170 throw new RuntimeException("Transaction must have a name"); 171 } 172 this.txName = txName; 173 } 174 175 /** 176 * Finishes the transaction and passes the command sequence to the framework. 177 */ 178 public void finishTransaction() { 179 if (commands == null) { 180 throw new RuntimeException("No command list available. Did you forget to call beginTransaction?"); 181 } 182 // execute the command 183 Main.main.undoRedo.add(new SequenceCommand(txName, commands)); 184 commands.clear(); 185 container.invalidate(); 186 } 187 188 /** 189 * Begins the transaction for a single object. 190 * 191 * @param entity the entity 192 */ 193 public void beginObjectTransaction(IOSMEntity entity) { 194 if (entity != null) { 195 entity.addCommandListener(this); 196 } else { 197 throw new RuntimeException("Entity must not be null"); 198 } 199 } 200 201 /** 202 * Finishes the transaction for a single object. 203 * 204 * @param entity the entity 205 */ 206 public void finishObjectTransaction(IOSMEntity entity) { 207 if (entity != null) { 208 entity.removeCommandListener(this); 209 } else { 210 throw new RuntimeException("Entity must not be null"); 211 } 212 } 213 214 @Override 215 public void commandIssued(IOSMEntity entity, Command command) { 216 if (commands == null) { 217 throw new RuntimeException("No command list available. Did you forget to call beginTransaction?"); 218 } 219 commands.add(command); 220 } 249 221 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/AddressActions.java
r27322 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 14 1 // License: GPL. For details, see LICENSE file. 15 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 16 3 17 4 public final class AddressActions { 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 5 /* Global action objects */ 6 private static SelectAddressesInMapAction selectAction = new SelectAddressesInMapAction(); 7 private static GuessAddressDataAction guessDataAction = new GuessAddressDataAction(); 8 private static ApplyAllGuessesAction applyGuessesAction = new ApplyAllGuessesAction(); 9 private static RemoveAddressTagsAction removeTagsAction = new RemoveAddressTagsAction(); 10 private static AssignAddressToStreetAction resolveAction = new AssignAddressToStreetAction(); 11 private static ConvertToRelationAction convertToRelationAction = new ConvertToRelationAction(); 12 private static ConvertAllToRelationAction convertAllToRelationAction = new ConvertAllToRelationAction(); 13 14 public static SelectAddressesInMapAction getSelectAction() { 15 return selectAction; 16 } 17 public static GuessAddressDataAction getGuessAddressAction() { 18 return guessDataAction; 19 } 20 public static ApplyAllGuessesAction getApplyGuessesAction() { 21 return applyGuessesAction; 22 } 23 public static RemoveAddressTagsAction getRemoveTagsAction() { 24 return removeTagsAction; 25 } 26 public static AssignAddressToStreetAction getResolveAction() { 27 return resolveAction; 28 } 29 public static ConvertToRelationAction getConvertToRelationAction() { 30 return convertToRelationAction; 31 } 32 public static ConvertAllToRelationAction getConvertAllToRelationAction() { 33 return convertAllToRelationAction; 34 } 48 35 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/ApplyAllGuessesAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 36 24 * 37 25 */ 38 39 26 @SuppressWarnings("serial") 40 27 public class ApplyAllGuessesAction extends AbstractAddressEditAction implements MouseListener{ 41 42 43 44 45 46 47 48 49 28 private String tag; 29 /** 30 * Instantiates a new "apply all guesses" action. 31 */ 32 public ApplyAllGuessesAction(String tag) { 33 super(tr("Apply"), "applyguesses_24", tr("Turns all guesses into the corresponding tag values."), 34 "fixaddresses/applyallguesses"); 35 this.tag = tag; 36 } 50 37 51 52 53 54 55 56 38 /** 39 * Instantiates a new "apply all guesses" action. 40 */ 41 public ApplyAllGuessesAction() { 42 this(null); 43 } 57 44 58 /* (non-Javadoc) 59 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent) 60 */ 61 @Override 62 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 63 if (ev == null) return; 45 @Override 46 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 47 if (ev == null) return; 64 48 65 66 67 68 49 if (ev.getSelectedUnresolvedAddresses() != null) { 50 List<OSMAddress> addrToFix = ev.getSelectedUnresolvedAddresses(); 51 applyGuesses(addrToFix); 52 } 69 53 70 71 72 73 74 54 if (ev.getSelectedIncompleteAddresses() != null) { 55 List<OSMAddress> addrToFix = ev.getSelectedIncompleteAddresses(); 56 applyGuesses(addrToFix); 57 } 58 } 75 59 76 /* (non-Javadoc) 77 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 78 */ 79 @Override 80 protected void updateEnabledState(AddressEditContainer container) { 81 setEnabled(container != null && container.getNumberOfGuesses() > 0); 82 } 60 @Override 61 protected void updateEnabledState(AddressEditContainer container) { 62 setEnabled(container != null && container.getNumberOfGuesses() > 0); 63 } 83 64 84 85 86 87 88 89 90 91 92 93 65 /** 66 * Apply guesses. 67 * 68 * @param addrToFix the addr to fix 69 */ 70 private void applyGuesses(List<OSMAddress> addrToFix) { 71 beginTransaction(tr("Applied guessed values")); 72 List<OSMAddress> addrToFixShadow = new ArrayList<OSMAddress>(addrToFix); 73 for (OSMAddress aNode : addrToFixShadow) { 74 beginObjectTransaction(aNode); 94 75 95 96 97 98 99 100 101 102 103 76 if (StringUtils.isNullOrEmpty(tag)) { // tag given? 77 aNode.applyAllGuesses(); // no -> apply all guesses 78 } else { // apply guessed values for single tag only 79 aNode.applyGuessForTag(tag); 80 } 81 finishObjectTransaction(aNode); 82 } 83 finishTransaction(); 84 } 104 85 105 /* (non-Javadoc) 106 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent) 107 */ 108 @Override 109 protected void updateEnabledState(AddressEditSelectionEvent event) { 110 setEnabled(event.hasAddressesWithGuesses()); 111 } 86 @Override 87 protected void updateEnabledState(AddressEditSelectionEvent event) { 88 setEnabled(event.hasAddressesWithGuesses()); 89 } 112 90 113 /* (non-Javadoc) 114 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 115 */ 116 @Override 117 public void addressEditActionPerformed(AddressEditContainer container) { 118 if (container == null || container.getNumberOfIncompleteAddresses() == 0) return; 91 @Override 92 public void addressEditActionPerformed(AddressEditContainer container) { 93 if (container == null || container.getNumberOfIncompleteAddresses() == 0) return; 119 94 120 121 95 List<OSMAddress> addrToFix = container.getUnresolvedAddresses(); 96 applyGuesses(addrToFix); 122 97 123 124 125 98 addrToFix = container.getIncompleteAddresses(); 99 applyGuesses(addrToFix); 100 } 126 101 127 /* (non-Javadoc) 128 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) 129 */ 130 @Override 131 public void mouseClicked(MouseEvent e) { 132 JTable table = (JTable)e.getSource(); 133 Point p = e.getPoint(); 134 if(e.getClickCount() == 2) { 135 AddressEditTableModel model = (AddressEditTableModel) table.getModel(); 136 if (model != null) { 137 int row = table.rowAtPoint(p); 138 IOSMEntity node = model.getEntityOfRow(row); 139 if (node instanceof OSMAddress) { 140 beginTransaction(tr("Applied guessed values for ") + node.getOsmObject()); 141 beginObjectTransaction(node); 142 OSMAddress aNode = (OSMAddress) node; 102 @Override 103 public void mouseClicked(MouseEvent e) { 104 JTable table = (JTable)e.getSource(); 105 Point p = e.getPoint(); 106 if(e.getClickCount() == 2) { 107 AddressEditTableModel model = (AddressEditTableModel) table.getModel(); 108 if (model != null) { 109 int row = table.rowAtPoint(p); 110 IOSMEntity node = model.getEntityOfRow(row); 111 if (node instanceof OSMAddress) { 112 beginTransaction(tr("Applied guessed values for ") + node.getOsmObject()); 113 beginObjectTransaction(node); 114 OSMAddress aNode = (OSMAddress) node; 143 115 144 116 aNode.applyAllGuesses(); 145 117 146 147 148 149 150 151 118 finishObjectTransaction(node); 119 finishTransaction(); 120 } 121 } 122 } 123 } 152 124 153 /* (non-Javadoc) 154 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) 155 */ 156 @Override 157 public void mouseEntered(MouseEvent arg0) { 158 } 125 @Override 126 public void mouseEntered(MouseEvent arg0) { 127 } 159 128 160 /* (non-Javadoc) 161 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) 162 */ 163 @Override 164 public void mouseExited(MouseEvent arg0) { 165 } 129 @Override 130 public void mouseExited(MouseEvent arg0) { 131 } 166 132 167 /* (non-Javadoc) 168 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) 169 */ 170 @Override 171 public void mousePressed(MouseEvent arg0) { 172 } 133 @Override 134 public void mousePressed(MouseEvent arg0) { 135 } 173 136 174 /* (non-Javadoc) 175 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) 176 */ 177 @Override 178 public void mouseReleased(MouseEvent arg0) { 179 } 137 @Override 138 public void mouseReleased(MouseEvent arg0) { 139 } 180 140 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/AssignAddressToStreetAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 29 17 public class AssignAddressToStreetAction extends AbstractAddressEditAction { 30 18 31 32 33 34 35 36 37 38 19 /** 20 * Instantiates a new "assign address to street" action. 21 */ 22 public AssignAddressToStreetAction() { 23 super(tr("Assign address to street"), "assignstreet_24", 24 tr("Assign the selected address(es) to the selected street."), 25 "fixaddresses/assignaddresstostreet"); 26 } 39 27 40 41 42 43 28 /** 29 * 30 */ 31 private static final long serialVersionUID = -6180491357232121384L; 44 32 45 /* (non-Javadoc) 46 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent) 47 */ 48 @Override 49 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 50 OSMStreet streetNode = ev.getSelectedStreet(); 33 @Override 34 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 35 OSMStreet streetNode = ev.getSelectedStreet(); 51 36 52 53 54 55 56 57 58 59 60 37 if (streetNode != null && ev.getSelectedUnresolvedAddresses() != null) { 38 beginTransaction(tr("Set street name") + " '" + streetNode.getName() + "'"); 39 for (OSMAddress addrNode : ev.getSelectedUnresolvedAddresses()) { 40 beginObjectTransaction(addrNode); 41 addrNode.assignStreet(streetNode); 42 finishObjectTransaction(addrNode); 43 } 44 finishTransaction(); 45 } 61 46 62 47 } 63 48 64 /* (non-Javadoc) 65 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent) 66 */ 67 @Override 68 public void updateEnabledState(AddressEditSelectionEvent ev) { 69 setEnabled(ev.getSelectedStreet() != null && ev.hasUnresolvedAddresses()); 70 } 49 @Override 50 public void updateEnabledState(AddressEditSelectionEvent ev) { 51 setEnabled(ev.getSelectedStreet() != null && ev.hasUnresolvedAddresses()); 52 } 71 53 72 73 74 75 76 54 @Override 55 public void updateEnabledState(AddressEditContainer container) { 56 // we only accept a selection here 57 setEnabled(false); 58 } 77 59 78 79 80 81 60 @Override 61 public void addressEditActionPerformed(AddressEditContainer container) { 62 // we only accept a selection: nothing to do here 63 } 82 64 83 65 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/ConvertAllToRelationAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 22 10 @SuppressWarnings("serial") 23 11 public class ConvertAllToRelationAction extends ConvertToRelationAction { 24 25 26 27 28 12 public ConvertAllToRelationAction() { 13 super(tr("Convert ALL streets."), "convert2rel_24", 14 tr("Create relation between street and related addresses for ALL streets in the current layer."), 15 "fixaddresses/convertalltorelation"); 16 } 29 17 30 31 32 33 18 @Override 19 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 20 // nothing to do 21 } 34 22 35 36 37 38 39 40 41 42 23 @Override 24 public void addressEditActionPerformed(AddressEditContainer container) { 25 if (container != null) { 26 for (OSMStreet street : container.getStreetList()) { 27 createRelationForStreet(street); 28 } 29 } 30 } 43 31 44 45 46 47 32 @Override 33 protected void updateEnabledState(AddressEditContainer container) { 34 setEnabled(hasStreetsToConvert()); 35 } 48 36 49 50 51 52 37 @Override 38 protected void updateEnabledState(AddressEditSelectionEvent event) { 39 setEnabled(hasStreetsToConvert()); 40 } 53 41 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 42 /** 43 * Checks for streets to convert to a relation. 44 * 45 * @return true, if successful 46 */ 47 private boolean hasStreetsToConvert() { 48 if (container != null) { 49 for (OSMStreet street : container.getStreetList()) { 50 if (street.hasAddresses() && !street.hasAssociatedStreetRelation()) { 51 return true; 52 } 53 } 54 } 55 return false; 56 } 69 57 70 58 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/ConvertToRelationAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 29 17 public class ConvertToRelationAction extends AbstractAddressEditAction { 30 18 31 32 33 34 35 19 public ConvertToRelationAction() { 20 super(tr("Convert to relation."), "convert2rel_24", 21 tr("Create relation between street and related addresses."), 22 "fixaddresses/converttorelation"); 23 } 36 24 37 38 39 40 41 42 43 44 45 46 25 /** 26 * Instantiates a new convert to relation action. 27 * 28 * @param name the name of the action 29 * @param iconName the icon name 30 * @param tooltip the tool tip to show on hover 31 */ 32 public ConvertToRelationAction(String name, String iconName, String tooltip, String toolbar) { 33 super(name, iconName, tooltip, toolbar); 34 } 47 35 48 /* (non-Javadoc) 49 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent) 50 */ 51 @Override 52 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 53 OSMStreet streetNode = ev.getSelectedStreet(); 36 @Override 37 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 38 OSMStreet streetNode = ev.getSelectedStreet(); 54 39 55 56 57 58 40 if (streetNode != null) { 41 createRelationForStreet(streetNode); 42 } 43 } 59 44 60 61 62 63 64 65 66 67 45 /** 46 * Creates the 'associatedStreet' relation for a given street by adding all addresses which 47 * matches the name of the street. 48 * 49 * @param streetNode the street node 50 */ 51 protected void createRelationForStreet(OSMStreet streetNode) { 52 if (streetNode == null || !streetNode.hasAddresses()) return; 68 53 69 70 71 72 73 74 75 76 54 beginTransaction(tr("Create address relation for ") + " '" + streetNode.getName() + "'"); 55 // Create the relation 56 Relation r = new Relation(); 57 commands.add(new AddCommand(r)); 58 commands.add(new ChangePropertyCommand(r, TagUtils.NAME_TAG, streetNode.getName())); 59 commands.add(new ChangePropertyCommand(r, TagUtils.RELATION_TYPE, TagUtils.ASSOCIATEDSTREET_RELATION_TYPE)); 60 // add street with role 'street' 61 r.addMember(new RelationMember(TagUtils.STREET_RELATION_ROLE, streetNode.getOsmObject())); 77 62 78 79 80 81 82 83 84 85 86 63 // add address members 64 for (OSMAddress addrNode : streetNode.getAddresses()) { 65 beginObjectTransaction(addrNode); 66 r.addMember(new RelationMember(TagUtils.HOUSE_RELATION_ROLE, addrNode.getOsmObject())); 67 addrNode.setStreetName(null); // remove street name 68 finishObjectTransaction(addrNode); 69 } 70 finishTransaction(); 71 } 87 72 88 /* (non-Javadoc) 89 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 90 */ 91 @Override 92 public void addressEditActionPerformed(AddressEditContainer container) { 93 // Nothing to do (yet). 94 } 73 @Override 74 public void addressEditActionPerformed(AddressEditContainer container) { 75 // Nothing to do (yet). 76 } 95 77 96 /* (non-Javadoc) 97 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 98 */ 99 @Override 100 protected void updateEnabledState(AddressEditContainer container) { 101 setEnabled(false); 102 } 78 @Override 79 protected void updateEnabledState(AddressEditContainer container) { 80 setEnabled(false); 81 } 103 82 104 /* (non-Javadoc) 105 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent) 106 */ 107 @Override 108 protected void updateEnabledState(AddressEditSelectionEvent event) { 109 if (event == null) return; 83 @Override 84 protected void updateEnabledState(AddressEditSelectionEvent event) { 85 if (event == null) return; 110 86 111 OSMStreet street = event.getSelectedStreet(); 112 setEnabled(street != null && street.hasAddresses() && !street.hasAssociatedStreetRelation()); 113 } 114 87 OSMStreet street = event.getSelectedStreet(); 88 setEnabled(street != null && street.hasAddresses() && !street.hasAssociatedStreetRelation()); 89 } 115 90 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/GuessAddressDataAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 31 19 * @author Oliver Wieland <oliver.wieland@online.de> 32 20 */ 33 34 21 @SuppressWarnings("serial") 35 22 public class GuessAddressDataAction extends AbstractAddressEditAction implements IProgressMonitorFinishedListener { 36 23 37 38 39 40 41 42 43 24 /** 25 * Instantiates a new "guess address data" action. 26 */ 27 public GuessAddressDataAction() { 28 super(tr("Guess"), "guessstreets_24", tr("Tries to guess address data by picking the name of the closest object with according tag."), 29 "fixaddresses/guessaddressdata"); 30 } 44 31 45 /* (non-Javadoc) 46 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent) 47 */ 48 @Override 49 public void updateEnabledState(AddressEditSelectionEvent ev) { 50 setEnabled(ev != null && ev.hasAddresses()); 51 } 32 @Override 33 public void updateEnabledState(AddressEditSelectionEvent ev) { 34 setEnabled(ev != null && ev.hasAddresses()); 35 } 52 36 53 /* (non-Javadoc) 54 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 55 */ 56 @Override 57 protected void updateEnabledState(AddressEditContainer container) { 58 setEnabled(container != null && container.getNumberOfInvalidAddresses() > 0); 59 } 37 @Override 38 protected void updateEnabledState(AddressEditContainer container) { 39 setEnabled(container != null && container.getNumberOfInvalidAddresses() > 0); 40 } 60 41 61 /* (non-Javadoc) 62 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 63 */ 64 @Override 65 public void addressEditActionPerformed(AddressEditContainer container) { 66 if (container == null || container.getNumberOfInvalidAddresses() == 0) return; 42 @Override 43 public void addressEditActionPerformed(AddressEditContainer container) { 44 if (container == null || container.getNumberOfInvalidAddresses() == 0) return; 67 45 68 69 46 internalGuessAddresses(container.getAllAddressesToFix()); 47 } 70 48 71 /* (non-Javadoc) 72 * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent) 73 */ 74 @Override 75 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 76 if (ev == null || !ev.hasAddresses()) return; 49 @Override 50 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 51 if (ev == null || !ev.hasAddresses()) return; 77 52 78 79 80 81 53 // guess tags for selected addresses only 54 internalGuessAddresses(ev.getSelectedIncompleteAddresses()); 55 internalGuessAddresses(ev.getSelectedUnresolvedAddresses()); 56 } 82 57 83 84 85 86 87 88 58 /** 59 * Internal method to start several threads guessing tag values for the given list of addresses. 60 * @param addrNodes 61 */ 62 private void internalGuessAddresses(List<OSMAddress> nodes) { 63 if (nodes == null) return; 89 64 90 91 92 93 94 65 // Launch address guessing thread 66 GuessAddressRunnable aft = new GuessAddressRunnable(nodes, tr("Guessing address values")); 67 aft.addFinishListener(this); 68 Main.worker.submit(aft); 69 } 95 70 96 97 98 99 100 101 71 @Override 72 public void finished() { 73 if (container != null) { 74 container.invalidate(); 75 } 76 } 102 77 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/RemoveAddressTagsAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 23 11 public class RemoveAddressTagsAction extends AbstractAddressEditAction { 24 12 25 26 27 28 13 public RemoveAddressTagsAction() { 14 super(tr("Remove"), "removeaddrtags_24", tr("Removes address related tags from the object."), 15 "fixaddresses/removeaddresstags"); 16 } 29 17 30 31 32 33 34 35 36 37 38 39 18 @Override 19 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 20 beginTransaction(tr("Remove address tags")); 21 if (ev.hasUnresolvedAddresses()) { 22 for (OSMAddress aNode : ev.getSelectedUnresolvedAddresses()) { 23 beginObjectTransaction(aNode); 24 aNode.removeAllAddressTags(); 25 finishObjectTransaction(aNode); 26 } 27 } 40 28 41 42 43 44 45 46 47 48 49 29 if (ev.hasIncompleteAddresses()) { 30 for (OSMAddress aNode : ev.getSelectedIncompleteAddresses()) { 31 beginObjectTransaction(aNode); 32 aNode.removeAllAddressTags(); 33 finishObjectTransaction(aNode); 34 } 35 } 36 finishTransaction(); 37 } 50 38 51 52 53 54 39 @Override 40 public void addressEditActionPerformed(AddressEditContainer container) { 41 // do nothing 42 } 55 43 56 57 58 59 44 @Override 45 protected void updateEnabledState(AddressEditContainer container) { 46 setEnabled(false); 47 } 60 48 61 62 63 64 65 49 @Override 50 protected void updateEnabledState(AddressEditSelectionEvent event) { 51 if (event == null) { 52 setEnabled(false); 53 } 66 54 67 68 55 setEnabled(event.hasAddresses()); 56 } 69 57 70 58 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/SelectAddressesInMapAction.java
r27907 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 14 /** 15 * This program is free software: you can redistribute it and/or modify it under 16 * the terms of the GNU General Public License as published by the 17 * Free Software Foundation, either version 3 of the License, or 18 * (at your option) any later version. 19 * 20 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 21 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 * See the GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License along with this program. 25 * If not, see <http://www.gnu.org/licenses/>. 26 */ 27 28 /* File created on 30.10.2010 */ 1 // License: GPL. For details, see LICENSE file. 29 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 30 3 … … 45 18 * 46 19 */ 47 48 20 @SuppressWarnings("serial") 49 21 public class SelectAddressesInMapAction extends AbstractAddressEditAction { 50 22 51 52 53 54 55 56 57 23 /** 24 * Instantiates a new "select addresses in map" action. 25 */ 26 public SelectAddressesInMapAction() { 27 super(tr("Select"), "selectall", tr("Marks selected addresses in the map"), 28 "fixaddresses/selectaddressesinmap"); 29 } 58 30 59 /* (non-Javadoc) 60 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent) 61 */ 62 @Override 63 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 64 if (ev == null) return; 31 @Override 32 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 33 if (ev == null) return; 65 34 66 67 68 69 70 71 35 if (ev.hasUnresolvedAddresses()) { 36 internalSelectAddresses(ev.getSelectedUnresolvedAddresses()); 37 } else if (ev.hasIncompleteAddresses()) { 38 internalSelectAddresses(ev.getSelectedIncompleteAddresses()); 39 } 40 } 72 41 73 74 75 76 42 @Override 43 public void addressEditActionPerformed(AddressEditContainer container) { 44 // do nothing 45 } 77 46 78 /* (non-Javadoc) 79 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer) 80 */ 81 @Override 82 protected void updateEnabledState(AddressEditContainer container) { 83 setEnabled(false); 84 } 47 @Override 48 protected void updateEnabledState(AddressEditContainer container) { 49 setEnabled(false); 50 } 85 51 86 /* (non-Javadoc) 87 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent) 88 */ 89 @Override 90 protected void updateEnabledState(AddressEditSelectionEvent event) { 91 setEnabled(event != null && event.hasAddresses()); 92 } 52 @Override 53 protected void updateEnabledState(AddressEditSelectionEvent event) { 54 setEnabled(event != null && event.hasAddresses()); 55 } 93 56 94 95 96 97 98 99 57 /** 58 * Internal helper to select the given addresses in the map. 59 * @param addrToSel 60 */ 61 private void internalSelectAddresses(List<OSMAddress> addrToSel) { 62 if (addrToSel == null) return; 100 63 101 64 List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(); 102 65 103 104 105 66 getCurrentDataSet().clearSelection(); 67 for (OSMAddress aNode : addrToSel) { 68 sel.add(aNode.getOsmObject()); 106 69 107 108 109 110 111 112 113 70 // Select also guessed objects, if wished 71 if (FixAddressesPlugin.getPreferences().isSelectGuessedObjects()) { 72 for (OsmPrimitive osmPrimitive : aNode.getGuessedObjects()) { 73 sel.add(osmPrimitive); 74 } 75 } 76 } 114 77 115 116 78 getCurrentDataSet().setSelected(sel); 79 } 117 80 118 81 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/SelectIncompleteAddressesAction.java
r25373 r30348 1 /* 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 12 * If not, see <http://www.gnu.org/licenses/>. 13 */ 1 // License: GPL. For details, see LICENSE file. 14 2 package org.openstreetmap.josm.plugins.fixAddresses.gui.actions; 15 3 … … 29 17 30 18 31 19 private AddressEditContainer addressEditContainer; 32 20 33 34 35 36 21 public SelectIncompleteAddressesAction() { 22 super(tr("Select incomplete addresses"), "select_invaddr_24", 23 tr("Selects all addresses with incomplete data."), null, false); 24 } 37 25 38 39 40 41 26 @Override 27 public void actionPerformed(ActionEvent arg0) { 28 addressEditContainer = new AddressEditContainer(); 29 addressEditContainer.invalidate(); 42 30 43 44 31 if (addressEditContainer.getIncompleteAddresses() != null) { 32 List<OsmPrimitive> osms = new ArrayList<OsmPrimitive>(); 45 33 46 47 48 49 50 51 34 for (OSMAddress aNode : addressEditContainer.getIncompleteAddresses()) { 35 osms.add(aNode.getOsmObject()); 36 } 37 getCurrentDataSet().setSelected(osms); 38 } 39 } 52 40 53 /* (non-Javadoc) 54 * @see org.openstreetmap.josm.actions.JosmAction#updateEnabledState() 55 */ 56 @Override 57 protected void updateEnabledState() { 58 setEnabled(getCurrentDataSet() != null); 59 } 41 @Override 42 protected void updateEnabledState() { 43 setEnabled(getCurrentDataSet() != null); 44 } 60 45 }
Note:
See TracChangeset
for help on using the changeset viewer.