Changeset 7395 in josm for trunk/src/org
- Timestamp:
- 2014-08-14T15:33:52+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r7073 r7395 122 122 private final Object selectionLock = new Object(); 123 123 124 /** 125 * Constructs a new {@code DataSet}. 126 */ 124 127 public DataSet() { 125 128 /* … … 130 133 } 131 134 135 /** 136 * Returns the lock used for reading. 137 * @return the lock used for reading 138 */ 132 139 public Lock getReadLock() { 133 140 return lock.readLock(); … … 165 172 166 173 /** 167 * Maintain a list of used tags for autocompletion174 * Maintains a list of used tags for autocompletion. 168 175 */ 169 176 private AutoCompletionManager autocomplete; 170 177 178 /** 179 * Returns the autocompletion manager, which maintains a list of used tags for autocompletion. 180 * @return the autocompletion manager 181 */ 171 182 public AutoCompletionManager getAutoCompletionManager() { 172 183 if (autocomplete == null) { … … 200 211 } 201 212 213 /** 214 * Determines if upload is being discouraged (i.e. this dataset contains private data which should not be uploaded) 215 * @return {@code true} if upload is being discouraged, {@code false} otherwise 216 * @see #setUploadDiscouraged 217 */ 202 218 public final boolean isUploadDiscouraged() { 203 219 return uploadDiscouraged; 204 220 } 205 221 222 /** 223 * Sets the "upload discouraged" flag. 224 * @param uploadDiscouraged {@code true} if this dataset contains private data which should not be uploaded 225 * @see #isUploadDiscouraged 226 */ 206 227 public final void setUploadDiscouraged(boolean uploadDiscouraged) { 207 228 this.uploadDiscouraged = uploadDiscouraged; … … 213 234 private Map<String, String> changeSetTags = new HashMap<>(); 214 235 236 /** 237 * Replies the set of changeset tags to be applied when or if this is ever uploaded. 238 * @return the set of changeset tags 239 * @see #addChangeSetTag 240 */ 215 241 public Map<String, String> getChangeSetTags() { 216 242 return changeSetTags; 217 243 } 218 244 245 /** 246 * Adds a new changeset tag. 247 * @param k Key 248 * @param v Value 249 * @see #getChangeSetTags 250 */ 219 251 public void addChangeSetTag(String k, String v) { 220 252 this.changeSetTags.put(k,v); … … 240 272 } 241 273 274 /** 275 * Searches for nodes in the given bounding box. 276 * @param bbox the bounding box 277 * @return List of nodes in the given bbox. Can be empty but not null 278 */ 242 279 public List<Node> searchNodes(BBox bbox) { 243 280 lock.readLock().lock(); … … 265 302 } 266 303 304 /** 305 * Searches for ways in the given bounding box. 306 * @param bbox the bounding box 307 * @return List of ways in the given bbox. Can be empty but not null 308 */ 267 309 public List<Way> searchWays(BBox bbox) { 268 310 lock.readLock().lock(); … … 288 330 } 289 331 332 /** 333 * Searches for relations in the given bounding box. 334 * @param bbox the bounding box 335 * @return List of relations in the given bbox. Can be empty but not null 336 */ 290 337 public List<Relation> searchRelations(BBox bbox) { 291 338 lock.readLock().lock(); … … 310 357 311 358 /** 312 * @return A collection containing all primitives of the dataset. Data are not ordered 359 * Returns a collection containing all primitives of the dataset. 360 * @return A collection containing all primitives of the dataset. Data is not ordered 313 361 */ 314 362 public Collection<OsmPrimitive> allPrimitives() { … … 317 365 318 366 /** 319 * @return A collection containing all not-deleted primitives (except keys). 367 * Returns a collection containing all not-deleted primitives. 368 * @return A collection containing all not-deleted primitives. 369 * @see OsmPrimitive#isDeleted 320 370 */ 321 371 public Collection<OsmPrimitive> allNonDeletedPrimitives() { … … 323 373 } 324 374 375 /** 376 * Returns a collection containing all not-deleted complete primitives. 377 * @return A collection containing all not-deleted complete primitives. 378 * @see OsmPrimitive#isDeleted 379 * @see OsmPrimitive#isIncomplete 380 */ 325 381 public Collection<OsmPrimitive> allNonDeletedCompletePrimitives() { 326 382 return getPrimitives(OsmPrimitive.nonDeletedCompletePredicate); 327 383 } 328 384 385 /** 386 * Returns a collection containing all not-deleted complete physical primitives. 387 * @return A collection containing all not-deleted complete physical primitives (nodes and ways). 388 * @see OsmPrimitive#isDeleted 389 * @see OsmPrimitive#isIncomplete 390 */ 329 391 public Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives() { 330 392 return getPrimitives(OsmPrimitive.nonDeletedPhysicalPredicate); 331 393 } 332 394 395 /** 396 * Returns a collection containing all modified primitives. 397 * @return A collection containing all modified primitives. 398 * @see OsmPrimitive#isModified 399 */ 333 400 public Collection<OsmPrimitive> allModifiedPrimitives() { 334 401 return getPrimitives(OsmPrimitive.modifiedPredicate); … … 336 403 337 404 /** 338 * Adds a primitive to the dataset 405 * Adds a primitive to the dataset. 339 406 * 340 407 * @param primitive the primitive. … … 414 481 private static final Collection<SelectionChangedListener> selListeners = new CopyOnWriteArrayList<>(); 415 482 483 /** 484 * Adds a new selection listener. 485 * @param listener The selection listener to add 486 */ 416 487 public static void addSelectionListener(SelectionChangedListener listener) { 417 488 ((CopyOnWriteArrayList<SelectionChangedListener>)selListeners).addIfAbsent(listener); 418 489 } 419 490 491 /** 492 * Removes a selection listener. 493 * @param listener The selection listener to remove 494 */ 420 495 public static void removeSelectionListener(SelectionChangedListener listener) { 421 496 selListeners.remove(listener); … … 437 512 private Collection<OsmPrimitive> selectionSnapshot; 438 513 514 /** 515 * Returns selected nodes and ways. 516 * @return selected nodes and ways 517 */ 439 518 public Collection<OsmPrimitive> getSelectedNodesAndWays() { 440 519 return new FilteredCollection<>(getSelected(), new Predicate<OsmPrimitive>() { … … 447 526 448 527 /** 449 * returns an unmodifiable collection of *WaySegments* whose virtual528 * Returns an unmodifiable collection of *WaySegments* whose virtual 450 529 * nodes should be highlighted. WaySegments are used to avoid having 451 530 * to create a VirtualNode class that wouldn't have much purpose otherwise. … … 458 537 459 538 /** 460 * returns an unmodifiable collection of WaySegments that should be 461 * highlighted. 539 * Returns an unmodifiable collection of WaySegments that should be highlighted. 462 540 * 463 541 * @return unmodifiable collection of WaySegments … … 495 573 496 574 /** 497 * Return selected nodes. 575 * Returns selected nodes. 576 * @return selected nodes 498 577 */ 499 578 public Collection<Node> getSelectedNodes() { … … 502 581 503 582 /** 504 * Return selected ways. 583 * Returns selected ways. 584 * @return selected ways 505 585 */ 506 586 public Collection<Way> getSelectedWays() { … … 509 589 510 590 /** 511 * Return selected relations. 591 * Returns selected relations. 592 * @return selected relations 512 593 */ 513 594 public Collection<Relation> getSelectedRelations() { … … 516 597 517 598 /** 599 * Determines whether the selection is empty or not 518 600 * @return whether the selection is empty or not 519 601 */ … … 522 604 } 523 605 606 /** 607 * Determines whether the given primitive is selected or not 608 * @param osm the primitive 609 * @return whether {@code osm} is selected or not 610 */ 524 611 public boolean isSelected(OsmPrimitive osm) { 525 612 return selectedPrimitives.contains(osm); 526 613 } 527 614 615 /** 616 * Toggles the selected state of the given collection of primitives. 617 * @param osm The primitives to toggle 618 */ 528 619 public void toggleSelected(Collection<? extends PrimitiveId> osm) { 529 620 boolean changed = false; … … 540 631 } 541 632 } 633 634 /** 635 * Toggles the selected state of the given collection of primitives. 636 * @param osm The primitives to toggle 637 */ 542 638 public void toggleSelected(PrimitiveId... osm) { 543 639 toggleSelected(Arrays.asList(osm)); 544 640 } 641 545 642 private boolean __toggleSelected(PrimitiveId primitiveId) { 546 643 OsmPrimitive primitive = getPrimitiveByIdChecked(primitiveId); … … 617 714 } 618 715 716 /** 717 * Sets the current selection to the primitives in <code>osm</code> 718 * and notifies all {@link SelectionChangedListener}. 719 * 720 * @param osm the primitives to set 721 */ 619 722 public void setSelected(PrimitiveId... osm) { 620 723 if (osm.length == 1 && osm[0] == null) { … … 627 730 628 731 /** 629 * Adds 732 * Adds the primitives in <code>selection</code> to the current selection 630 733 * and notifies all {@link SelectionChangedListener}. 631 734 * … … 636 739 } 637 740 741 /** 742 * Adds the primitives in <code>osm</code> to the current selection 743 * and notifies all {@link SelectionChangedListener}. 744 * 745 * @param osm the primitives to add 746 */ 638 747 public void addSelected(PrimitiveId... osm) { 639 748 addSelected(Arrays.asList(osm)); … … 682 791 683 792 /** 684 * Remove the selection from every value in the collection.793 * Removes the selection from every value in the collection. 685 794 * @param osm The collection of ids to remove the selection from. 686 795 */ … … 688 797 clearSelection(Arrays.asList(osm)); 689 798 } 799 800 /** 801 * Removes the selection from every value in the collection. 802 * @param list The collection of ids to remove the selection from. 803 */ 690 804 public void clearSelection(Collection<? extends PrimitiveId> list) { 691 805 boolean changed = false; … … 705 819 } 706 820 } 821 822 /** 823 * Clears the current selection. 824 */ 707 825 public void clearSelection() { 708 826 if (!selectedPrimitives.isEmpty()) { … … 715 833 } 716 834 717 @Override public DataSet clone() { 835 @Override 836 public DataSet clone() { 718 837 getReadLock().lock(); 719 838 try { … … 776 895 777 896 /** 778 * returns a primitive with a given id from the data set. null, if no such primitive 779 * exists 897 * Returns a primitive with a given id from the data set. null, if no such primitive exists 780 898 * 781 899 * @param id uniqueId of the primitive. Might be < 0 for newly created primitives … … 788 906 } 789 907 908 /** 909 * Returns a primitive with a given id from the data set. null, if no such primitive exists 910 * 911 * @param primitiveId type and uniqueId of the primitive. Might be < 0 for newly created primitives 912 * @return the primitive 913 */ 790 914 public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId) { 791 915 return primitivesMap.get(primitiveId); … … 949 1073 } 950 1074 1075 /** 1076 * Adds a new data set listener. 1077 * @param dsl The data set listener to add 1078 */ 951 1079 public void addDataSetListener(DataSetListener dsl) { 952 1080 listeners.addIfAbsent(dsl); 953 1081 } 954 1082 1083 /** 1084 * Removes a data set listener. 1085 * @param dsl The data set listener to remove 1086 */ 955 1087 public void removeDataSetListener(DataSetListener dsl) { 956 1088 listeners.remove(dsl); … … 1078 1210 } 1079 1211 1212 /** 1213 * Cleanups all deleted primitives (really delete them from the dataset). 1214 */ 1080 1215 public void cleanupDeletedPrimitives() { 1081 1216 beginUpdate(); … … 1169 1304 1170 1305 /** 1171 * Moves all primitives and datasources from DataSet "from" to this DataSet 1306 * Moves all primitives and datasources from DataSet "from" to this DataSet. 1172 1307 * @param from The source DataSet 1173 1308 */ … … 1177 1312 1178 1313 /** 1179 * Moves all primitives and datasources from DataSet "from" to this DataSet 1314 * Moves all primitives and datasources from DataSet "from" to this DataSet. 1180 1315 * @param from The source DataSet 1316 * @param progressMonitor The progress monitor 1181 1317 */ 1182 1318 public void mergeFrom(DataSet from, ProgressMonitor progressMonitor) { -
trunk/src/org/openstreetmap/josm/data/osm/MultipolygonBuilder.java
r7392 r7395 285 285 } else if (intersection == PolygonIntersection.SECOND_INSIDE_FIRST) { 286 286 innerCandidates.add(innerWay); 287 } 288 else if (intersection == PolygonIntersection.CROSSING) { 287 } else if (intersection == PolygonIntersection.CROSSING) { 289 288 //ways intersect 290 289 return null; -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java
r7295 r7395 28 28 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData.Intersection; 29 29 30 /** 31 * Multipolygon data used to represent complex areas, see <a href="https://wiki.openstreetmap.org/wiki/Relation:multipolygon">wiki</a>. 32 * @since 2788 33 */ 30 34 public class Multipolygon { 35 31 36 /** preference key for a collection of roles which indicate that the respective member belongs to an 32 37 * <em>outer</em> polygon. Default is <tt>outer</tt>. 33 38 */ 34 39 public static final String PREF_KEY_OUTER_ROLES = "mappaint.multipolygon.outer.roles"; 40 35 41 /** preference key for collection of role prefixes which indicate that the respective 36 42 * member belongs to an <em>outer</em> polygon. Default is empty. 37 43 */ 38 44 public static final String PREF_KEY_OUTER_ROLE_PREFIXES = "mappaint.multipolygon.outer.role-prefixes"; 45 39 46 /** preference key for a collection of roles which indicate that the respective member belongs to an 40 47 * <em>inner</em> polygon. Default is <tt>inner</tt>. 41 48 */ 42 49 public static final String PREF_KEY_INNER_ROLES = "mappaint.multipolygon.inner.roles"; 50 43 51 /** preference key for collection of role prefixes which indicate that the respective 44 52 * member belongs to an <em>inner</em> polygon. Default is empty. … … 53 61 * <p>The decision is taken based on preference settings, see the four preference keys 54 62 * above.</p> 55 * 56 */ 57 private static class MultipolygonRoleMatcher implements PreferenceChangedListener{ 63 */ 64 private static class MultipolygonRoleMatcher implements PreferenceChangedListener { 58 65 private final List<String> outerExactRoles = new ArrayList<>(); 59 66 private final List<String> outerRolePrefixes = new ArrayList<>(); … … 70 77 } 71 78 72 private void setNormalized(Collection<String> literals, List<String> target) {79 private void setNormalized(Collection<String> literals, List<String> target) { 73 80 target.clear(); 74 for (String l: literals) {81 for (String l: literals) { 75 82 if (l == null) { 76 83 continue; … … 115 122 } 116 123 117 public boolean isOuterRole(String role) {124 public boolean isOuterRole(String role) { 118 125 if (role == null) return false; 119 126 for (String candidate: outerExactRoles) { … … 126 133 } 127 134 128 public boolean isInnerRole(String role) {135 public boolean isInnerRole(String role) { 129 136 if (role == null) return false; 130 137 for (String candidate: innerExactRoles) { … … 139 146 140 147 /* 141 * Init a private global matcher object which will listen to preference 142 * changes. 148 * Init a private global matcher object which will listen to preference changes. 143 149 */ 144 150 private static MultipolygonRoleMatcher roleMatcher; … … 493 499 } 494 500 495 if (nodes == null ) {501 if (nodes == null && w != null) { 496 502 nodes = w.getNodes(); 497 503 wayIds.add(w.getUniqueId()); … … 568 574 } 569 575 576 /** 577 * Replies the list of outer ways. 578 * @return the list of outer ways 579 */ 570 580 public List<Way> getOuterWays() { 571 581 return outerWays; 572 582 } 573 583 584 /** 585 * Replies the list of inner ways. 586 * @return the list of inner ways 587 */ 574 588 public List<Way> getInnerWays() { 575 589 return innerWays; -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
r7005 r7395 35 35 36 36 /** 37 * A memory cache for Multipolygonobjects.37 * A memory cache for {@link Multipolygon} objects. 38 38 * @since 4623 39 39 */ 40 40 public final class MultipolygonCache implements DataSetListener, LayerChangeListener, ProjectionChangeListener, SelectionChangedListener { 41 41 42 private static final MultipolygonCache INSTANCE = new MultipolygonCache(); 43 42 private static final MultipolygonCache INSTANCE = new MultipolygonCache(); 43 44 44 private final Map<NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>> cache; 45 45 46 46 private final Collection<PolyData> selectedPolyData; 47 47 48 48 private MultipolygonCache() { 49 49 this.cache = new HashMap<>(); … … 62 62 } 63 63 64 /** 65 * Gets a multipolygon from cache. 66 * @param nc The navigatable component 67 * @param r The multipolygon relation 68 * @return A multipolygon object for the given relation, or {@code null} 69 */ 64 70 public final Multipolygon get(NavigatableComponent nc, Relation r) { 65 71 return get(nc, r, false); 66 72 } 67 73 74 /** 75 * Gets a multipolygon from cache. 76 * @param nc The navigatable component 77 * @param r The multipolygon relation 78 * @param forceRefresh if {@code true}, a new object will be created even of present in cache 79 * @return A multipolygon object for the given relation, or {@code null} 80 */ 68 81 public final Multipolygon get(NavigatableComponent nc, Relation r, boolean forceRefresh) { 69 82 Multipolygon multipolygon = null; … … 89 102 return multipolygon; 90 103 } 91 104 105 /** 106 * Clears the cache for the given navigatable component. 107 * @param nc the navigatable component 108 */ 92 109 public final void clear(NavigatableComponent nc) { 93 110 Map<DataSet, Map<Relation, Multipolygon>> map = cache.remove(nc); … … 98 115 } 99 116 117 /** 118 * Clears the cache for the given dataset. 119 * @param ds the data set 120 */ 100 121 public final void clear(DataSet ds) { 101 122 for (Map<DataSet, Map<Relation, Multipolygon>> map1 : cache.values()) { … … 108 129 } 109 130 131 /** 132 * Clears the whole cache. 133 */ 110 134 public final void clear() { 111 135 cache.clear(); 112 136 } 113 137 114 138 private final Collection<Map<Relation, Multipolygon>> getMapsFor(DataSet ds) { 115 139 List<Map<Relation, Multipolygon>> result = new ArrayList<>(); … … 122 146 return result; 123 147 } 124 148 125 149 private static final boolean isMultipolygon(OsmPrimitive p) { 126 150 return p instanceof Relation && ((Relation) p).isMultipolygon(); 127 151 } 128 152 129 153 private final void updateMultipolygonsReferringTo(AbstractDatasetChangedEvent event) { 130 154 updateMultipolygonsReferringTo(event, event.getPrimitives(), event.getDataset()); … … 135 159 updateMultipolygonsReferringTo(event, primitives, ds, null); 136 160 } 137 161 138 162 private final Collection<Map<Relation, Multipolygon>> updateMultipolygonsReferringTo( 139 AbstractDatasetChangedEvent event, Collection<? extends OsmPrimitive> primitives, 163 AbstractDatasetChangedEvent event, Collection<? extends OsmPrimitive> primitives, 140 164 DataSet ds, Collection<Map<Relation, Multipolygon>> initialMaps) { 141 165 Collection<Map<Relation, Multipolygon>> maps = initialMaps; … … 147 171 } 148 172 processEvent(event, (Relation) p, maps); 149 173 150 174 } else if (p instanceof Way && p.getDataSet() != null) { 151 175 for (OsmPrimitive ref : p.getReferrers()) { … … 164 188 return maps; 165 189 } 166 190 167 191 private final void processEvent(AbstractDatasetChangedEvent event, Relation r, Collection<Map<Relation, Multipolygon>> maps) { 168 192 if (event instanceof NodeMovedEvent || event instanceof WayNodesChangedEvent) { … … 173 197 } 174 198 } else { 175 // Default (non-optimal) action: remove multipolygon from cache 199 // Default (non-optimal) action: remove multipolygon from cache 176 200 removeMultipolygonFrom(r, maps); 177 201 } 178 202 } 179 203 180 204 private final void dispatchEvent(AbstractDatasetChangedEvent event, Relation r, Collection<Map<Relation, Multipolygon>> maps) { 181 205 for (Map<Relation, Multipolygon> map : maps) { … … 192 216 } 193 217 } 194 218 195 219 private final void removeMultipolygonFrom(Relation r, Collection<Map<Relation, Multipolygon>> maps) { 196 220 for (Map<Relation, Multipolygon> map : maps) { … … 236 260 @Override 237 261 public void dataChanged(DataChangedEvent event) { 238 // Do not call updateMultipolygonsReferringTo as getPrimitives() 262 // Do not call updateMultipolygonsReferringTo as getPrimitives() 239 263 // can return all the data set primitives for this event 240 264 Collection<Map<Relation, Multipolygon>> maps = null; … … 280 304 @Override 281 305 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 282 306 283 307 for (Iterator<PolyData> it = selectedPolyData.iterator(); it.hasNext();) { 284 308 it.next().selected = false; 285 309 it.remove(); 286 310 } 287 311 288 312 DataSet ds = null; 289 313 Collection<Map<Relation, Multipolygon>> maps = null; -
trunk/src/org/openstreetmap/josm/tools/FilteredCollection.java
r3802 r7395 7 7 * The same as SubclassFilteredCollection, but does not restrict the type 8 8 * of the collection to a certain subclass. 9 * @param <T> element type of the underlying collection 10 * @since 3802 9 11 */ 10 12 public class FilteredCollection<T> extends SubclassFilteredCollection<T, T> { 11 13 14 /** 15 * Constructs a new {@code FilteredCollection}. 16 * @param collection The base collection to filter 17 * @param predicate The predicate to use as filter 18 */ 12 19 public FilteredCollection(Collection<? extends T> collection, Predicate<? super T> predicate) { 13 20 super(collection, predicate); 14 21 } 15 16 22 } -
trunk/src/org/openstreetmap/josm/tools/SubclassFilteredCollection.java
r6792 r7395 14 14 * @param <T> element type of filtered collection (and subclass of S). The predicate 15 15 * must accept only objects of type T. 16 * @since 3147 16 17 */ 17 18 public class SubclassFilteredCollection<S, T extends S> extends AbstractCollection<T> { … … 63 64 } 64 65 66 /** 67 * Constructs a new {@code SubclassFilteredCollection}. 68 * @param collection The base collection to filter 69 * @param predicate The predicate to use as filter 70 */ 65 71 public SubclassFilteredCollection(Collection<? extends S> collection, Predicate<? super S> predicate) { 66 72 this.collection = collection; … … 90 96 return !iterator().hasNext(); 91 97 } 92 93 98 }
Note:
See TracChangeset
for help on using the changeset viewer.