Package org.openstreetmap.josm.gui.layer
Class LayerManager
java.lang.Object
org.openstreetmap.josm.gui.layer.LayerManager
- Direct Known Subclasses:
MainLayerManager
This class handles the layer management.
This manager handles a list of layers with the first layer being the front layer.
Threading
Synchronization of the layer manager is done by synchronizing all read/write access. All changes are internally done in the EDT thread.Methods of this manager may be called from any thread in any order. Listeners are called while this layer manager is locked, so they should not block on other threads.
- Since:
- 10273
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe event that is fired whenever a layer was added.static interfaceInterface to notify listeners of a layer change.protected static classBase class of layer manager events.static classAn event that is fired whenever the order of layers changed.static classThe event that is fired before removing a layer. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final List<LayerManager.LayerChangeListener>This is the list of layers we manage.private static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a layer change listener and fire an add event for every layer in this manager.voidAdd a layer.voidAdd a layer.voidAdds a layer change listenerprotected voidcheckContainsLayer(Layer layer) Checks if the specified layer is handled by this layer manager.private voidcheckPosition(int position) Check if the (new) position is validbooleancontainsLayer(Layer layer) replies true if the list of layers managed by this map view contain layerprivate voidfireLayerAdded(Layer layer, boolean initialZoom) private voidprivate Collection<Layer>fireLayerRemoving(Layer layer) Fire the layer remove eventGets an unmodifiable list of all layers that are currently in this manager.getLayersOfType(Class<T> ofType) Replies an unmodifiable list of layers of a certain type.private static voidinsertLayerAt(List<Layer> layers, Layer layer, int position) private voidinsertLayerAt(Layer layer, int position) Insert a layer at a given position.voidMove a layer to a new position.protected voidrealAddLayer(Layer layer, boolean initialZoom) Add a layer (implementation).protected voidrealMoveLayer(Layer layer, int position) Move a layer to a new position (implementation).protected voidrealRemoveLayer(Layer layer) Remove the layer from the mapview (implementation).protected Collection<Layer>realRemoveSingleLayer(Layer layerToRemove) Remove a single layer from the mapview (implementation).protected voidReset all layer manager state (implementation).voidRemoves a layer change listener and fire a remove event for every layer in this manager.voidremoveLayer(Layer layer) Remove the layer from the mapview.voidRemoves a layer change listenervoidReset all layer manager state.private voidupdateLayers(Consumer<List<Layer>> mutator) Update thelayersfield.
-
Field Details
-
LISTENER
- See Also:
-
EVENT
- See Also:
-
layers
This is the list of layers we manage. The list is unmodifiable. That way, read access does not need to be synchronized.It is only changed in the EDT.
- See Also:
-
layerChangeListeners
-
-
Constructor Details
-
LayerManager
public LayerManager()
-
-
Method Details
-
addLayer
Add a layer. The layer will be added at a given position and the mapview zoomed at its projection bounds.- Parameters:
layer- The layer to add
-
addLayer
Add a layer. The layer will be added at a given position.- Parameters:
layer- The layer to addinitialZoom- whether if the mapview must be zoomed at layer projection bounds
-
realAddLayer
Add a layer (implementation).- Parameters:
layer- The layer to addinitialZoom- whether if the mapview must be zoomed at layer projection bounds
-
removeLayer
Remove the layer from the mapview. If the layer was in the list before, an LayerChange event is fired.- Parameters:
layer- The layer to remove
-
realRemoveLayer
Remove the layer from the mapview (implementation).- Parameters:
layer- The layer to remove
-
realRemoveSingleLayer
Remove a single layer from the mapview (implementation).- Parameters:
layerToRemove- The layer to remove- Returns:
- A list of layers that should be removed afterwards.
-
moveLayer
Move a layer to a new position.- Parameters:
layer- The layer to move.position- The position.- Throws:
IndexOutOfBoundsException- if the position is out of bounds.
-
realMoveLayer
Move a layer to a new position (implementation).- Parameters:
layer- The layer to move.position- The position.- Throws:
IndexOutOfBoundsException- if the position is out of bounds.
-
insertLayerAt
Insert a layer at a given position.- Parameters:
layer- The layer to add.position- The position on which we should add it.
-
insertLayerAt
-
checkPosition
Check if the (new) position is valid- Parameters:
position- The position index- Throws:
IndexOutOfBoundsException- if it is not.
-
updateLayers
Update thelayersfield. This method should be used instead of a direct field access.- Parameters:
mutator- A method that gets the writable list of layers and should modify it.
-
getLayers
Gets an unmodifiable list of all layers that are currently in this manager. This list won't update once layers are added or removed.- Returns:
- The list of layers.
-
getLayersOfType
Replies an unmodifiable list of layers of a certain type.Example:
List<WMSLayer> wmsLayers = getLayersOfType(WMSLayer.class);- Type Parameters:
T- The layer type- Parameters:
ofType- The layer type.- Returns:
- an unmodifiable list of layers of a certain type.
-
containsLayer
replies true if the list of layers managed by this map view contain layer- Parameters:
layer- the layer- Returns:
- true if the list of layers managed by this map view contain layer
-
checkContainsLayer
Checks if the specified layer is handled by this layer manager.- Parameters:
layer- layer to check- Throws:
IllegalArgumentException- if layer is not handled by this layer manager
-
addLayerChangeListener
Adds a layer change listener- Parameters:
listener- the listener.- Throws:
IllegalArgumentException- If the listener was added twice.- See Also:
-
addAndFireLayerChangeListener
Adds a layer change listener and fire an add event for every layer in this manager.- Parameters:
listener- the listener.- Throws:
IllegalArgumentException- If the listener was added twice.- Since:
- 11905
- See Also:
-
removeLayerChangeListener
Removes a layer change listener- Parameters:
listener- the listener. Ignored if null or already registered.- See Also:
-
removeAndFireLayerChangeListener
Removes a layer change listener and fire a remove event for every layer in this manager. The event is fired as if the layer was deleted butLayerManager.LayerRemoveEvent.scheduleRemoval(Collection)is ignored.- Parameters:
listener- the listener.- Since:
- 11905
- See Also:
-
fireLayerAdded
-
fireLayerRemoving
Fire the layer remove event- Parameters:
layer- The layer that was removed- Returns:
- A list of layers that should be removed afterwards.
-
fireLayerOrderChanged
-
resetState
Reset all layer manager state. This includes removing all layers and then unregistering all listeners- Since:
- 10432
-
realResetState
Reset all layer manager state (implementation).
-