- Timestamp:
- 2017-02-26T00:59:32+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r10382 r11627 51 51 52 52 List<Area> areas = new ArrayList<>(); 53 for (DataSource ds : editLayer.data. dataSources) {53 for (DataSource ds : editLayer.data.getDataSources()) { 54 54 areas.add(new Area(ds.bounds.asRect())); 55 55 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r11553 r11627 343 343 } 344 344 // need to synthesize a download bounds lest the visual indication of downloaded area doesn't work 345 dataSet. dataSources.add(new DataSource(currentBounds != null ? currentBounds :345 dataSet.addDataSource(new DataSource(currentBounds != null ? currentBounds : 346 346 new Bounds(LatLon.ZERO), "OpenStreetMap server")); 347 347 } -
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r11553 r11627 52 52 CheckParameterUtil.ensureParameterNotNull(c, "c"); 53 53 c.executeCommand(); 54 c.invalidateAffectedLayers();55 54 commands.add(c); 56 55 // Limit the number of commands in the undo list. … … 81 80 } 82 81 addNoRedraw(c); 82 c.invalidateAffectedLayers(); 83 83 afterAdd(); 84 84 -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r11440 r11627 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.geom.Area; 6 7 import java.util.ArrayList; 7 8 import java.util.Arrays; … … 25 26 26 27 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.data.Bounds; 27 29 import org.openstreetmap.josm.data.Data; 28 30 import org.openstreetmap.josm.data.DataSource; … … 127 129 private final Object selectionLock = new Object(); 128 130 131 private Area cachedDataSourceArea; 132 private List<Bounds> cachedDataSourceBounds; 133 129 134 /** 130 135 * Constructs a new {@code DataSet}. … … 184 189 copyFrom.getReadLock().unlock(); 185 190 } 191 } 192 193 /** 194 * Adds a new data source. 195 * @param source data source to add 196 * @return {@code true} if the collection changed as a result of the call 197 * @since 11626 198 */ 199 public synchronized boolean addDataSource(DataSource source) { 200 return addDataSources(Collections.singleton(source)); 201 } 202 203 /** 204 * Adds new data sources. 205 * @param sources data sources to add 206 * @return {@code true} if the collection changed as a result of the call 207 * @since 11626 208 */ 209 public synchronized boolean addDataSources(Collection<DataSource> sources) { 210 boolean changed = dataSources.addAll(sources); 211 if (changed) { 212 cachedDataSourceArea = null; 213 cachedDataSourceBounds = null; 214 } 215 return changed; 186 216 } 187 217 … … 917 947 fireSelectionChanged(); 918 948 } 949 } 950 951 @Override 952 public synchronized Area getDataSourceArea() { 953 if (cachedDataSourceArea == null) { 954 cachedDataSourceArea = Data.super.getDataSourceArea(); 955 } 956 return cachedDataSourceArea; 957 } 958 959 @Override 960 public synchronized List<Bounds> getDataSourceBounds() { 961 if (cachedDataSourceBounds == null) { 962 cachedDataSourceBounds = Data.super.getDataSourceBounds(); 963 } 964 return Collections.unmodifiableList(cachedDataSourceBounds); 919 965 } 920 966 … … 1334 1380 * @param progressMonitor The progress monitor 1335 1381 */ 1336 public void mergeFrom(DataSet from, ProgressMonitor progressMonitor) {1382 public synchronized void mergeFrom(DataSet from, ProgressMonitor progressMonitor) { 1337 1383 if (from != null) { 1338 1384 new DataSetMerger(this, from).merge(progressMonitor); 1339 dataSources.addAll(from.dataSources); 1340 from.dataSources.clear(); 1385 if (!from.dataSources.isEmpty()) { 1386 if (dataSources.addAll(from.dataSources)) { 1387 cachedDataSourceArea = null; 1388 cachedDataSourceBounds = null; 1389 } 1390 from.dataSources.clear(); 1391 from.cachedDataSourceArea = null; 1392 from.cachedDataSourceBounds = null; 1393 } 1341 1394 } 1342 1395 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
r11590 r11627 309 309 @Override 310 310 public Command fixError(TestError testError) { 311 if (!isFixable(testError)) return null;312 311 Collection<OsmPrimitive> sel = new LinkedList<>(testError.getPrimitives()); 313 312 Set<Node> nodes = new LinkedHashSet<>(OsmPrimitive.getFilteredList(sel, Node.class)); -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java
r11452 r11627 293 293 } 294 294 295 // Delete all relations in the list295 // Delete all relations in the list 296 296 relFix.remove(relationToKeep); 297 297 commands.add(new DeleteCommand(relFix)); … … 306 306 // We fix it only if there is no more than one relation that is relation member. 307 307 Collection<? extends OsmPrimitive> sel = testError.getPrimitives(); 308 Set<Relation> rel ations = new HashSet<>();308 Set<Relation> rels = new HashSet<>(); 309 309 310 310 for (OsmPrimitive osm : sel) { 311 311 if (osm instanceof Relation) { 312 rel ations.add((Relation) osm);313 } 314 } 315 316 if (rel ations.size() < 2)312 rels.add((Relation) osm); 313 } 314 } 315 316 if (rels.size() < 2) 317 317 return false; 318 318 319 319 int relationsWithRelations = 0; 320 for (Relation w : rel ations) {320 for (Relation w : rels) { 321 321 List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class); 322 322 if (!rel.isEmpty()) { -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
r11129 r11627 249 249 public Command fixError(TestError testError) { 250 250 Collection<? extends OsmPrimitive> sel = testError.getPrimitives(); 251 Set<Way> way s= new HashSet<>();251 Set<Way> wayz = new HashSet<>(); 252 252 253 253 for (OsmPrimitive osm : sel) { 254 254 if (osm instanceof Way && !osm.isDeleted()) { 255 way s.add((Way) osm);256 } 257 } 258 259 if (way s.size() < 2)255 wayz.add((Way) osm); 256 } 257 } 258 259 if (wayz.size() < 2) 260 260 return null; 261 261 262 262 long idToKeep = 0; 263 Way wayToKeep = way s.iterator().next();263 Way wayToKeep = wayz.iterator().next(); 264 264 // Find the way that is member of one or more relations. (If any) 265 265 Way wayWithRelations = null; 266 266 List<Relation> relations = null; 267 for (Way w : way s) {267 for (Way w : wayz) { 268 268 List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class); 269 269 if (!rel.isEmpty()) { … … 284 284 285 285 // Fix relations. 286 if (wayWithRelations != null && wayToKeep != wayWithRelations) {286 if (wayWithRelations != null && relations != null && wayToKeep != wayWithRelations) { 287 287 for (Relation rel : relations) { 288 288 Relation newRel = new Relation(rel); … … 297 297 } 298 298 299 // Delete all ways in the list300 // Note: nodes are not deleted, these can be detected and deleted at next pass301 way s.remove(wayToKeep);302 commands.add(new DeleteCommand(way s));299 // Delete all ways in the list 300 // Note: nodes are not deleted, these can be detected and deleted at next pass 301 wayz.remove(wayToKeep); 302 commands.add(new DeleteCommand(wayz)); 303 303 return new SequenceCommand(tr("Delete duplicate ways"), commands); 304 304 } … … 309 309 return false; 310 310 311 // Do not automatically fix same ways with different tags311 // Do not automatically fix same ways with different tags 312 312 if (testError.getCode() != DUPLICATE_WAY) return false; 313 313 314 314 // We fix it only if there is no more than one way that is relation member. 315 315 Collection<? extends OsmPrimitive> sel = testError.getPrimitives(); 316 Set<Way> way s= new HashSet<>();316 Set<Way> wayz = new HashSet<>(); 317 317 318 318 for (OsmPrimitive osm : sel) { 319 319 if (osm instanceof Way) { 320 way s.add((Way) osm);321 } 322 } 323 324 if (way s.size() < 2)320 wayz.add((Way) osm); 321 } 322 } 323 324 if (wayz.size() < 2) 325 325 return false; 326 326 327 327 int waysWithRelations = 0; 328 for (Way w : way s) {328 for (Way w : wayz) { 329 329 List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class); 330 330 if (!rel.isEmpty()) { -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
r11606 r11627 132 132 */ 133 133 public void setTargetPrimitive(final OsmPrimitive primitive) { 134 setTargetPrimitive(primitive, true); 135 } 136 137 /** 138 * Sets the primitive the collection of primitives is merged or combined to. 139 * 140 * @param primitive the target primitive 141 * @param updateTitle {@code true} to call {@link #updateTitle} in EDT (can be a slow operation) 142 * @since 11626 143 */ 144 private void setTargetPrimitive(final OsmPrimitive primitive, boolean updateTitle) { 134 145 this.targetPrimitive = primitive; 135 GuiHelper.runInEDTAndWait(() -> { 136 updateTitle(); 137 if (primitive instanceof Way) { 138 pnlRelationMemberConflictResolver.initForWayCombining(); 139 } else if (primitive instanceof Node) { 140 pnlRelationMemberConflictResolver.initForNodeMerging(); 141 } 142 }); 146 if (updateTitle) { 147 GuiHelper.runInEDTAndWait(this::updateTitle); 148 } 143 149 } 144 150 … … 153 159 helpAction.setHelpTopic(ht("/Action/CombineWay#ResolvingConflicts")); 154 160 getRootPane().putClientProperty("help", ht("/Action/CombineWay#ResolvingConflicts")); 161 pnlRelationMemberConflictResolver.initForWayCombining(); 155 162 } else if (targetPrimitive instanceof Node) { 156 163 setTitle(tr("Conflicts when merging nodes - target node is ''{0}''", targetPrimitive … … 158 165 helpAction.setHelpTopic(ht("/Action/MergeNodes#ResolvingConflicts")); 159 166 getRootPane().putClientProperty("help", ht("/Action/MergeNodes#ResolvingConflicts")); 167 pnlRelationMemberConflictResolver.initForNodeMerging(); 160 168 } 161 169 } … … 295 303 */ 296 304 public void prepareDefaultDecisions() { 297 getTagConflictResolverModel().prepareDefaultTagDecisions(); 298 getRelationMemberConflictResolverModel().prepareDefaultRelationDecisions(); 305 prepareDefaultDecisions(true); 306 } 307 308 /** 309 * Prepares the default decisions for populated tag and relation membership conflicts. 310 * @param fireEvent {@code true} to call {@code fireTableDataChanged} (can be a slow operation) 311 * @since 11626 312 */ 313 private void prepareDefaultDecisions(boolean fireEvent) { 314 getTagConflictResolverModel().prepareDefaultTagDecisions(fireEvent); 315 getRelationMemberConflictResolverModel().prepareDefaultRelationDecisions(fireEvent); 299 316 } 300 317 … … 501 518 final CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance(); 502 519 503 dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues() );504 dialog.getRelationMemberConflictResolverModel().populate(parentRelations, primitives );505 dialog.prepareDefaultDecisions( );520 dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues(), false); 521 dialog.getRelationMemberConflictResolverModel().populate(parentRelations, primitives, false); 522 dialog.prepareDefaultDecisions(false); 506 523 507 524 // Ensure a proper title is displayed instead of a previous target (fix #7925) 508 525 if (targetPrimitives.size() == 1) { 509 dialog.setTargetPrimitive(targetPrimitives.iterator().next() );526 dialog.setTargetPrimitive(targetPrimitives.iterator().next(), false); 510 527 } else { 511 dialog.setTargetPrimitive(null );528 dialog.setTargetPrimitive(null, false); 512 529 } 513 530 514 531 // Resolve tag conflicts if necessary 515 532 if (!dialog.isResolvedCompletely()) { 533 GuiHelper.runInEDTAndWait(() -> { 534 dialog.getTagConflictResolverModel().fireTableDataChanged(); 535 dialog.getRelationMemberConflictResolverModel().fireTableDataChanged(); 536 dialog.updateTitle(); 537 }); 516 538 dialog.setVisible(true); 517 539 if (!dialog.isApplied()) { … … 520 542 } 521 543 for (OsmPrimitive i : targetPrimitives) { 522 dialog.setTargetPrimitive(i );544 dialog.setTargetPrimitive(i, false); 523 545 cmds.addAll(dialog.buildResolutionCommands()); 524 546 } -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java
r11601 r11627 129 129 case 4: /* decision */ 130 130 d.decide((RelationMemberConflictDecisionType) value); 131 refresh( );131 refresh(false); 132 132 break; 133 133 default: // Do nothing … … 159 159 */ 160 160 public void populate(Collection<Relation> relations, Collection<? extends OsmPrimitive> memberPrimitives) { 161 populate(relations, memberPrimitives, true); 162 } 163 164 /** 165 * Populates the model with the relation members belonging to one of the relations in <code>relations</code> 166 * and referring to one of the primitives in <code>memberPrimitives</code>. 167 * 168 * @param relations the parent relations. Empty list assumed if null. 169 * @param memberPrimitives the child primitives. Empty list assumed if null. 170 * @param fireEvent {@code true} to call {@code fireTableDataChanged} (can be a slow operation) 171 * @since 11626 172 */ 173 void populate(Collection<Relation> relations, Collection<? extends OsmPrimitive> memberPrimitives, boolean fireEvent) { 161 174 decisions.clear(); 162 175 relations = relations == null ? Collections.<Relation>emptyList() : relations; … … 169 182 this.relations = relations; 170 183 this.primitives = memberPrimitives; 171 refresh( );184 refresh(fireEvent); 172 185 } 173 186 … … 199 212 */ 200 213 public void prepareDefaultRelationDecisions() { 201 214 prepareDefaultRelationDecisions(true); 215 } 216 217 /** 218 * Prepare the default decisions for the current model. 219 * 220 * Keep/delete decisions are made if every member has the same role and the members are in consecutive order within the relation. 221 * For multiple occurrences those conditions are tested stepwise for each occurrence. 222 * 223 * @param fireEvent {@code true} to call {@code fireTableDataChanged} (can be a slow operation) 224 * @since 11626 225 */ 226 void prepareDefaultRelationDecisions(boolean fireEvent) { 202 227 if (primitives.stream().allMatch(Node.class::isInstance)) { 203 228 final Collection<OsmPrimitive> primitivesInDecisions = new HashSet<>(); … … 256 281 } 257 282 258 refresh( );283 refresh(fireEvent); 259 284 } 260 285 … … 300 325 */ 301 326 public void refresh() { 327 refresh(true); 328 } 329 330 /** 331 * Refreshes the model state. Invoke this method to trigger necessary change 332 * events after an update of the model data. 333 * @param fireEvent {@code true} to call {@code fireTableDataChanged} (can be a slow operation) 334 * @since 11626 335 */ 336 void refresh(boolean fireEvent) { 302 337 updateNumConflicts(); 303 GuiHelper.runInEDTAndWait(this::fireTableDataChanged); 338 if (fireEvent) { 339 GuiHelper.runInEDTAndWait(this::fireTableDataChanged); 340 } 304 341 } 305 342 -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverModel.java
r10939 r11627 73 73 */ 74 74 public void rebuild() { 75 rebuild(true); 76 } 77 78 /** 79 * initializes the model from the current tags 80 * @param fireEvent {@code true} to call {@code fireTableDataChanged} (can be a slow operation) 81 * @since 11626 82 */ 83 void rebuild(boolean fireEvent) { 75 84 if (tags == null) return; 76 85 for (String key: tags.getKeys()) { … … 102 111 refreshNumConflicts(); 103 112 sort(); 104 GuiHelper.runInEDTAndWait(this::fireTableDataChanged); 113 if (fireEvent) { 114 GuiHelper.runInEDTAndWait(this::fireTableDataChanged); 115 } 105 116 } 106 117 … … 113 124 */ 114 125 public void populate(TagCollection tags, Set<String> keysWithConflicts) { 126 populate(tags, keysWithConflicts, true); 127 } 128 129 /** 130 * Populates the model with the tags for which conflicts are to be resolved. 131 * 132 * @param tags the tag collection with the tags. Must not be null. 133 * @param keysWithConflicts the set of tag keys with conflicts 134 * @param fireEvent {@code true} to call {@code fireTableDataChanged} (can be a slow operation) 135 * @throws IllegalArgumentException if tags is null 136 * @since 11626 137 */ 138 void populate(TagCollection tags, Set<String> keysWithConflicts, boolean fireEvent) { 115 139 CheckParameterUtil.ensureParameterNotNull(tags, "tags"); 116 140 this.tags = tags; … … 120 144 } 121 145 decisions = new HashMap<>(); 122 rebuild( );146 rebuild(fireEvent); 123 147 } 124 148 … … 250 274 */ 251 275 public void prepareDefaultTagDecisions() { 276 prepareDefaultTagDecisions(true); 277 } 278 279 /** 280 * Prepare the default decisions for the current model 281 * @param fireEvent {@code true} to call {@code fireTableDataChanged} (can be a slow operation) 282 * @since 11626 283 */ 284 void prepareDefaultTagDecisions(boolean fireEvent) { 252 285 for (MultiValueResolutionDecision decision: decisions.values()) { 253 286 List<String> values = decision.getValues(); … … 260 293 // else: Do not suggest to keep all values in order to reduce the wrong usage of semicolon values, see #9104! 261 294 } 262 rebuild( );295 rebuild(fireEvent); 263 296 } 264 297 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r11374 r11627 57 57 import org.openstreetmap.josm.tools.JosmRuntimeException; 58 58 import org.openstreetmap.josm.tools.Shortcut; 59 import org.openstreetmap.josm.tools.Utils; 59 60 import org.xml.sax.SAXException; 60 61 … … 595 596 protected void fixError(TestError error) throws InterruptedException, InvocationTargetException { 596 597 if (error.isFixable()) { 598 long start = System.currentTimeMillis(); 597 599 final Command fixCommand = error.getFix(); 600 long phase1 = System.currentTimeMillis() - start; 601 start = System.currentTimeMillis(); 598 602 if (fixCommand != null) { 599 603 SwingUtilities.invokeAndWait(() -> Main.main.undoRedo.addNoRedraw(fixCommand)); 604 if (Main.isDebugEnabled()) { 605 long phase2 = System.currentTimeMillis() - start; 606 Main.debug(String.format("%s fix: %s + %s", 607 error.getTester().getClass().getSimpleName(), Utils.getDurationString(phase1), 608 Utils.getDurationString(phase2))); 609 } 600 610 } 601 611 // It is wanted to ignore an error if it said fixable, even if fixCommand was null -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java
r11553 r11627 161 161 162 162 // copy the merged layer's data source info 163 getLayer().data. dataSources.addAll(referrers.dataSources);163 getLayer().data.addDataSources(referrers.getDataSources()); 164 164 // FIXME: this is necessary because there are dialogs listening 165 165 // for DataChangeEvents which manipulate Swing components on this thread. -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r11608 r11627 406 406 // draw the hatched area for non-downloaded region. only draw if we're the active 407 407 // and bounds are defined; don't draw for inactive layers or loaded GPX files etc 408 if (active && Main.pref.getBoolean("draw.data.downloaded_area", true) && !data. dataSources.isEmpty()) {408 if (active && Main.pref.getBoolean("draw.data.downloaded_area", true) && !data.getDataSources().isEmpty()) { 409 409 // initialize area with current viewport 410 410 Rectangle b = mv.getBounds(); … … 496 496 // copy the merged layer's data source info. 497 497 // only add source rectangles if they are not contained in the layer already. 498 for (DataSource src : from. dataSources) {498 for (DataSource src : from.getDataSources()) { 499 499 if (a == null || !a.contains(src.bounds.asRect())) { 500 data. dataSources.add(src);500 data.addDataSource(src); 501 501 } 502 502 } … … 846 846 // we'll assume that if this has no data sources 847 847 // that it also has no borders 848 if (this.data. dataSources.isEmpty())848 if (this.data.getDataSources().isEmpty()) 849 849 return true; 850 850 851 851 boolean layerBoundsPoint = false; 852 for (DataSource src : this.data. dataSources) {852 for (DataSource src : this.data.getDataSources()) { 853 853 if (src.bounds.contains(coor)) { 854 854 layerBoundsPoint = true; -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r11435 r11627 198 198 } 199 199 DataSource src = new DataSource(bounds, origin); 200 ds. dataSources.add(src);200 ds.addDataSource(src); 201 201 } else { 202 202 throwException(tr("Missing mandatory attributes on element ''bounds''. " + -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r10619 r11627 174 174 175 175 public void writeDataSources(DataSet ds) { 176 for (DataSource s : ds. dataSources) {176 for (DataSource s : ds.getDataSources()) { 177 177 out.println(" <bounds minlat='" 178 178 + s.bounds.getMin().latToString(CoordinateFormat.DECIMAL_DEGREES) -
trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java
r11560 r11627 169 169 170 170 // add bounds if necessary (note that Overpass API does not return bounds in the response XML) 171 if (ds != null && ds. dataSources.isEmpty() && overpassQuery.contains("{{bbox}}")) {171 if (ds != null && ds.getDataSources().isEmpty() && overpassQuery.contains("{{bbox}}")) { 172 172 if (crosses180th) { 173 173 Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0); 174 174 DataSource src = new DataSource(bounds, getBaseUrl()); 175 ds. dataSources.add(src);175 ds.addDataSource(src); 176 176 177 177 bounds = new Bounds(lat1, -180.0, lat2, lon2); 178 178 src = new DataSource(bounds, getBaseUrl()); 179 ds. dataSources.add(src);179 ds.addDataSource(src); 180 180 } else { 181 181 Bounds bounds = new Bounds(lat1, lon1, lat2, lon2); 182 182 DataSource src = new DataSource(bounds, getBaseUrl()); 183 ds. dataSources.add(src);183 ds.addDataSource(src); 184 184 } 185 185 }
Note:
See TracChangeset
for help on using the changeset viewer.