public final class TLcyShapeVisibilityManager extends Object implements ILcdDisposable
Creates and manages observers that calculate the visibility between the observer and other shapes on the map.
Note: all interactions with this class should happen on the AWT Thread (the Event Dispatch Thread).
//Retrieve the manager from the services
TLcyShapeVisibilityManager manager = aLucyEnv.getService(TLcyShapeVisibilityManager.class);
addObserver(TLcdDomainObjectContext)
method:
//Retrieve the manager from the services
TLcyShapeVisibilityManager manager = aLucyEnv.getService(TLcyShapeVisibilityManager.class);
//Ask the manager to create an observer for the specified domain object
//Interacting with the manager must happen on the AWT thread (Event Dispatch Thread)
if (manager.canAddObserver(aDomainObjectContext)) {
TLcyShapeObserver pointObserver = manager.addObserver(aDomainObjectContext);
}
The returned TLcyShapeObserver
will be kept in sync with the domain object for which it was created:
//Find the observer model in the view
ILcdModel pointObserverModel = view.getLayers()
.stream()
.map(ILcdLayer::getModel)
.filter(model -> Objects.equals(TLcyShapeVisibilityAddOn.OBSERVER_MODEL_TYPE_NAME, model.getModelDescriptor().getTypeName()))
.findFirst()
.orElseThrow(() -> new RuntimeException("Cannot find the model containing the observers"));
//Let the observer observe another shape
//As this modifies the point observer, it requires a lock on the point observer model
try (TLcdLockUtil.Lock autoUnlock = TLcdLockUtil.writeLock(pointObserverModel)) {
if (pointObserver.canObserve(aDomainObjectContextToObserve)) {
//Tell the observer to start observing another object
pointObserver.startObserving(aDomainObjectContextToObserve);
//Indicate to the model that the observer has been changed
pointObserverModel.elementChanged(pointObserver, ILcdModel.FIRE_LATER);
}
} finally {
pointObserverModel.fireCollectedModelChanges();
}
Once the result of the calculation is available, it will become visible on the map.Modifier and Type | Method and Description |
---|---|
TLcyShapeObserver |
addObserver(TLcdDomainObjectContext aDomainObjectContext)
Create and add a new observer for the specified domain object, allowing to calculate the visibility between this domain object and
other domain objects.
|
boolean |
canAddObserver(TLcdDomainObjectContext aDomainObjectContext)
Returns
true when a new observer can be created for aDomainObjectContext . |
boolean |
canRemoveObserver(TLcdDomainObjectContext aDomainObjectContext)
Returns
true when an observer was previously created for aDomainObjectContext , and it can be removed. |
void |
dispose()
Disposes of this object and allows it to release any system resources that it is holding.
|
void |
removeObserver(TLcdDomainObjectContext aDomainObjectContext)
Removes the observer for the specified domain object.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public boolean canAddObserver(TLcdDomainObjectContext aDomainObjectContext)
true
when a new observer can be created for aDomainObjectContext
.
Currently this requires that the domain object uses a point geometry, and that no observer exists yet for this domain object.aDomainObjectContext
- The domain object contexttrue
when a new observer can be created for aDomainObjectContext
public boolean canRemoveObserver(TLcdDomainObjectContext aDomainObjectContext)
true
when an observer was previously created for aDomainObjectContext
, and it can be removed.aDomainObjectContext
- The domain object context for which an observer was created before.true
when there still exists an observer for aDomainObjectContext
, and that observer can be removed.public TLcyShapeObserver addObserver(TLcdDomainObjectContext aDomainObjectContext) throws IllegalArgumentException
Create and add a new observer for the specified domain object, allowing to calculate the visibility between this domain object and other domain objects.
The created observer will be added to the observer layer on the map. If no such layer exist yet, it will be created and added to the map.
aDomainObjectContext
- The domain object for which to create an observerIllegalArgumentException
- If no observer could be created for aDomainObjectContext
canAddObserver(TLcdDomainObjectContext)
public void removeObserver(TLcdDomainObjectContext aDomainObjectContext)
aDomainObjectContext
- The domain object context for which the previously created observer must be removedpublic void dispose()
ILcdDisposable
Disposes of this object and allows it to release any system resources that it is holding.
The result of calling any other method (other than finalize
) on this object subsequent to a call to
this method is undefined.
dispose
in interface ILcdDisposable