Changeset 10412 in josm


Ignore:
Timestamp:
2016-06-17T23:50:27+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #12981 - mimic the old behavior of the layer listeners (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r10400 r10412  
    8383import org.openstreetmap.josm.gui.MapFrame;
    8484import org.openstreetmap.josm.gui.MapFrameListener;
     85import org.openstreetmap.josm.gui.MapView;
    8586import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    8687import org.openstreetmap.josm.gui.help.HelpUtil;
     
    526527        Main.map = map;
    527528
     529        // Notify map frame listeners, mostly plugins.
     530        if ((map == null) == (old == null)) {
     531            Main.warn("Replacing the map frame. This is not expected by some plugins and should not happen.");
     532        }
    528533        for (MapFrameListener listener : mapFrameListeners) {
     534            MapView.fireDeprecatedListenerOnAdd = true;
    529535            listener.mapFrameInitialized(old, map);
     536            MapView.fireDeprecatedListenerOnAdd = false;
    530537        }
    531538        if (map == null && currentProgressMonitor != null) {
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r10401 r10412  
    375375    @Deprecated
    376376    public static void addLayerChangeListener(LayerChangeListener listener) {
    377         addLayerChangeListener(listener, false);
     377        if (fireDeprecatedListenerOnAdd) {
     378            Main.warn("Plugin seems to be adding listener during mapFrameInitialized(): " + BugReport.getCallingMethod(2)
     379            + ". Layer listeners should be set on plugin load.");
     380        }
     381        addLayerChangeListener(listener, fireDeprecatedListenerOnAdd);
    378382    }
    379383
     
    391395    public static void addLayerChangeListener(LayerChangeListener listener, boolean initialFire) {
    392396        if (listener != null) {
    393             initialFire = initialFire && Main.isDisplayingMapView();
     397            initialFire = initialFire && (Main.isDisplayingMapView() || fireDeprecatedListenerOnAdd);
    394398
    395399            LayerChangeAdapter adapter = new LayerChangeAdapter(listener, initialFire);
    396             Main.getLayerManager().addLayerChangeListener(adapter, false);
     400            Main.getLayerManager().addLayerChangeListener(adapter, initialFire);
    397401            if (initialFire) {
    398402                Main.getLayerManager().addAndFireActiveLayerChangeListener(adapter);
     
    438442        addEditLayerChangeListener(listener, false);
    439443    }
     444
     445
     446    /**
     447     * Temporary. To be removed as soon as the {@link LayerChangeListener}s are removed.
     448     * <p>
     449     * Some plugins add their listeners in {@link Main#setMapFrame(MapFrame)}. This method is now called just after the first layer was added to
     450     * the layer manager. So that listener would not receive the addition of the first layer. As long as this field is set, we fake an add call
     451     * to that listener when it is added to immitate the old behaviour. You should not access it from anywhere else.
     452     */
     453    public static boolean fireDeprecatedListenerOnAdd;
    440454
    441455    public boolean viewportFollowing;
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java

    r10375 r10412  
    6363     * @return The method name.
    6464     */
    65     static String getCallingMethod(int offset) {
     65    public static String getCallingMethod(int offset) {
    6666        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    6767        String className = BugReport.class.getName();
Note: See TracChangeset for help on using the changeset viewer.