Changeset 10507 in josm
- Timestamp:
- 2016-07-03T11:49:45+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r10498 r10507 658 658 public void initialize() { 659 659 validator = new OsmValidator(); 660 getLayerManager().addLayerChangeListener(validator);661 660 } 662 661 }); -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r10436 r10507 60 60 import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea; 61 61 import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays; 62 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;63 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;64 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;65 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;66 import org.openstreetmap.josm.gui.layer.OsmDataLayer;67 62 import org.openstreetmap.josm.gui.layer.ValidatorLayer; 68 63 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; … … 75 70 * @author Francisco R. Santos <frsantos@gmail.com> 76 71 */ 77 public class OsmValidator implements LayerChangeListener{72 public class OsmValidator { 78 73 79 74 public static volatile ValidatorLayer errorLayer; … … 346 341 } 347 342 348 /* -------------------------------------------------------------------------- */349 /* interface LayerChangeListener */350 /* -------------------------------------------------------------------------- */351 @Override352 public void layerAdded(LayerAddEvent e) {353 // do nothing354 }355 356 @Override357 public void layerOrderChanged(LayerOrderChangeEvent e) {358 // do nothing359 }360 361 @Override362 public void layerRemoving(LayerRemoveEvent e) {363 if (e.getRemovedLayer() == errorLayer) {364 errorLayer = null;365 return;366 }367 if (e.getSource().getLayersOfType(OsmDataLayer.class).isEmpty()) {368 if (errorLayer != null) {369 Main.getLayerManager().removeLayer(errorLayer);370 }371 }372 }373 343 } -
trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java
r10467 r10507 3 3 4 4 import java.util.ArrayList; 5 import java.util.Collection; 5 6 import java.util.Collections; 7 import java.util.IdentityHashMap; 8 import java.util.Iterator; 6 9 import java.util.List; 10 import java.util.Set; 7 11 import java.util.concurrent.CopyOnWriteArrayList; 8 12 … … 98 102 private final Layer removedLayer; 99 103 private final boolean lastLayer; 104 private Collection<Layer> scheduleForRemoval = new ArrayList<>(); 100 105 101 106 LayerRemoveEvent(LayerManager source, Layer removedLayer) { … … 120 125 public boolean isLastLayer() { 121 126 return lastLayer; 127 } 128 129 /** 130 * Schedule the removal of other layers after this layer has been deleted. 131 * <p> 132 * Dupplicate removal requests are ignored. 133 * @param layers The layers to remove. 134 * @since 10507 135 */ 136 public void scheduleRemoval(Collection<? extends Layer> layers) { 137 for (Layer layer : layers) { 138 getSource().checkContainsLayer(layer); 139 } 140 scheduleForRemoval.addAll(layers); 122 141 } 123 142 … … 198 217 199 218 protected synchronized void realRemoveLayer(Layer layer) { 200 checkContainsLayer(layer); 201 202 fireLayerRemoving(layer); 203 layers.remove(layer); 219 GuiHelper.assertCallFromEdt(); 220 Set<Layer> toRemove = Collections.newSetFromMap(new IdentityHashMap<Layer, Boolean>()); 221 toRemove.add(layer); 222 223 while (!toRemove.isEmpty()) { 224 Iterator<Layer> iterator = toRemove.iterator(); 225 Layer layerToRemove = iterator.next(); 226 iterator.remove(); 227 checkContainsLayer(layerToRemove); 228 229 Collection<Layer> newToRemove = realRemoveSingleLayer(layerToRemove); 230 toRemove.addAll(newToRemove); 231 } 232 } 233 234 protected Collection<Layer> realRemoveSingleLayer(Layer layerToRemove) { 235 Collection<Layer> newToRemove = fireLayerRemoving(layerToRemove); 236 layers.remove(layerToRemove); 237 return newToRemove; 204 238 } 205 239 … … 334 368 } 335 369 336 337 370 /** 338 371 * Removes a layer change listener 339 372 * 340 373 * @param listener the listener. 341 * @param fireRemove if we should fire a remove event for every layer in this manager. 374 * @param fireRemove if we should fire a remove event for every layer in this manager. The event is fired as if the layer was deleted but 375 * {@link LayerRemoveEvent#scheduleRemoval(Collection)} is ignored. 342 376 */ 343 377 public synchronized void removeLayerChangeListener(LayerChangeListener listener, boolean fireRemove) { … … 365 399 } 366 400 367 private void fireLayerRemoving(Layer layer) { 401 /** 402 * Fire the layer remove event 403 * @param layer The layer to remove 404 * @return A list of layers that should be removed afterwards. 405 */ 406 private Collection<Layer> fireLayerRemoving(Layer layer) { 368 407 GuiHelper.assertCallFromEdt(); 369 408 LayerRemoveEvent e = new LayerRemoveEvent(this, layer); … … 372 411 l.layerRemoving(e); 373 412 } catch (RuntimeException t) { 374 throw BugReport.intercept(t).put("listener", l).put("event", e); 375 } 376 } 413 throw BugReport.intercept(t).put("listener", l).put("event", e).put("layer", layer); 414 } 415 } 416 return e.scheduleForRemoval; 377 417 } 378 418 -
trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java
r10433 r10507 3 3 4 4 import java.util.ArrayList; 5 import java.util.Collection; 5 6 import java.util.List; 6 7 import java.util.ListIterator; … … 207 208 208 209 @Override 209 protected synchronized void realRemoveLayer(Layer layer) {210 protected Collection<Layer> realRemoveSingleLayer(Layer layer) { 210 211 if (layer == activeLayer || layer == editLayer) { 211 212 Layer nextActive = suggestNextActiveLayer(layer); … … 213 214 } 214 215 215 super.realRemoveLayer(layer);216 return super.realRemoveSingleLayer(layer); 216 217 } 217 218 -
trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
r10453 r10507 5 5 6 6 import java.awt.Graphics2D; 7 import java.util.Collections; 7 8 import java.util.Enumeration; 8 9 import java.util.List; … … 165 166 // Removed layer is still in that list. 166 167 if (e.getRemovedLayer() instanceof OsmDataLayer && e.getSource().getLayersOfType(OsmDataLayer.class).size() <= 1) { 167 Main.getLayerManager().removeLayer(this);168 e.scheduleRemoval(Collections.singleton(this)); 168 169 } else if (e.getRemovedLayer() == this) { 169 170 Main.getLayerManager().removeLayerChangeListener(this);
Note:
See TracChangeset
for help on using the changeset viewer.