public final class FeatureStateManager extends Object implements AutoCloseable
In essence, it keeps a mapping of enabled/disabled states for each feature for specific FeatureState
instances. This class can for example manage which features are selected.
// Create and add a selection observer that prints which feature is selected or deselected
IFeatureStateObserver selectionObserver = new IFeatureStateObserver() {
@Override
public void onFeatureStateChanged(FeatureStateEvent featureStateEvent) {
for (LayerFeatureId changedFeature : featureStateEvent.getChangedFeatures(FeatureState.Selected)) {
boolean selected = featureStateEvent.getChange(FeatureState.Selected, changedFeature);
String selectedMessage = selected ? "Selected" : "Deselected";
Log.i("feature-state", "Feature " + changedFeature.getFeatureId() + " => " + selectedMessage);
}
}
};
featureStateManager.addObserver(selectionObserver);
// Apply a state change.
FeatureStateManager.Change change = FeatureStateManager.Change.create();
change.clearState(FeatureState.Selected);
change.setState(feature1, FeatureState.Selected, true);
featureStateManager.applyStateChange(change);
// Assuming that feature 2 was already selected before, the output will be:
// Feature 2 => Deselected
// Feature 1 => Selected
featureStateManager.removeObserver(selectionObserver);
Modifier and Type | Class and Description |
---|---|
static class |
FeatureStateManager.Change
This class is used to build feature state changes.
|
Modifier and Type | Method and Description |
---|---|
void |
addObserver(IFeatureStateObserver observer)
Adds an observer that allows to inspect feature state changes.
|
void |
addObserver(IFeatureStateObserver observer,
boolean seedObserver)
Adds an observer that allows to inspect feature state changes.
|
void |
applyStateChange(FeatureStateManager.Change featureStateChange)
Applies the given state change.
|
void |
clearEnabledStates(LayerFeatureId layerFeatureId)
Clears (i.e.
|
void |
close() |
protected void |
finalize() |
boolean |
isStateEnabled(LayerFeatureId layerFeatureId,
FeatureState featureState)
Checks if the given feature state is enabled for the given feature identifier.
|
void |
removeObserver(IFeatureStateObserver observer)
Removes the given observer.
|
public void close()
close
in interface AutoCloseable
public void applyStateChange(@NotNull FeatureStateManager.Change featureStateChange)
After this call, the FeatureStateManager#isStateEnabled
method will reflect the given changes, and the registered observers will have been notified of the concrete changes for each feature.
Note: this method should only be called on the UI thread
featureStateChange
- a feature state changepublic void clearEnabledStates(@NotNull LayerFeatureId layerFeatureId)
sets to false) all enabled stated for the given feature.
Note: this method should only be called on the UI thread
layerFeatureId
- the feature for which to clear all enabled states.public boolean isStateEnabled(@NotNull LayerFeatureId layerFeatureId, @NotNull FeatureState featureState)
Note: this method can be called on any thread.
layerFeatureId
- a feature identifierfeatureState
- a feature statepublic void addObserver(@NotNull IFeatureStateObserver observer, boolean seedObserver) throws IllegalArgumentException, NullPointerException
Note: this method should only be called on the UI thread
observer
- an observerseedObserver
- whether to inform the observer about the features for which a FeatureState
is currently enabledIllegalArgumentException
- if the observer is already added.NullPointerException
- if observer is null
.public void addObserver(@NotNull IFeatureStateObserver observer) throws IllegalArgumentException, NullPointerException
Note: this method should only be called on the UI thread
observer
- an observerIllegalArgumentException
- if the observer is already added.NullPointerException
- if observer is null
.public void removeObserver(@NotNull IFeatureStateObserver observer) throws IllegalArgumentException, NullPointerException
Note: this method should only be called on the UI thread
observer
- an observerIllegalArgumentException
- if the observer was not added.NullPointerException
- if observer is null
.