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:
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
});
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);
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
}
}
});
getActiveMapComponent()
,
setActiveMapComponent(ILcyGenericMapComponent)
Constructor and Description |
---|
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() ). |
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() ). |
Modifier and Type | Method and Description |
---|---|
void |
addMapManager(TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer> aMapManager)
Add a map manager to this active map manager.
|
void |
addMapManagerListener(ILcyGenericMapManagerListener<ILcdView,ILcdLayer> aListener)
Register a listener which will be warned about any
TLcyGeneralMapManagerEvent 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 any
TLcyGeneralMapManagerEvent s
occurring in any of the registered map managers of this active map manager. |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Registers the given
PropertyChangeListener to be notified when this object's
properties change. |
void |
findAndSetNewActiveMap()
Utility method to find a new active map component.
|
ILcyGenericMapComponent |
findMapComponent(ILcdView aView)
Returns the map component of which
ILcyGenericMapComponent.getMainView() returns aView . |
ILcyGenericMapComponent |
getActiveMapComponent()
Returns the application wide active map component.
|
ILcyLucyEnv |
getLucyEnv()
Returns the Lucy environment to which this combined map manager is associated.
|
List<ILcyGenericMapComponent<? extends ILcdView,? extends ILcdLayer>> |
getMapComponents()
Returns a list containing all the map components of all the registered map managers.
|
List<TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer>> |
getMapManagers()
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 |
removeMapManagerListener(ILcyGenericMapManagerListener<ILcdView,ILcdLayer> aListener)
Un-register the listener
aListener so it will no longer be warned about
TLcyGeneralMapManagerEvent s occurring in the registered map managers of this active
map manager. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
De-registers the given
PropertyChangeListener from receiving property change events
for this object. |
<S extends ILcdView,T extends ILcdLayer> |
setActiveMapComponent(ILcyGenericMapComponent<S,T> aActiveMapComponent)
Set the active map component to
aActiveMapComponent . |
@Deprecated public TLcyCombinedMapManager(TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer>[] aMapManagers)
ILcyLucyEnv.getCombinedMapManager()
).aMapManagers
.aMapManagers
- an array with map managers@Deprecated public TLcyCombinedMapManager(Collection<TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer>> aMapManagers, ILcyLucyEnv aLucyEnv)
ILcyLucyEnv.getCombinedMapManager()
).aMapManagers
.aMapManagers
- a collection with map managers.aLucyEnv
- The Lucy backendpublic List<ILcyGenericMapComponent<? extends ILcdView,? extends ILcdLayer>> getMapComponents()
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
.
setActiveMapComponent(ILcyGenericMapComponent)
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.
aActiveMapComponent
- The active map component, or null
.getActiveMapComponent()
public void addPropertyChangeListener(PropertyChangeListener listener)
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.
addPropertyChangeListener
in interface ILcdPropertyChangeSource
listener
- The listener to be notifiedALcdWeakPropertyChangeListener
,
ILcdPropertyChangeSource.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener listener)
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.
removePropertyChangeListener
in interface ILcdPropertyChangeSource
listener
- the listener that should no longer be notified of changes of
this object's propertiesILcdPropertyChangeSource.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void addMapManagerListener(ILcyGenericMapManagerListener<ILcdView,ILcdLayer> aListener)
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 calling TLcyGenericMapManagerEvent.getMapManager()
.
aListener
- the listener to be registeredaddMapManagerListener(ILcyGenericMapManagerListener, boolean)
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 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.
aListener
- The listener to be registeredaFireEventForExistingMaps
- true
when aListener
must be warned
about all existing maps, false
otherwiseaddMapManagerListener(ILcyGenericMapManagerListener)
public void removeMapManagerListener(ILcyGenericMapManagerListener<ILcdView,ILcdLayer> aListener)
Un-register the listener aListener
so it will no longer be warned about
TLcyGeneralMapManagerEvent
s occurring in the registered map managers of this active
map manager.
aListener
- the listener to be removedTLcyGenericMapManager.removeMapManagerListener(ILcyGenericMapManagerListener)
public List<TLcyGenericMapManager<? extends ILcdView,? extends ILcdLayer>> getMapManagers()
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.
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.
aMapManager
- the map manager to be addedpublic 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.
aMapManager
- the map manager to be removed.public ILcyLucyEnv getLucyEnv()
ILcyLucyEnv.getCombinedMapManager()
public final ILcyGenericMapComponent findMapComponent(ILcdView aView)
Returns the map component of which ILcyGenericMapComponent.getMainView()
returns aView
.
aView
- The view.ILcyGenericMapComponent.getMainView()
returns aView
,
or null
in case no such map component is known to the map manager