Package org.eclipse.gef.fx.anchors
Class AbstractAnchor
- java.lang.Object
-
- org.eclipse.gef.fx.anchors.AbstractAnchor
-
- All Implemented Interfaces:
IAnchor
- Direct Known Subclasses:
DynamicAnchor
,StaticAnchor
public abstract class AbstractAnchor extends java.lang.Object implements IAnchor
AbstractAnchor
is the abstract base implementation forIAnchor
s. It provides the facility to bind an anchor to an anchorageNode
(anchorageProperty()
), to attach and detachNode
s viaAnchorKey
s, and to provide positions (positionsUnmodifiableProperty()
) for the attachedAnchorKey
s.It also registers the necessary listeners at the anchorage
Node
and the attachedNode
s as well as relevant ancestorNode
s, to trigger the (re-)computation of positions.The actual computation of positions for attached nodes is delegated to
computePosition(AnchorKey)
, thus left to subclasses. If a subclass needs additional information to compute positions for attachedAnchorKey
s, it may request that anIAdaptable
info gets passed intoattach(AnchorKey)
anddetach(AnchorKey)
, and may overwrite both methods to get access to it.
-
-
Constructor Summary
Constructors Constructor Description AbstractAnchor(javafx.scene.Node anchorage)
Creates a newAbstractAnchor
for the given anchorageNode
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.Node>
anchorageProperty()
Provides a read-only property with the anchorageNode
thisIAnchor
is bound to.void
attach(AnchorKey key)
protected abstract Point
computePosition(AnchorKey key)
Recomputes the position for the given attachedAnchorKey
by delegating to the respectiveIComputationStrategy
.void
detach(AnchorKey key)
javafx.scene.Node
getAnchorage()
Provides the anchorageNode
thisIAnchor
is bound to.protected java.util.Set<AnchorKey>
getKeys()
Returns all keys maintained by this anchor.protected SetMultimap<javafx.scene.Node,AnchorKey>
getKeysByNode()
Point
getPosition(AnchorKey key)
Provides a position for the givenAnchorKey
.javafx.collections.ObservableMap<AnchorKey,Point>
getPositionsUnmodifiable()
Provides an observable read-only (map) with positions (in local coordinates of the anchoredNode
s) for all attachedAnchorKey
s.boolean
isAttached(AnchorKey key)
javafx.beans.property.ReadOnlyMapProperty<AnchorKey,Point>
positionsUnmodifiableProperty()
Provides a read-only (map) property with positions (in local coordinates of the anchoredNode
s) for all attachedAnchorKey
s.protected void
registerVCL(javafx.scene.Node anchored)
Registers aVisualChangeListener
for the given anchoredNode
.protected void
registerVCLs()
RegistersVisualChangeListener
s for all anchoredNode
s, or schedules their registration if the VCL cannot be registered yet.protected void
setAnchorage(javafx.scene.Node anchorage)
Sets the anchorage of thisAbstractAnchor
to the given value.protected void
unregisterVCL(javafx.scene.Node anchored)
Unregisters theVisualChangeListener
s for the given anchoredNode
.protected void
unregisterVCLs()
Unregisters theVisualChangeListener
s for all anchoredNode
s.protected void
updatePosition(AnchorKey key)
Updates the position for the givenAnchorKey
, i.e.protected void
updatePositions()
Updates the positions for all attachedAnchorKey
s.
-
-
-
Constructor Detail
-
AbstractAnchor
public AbstractAnchor(javafx.scene.Node anchorage)
Creates a newAbstractAnchor
for the given anchorageNode
.- Parameters:
anchorage
- The anchorageNode
for thisAbstractAnchor
.
-
-
Method Detail
-
anchorageProperty
public javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.Node> anchorageProperty()
Description copied from interface:IAnchor
Provides a read-only property with the anchorageNode
thisIAnchor
is bound to. The property value may benull
in case thisIAnchor
is not bound to an anchorageNode
.- Specified by:
anchorageProperty
in interfaceIAnchor
- Returns:
- A read-only property storing the anchorage
Node
.
-
computePosition
protected abstract Point computePosition(AnchorKey key)
Recomputes the position for the given attachedAnchorKey
by delegating to the respectiveIComputationStrategy
.
-
getAnchorage
public javafx.scene.Node getAnchorage()
Description copied from interface:IAnchor
Provides the anchorageNode
thisIAnchor
is bound to. Will return the value of theIAnchor.anchorageProperty()
.- Specified by:
getAnchorage
in interfaceIAnchor
- Returns:
- The value of the
IAnchor.anchorageProperty()
.
-
getKeys
protected java.util.Set<AnchorKey> getKeys()
Returns all keys maintained by this anchor.- Returns:
- A set containing all
AnchorKey
s.
-
getKeysByNode
protected SetMultimap<javafx.scene.Node,AnchorKey> getKeysByNode()
- Returns:
- The
Map
which stores the registeredAnchorKey
s perNode
by reference.
-
getPosition
public Point getPosition(AnchorKey key)
Description copied from interface:IAnchor
Provides a position for the givenAnchorKey
. The providedAnchorKey
has to be attached to thisIAnchor
(seeIAnchor.attach(AnchorKey)
).- Specified by:
getPosition
in interfaceIAnchor
- Parameters:
key
- TheAnchorKey
to retrieve a position for. It has to be attached (IAnchor.attach(AnchorKey)
) to thisIAnchor
before.- Returns:
- The position for the given
AnchorKey
within local coordinates of theAnchorKey
's anchoredNode
.
-
getPositionsUnmodifiable
public javafx.collections.ObservableMap<AnchorKey,Point> getPositionsUnmodifiable()
Description copied from interface:IAnchor
Provides an observable read-only (map) with positions (in local coordinates of the anchoredNode
s) for all attachedAnchorKey
s. The positions will be updated for all attachedAnchorKey
s if the attachedNode
s or the anchorageNode
, theIAnchor
is bound to, or any of their ancestors changes in a way that will effect the positions (within the local coordinate space of the attachedNode
s).- Specified by:
getPositionsUnmodifiable
in interfaceIAnchor
- Returns:
- A read-only observable map storing positions for all attached
AnchorKey
s.
-
isAttached
public boolean isAttached(AnchorKey key)
Description copied from interface:IAnchor
- Specified by:
isAttached
in interfaceIAnchor
- Parameters:
key
- TheAnchorKey
to test.- Returns:
true
if the given key is attached, otherwisefalse
.
-
positionsUnmodifiableProperty
public javafx.beans.property.ReadOnlyMapProperty<AnchorKey,Point> positionsUnmodifiableProperty()
Description copied from interface:IAnchor
Provides a read-only (map) property with positions (in local coordinates of the anchoredNode
s) for all attachedAnchorKey
s. The positions will be updated for all attachedAnchorKey
s if the attachedNode
s or the anchorageNode
, theIAnchor
is bound to, or any of their ancestors changes in a way that will effect the positions (within the local coordinate space of the attachedNode
s).- Specified by:
positionsUnmodifiableProperty
in interfaceIAnchor
- Returns:
- A read-only (map) property storing positions for all attached
AnchorKey
s.
-
registerVCL
protected void registerVCL(javafx.scene.Node anchored)
Registers aVisualChangeListener
for the given anchoredNode
.- Parameters:
anchored
- The anchoredNode
to register aVisualChangeListener
at.
-
registerVCLs
protected void registerVCLs()
RegistersVisualChangeListener
s for all anchoredNode
s, or schedules their registration if the VCL cannot be registered yet.
-
setAnchorage
protected void setAnchorage(javafx.scene.Node anchorage)
Sets the anchorage of thisAbstractAnchor
to the given value.- Parameters:
anchorage
- The new anchorage for thisAbstractAnchor
.
-
unregisterVCL
protected void unregisterVCL(javafx.scene.Node anchored)
Unregisters theVisualChangeListener
s for the given anchoredNode
.- Parameters:
anchored
- The anchored Node to unregister aVisualChangeListener
from.
-
unregisterVCLs
protected void unregisterVCLs()
Unregisters theVisualChangeListener
s for all anchoredNode
s.
-
updatePosition
protected void updatePosition(AnchorKey key)
Updates the position for the givenAnchorKey
, i.e.- Queries its current position.
- Computes its new position.
- Checks if the position changed, and fires an appropriate event by
putting the new position into the
positionsUnmodifiableProperty()
- Parameters:
key
- TheAnchorKey
for which the position is updated.
-
updatePositions
protected void updatePositions()
Updates the positions for all attachedAnchorKey
s.
-
-