Class FeatureStateManager
- All Implemented Interfaces:
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.
Example
// 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);
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
This class is used to build feature state changes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
applyStateChange
Applies the given state change.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
- Parameters:
featureStateChange
- a feature state change
-
clearEnabledStates
Clears (i.e.sets to false) all enabled stated for the given feature.
Note: this method should only be called on the UI thread
- Parameters:
layerFeatureId
- the feature for which to clear all enabled states.
-
isStateEnabled
public boolean isStateEnabled(@NotNull LayerFeatureId layerFeatureId, @NotNull FeatureState featureState) Checks if the given feature state is enabled for the given feature identifier.Note: this method can be called on any thread.
- Parameters:
layerFeatureId
- a feature identifierfeatureState
- a feature state- Returns:
- if the given feature state is enabled for the given feature identifier.
-
addObserver
public void addObserver(@NotNull IFeatureStateObserver observer, boolean seedObserver) throws IllegalArgumentException, NullPointerException Adds an observer that allows to inspect feature state changes.Note: this method should only be called on the UI thread
- Parameters:
observer
- an observerseedObserver
- whether to inform the observer about the features for which aFeatureState
is currently enabled- Throws:
IllegalArgumentException
- if the observer is already added.NullPointerException
- if observer isnull
.
-
addObserver
public void addObserver(@NotNull IFeatureStateObserver observer) throws IllegalArgumentException, NullPointerException Adds an observer that allows to inspect feature state changes.Note: this method should only be called on the UI thread
- Parameters:
observer
- an observer- Throws:
IllegalArgumentException
- if the observer is already added.NullPointerException
- if observer isnull
.
-
removeObserver
public void removeObserver(@NotNull IFeatureStateObserver observer) throws IllegalArgumentException, NullPointerException Removes the given observer.Note: this method should only be called on the UI thread
- Parameters:
observer
- an observer- Throws:
IllegalArgumentException
- if the observer was not added.NullPointerException
- if observer isnull
.
-