public class Layer extends Object implements AutoCloseable
A layer has a few properties that can be changed.
An observer can be attached to get notifications about layer changes.
Use one of the concrete classes extending this class.
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 Layer
(and its subclasses) 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
Modifier and Type | Field and Description |
---|---|
static String |
PropertyTitle
Property name for the
LayerEvent that is fired as a result of changing the layer's title. |
static String |
PropertyVisible
Property name for the
LayerEvent that is fired as a result of changing the layer's visible flag. |
Modifier | Constructor and Description |
---|---|
protected |
Layer()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addObserver(ILayerObserver layerObserver)
Adds an observer that allows to receive change events from this layer.
|
void |
close() |
protected void |
finalize() |
long |
getId()
Returns the layer's unique id.
|
String |
getTitle()
Returns the layer's title.
|
boolean |
isVisible()
Returns whether this layer is visible.
|
void |
removeObserver(ILayerObserver layerObserver)
Removes the given observer.
|
void |
setTitle(String title)
Sets the layer's title.
|
void |
setVisible(boolean visible)
Sets whether this layer is visible.
|
public static final String PropertyTitle
LayerEvent
that is fired as a result of changing the layer's title.setTitle
public static final String PropertyVisible
LayerEvent
that is fired as a result of changing the layer's visible flag.setVisible
protected Layer()
It's not the intent to extend from this class, nor is it the intent to directly instantiate this class, so this constructor must not be used.
public void close()
close
in interface AutoCloseable
public long getId()
@NotNull public String getTitle()
Should be suitable for presenting to the user.
public void setTitle(@NotNull String title)
Should be suitable for presenting to the user.
If the new title is indeed different from the old one, a LayerEvent
is delivered to the observers with the property name PropertyTitle.
title
- the new title.public boolean isVisible()
public void setVisible(boolean visible)
Changes this layer's visibility. If the new visibility is different from the old one, a LayerEvent
is delivered to the observers with the property name PropertyVisible.
visible
- the new visibility.public void addObserver(@NotNull ILayerObserver layerObserver) throws IllegalArgumentException, NullPointerException
Adding the same observer twice is forbidden, and will cause an exception to be thrown.
layerObserver
- an observer.IllegalArgumentException
- when the observer was already added.NullPointerException
- when the observer is null
.public void removeObserver(@NotNull ILayerObserver layerObserver) throws IllegalArgumentException, NullPointerException
If the given observer was never added, an exception is thrown.
layerObserver
- an observer.IllegalArgumentException
- when the observer is not known.NullPointerException
- when the observer is null
.