Changeset 1952 in josm


Ignore:
Timestamp:
2009-08-11T09:31:09+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3241: Removing active layer should active one of the remaining layers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r1943 r1952  
    218218
    219219    /**
     220     * Determines the next active data layer according to the following
     221     * rules:
     222     * <ul>
     223     *   <li>if there is at least one {@see OsmDataLayer} the first one
     224     *     becomes active</li>
     225     *   <li>otherwise, the top most layer of any type becomes active</li>
     226     * </ul>
     227     *
     228     * @return the next active data layer
     229     */
     230    protected Layer determineNextActiveLayer() {
     231        if (layers.isEmpty()) return null;
     232        // if possible, activate the first data layer
     233        //
     234        List<OsmDataLayer> dataLayers = getLayersOfType(OsmDataLayer.class);
     235        if (!dataLayers.isEmpty())
     236            return dataLayers.get(0);
     237
     238        // else the first layer of any type
     239        //
     240        return layers.get(0);
     241    }
     242
     243    /**
    220244     * Remove the layer from the mapview. If the layer was in the list before,
    221245     * an LayerChange event is fired.
     
    237261        layer.destroy();
    238262        AudioPlayer.reset();
    239         if (layer instanceof OsmDataLayer && deletedLayerWasActiveLayer) {
    240             for (Layer l : layers) {
    241                 if (l instanceof OsmDataLayer) {
    242                     activeLayer = l;
    243                     fireActiveLayerChanged(null, activeLayer);
    244                 }
     263        if (deletedLayerWasActiveLayer) {
     264            Layer l = determineNextActiveLayer();
     265            if (l != null) {
     266                activeLayer = l;
     267                fireActiveLayerChanged(null, l);
    245268            }
    246269        }
Note: See TracChangeset for help on using the changeset viewer.