Index: /trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12803)
+++ /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12804)
@@ -99,4 +99,5 @@
 import org.openstreetmap.josm.gui.io.SaveLayersDialog;
 import org.openstreetmap.josm.gui.layer.AutosaveTask;
+import org.openstreetmap.josm.gui.layer.ImageryLayer;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
@@ -387,4 +388,17 @@
         return Arrays.asList(
             new InitializationTask(tr("Initializing OSM API"), () -> {
+                    OsmApi.addOsmApiInitializationListener(api -> {
+                        // This checks if there are any layers currently displayed that are now on the blacklist, and removes them.
+                        // This is a rare situation - probably only occurs if the user changes the API URL in the preferences menu.
+                        // Otherwise they would not have been able to load the layers in the first place because they would have been disabled
+                        if (isDisplayingMapView()) {
+                            for (Layer l : getLayerManager().getLayersOfType(ImageryLayer.class)) {
+                                if (((ImageryLayer) l).getInfo().isBlacklisted()) {
+                                    Logging.info(tr("Removed layer {0} because it is not allowed by the configured API.", l.getName()));
+                                    getLayerManager().removeLayer(l);
+                                }
+                            }
+                        }
+                    });
                     // We try to establish an API connection early, so that any API
                     // capabilities are already known to the editor instance. However
Index: /trunk/src/org/openstreetmap/josm/io/OsmApi.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 12803)
+++ /trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 12804)
@@ -30,7 +30,4 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
-import org.openstreetmap.josm.gui.MainApplication;
-import org.openstreetmap.josm.gui.layer.ImageryLayer;
-import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
@@ -38,4 +35,5 @@
 import org.openstreetmap.josm.tools.CheckParameterUtil;
 import org.openstreetmap.josm.tools.HttpClient;
+import org.openstreetmap.josm.tools.ListenerList;
 import org.openstreetmap.josm.tools.Logging;
 import org.openstreetmap.josm.tools.Utils;
@@ -52,5 +50,5 @@
  * It is conceivable to extract this into an interface later and create various
  * classes implementing the interface, to be able to talk to various kinds of servers.
- *
+ * @ince 1523
  */
 public class OsmApi extends OsmConnection {
@@ -76,7 +74,39 @@
 
     // The collection of instantiated OSM APIs
-    private static Map<String, OsmApi> instances = new HashMap<>();
+    private static final Map<String, OsmApi> instances = new HashMap<>();
+
+    private static final ListenerList<OsmApiInitializationListener> listeners = ListenerList.create();
 
     private URL url;
+
+    /**
+     * OSM API initialization listener.
+     * @since 12804
+     */
+    public interface OsmApiInitializationListener {
+        /**
+         * Called when an OSM API instance has been successfully initialized.
+         * @param instance the initialized OSM API instance
+         */
+        void apiInitialized(OsmApi instance);
+    }
+
+    /**
+     * Adds a new OSM API initialization listener.
+     * @param listener OSM API initialization listener to add
+     * @since 12804
+     */
+    public static void addOsmApiInitializationListener(OsmApiInitializationListener listener) {
+        listeners.addListener(listener);
+    }
+
+    /**
+     * Removes an OSM API initialization listener.
+     * @param listener OSM API initialization listener to remove
+     * @since 12804
+     */
+    public static void removeOsmApiInitializationListener(OsmApiInitializationListener listener) {
+        listeners.removeListener(listener);
+    }
 
     /**
@@ -236,19 +266,5 @@
             }
 
-            /* This checks if there are any layers currently displayed that
-             * are now on the blacklist, and removes them. This is a rare
-             * situation - probably only occurs if the user changes the API URL
-             * in the preferences menu. Otherwise they would not have been able
-             * to load the layers in the first place because they would have
-             * been disabled! */
-            if (MainApplication.isDisplayingMapView()) {
-                for (Layer l : MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class)) {
-                    if (((ImageryLayer) l).getInfo().isBlacklisted()) {
-                        Logging.info(tr("Removed layer {0} because it is not allowed by the configured API.", l.getName()));
-                        MainApplication.getLayerManager().removeLayer(l);
-                    }
-                }
-            }
-
+            listeners.fireEvent(l -> l.apiInitialized(this));
         } catch (OsmTransferCanceledException e) {
             throw e;
