Class TLcyCombinedMapManager
- All Implemented Interfaces:
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 Summary
ConstructorDescriptionTLcyCombinedMapManager
(TLcyGenericMapManager<? extends ILcdView, ? extends ILcdLayer>[] aMapManagers) Deprecated.You should not create your own instances of this class.TLcyCombinedMapManager
(Collection<TLcyGenericMapManager<? extends ILcdView, ? extends ILcdLayer>> aMapManagers, ILcyLucyEnv aLucyEnv) Deprecated.You should not create your own instances of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMapManager
(TLcyGenericMapManager<? extends ILcdView, ? extends ILcdLayer> aMapManager) Add a map manager to this active map manager.void
Register a listener which will be warned about anyTLcyGeneralMapManagerEvent
s occurring in any of the registered map managers of this active map manager.void
addMapManagerListener
(ILcyGenericMapManagerListener<ILcdView, ILcdLayer> aListener, boolean aFireEventForExistingMaps) Register a listener which will be warned about anyTLcyGeneralMapManagerEvent
s occurring in any of the registered map managers of this active map manager.void
Registers the givenPropertyChangeListener
to be notified when this object's properties change.void
Utility method to find a new active map component.final ILcyGenericMapComponent
findMapComponent
(ILcdView aView) Returns the map component of whichILcyGenericMapComponent.getMainView()
returnsaView
.Returns the application wide active map component.Returns the Lucy environment to which this combined map manager is associated.List
<ILcyGenericMapComponent<? extends ILcdView, ? extends ILcdLayer>> Returns a list containing all the map components of all the registered map managers.List
<TLcyGenericMapManager<? extends ILcdView, ? extends ILcdLayer>> Returns a list containing all the map managers registered to this combined map manager.void
removeMapManager
(TLcyGenericMapManager<? extends ILcdView, ? extends ILcdLayer> aMapManager) Remove a map manager from this active map manager.void
Un-register the listeneraListener
so it will no longer be warned aboutTLcyGeneralMapManagerEvent
s occurring in the registered map managers of this active map manager.void
De-registers the givenPropertyChangeListener
from receiving property change events for this object.setActiveMapComponent
(ILcyGenericMapComponent<S, T> aActiveMapComponent) Set the active map component toaActiveMapComponent
.
-
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 (seeILcyLucyEnv.getCombinedMapManager()
).Create a new combined map manager for all the map managers contained in the arrayaMapManagers
.- 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 (seeILcyLucyEnv.getCombinedMapManager()
).Create a new combined map manager for all the map managers contained in the collectionaMapManagers
.- Parameters:
aMapManagers
- a collection with map managers.aLucyEnv
- The Lucy backend
-
-
Method Details
-
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
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 returnnull
, 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 returnnull
.- 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 passnull
to all registered map managers.- Parameters:
aActiveMapComponent
- The active map component, ornull
.- See Also:
-
addPropertyChangeListener
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 interfaceILcdPropertyChangeSource
- Parameters:
listener
- The listener to be notified- See Also:
-
removePropertyChangeListener
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 interfaceILcdPropertyChangeSource
- Parameters:
listener
- the listener that should no longer be notified of changes of this object's properties- See Also:
-
addMapManagerListener
Register a listener which will be warned about any
TLcyGeneralMapManagerEvent
s occurring in any of the registered map managers of this active map manager. The source map manager can be retrieved from the event by callingTLcyGenericMapManagerEvent.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
TLcyGeneralMapManagerEvent
s occurring in any of the registered map managers of this active map manager. The source map manager can be retrieved from the event by callingTLcyGenericMapManagerEvent.getMapManager()
.For every existing map a MAP_COMPONENT_ADDED event will be fired to
aListener
whenaFireEventForExistingMaps
istrue
. 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 registeredaFireEventForExistingMaps
-true
whenaListener
must be warned about all existing maps,false
otherwise- See Also:
-
removeMapManagerListener
Un-register the listener
aListener
so it will no longer be warned aboutTLcyGeneralMapManagerEvent
s occurring in the registered map managers of this active map manager.- Parameters:
aListener
- the listener to be removed- See Also:
-
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
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
Returns the map component of which
ILcyGenericMapComponent.getMainView()
returnsaView
.- Parameters:
aView
- The view.- Returns:
- the map component of which
ILcyGenericMapComponent.getMainView()
returnsaView
, ornull
in case no such map component is known to the map manager - Since:
- 2016.1
-