Changeset 32863 in osm for applications/editors


Ignore:
Timestamp:
2016-08-21T20:23:56+02:00 (8 years ago)
Author:
holgermappt
Message:

Move layer change listeners back to map mode constructor and destroy(). See #josm13209, #josm13261, #josm13262.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java

    r32756 r32863  
    4343    private IconToggleButton mmButton;
    4444    private PhotoAdjustWorker worker;
     45    /** True if one existing GeoImageLayer is to be ignored. */
     46    private boolean ignoreOneGILayer = false;
    4547
    4648    public PhotoAdjustMapMode(MapFrame mapFrame, PhotoAdjustWorker worker) {
     
    5557        initAdapters();
    5658        this.worker = worker;
     59        Main.getLayerManager().addLayerChangeListener(this);
     60        Main.getLayerManager().addActiveLayerChangeListener(this);
    5761    }
    5862
     
    133137        super.enterMode();
    134138        modeSelected = true;
    135         Main.getLayerManager().addLayerChangeListener(this);
    136         Main.getLayerManager().addActiveLayerChangeListener(this);
    137139        // Activate the mode only if the current layer is not a GeoImageLayer.
    138140        // GeoImageLayer's are handled by the plug-in directly.
     
    145147    public void exitMode() {
    146148        super.exitMode();
    147         Main.getLayerManager().removeActiveLayerChangeListener(this);
    148         Main.getLayerManager().removeLayerChangeListener(this);
    149149        deactivateMode();
    150150        modeSelected = false;
     
    168168
    169169    @Override
    170     public void layerRemoving(LayerRemoveEvent e) {
     170    public void layerRemoving(LayerRemoveEvent lre) {
     171        if (lre.getRemovedLayer() instanceof GeoImageLayer) {
     172            // A GeoImageLayer is about to be removed.  We ignore this layer
     173            // in the following update methods to get the correct number of
     174            // future GeoImageLayers.
     175            ignoreOneGILayer = true;
     176        }
    171177        if (modeActive) updateStatusLine();
    172178        updateButtonState();
     179        ignoreOneGILayer = false;
    173180    }
    174181
     
    213220    private boolean hasLayersToAdjust() {
    214221        if (Main.map == null || Main.map.mapView == null) return false;
    215         return ! Main.getLayerManager().getLayersOfType(GeoImageLayer.class).isEmpty();
     222        int giLayerNum = Main.getLayerManager().getLayersOfType(GeoImageLayer.class).size();
     223        if (ignoreOneGILayer) {
     224            giLayerNum--;
     225        }
     226        return giLayerNum > 0;
    216227    }
    217228
     
    229240        return all;
    230241    }
     242
     243 
     244    @Override
     245    public void destroy() {
     246        super.destroy();
     247        Main.getLayerManager().removeActiveLayerChangeListener(this);
     248        Main.getLayerManager().removeLayerChangeListener(this);
     249    }
     250
    231251}
Note: See TracChangeset for help on using the changeset viewer.