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
AbstractAnchoris the abstract base implementation forIAnchors. It provides the facility to bind an anchor to an anchorageNode(anchorageProperty()), to attach and detachNodes viaAnchorKeys, and to provide positions (positionsUnmodifiableProperty()) for the attachedAnchorKeys.It also registers the necessary listeners at the anchorage
Nodeand the attachedNodes as well as relevant ancestorNodes, 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 attachedAnchorKeys, it may request that anIAdaptableinfo 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 newAbstractAnchorfor 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 anchorageNodethisIAnchoris bound to.voidattach(AnchorKey key)protected abstract PointcomputePosition(AnchorKey key)Recomputes the position for the given attachedAnchorKeyby delegating to the respectiveIComputationStrategy.voiddetach(AnchorKey key)javafx.scene.NodegetAnchorage()Provides the anchorageNodethisIAnchoris bound to.protected java.util.Set<AnchorKey>getKeys()Returns all keys maintained by this anchor.protected SetMultimap<javafx.scene.Node,AnchorKey>getKeysByNode()PointgetPosition(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 anchoredNodes) for all attachedAnchorKeys.booleanisAttached(AnchorKey key)javafx.beans.property.ReadOnlyMapProperty<AnchorKey,Point>positionsUnmodifiableProperty()Provides a read-only (map) property with positions (in local coordinates of the anchoredNodes) for all attachedAnchorKeys.protected voidregisterVCL(javafx.scene.Node anchored)Registers aVisualChangeListenerfor the given anchoredNode.protected voidregisterVCLs()RegistersVisualChangeListeners for all anchoredNodes, or schedules their registration if the VCL cannot be registered yet.protected voidsetAnchorage(javafx.scene.Node anchorage)Sets the anchorage of thisAbstractAnchorto the given value.protected voidunregisterVCL(javafx.scene.Node anchored)Unregisters theVisualChangeListeners for the given anchoredNode.protected voidunregisterVCLs()Unregisters theVisualChangeListeners for all anchoredNodes.protected voidupdatePosition(AnchorKey key)Updates the position for the givenAnchorKey, i.e.protected voidupdatePositions()Updates the positions for all attachedAnchorKeys.
-
-
-
Constructor Detail
-
AbstractAnchor
public AbstractAnchor(javafx.scene.Node anchorage)
Creates a newAbstractAnchorfor the given anchorageNode.- Parameters:
anchorage- The anchorageNodefor thisAbstractAnchor.
-
-
Method Detail
-
anchorageProperty
public javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.Node> anchorageProperty()
Description copied from interface:IAnchorProvides a read-only property with the anchorageNodethisIAnchoris bound to. The property value may benullin case thisIAnchoris not bound to an anchorageNode.- Specified by:
anchoragePropertyin interfaceIAnchor- Returns:
- A read-only property storing the anchorage
Node.
-
computePosition
protected abstract Point computePosition(AnchorKey key)
Recomputes the position for the given attachedAnchorKeyby delegating to the respectiveIComputationStrategy.
-
getAnchorage
public javafx.scene.Node getAnchorage()
Description copied from interface:IAnchorProvides the anchorageNodethisIAnchoris bound to. Will return the value of theIAnchor.anchorageProperty().- Specified by:
getAnchoragein 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
AnchorKeys.
-
getKeysByNode
protected SetMultimap<javafx.scene.Node,AnchorKey> getKeysByNode()
- Returns:
- The
Mapwhich stores the registeredAnchorKeys perNodeby reference.
-
getPosition
public Point getPosition(AnchorKey key)
Description copied from interface:IAnchorProvides a position for the givenAnchorKey. The providedAnchorKeyhas to be attached to thisIAnchor(seeIAnchor.attach(AnchorKey)).- Specified by:
getPositionin interfaceIAnchor- Parameters:
key- TheAnchorKeyto retrieve a position for. It has to be attached (IAnchor.attach(AnchorKey)) to thisIAnchorbefore.- Returns:
- The position for the given
AnchorKeywithin local coordinates of theAnchorKey's anchoredNode.
-
getPositionsUnmodifiable
public javafx.collections.ObservableMap<AnchorKey,Point> getPositionsUnmodifiable()
Description copied from interface:IAnchorProvides an observable read-only (map) with positions (in local coordinates of the anchoredNodes) for all attachedAnchorKeys. The positions will be updated for all attachedAnchorKeys if the attachedNodes or the anchorageNode, theIAnchoris bound to, or any of their ancestors changes in a way that will effect the positions (within the local coordinate space of the attachedNodes).- Specified by:
getPositionsUnmodifiablein interfaceIAnchor- Returns:
- A read-only observable map storing positions for all attached
AnchorKeys.
-
isAttached
public boolean isAttached(AnchorKey key)
Description copied from interface:IAnchor- Specified by:
isAttachedin interfaceIAnchor- Parameters:
key- TheAnchorKeyto test.- Returns:
trueif the given key is attached, otherwisefalse.
-
positionsUnmodifiableProperty
public javafx.beans.property.ReadOnlyMapProperty<AnchorKey,Point> positionsUnmodifiableProperty()
Description copied from interface:IAnchorProvides a read-only (map) property with positions (in local coordinates of the anchoredNodes) for all attachedAnchorKeys. The positions will be updated for all attachedAnchorKeys if the attachedNodes or the anchorageNode, theIAnchoris bound to, or any of their ancestors changes in a way that will effect the positions (within the local coordinate space of the attachedNodes).- Specified by:
positionsUnmodifiablePropertyin interfaceIAnchor- Returns:
- A read-only (map) property storing positions for all attached
AnchorKeys.
-
registerVCL
protected void registerVCL(javafx.scene.Node anchored)
Registers aVisualChangeListenerfor the given anchoredNode.- Parameters:
anchored- The anchoredNodeto register aVisualChangeListenerat.
-
registerVCLs
protected void registerVCLs()
RegistersVisualChangeListeners for all anchoredNodes, or schedules their registration if the VCL cannot be registered yet.
-
setAnchorage
protected void setAnchorage(javafx.scene.Node anchorage)
Sets the anchorage of thisAbstractAnchorto the given value.- Parameters:
anchorage- The new anchorage for thisAbstractAnchor.
-
unregisterVCL
protected void unregisterVCL(javafx.scene.Node anchored)
Unregisters theVisualChangeListeners for the given anchoredNode.- Parameters:
anchored- The anchored Node to unregister aVisualChangeListenerfrom.
-
unregisterVCLs
protected void unregisterVCLs()
Unregisters theVisualChangeListeners for all anchoredNodes.
-
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- TheAnchorKeyfor which the position is updated.
-
updatePositions
protected void updatePositions()
Updates the positions for all attachedAnchorKeys.
-
-