Ignore:
Timestamp:
2016-06-08T23:17:19+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #12937 - Use the new LayerChangeListener (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
2 edited

Legend:

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

    r10212 r10345  
    2222import org.openstreetmap.josm.data.osm.history.History;
    2323import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    24 import org.openstreetmap.josm.gui.MapView;
    25 import org.openstreetmap.josm.gui.layer.Layer;
     24import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     25import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     26import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     27import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    2628import org.openstreetmap.josm.tools.Predicate;
    2729import org.openstreetmap.josm.tools.Utils;
     
    3335 * @since 2019
    3436 */
    35 public final class HistoryBrowserDialogManager implements MapView.LayerChangeListener {
     37public final class HistoryBrowserDialogManager implements LayerChangeListener {
    3638
    3739    private static final String WINDOW_GEOMETRY_PREF = HistoryBrowserDialogManager.class.getName() + ".geometry";
     
    5456    protected HistoryBrowserDialogManager() {
    5557        dialogs = new HashMap<>();
    56         MapView.addLayerChangeListener(this);
     58        Main.getLayerManager().addLayerChangeListener(this);
    5759    }
    5860
     
    153155    /* ----------------------------------------------------------------------------- */
    154156    @Override
    155     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     157    public void layerAdded(LayerAddEvent e) {
    156158        // Do nothing
    157159    }
    158160
    159161    @Override
    160     public void layerAdded(Layer newLayer) {
     162    public void layerRemoving(LayerRemoveEvent e) {
     163        // remove all history browsers if the number of layers drops to 0
     164        if (e.getSource().getLayers().isEmpty()) {
     165            hideAll();
     166        }
     167    }
     168
     169    @Override
     170    public void layerOrderChanged(LayerOrderChangeEvent e) {
    161171        // Do nothing
    162     }
    163 
    164     @Override
    165     public void layerRemoved(Layer oldLayer) {
    166         // remove all history browsers if the number of layers drops to 0
    167         if (Main.isDisplayingMapView() && Main.map.mapView.getNumLayers() == 0) {
    168             hideAll();
    169         }
    170172    }
    171173
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r10308 r10345  
    4141import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
    4242import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    43 import org.openstreetmap.josm.gui.MapView;
    44 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    4543import org.openstreetmap.josm.gui.layer.Layer;
     44import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     45import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    4646import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4747import org.openstreetmap.josm.gui.util.ChangeNotifier;
     
    7474 * @see HistoryBrowser
    7575 */
    76 public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeListener, DataSetListener {
     76public class HistoryBrowserModel extends ChangeNotifier implements ActiveLayerChangeListener, DataSetListener {
    7777    /** the history of an OsmPrimitive */
    7878    private History history;
     
    111111            }
    112112        }
    113         MapView.addLayerChangeListener(this);
     113        Main.getLayerManager().addActiveLayerChangeListener(this);
    114114    }
    115115
     
    670670            editLayer.data.removeDataSetListener(this);
    671671        }
    672         MapView.removeLayerChangeListener(this);
     672        Main.getLayerManager().removeActiveLayerChangeListener(this);
    673673    }
    674674
     
    747747
    748748    /* ---------------------------------------------------------------------- */
    749     /* LayerChangeListener                                                    */
     749    /* ActiveLayerChangeListener                                              */
    750750    /* ---------------------------------------------------------------------- */
    751751    @Override
    752     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     752    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     753        Layer oldLayer = e.getPreviousActiveLayer();
    753754        if (oldLayer instanceof OsmDataLayer) {
    754755            OsmDataLayer l = (OsmDataLayer) oldLayer;
    755756            l.data.removeDataSetListener(this);
    756757        }
     758        Layer newLayer = e.getSource().getActiveLayer();
    757759        if (!(newLayer instanceof OsmDataLayer)) {
    758760            latest = null;
     
    773775    }
    774776
    775     @Override
    776     public void layerAdded(Layer newLayer) {
    777         // Do nothing
    778     }
    779 
    780     @Override
    781     public void layerRemoved(Layer oldLayer) {
    782         // Do nothing
    783     }
    784 
    785777    /**
    786778     * Creates a {@link HistoryOsmPrimitive} from a {@link OsmPrimitive}
     
    825817        }
    826818    }
     819
    827820}
Note: See TracChangeset for help on using the changeset viewer.