Changeset 10008 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-03-18T00:56:54+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r9818 r10008 58 58 import org.openstreetmap.josm.gui.layer.ImageryLayer; 59 59 import org.openstreetmap.josm.gui.layer.Layer; 60 import org.openstreetmap.josm.gui.layer.LayerPositionStrategy; 60 61 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 62 import org.openstreetmap.josm.gui.layer.NativeScaleLayer; 61 63 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 62 import org.openstreetmap.josm.gui.layer.NativeScaleLayer;63 64 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 64 65 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; … … 347 348 348 349 /** 349 * Adds a GPX layer. A GPX layer is added below the lowest data layer.350 * <p>351 * Does not call {@link #fireLayerAdded(Layer)}.352 *353 * @param layer the GPX layer354 */355 protected void addGpxLayer(GpxLayer layer) {356 synchronized (layers) {357 if (layers.isEmpty()) {358 layers.add(layer);359 return;360 }361 for (int i = layers.size()-1; i >= 0; i--) {362 if (layers.get(i) instanceof OsmDataLayer) {363 if (i == layers.size()-1) {364 layers.add(layer);365 } else {366 layers.add(i+1, layer);367 }368 return;369 }370 }371 layers.add(0, layer);372 }373 }374 375 /**376 350 * Add a layer to the current MapView. The layer will be added at topmost 377 351 * position. … … 389 363 } 390 364 391 if (layer instanceof GpxLayer) { 392 addGpxLayer((GpxLayer) layer); 393 } else if (layers.isEmpty()) { 394 layers.add(layer); 395 } else if (layer.isBackgroundLayer()) { 396 int i = 0; 397 for (; i < layers.size(); i++) { 398 if (layers.get(i).isBackgroundLayer()) { 399 break; 400 } 401 } 402 layers.add(i, layer); 403 } else { 404 layers.add(0, layer); 405 } 365 LayerPositionStrategy positionStrategy = layer.getDefaultLayerPosition(); 366 int position = positionStrategy.getPosition(this); 367 checkPosition(position); 368 insertLayerAt(layer, position); 406 369 407 370 if (isOsmDataLayer || oldActiveLayer == null) { … … 427 390 if (!listenersToFire.isEmpty()) { 428 391 repaint(); 392 } 393 } 394 395 /** 396 * Check if the (new) position is valid 397 * @param position The position index 398 * @throws IndexOutOfBoundsException if it is not. 399 */ 400 private void checkPosition(int position) { 401 if (position < 0 || position > layers.size()) { 402 throw new IndexOutOfBoundsException("Position " + position + " out of range."); 403 } 404 } 405 406 /** 407 * Insert a layer at a given position. 408 * @param layer The layer to add. 409 * @param position The position on which we should add it. 410 */ 411 private void insertLayerAt(Layer layer, int position) { 412 if (position == layers.size()) { 413 layers.add(layer); 414 } else { 415 layers.add(position, layer); 429 416 } 430 417 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r9949 r10008 385 385 } 386 386 387 @Override 388 public LayerPositionStrategy getDefaultLayerPosition() { 389 return LayerPositionStrategy.AFTER_LAST_DATA_LAYER; 390 } 387 391 } -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r9978 r10008 581 581 return 0; 582 582 } 583 584 /** 585 * Gets the strategy that specifies where this layer should be inserted in a layer list. 586 * @return That strategy. 587 * @since 10008 588 */ 589 public LayerPositionStrategy getDefaultLayerPosition() { 590 if (isBackgroundLayer()) { 591 return LayerPositionStrategy.BEFORE_FIRST_BACKGROUND_LAYER; 592 } else { 593 return LayerPositionStrategy.AFTER_LAST_VALIDATION_LAYER; 594 } 595 } 583 596 } -
trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
r8633 r10008 160 160 } 161 161 } 162 163 @Override 164 public LayerPositionStrategy getDefaultLayerPosition() { 165 return LayerPositionStrategy.IN_FRONT; 166 } 162 167 }
Note:
See TracChangeset
for help on using the changeset viewer.