- Timestamp:
- 2017-09-09T16:58:45+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12803 r12804 99 99 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 100 100 import org.openstreetmap.josm.gui.layer.AutosaveTask; 101 import org.openstreetmap.josm.gui.layer.ImageryLayer; 101 102 import org.openstreetmap.josm.gui.layer.Layer; 102 103 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 387 388 return Arrays.asList( 388 389 new InitializationTask(tr("Initializing OSM API"), () -> { 390 OsmApi.addOsmApiInitializationListener(api -> { 391 // This checks if there are any layers currently displayed that are now on the blacklist, and removes them. 392 // This is a rare situation - probably only occurs if the user changes the API URL in the preferences menu. 393 // Otherwise they would not have been able to load the layers in the first place because they would have been disabled 394 if (isDisplayingMapView()) { 395 for (Layer l : getLayerManager().getLayersOfType(ImageryLayer.class)) { 396 if (((ImageryLayer) l).getInfo().isBlacklisted()) { 397 Logging.info(tr("Removed layer {0} because it is not allowed by the configured API.", l.getName())); 398 getLayerManager().removeLayer(l); 399 } 400 } 401 } 402 }); 389 403 // We try to establish an API connection early, so that any API 390 404 // capabilities are already known to the editor instance. However -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r12636 r12804 30 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 31 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 32 import org.openstreetmap.josm.gui.MainApplication;33 import org.openstreetmap.josm.gui.layer.ImageryLayer;34 import org.openstreetmap.josm.gui.layer.Layer;35 32 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 36 33 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 38 35 import org.openstreetmap.josm.tools.CheckParameterUtil; 39 36 import org.openstreetmap.josm.tools.HttpClient; 37 import org.openstreetmap.josm.tools.ListenerList; 40 38 import org.openstreetmap.josm.tools.Logging; 41 39 import org.openstreetmap.josm.tools.Utils; … … 52 50 * It is conceivable to extract this into an interface later and create various 53 51 * classes implementing the interface, to be able to talk to various kinds of servers. 54 * 52 * @ince 1523 55 53 */ 56 54 public class OsmApi extends OsmConnection { … … 76 74 77 75 // The collection of instantiated OSM APIs 78 private static Map<String, OsmApi> instances = new HashMap<>(); 76 private static final Map<String, OsmApi> instances = new HashMap<>(); 77 78 private static final ListenerList<OsmApiInitializationListener> listeners = ListenerList.create(); 79 79 80 80 private URL url; 81 82 /** 83 * OSM API initialization listener. 84 * @since 12804 85 */ 86 public interface OsmApiInitializationListener { 87 /** 88 * Called when an OSM API instance has been successfully initialized. 89 * @param instance the initialized OSM API instance 90 */ 91 void apiInitialized(OsmApi instance); 92 } 93 94 /** 95 * Adds a new OSM API initialization listener. 96 * @param listener OSM API initialization listener to add 97 * @since 12804 98 */ 99 public static void addOsmApiInitializationListener(OsmApiInitializationListener listener) { 100 listeners.addListener(listener); 101 } 102 103 /** 104 * Removes an OSM API initialization listener. 105 * @param listener OSM API initialization listener to remove 106 * @since 12804 107 */ 108 public static void removeOsmApiInitializationListener(OsmApiInitializationListener listener) { 109 listeners.removeListener(listener); 110 } 81 111 82 112 /** … … 236 266 } 237 267 238 /* This checks if there are any layers currently displayed that 239 * are now on the blacklist, and removes them. This is a rare 240 * situation - probably only occurs if the user changes the API URL 241 * in the preferences menu. Otherwise they would not have been able 242 * to load the layers in the first place because they would have 243 * been disabled! */ 244 if (MainApplication.isDisplayingMapView()) { 245 for (Layer l : MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class)) { 246 if (((ImageryLayer) l).getInfo().isBlacklisted()) { 247 Logging.info(tr("Removed layer {0} because it is not allowed by the configured API.", l.getName())); 248 MainApplication.getLayerManager().removeLayer(l); 249 } 250 } 251 } 252 268 listeners.fireEvent(l -> l.apiInitialized(this)); 253 269 } catch (OsmTransferCanceledException e) { 254 270 throw e;
Note:
See TracChangeset
for help on using the changeset viewer.