Package org.openstreetmap.josm.gui.layer
Class LayerManager
- java.lang.Object
-
- org.openstreetmap.josm.gui.layer.LayerManager
-
- Direct Known Subclasses:
MainLayerManager
public class LayerManager extends java.lang.Object
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 Classes Modifier and Type Class Description static class
LayerManager.LayerAddEvent
The event that is fired whenever a layer was added.static interface
LayerManager.LayerChangeListener
Interface to notify listeners of a layer change.protected static class
LayerManager.LayerManagerEvent
Base class of layer manager events.static class
LayerManager.LayerOrderChangeEvent
An event that is fired whenever the order of layers changed.static class
LayerManager.LayerRemoveEvent
The event that is fired before removing a layer.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
EVENT
private java.util.List<LayerManager.LayerChangeListener>
layerChangeListeners
private java.util.List<Layer>
layers
This is the list of layers we manage.private static java.lang.String
LISTENER
-
Constructor Summary
Constructors Constructor Description LayerManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAndFireLayerChangeListener(LayerManager.LayerChangeListener listener)
Adds a layer change listener and fire an add event for every layer in this manager.void
addLayer(Layer layer)
Add a layer.void
addLayer(Layer layer, boolean initialZoom)
Add a layer.void
addLayerChangeListener(LayerManager.LayerChangeListener listener)
Adds a layer change listenerprotected void
checkContainsLayer(Layer layer)
Checks if the specified layer is handled by this layer manager.private void
checkPosition(int position)
Check if the (new) position is validboolean
containsLayer(Layer layer)
replies true if the list of layers managed by this map view contain layerprivate void
fireLayerAdded(Layer layer, boolean initialZoom)
private void
fireLayerOrderChanged()
private java.util.Collection<Layer>
fireLayerRemoving(Layer layer)
Fire the layer remove eventjava.util.List<Layer>
getLayers()
Gets an unmodifiable list of all layers that are currently in this manager.<T extends Layer>
java.util.List<T>getLayersOfType(java.lang.Class<T> ofType)
Replies an unmodifiable list of layers of a certain type.private static void
insertLayerAt(java.util.List<Layer> layers, Layer layer, int position)
private void
insertLayerAt(Layer layer, int position)
Insert a layer at a given position.void
moveLayer(Layer layer, int position)
Move a layer to a new position.protected void
realAddLayer(Layer layer, boolean initialZoom)
Add a layer (implementation).protected void
realMoveLayer(Layer layer, int position)
Move a layer to a new position (implementation).protected void
realRemoveLayer(Layer layer)
Remove the layer from the mapview (implementation).protected java.util.Collection<Layer>
realRemoveSingleLayer(Layer layerToRemove)
Remove a single layer from the mapview (implementation).protected void
realResetState()
Reset all layer manager state (implementation).void
removeAndFireLayerChangeListener(LayerManager.LayerChangeListener listener)
Removes a layer change listener and fire a remove event for every layer in this manager.void
removeLayer(Layer layer)
Remove the layer from the mapview.void
removeLayerChangeListener(LayerManager.LayerChangeListener listener)
Removes a layer change listenervoid
resetState()
Reset all layer manager state.private void
updateLayers(java.util.function.Consumer<java.util.List<Layer>> mutator)
Update thelayers
field.
-
-
-
Field Detail
-
LISTENER
private static final java.lang.String LISTENER
- See Also:
- Constant Field Values
-
EVENT
private static final java.lang.String EVENT
- See Also:
- Constant Field Values
-
layers
private volatile java.util.List<Layer> 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:
updateLayers(Consumer)
-
layerChangeListeners
private final java.util.List<LayerManager.LayerChangeListener> layerChangeListeners
-
-
Constructor Detail
-
LayerManager
public LayerManager()
-
-
Method Detail
-
addLayer
public void addLayer(Layer layer)
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
public void addLayer(Layer layer, boolean initialZoom)
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
protected void realAddLayer(Layer layer, boolean initialZoom)
Add a layer (implementation).- Parameters:
layer
- The layer to addinitialZoom
- whether if the mapview must be zoomed at layer projection bounds
-
removeLayer
public void removeLayer(Layer layer)
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
protected void realRemoveLayer(Layer layer)
Remove the layer from the mapview (implementation).- Parameters:
layer
- The layer to remove
-
realRemoveSingleLayer
protected java.util.Collection<Layer> realRemoveSingleLayer(Layer layerToRemove)
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
public void moveLayer(Layer layer, int position)
Move a layer to a new position.- Parameters:
layer
- The layer to move.position
- The position.- Throws:
java.lang.IndexOutOfBoundsException
- if the position is out of bounds.
-
realMoveLayer
protected void realMoveLayer(Layer layer, int position)
Move a layer to a new position (implementation).- Parameters:
layer
- The layer to move.position
- The position.- Throws:
java.lang.IndexOutOfBoundsException
- if the position is out of bounds.
-
insertLayerAt
private void insertLayerAt(Layer layer, int position)
Insert a layer at a given position.- Parameters:
layer
- The layer to add.position
- The position on which we should add it.
-
insertLayerAt
private static void insertLayerAt(java.util.List<Layer> layers, Layer layer, int position)
-
checkPosition
private void checkPosition(int position)
Check if the (new) position is valid- Parameters:
position
- The position index- Throws:
java.lang.IndexOutOfBoundsException
- if it is not.
-
updateLayers
private void updateLayers(java.util.function.Consumer<java.util.List<Layer>> mutator)
Update thelayers
field. 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
public java.util.List<Layer> 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
public <T extends Layer> java.util.List<T> getLayersOfType(java.lang.Class<T> ofType)
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
public boolean containsLayer(Layer layer)
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
protected void checkContainsLayer(Layer layer)
Checks if the specified layer is handled by this layer manager.- Parameters:
layer
- layer to check- Throws:
java.lang.IllegalArgumentException
- if layer is not handled by this layer manager
-
addLayerChangeListener
public void addLayerChangeListener(LayerManager.LayerChangeListener listener)
Adds a layer change listener- Parameters:
listener
- the listener.- Throws:
java.lang.IllegalArgumentException
- If the listener was added twice.- See Also:
addAndFireLayerChangeListener(org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener)
-
addAndFireLayerChangeListener
public void addAndFireLayerChangeListener(LayerManager.LayerChangeListener listener)
Adds a layer change listener and fire an add event for every layer in this manager.- Parameters:
listener
- the listener.- Throws:
java.lang.IllegalArgumentException
- If the listener was added twice.- Since:
- 11905
- See Also:
addLayerChangeListener(org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener)
-
removeLayerChangeListener
public void removeLayerChangeListener(LayerManager.LayerChangeListener listener)
Removes a layer change listener- Parameters:
listener
- the listener. Ignored if null or already registered.- See Also:
removeAndFireLayerChangeListener(org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener)
-
removeAndFireLayerChangeListener
public void removeAndFireLayerChangeListener(LayerManager.LayerChangeListener listener)
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:
removeLayerChangeListener(org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener)
-
fireLayerAdded
private void fireLayerAdded(Layer layer, boolean initialZoom)
-
fireLayerRemoving
private java.util.Collection<Layer> fireLayerRemoving(Layer layer)
Fire the layer remove event- Parameters:
layer
- The layer that was removed- Returns:
- A list of layers that should be removed afterwards.
-
fireLayerOrderChanged
private void fireLayerOrderChanged()
-
resetState
public void resetState()
Reset all layer manager state. This includes removing all layers and then unregistering all listeners- Since:
- 10432
-
realResetState
protected void realResetState()
Reset all layer manager state (implementation).
-
-