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
Nested ClassesModifier and TypeClassDescriptionstatic final classThis class is used to build feature state changes. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObserver(IFeatureStateObserver observer) Adds an observer that allows to inspect feature state changes.voidaddObserver(IFeatureStateObserver observer, boolean seedObserver) Adds an observer that allows to inspect feature state changes.voidapplyStateChange(FeatureStateManager.Change featureStateChange) Applies the given state change.voidclearEnabledStates(LayerFeatureId layerFeatureId) Clears (i.e.voidclose()booleanprotected voidfinalize()getFeaturesWithStateEnabled(long layerId, FeatureState featureState) Returns the collection of feature IDs of the given layer for which the given feature state is enabled.inthashCode()booleanisStateEnabled(LayerFeatureId layerFeatureId, FeatureState featureState) Checks if the given feature state is enabled for the given feature identifier.voidremoveObserver(IFeatureStateObserver observer) Removes the given observer.
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
applyStateChange
Applies the given state change.After this call, the
FeatureStateManager#isStateEnabledmethod 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.
-
getFeaturesWithStateEnabled
@NotNull public List<Long> getFeaturesWithStateEnabled(long layerId, @NotNull FeatureState featureState) Returns the collection of feature IDs of the given layer for which the given feature state is enabled.Note: this method should only be called on the UI thread
- Parameters:
layerId- a layerfeatureState- a feature state- Returns:
- the collection of feature IDs of the given layer for which the given feature state is enabled.
- Since:
- 2025.0
-
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 aFeatureStateis 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.
-
hashCode
public int hashCode() -
equals
-