public final class LayerList extends Object implements AutoCloseable
The order within this list determines the order in which layers are painted.
Note that this class tracks on which thread it is constructed. This is done so that, in subsequent calls, it can verify that the same threads are used consistently. When an inconsistency is detected, an assertion is triggered. This means that all functions on LayerList
must be called on the thread on which the Map
was constructed (the "UI" thread). The only exception is adding and removing observers. Related article: Threading rules for the Map
Constructor and Description |
---|
LayerList()
Constructs an empty layer list.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Layer layer)
Adds the given layer to this layer list.
|
void |
add(Layer layer,
long targetIndex)
Adds the given layer to this layer list.
|
void |
addObserver(ILayerListObserver observer)
Adds an observer to be notified of changes to this layer list.
|
void |
addObserver(ILayerListObserver observer,
boolean seedObserver)
Adds an observer to be notified of changes to this layer list.
|
void |
close() |
protected void |
finalize() |
Layer |
findLayerById(long layerId)
Searches for the layer with a provided id in the layer list.
|
List<Layer> |
getLayers()
Returns the vector that represents the ordering of all layers in this layer list.
|
void |
move(long layerId,
long targetIndex)
Moves the layer with the given id to the target index.
|
void |
remove(long layerId)
Removes the layer with the given id.
|
void |
removeObserver(ILayerListObserver observer)
Removes the given observer.
|
public void close()
close
in interface AutoCloseable
@NotNull public List<Layer> getLayers()
The order is defined as bottom-to-top. This means that the first layer in this vector is painted first (and appears at the bottom), and that the last layer of this vector is painted last (and appears at the top).
@Nullable public Layer findLayerById(long layerId)
layerId
- a layer idnull
.public void add(@NotNull Layer layer) throws IllegalArgumentException, NullPointerException
layer
- a layerIllegalArgumentException
- when the layer has already been added.NullPointerException
- when the layer is null
.public void add(@NotNull Layer layer, long targetIndex) throws IllegalArgumentException, NullPointerException
layer
- a layertargetIndex
- the index at which to add the layerIllegalArgumentException
- exception when the layer has already been added or when the target index is not in range.NullPointerException
- when the layer is null
.public void remove(long layerId) throws IllegalArgumentException
layerId
- the id of the layer to removeIllegalArgumentException
- when this LayerList
does not contain a layer with the given idpublic void move(long layerId, long targetIndex) throws IllegalArgumentException
layerId
- the id of the layer to movetargetIndex
- a target indexIllegalArgumentException
- when this LayerList
does not contain a layer with the given id or when the target index is not in rangepublic void addObserver(@NotNull ILayerListObserver observer, boolean seedObserver) throws IllegalArgumentException, NullPointerException
Adding the same observer twice is forbidden, and will cause an exception to be thrown.
observer
- an observer, must not be null
seedObserver
- whether to inform the observer about the layers that are currently presentIllegalArgumentException
- when the observer was already added.NullPointerException
- when the observer is null
.public void addObserver(@NotNull ILayerListObserver observer) throws IllegalArgumentException, NullPointerException
Adding the same observer twice is forbidden, and will cause an exception to be thrown.
observer
- an observer, must not be null
IllegalArgumentException
- when the observer was already added.NullPointerException
- when the observer is null
.public void removeObserver(@NotNull ILayerListObserver observer) throws IllegalArgumentException, NullPointerException
If the given observer was never added, an exception is thrown.
observer
- an observer, must not be null
IllegalArgumentException
- when the observer is not known.NullPointerException
- when the observer is null
.