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

It also registers the necessary listeners at the anchorage `Node` and the attached `Node`s as well as relevant ancestor `Node`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 attached `AnchorKey`s, 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 Summary

Properties
Type
Property
Description
`ReadOnlyObjectProperty<Node>`
`anchorage`
Provides a read-only property with the anchorage `Node` this `IAnchor` is bound to.
`ReadOnlyMapProperty<AnchorKey,Point>`
`positionsUnmodifiable`
Provides a read-only (map) property with positions (in local coordinates of the anchored `Node`s) for all attached `AnchorKey`s.

## Constructor Summary

Constructors
Constructor
Description
`AbstractAnchor(Node anchorage)`
Creates a new `AbstractAnchor` for the given anchorage `Node`.

## Method Summary

Modifier and Type
Method
Description
`ReadOnlyObjectProperty<Node>`
`anchorageProperty()`
Provides a read-only property with the anchorage `Node` this `IAnchor` is bound to.
`void`
`attach(AnchorKey key)`
Attaches the given `AnchorKey` to this `IAnchor`.
`protected abstract Point`
`computePosition(AnchorKey key)`
Recomputes the position for the given attached `AnchorKey` by delegating to the respective `IComputationStrategy`.
`void`
`detach(AnchorKey key)`
Detaches the given `AnchorKey` from this `IAnchor`.
`Node`
`getAnchorage()`
Gets the value of the property anchorage.
`protected Set<AnchorKey>`
`getKeys()`
Returns all keys maintained by this anchor.
`protected SetMultimap<Node,AnchorKey>`
`getKeysByNode()`
Returns the `Map` which stores the registered `AnchorKey`s per `Node` by reference.
`Point`
`getPosition(AnchorKey key)`
Provides a position for the given `AnchorKey`.
`ObservableMap<AnchorKey,Point>`
`getPositionsUnmodifiable()`
Gets the value of the property positionsUnmodifiable.
`boolean`
`isAttached(AnchorKey key)`
Determines if the given `AnchorKey` is currently attached to this `IAnchor`.
`ReadOnlyMapProperty<AnchorKey,Point>`
`positionsUnmodifiableProperty()`
Provides a read-only (map) property with positions (in local coordinates of the anchored `Node`s) for all attached `AnchorKey`s.
`protected void`
`registerVCL(Node anchored)`
Registers a `VisualChangeListener` for the given anchored `Node`.
`protected void`
`registerVCLs()`
Registers `VisualChangeListener`s for all anchored `Node`s, or schedules their registration if the VCL cannot be registered yet.
`protected void`
`setAnchorage(Node anchorage)`
Sets the anchorage of this `AbstractAnchor` to the given value.
`protected void`
`unregisterVCL(Node anchored)`
Unregisters the `VisualChangeListener`s for the given anchored `Node`.
`protected void`
`unregisterVCLs()`
Unregisters the `VisualChangeListener`s for all anchored `Node`s.
`protected void`
`updatePosition(AnchorKey key)`
Updates the position for the given `AnchorKey`, i.e.
`protected void`
`updatePositions()`
Updates the positions for all attached `AnchorKey`s.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Property Details

### anchorage

public ReadOnlyObjectProperty<Node> anchorageProperty

Specified by:
  `anchorageProperty` in interface `IAnchor`
Returns:
  A read-only property storing the anchorage `Node`.
See Also:
  - `getAnchorage()`
  - `setAnchorage(Node)`

### positionsUnmodifiable

public ReadOnlyMapProperty<AnchorKey,Point> positionsUnmodifiableProperty

Specified by:
  `positionsUnmodifiableProperty` in interface `IAnchor`
Returns:
  A read-only (map) property storing positions for all attached `AnchorKey`s.
See Also:
  - `getPositionsUnmodifiable()`

## Constructor Details

### AbstractAnchor

public AbstractAnchor(Node anchorage)
Creates a new `AbstractAnchor` for the given anchorage `Node`.

Parameters:
  `anchorage` - The anchorage `Node` for this `AbstractAnchor`.

## Method Details

### anchorageProperty

public ReadOnlyObjectProperty<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:
  - `getAnchorage()`
  - `setAnchorage(Node)`

### 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 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 `AnchorKey`s.

### getKeysByNode

protected SetMultimap<Node,AnchorKey> getKeysByNode()
Returns the `Map` which stores the registered `AnchorKey`s per `Node` by reference.

Returns:
  The `Map` which stores the registered `AnchorKey`s 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 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 `AnchorKey`s.

### 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 ReadOnlyMapProperty<AnchorKey,Point> positionsUnmodifiableProperty()
Description copied from interface: `IAnchor`
Provides a read-only (map) property with positions (in local coordinates of the anchored `Node`s) for all attached `AnchorKey`s. The positions will be updated for all attached `AnchorKey`s if the attached `Node`s 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 `Node`s).

Specified by:
  `positionsUnmodifiableProperty` in interface `IAnchor`
Returns:
  A read-only (map) property storing positions for all attached `AnchorKey`s.
See Also:
  - `getPositionsUnmodifiable()`

### registerVCL

protected void registerVCL(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 `VisualChangeListener`s for all anchored `Node`s, or schedules their registration if the VCL cannot be registered yet.

### setAnchorage

protected void setAnchorage(Node anchorage)
Sets the anchorage of this `AbstractAnchor` to the given value.

Parameters:
  `anchorage` - The new anchorage for this `AbstractAnchor`.

### unregisterVCL

protected void unregisterVCL(Node anchored)
Unregisters the `VisualChangeListener`s for the given anchored `Node`.

Parameters:
  `anchored` - The anchored Node to unregister a `VisualChangeListener` from.

### unregisterVCLs

protected void unregisterVCLs()
Unregisters the `VisualChangeListener`s for all anchored `Node`s.

### 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 `AnchorKey`s.