Ignore:
Timestamp:
2016-06-23T00:20:45+02:00 (8 years ago)
Author:
floscher
Message:

Use ActiveLayerChangeListener instead of EditLayerChangeListener and LayerChangeListener

See #11838, #12924, #12937

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r32329 r32365  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.mapillary;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.marktr;
    5 import static org.openstreetmap.josm.tools.I18n.tr;
    63
    74import java.awt.AlphaComposite;
     
    4340import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    4441import org.openstreetmap.josm.gui.MapView;
    45 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    46 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    4742import org.openstreetmap.josm.gui.NavigatableComponent;
    4843import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
     
    5045import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    5146import org.openstreetmap.josm.gui.layer.Layer;
     47import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     48import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    5249import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5350import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
     
    6360import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    6461
     62import static org.openstreetmap.josm.tools.I18n.marktr;
     63import static org.openstreetmap.josm.tools.I18n.tr;
     64
    6565/**
    6666 * This class represents the layer shown in JOSM. There can only exist one
     
    7171 */
    7272public final class MapillaryLayer extends AbstractModifiableLayer implements
    73     DataSetListener, EditLayerChangeListener, LayerChangeListener {
     73    DataSetListener, ActiveLayerChangeListener {
    7474
    7575  /** Maximum distance for the red/blue lines. */
     
    108108    if (Main.main != null && Main.map.mapView != null) {
    109109      setMode(new SelectMode());
    110       Main.map.mapView.addLayer(this);
    111       MapView.addEditLayerChangeListener(this, false);
    112       MapView.addLayerChangeListener(this);
     110      Main.getLayerManager().addLayer(this);
     111      Main.getLayerManager().addActiveLayerChangeListener(this, false);
    113112      if (Main.getLayerManager().getEditLayer() != null)
    114113        Main.getLayerManager().getEditLayer().data.addDataSetListener(this);
     
    222221    Main.map.mapView.removeMouseListener(this.mode);
    223222    Main.map.mapView.removeMouseMotionListener(this.mode);
    224     MapView.removeEditLayerChangeListener(this);
     223    Main.getLayerManager().removeActiveLayerChangeListener(this);
    225224    if (Main.getLayerManager().getEditLayer() != null)
    226225      Main.getLayerManager().getEditLayer().data.removeDataSetListener(this);
     
    498497
    499498  @Override
    500   public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
    501     if (oldLayer == null && newLayer != null) {
    502       newLayer.data.addDataSetListener(this);
    503     } else if (oldLayer != null && newLayer == null) {
    504       oldLayer.data.removeDataSetListener(this);
     499  public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     500    if (Main.getLayerManager().getActiveLayer() == this) {
     501      MapillaryUtils.updateHelpText();
     502    }
     503    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getJoinMenu(), Main.getLayerManager().getActiveLayer() == this);
     504
     505    if (Main.getLayerManager().getEditLayer() != e.getPreviousEditLayer()) {
     506      if (Main.getLayerManager().getEditLayer() != null) {
     507        Main.getLayerManager().getEditLayer().data.addDataSetListener(this);
     508      }
     509      if (e.getPreviousEditLayer() != null) {
     510        e.getPreviousEditLayer().data.removeDataSetListener(this);
     511      }
    505512    }
    506513  }
     
    550557  @Override
    551558  public void visitBoundingBox(BoundingXYVisitor v) {
    552   }
    553 
    554   @Override
    555   public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    556     if (newLayer == this) {
    557       MapillaryUtils.updateHelpText();
    558       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getJoinMenu(), true);
    559     } else
    560       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getJoinMenu(), false);
    561   }
    562 
    563   @Override
    564   public void layerAdded(Layer newLayer) {
    565     // Do nothing, we're only interested in layer change, not addition
    566   }
    567 
    568   @Override
    569   public void layerRemoved(Layer oldLayer) {
    570     // Do nothing, we're only interested in layer change, not removal
    571559  }
    572560
Note: See TracChangeset for help on using the changeset viewer.