Class FeatureStateManager

java.lang.Object
com.luciad.layers.features.FeatureStateManager
All Implemented Interfaces:
AutoCloseable

public final class FeatureStateManager extends Object implements AutoCloseable
Manages feature states.

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 Link icon

// 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);
  • Method Details Link icon

    • finalize Link icon

      protected void finalize()
      Overrides:
      finalize in class Object
    • close Link icon

      public void close()
      Specified by:
      close in interface AutoCloseable
    • applyStateChange Link icon

      public void applyStateChange(@NotNull FeatureStateManager.Change featureStateChange)
      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 Link icon

      public void clearEnabledStates(@NotNull LayerFeatureId layerFeatureId)
      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 Link icon

      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 identifier
      featureState - a feature state
      Returns:
      if the given feature state is enabled for the given feature identifier.
    • addObserver Link icon

      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 observer
      seedObserver - whether to inform the observer about the features for which a FeatureState is currently enabled
      Throws:
      IllegalArgumentException - if the observer is already added.
      NullPointerException - if observer is null.
    • addObserver Link icon

      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 is null.
    • removeObserver Link icon

      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 is null.