Class TLcyCombinedMapManager

java.lang.Object
com.luciad.lucy.map.TLcyCombinedMapManager
All Implemented Interfaces:
ILcdPropertyChangeSource

public class TLcyCombinedMapManager extends Object implements ILcdPropertyChangeSource

This class is a manager for the TLcyGenericMapManager instances used in Lucy.

It provides a central access point to those managers, and a central point to register listeners. It also introduces the concept of the application wide active map component. Every registered map manager can have its own active map component, but only one of those map components is considered as the application wide active map component.

Events are fired when:

  • Map components are added to and/or removed from one of the registered map managers.
  • The application-wide active map component changes.

Use-cases

Looping over all available maps


   ILcyLucyEnv lucy = ...;

    //Retrieve the map manager
    TLcyCombinedMapManager mapManager = lucy.getCombinedMapManager();

    //Ask the map manager for all currently available maps
    List<ILcyGenericMapComponent<? extends ILcdView, ? extends ILcdLayer>> mapComponents = combinedMapManager.getMapComponents();
    mapComponents.forEach(map -> {
      //do something with the map
    });
 

Executing code for every current and future map

A very common use-case in Lucy is that you have a piece of code that you want to execute once for every map, for example inserting a new action on each map. This includes all the maps which are already available, and all maps which will be created in the future.

   ILcyLucyEnv lucy = ...;

   //Retrieve the map manager
   TLcyCombinedMapManager mapManager = lucy.getCombinedMapManager();

   //Create the listener using a factory method, and indicate the type of view we are interested in
   //When the view type is not specified, the listener will be triggered for all the maps,
   //independent of their type
   ILcyGenericMapManagerListener<ILcdView, ILcdLayer> listener = ILcyGenericMapManagerListener.onMapAdded(ILspView.class, map -> {
     //do something with the new Lightspeed map
   });

   //Register the listener
   //Note the true as second argument
   //This will trigger the listener for each of the already available maps
   combinedMapManager.addMapManagerListener(listener, true);
 

Tracking the active map


 ILcyLucyEnv lucy = ...;

 //Retrieve the map manager
 TLcyCombinedMapManager mapManager = lucy.getCombinedMapManager();

 //Register the property change listener
 mapManager.addPropertyChangeListener(evt -> {
   String propertyName = evt.getPropertyName();
   if("activeMapComponent".equals(propertyName)){
     ILcyGenericMapComponent activeMap = (ILcyGenericMapComponent) evt.getNewValue();

     if(activeMap != null){
     //do something with the map
     }
   }
 });
 
