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 Object implements IAnchor
AbstractAnchor is the abstract base implementation for IAnchors. It provides the facility to bind an anchor to an anchorage Node (anchorageProperty()), to attach and detach Nodes via AnchorKeys, and to provide positions ( positionsUnmodifiableProperty()) for the attached AnchorKey s.

It also registers the necessary listeners at the anchorage Node and the attached Nodes as well as relevant ancestor Nodes, 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 attached AnchorKeys, it may request that an IAdaptable info gets passed into attach(AnchorKey) and detach(AnchorKey), and may overwrite both methods to get access to it.

  • Property Details

  • Constructor Details

    • AbstractAnchor

      public AbstractAnchor(javafx.scene.Node anchorage)
      Creates a new AbstractAnchor for the given anchorage Node.
      Parameters:
      anchorage - The anchorage Node for this AbstractAnchor.
  • Method Details

    • anchorageProperty

      public javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.Node> anchorageProperty()
      Description copied from interface: IAnchor
      Provides a read-only property with the anchorage Node this IAnchor is bound to. The property value may be null in case this IAnchor is not bound to an anchorage Node.
      Specified by:
      anchorageProperty in interface IAnchor
      Returns:
      A read-only property storing the anchorage Node.
      See Also:
    • attach

      public void attach(AnchorKey key)
      Description copied from interface: IAnchor
      Attaches the given AnchorKey to this IAnchor.
      Specified by:
      attach in interface IAnchor
      Parameters:
      key - The AnchorKey to be attached.
    • computePosition

      protected abstract Point computePosition(AnchorKey key)
      Recomputes the position for the given attached AnchorKey by delegating to the respective IComputationStrategy.
      Parameters:
      key - The AnchorKey for which to compute an anchor position.
      Returns:
      The point for the given AnchorKey in local coordinates of the anchored Node.
    • detach

      public void detach(AnchorKey key)
      Description copied from interface: IAnchor
      Detaches the given AnchorKey from this IAnchor.
      Specified by:
      detach in interface IAnchor
      Parameters:
      key - The AnchorKey to be detached.
    • getAnchorage

      public javafx.scene.Node getAnchorage()
      Gets the value of the property anchorage.
      Specified by:
      getAnchorage in interface IAnchor
      Property description:
      Returns:
      The value of the IAnchor.anchorageProperty().
    • getKeys

      protected 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 Map which stores the registered AnchorKeys per Node by reference.
      Returns:
      The Map which stores the registered AnchorKeys per Node by reference.
    • getPosition

      public Point getPosition(AnchorKey key)
      Description copied from interface: IAnchor
      Provides a position for the given AnchorKey. The provided AnchorKey has to be attached to this IAnchor (see IAnchor.attach(AnchorKey)).
      Specified by:
      getPosition in interface IAnchor
      Parameters:
      key - The AnchorKey to retrieve a position for. It has to be attached (IAnchor.attach(AnchorKey)) to this IAnchor before.
      Returns:
      The position for the given AnchorKey within local coordinates of the AnchorKey's anchored Node.
    • getPositionsUnmodifiable

      public javafx.collections.ObservableMap<AnchorKey,Point> getPositionsUnmodifiable()
      Gets the value of the property positionsUnmodifiable.
      Specified by:
      getPositionsUnmodifiable in interface IAnchor
      Property description:
      Returns:
      A read-only observable map storing positions for all attached AnchorKeys.
    • isAttached

      public boolean isAttached(AnchorKey key)
      Description copied from interface: IAnchor
      Determines if the given AnchorKey is currently attached to this IAnchor.
      Specified by:
      isAttached in interface IAnchor
      Parameters:
      key - The AnchorKey to test.
      Returns:
      true if the given key is attached, otherwise false.
    • 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 anchored Nodes) for all attached AnchorKeys. The positions will be updated for all attached AnchorKeys if the attached Nodes or the anchorage Node, the IAnchor is bound to, or any of their ancestors changes in a way that will effect the positions (within the local coordinate space of the attached Nodes).
      Specified by:
      positionsUnmodifiableProperty in interface IAnchor
      Returns:
      A read-only (map) property storing positions for all attached AnchorKeys.
      See Also:
    • registerVCL

      protected void registerVCL(javafx.scene.Node anchored)
      Registers a VisualChangeListener for the given anchored Node.
      Parameters:
      anchored - The anchored Node to register a VisualChangeListener at.
    • registerVCLs

      protected void registerVCLs()
      Registers VisualChangeListeners for all anchored Nodes, or schedules their registration if the VCL cannot be registered yet.
    • setAnchorage

      protected void setAnchorage(javafx.scene.Node anchorage)
      Sets the anchorage of this AbstractAnchor to the given value.
      Parameters:
      anchorage - The new anchorage for this AbstractAnchor.
    • unregisterVCL

      protected void unregisterVCL(javafx.scene.Node anchored)
      Unregisters the VisualChangeListeners for the given anchored Node.
      Parameters:
      anchored - The anchored Node to unregister a VisualChangeListener from.
    • unregisterVCLs

      protected void unregisterVCLs()
      Unregisters the VisualChangeListeners for all anchored Nodes.
    • updatePosition

      protected void updatePosition(AnchorKey key)
      Updates the position for the given AnchorKey, i.e.
      1. Queries its current position.
      2. Computes its new position.
      3. Checks if the position changed, and fires an appropriate event by putting the new position into the positionsUnmodifiableProperty()
      Parameters:
      key - The AnchorKey for which the position is updated.
    • updatePositions

      protected void updatePositions()
      Updates the positions for all attached AnchorKeys.