Since:
9.1
See Also:
  • Constructor Details

    • TLcyCombinedMapManager

      @Deprecated public TLcyCombinedMapManager(TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer>[] aMapManagers)
      Deprecated.
      You should not create your own instances of this class. Instead, retrieve the combined map manager from the Lucy back-end (see ILcyLucyEnv.getCombinedMapManager()).
      Create a new combined map manager for all the map managers contained in the array aMapManagers.
      Parameters:
      aMapManagers - an array with map managers
    • TLcyCombinedMapManager

      @Deprecated public TLcyCombinedMapManager(Collection<TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer>> aMapManagers, ILcyLucyEnv aLucyEnv)
      Deprecated.
      You should not create your own instances of this class. Instead, retrieve the combined map manager from the Lucy back-end (see ILcyLucyEnv.getCombinedMapManager()).
      Create a new combined map manager for all the map managers contained in the collection aMapManagers.
      Parameters:
      aMapManagers - a collection with map managers.
      aLucyEnv - The Lucy backend
  • Method Details

    • getMapComponents

      public List<ILcyGenericMapComponent<? extends ILcdView,? extends ILcdLayer>> getMapComponents()
      Returns a list containing all the map components of all the registered map managers.
      Returns:
      a list containing all the map components of all the registered map managers.
    • getActiveMapComponent

      public ILcyGenericMapComponent getActiveMapComponent()

      Returns the application wide active map component. By default this is the last map component which was set active on one of the registered map managers, or the map component which was set active on this combined map manager.

      When one of the registered map managers sets his active map component to null, calling this method will not return null, but it will return an active map component of one of the other registered map managers.

      Only when all registered map managers have null as active map component, this method will return null.

      Returns:
      the last map component which was set active on one of the registered map managers, or the map component which was set active on this combined map manager.
      See Also:
    • setActiveMapComponent

      public <S extends ILcdView, T extends ILcdLayer> void setActiveMapComponent(ILcyGenericMapComponent<S,T> aActiveMapComponent)

      Set the active map component to aActiveMapComponent.

      This method will delegate the call to the map manager containing the new active map component. When null is set as active map component, it will pass null to all registered map managers.

      Parameters:
      aActiveMapComponent - The active map component, or null.
      See Also:
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Description copied from interface: ILcdPropertyChangeSource

      Registers the given PropertyChangeListener to be notified when this object's properties change.

      In case you need to register a listener which keeps a reference to an object with a shorter life-time than this change source, you can use a ALcdWeakPropertyChangeListener instance as property change listener.

      Specified by:
      addPropertyChangeListener in interface ILcdPropertyChangeSource
      Parameters:
      listener - The listener to be notified
      See Also:
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
      Description copied from interface: ILcdPropertyChangeSource

      De-registers the given PropertyChangeListener from receiving property change events for this object.

      If the listener was added more than once, it will be notified one less time after being removed. If the listener is null, or was never added, no exception is thrown and no action is taken.

      Specified by:
      removePropertyChangeListener in interface ILcdPropertyChangeSource
      Parameters:
      listener - the listener that should no longer be notified of changes of this object's properties
      See Also:
    • addMapManagerListener

      public void addMapManagerListener(ILcyGenericMapManagerListener<ILcdView,ILcdLayer> aListener)

      Register a listener which will be warned about any TLcyGeneralMapManagerEvents occurring in any of the registered map managers of this active map manager. The source map manager can be retrieved from the event by calling TLcyGenericMapManagerEvent.getMapManager().

      Parameters:
      aListener - the listener to be registered
      See Also:
    • addMapManagerListener

      public void addMapManagerListener(ILcyGenericMapManagerListener<ILcdView,ILcdLayer> aListener, boolean aFireEventForExistingMaps)

      Register a listener which will be warned about any TLcyGeneralMapManagerEvents occurring in any of the registered map managers of this active map manager. The source map manager can be retrieved from the event by calling TLcyGenericMapManagerEvent.getMapManager().

      For every existing map a MAP_COMPONENT_ADDED event will be fired to aListener when aFireEventForExistingMaps is true. A use-case for this is when you want to use the listener to perform an action on any existing map and on all future maps.

      Parameters:
      aListener - The listener to be registered
      aFireEventForExistingMaps - true when aListener must be warned about all existing maps, false otherwise
      See Also:
    • removeMapManagerListener

      public void removeMapManagerListener(ILcyGenericMapManagerListener<ILcdView,ILcdLayer> aListener)

      Un-register the listener aListener so it will no longer be warned about TLcyGeneralMapManagerEvents occurring in the registered map managers of this active map manager.

      Parameters:
      aListener - the listener to be removed
      See Also:
    • getMapManagers

      public List<TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer>> getMapManagers()
      Returns a list containing all the map managers registered to this combined map manager.
      Returns:
      a list containing all the map managers registered to this combined map manager.
    • findAndSetNewActiveMap

      public void findAndSetNewActiveMap()

      Utility method to find a new active map component. If the active map component is null, this method will find a map component that is showing between all the map components of the registered map managers and set it as the active map component.

      If no showing map component could be found in one of the registered map managers, the last map component of the first registered map manager is used, if there is one. Otherwise the last one of the second registered map manager is used, ... . When no map component is found, nothing happens.

    • addMapManager

      public void addMapManager(TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer> aMapManager)

      Add a map manager to this active map manager. Nothing happens when the map manager was already registered to this active map manager.

      Parameters:
      aMapManager - the map manager to be added
    • removeMapManager

      public void removeMapManager(TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer> aMapManager)

      Remove a map manager from this active map manager. Nothing happens when the map manager was not registered to this active map manager.

      Parameters:
      aMapManager - the map manager to be removed.
    • getLucyEnv

      public ILcyLucyEnv getLucyEnv()
      Returns the Lucy environment to which this combined map manager is associated.
      Returns:
      the Lucy environment to which this combined map manager is associated.
      See Also:
    • findMapComponent

      public final ILcyGenericMapComponent findMapComponent(ILcdView aView)

      Returns the map component of which ILcyGenericMapComponent.getMainView() returns aView.

      Parameters:
      aView - The view.
      Returns:
      the map component of which ILcyGenericMapComponent.getMainView() returns aView, or null in case no such map component is known to the map manager
      Since:
      2016.1