Package org.eclipse.gef.mvc.fx.policies

# Class TransformPolicy

java.lang.Object
org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl<IVisualPart<? extends javafx.scene.Node>>
org.eclipse.gef.mvc.fx.policies.AbstractPolicy
org.eclipse.gef.mvc.fx.policies.TransformPolicy

All Implemented Interfaces:
  `IAdaptable.Bound<IVisualPart<? extends javafx.scene.Node>>`, `IPolicy`

public class TransformPolicy extends AbstractPolicy
The `TransformPolicy` is a JavaFX-specific `AbstractPolicy` that handles the transformation of its `host`.

When working with transformations, the order in which the individual transformations are concatenated is important. The transformation that is concatenated last will be applied first. For example, the rotation around a pivot point consists of 3 steps:

1. Translate the coordinate system, so that the pivot point is in the origin `(-px, -py)`.
2. Rotate the coordinate system.
3. Translate back to the original position `(px, py)`.

But the corresponding transformations have to be concatenated in reverse order, i.e. translate back first, rotate then, translate pivot to origin last. This is easy to confuse, that's why this policy manages a list of pre-transforms and a list of post-transforms. These transformations (as well as the initial node transformation) are concatenated as follows to yield the new node transformation for the host:

                --> --> -->  direction of concatenation --> --> -->

                postTransforms  initialNodeTransform  preTransforms
                |------------|                        |-----------|
     postIndex: n, n-1, ...  0              preIndex: 0, 1,  ...  m

                <-- <-- <-- <-- direction of effect <-- <-- <-- <--

As you can see, the last pre-transform is concatenated last, and therefore, will affect the host first. Generally, a post-transform manipulates the transformed node, while a pre-transform manipulates the coordinate system before the node is transformed.

You can use the `createPreTransform()` and `createPostTransform()` methods to create a pre- or a post-transform and append it to the respective list. Therefore, the most recently created pre-transform will be applied first, and the most recently created post-transform will be applied last. When creating a pre- or post-transform, the index of that transform within the respective list will be returned. This index can later be used to manipulate the transform.

The `setPostRotate(int, Angle)`, `setPostScale(int, double, double)`, `setPostTransform(int, AffineTransform)`, `setPostTranslate(int, double, double)`, `setPreRotate(int, Angle)`, `setPreScale(int, double, double)`, `setPreTransform(int, AffineTransform)`, and `setPreTranslate(int, double, double)` methods can be used to change a previously created pre- or post-transform.

## Property Summary

### Properties inherited from class org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl

`adaptable`

### Properties inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound

`adaptable`

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound

`IAdaptable.Bound.Impl<T extends IAdaptable>`

## Constructor Summary

Constructors
Constructor
Description
`TransformPolicy()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`applyTransform(AffineTransform finalTransform)`
Applies the given `AffineTransform` as the new transformation matrix to the `host`.
`ITransactionalOperation`
`commit()`
Returns an `ITransactionalOperation` that performs all manipulations applied by the policy since the previous `AbstractPolicy.init()` call.
`protected ITransactionalOperation`
`createOperation()`
Creates an `ITransactionalOperation` that is used to encapsulate the changes that are applied by this `AbstractPolicy` through its "work" methods.
`int`
`createPostTransform()`
Creates a new `AffineTransform` and appends it to the postTransforms list.
`int`
`createPreTransform()`
Creates a new `AffineTransform` and appends it to the preTransforms list.
`protected ITransactionalOperation`
`createTransformContentOperation()`
Returns an operation to transform the content.
`AffineTransform`
`getCurrentTransform()`
Returns the `AffineTransform` that matches the node transformation of the `host`.
`ITransformableContentPart<? extends javafx.scene.Node>`
`getHost()`
Returns the host of this `IPolicy`, i.e. the `IVisualPart` this `IPolicy` is attached to.
`AffineTransform`
`getInitialTransform()`
Returns a copy of the initial node transformation of the host (obtained via `getCurrentTransform()`).
`void`
`init()`
Initializes the policy, so that the policy's "work" methods can be used.
`protected boolean`
`isContentTransformable()`
Returns whether the content can be transformed.
`void`
`setPostRotate(int index, Angle rotation)`
Sets the specified post-transform to a rotation by the given angle.
`void`
`setPostScale(int index, double sx, double sy)`
Sets the specified post-transform to a scaling by the given factors.
`void`
`setPostTransform(int postTransformIndex, AffineTransform transform)`
Sets the specified post-transform to the given `AffineTransform`.
`void`
`setPostTranslate(int index, double tx, double ty)`
Sets the specified post-transform to a translation by the given offsets.
`void`
`setPreRotate(int index, Angle rotation)`
Sets the specified pre-transform to a rotation by the given angle.
`void`
`setPreScale(int index, double sx, double sy)`
Sets the specified pre-transform to a scaling by the given factors.
`void`
`setPreTransform(int preTransformIndex, AffineTransform transform)`
Sets the specified pre-transform to the given `AffineTransform`.
`void`
`setPreTranslate(int index, double tx, double ty)`
Sets the specified pre-transform to a translation by the given offsets.
`void`
`setTransform(AffineTransform finalTransform)`
Changes the `host's` transformation to the given `AffineTransform`.
`protected void`
`updateTransform()`
Composes the pre- and post-transforms lists and the initial node transform to one composite transformation.
`protected void`
`updateTransformOperation(AffineTransform newTransform)`
Updates the operation that was created within `createOperation()` so that it will set the `host's` transformation to match the given `AffineTransform` upon execution.

### Methods inherited from class org.eclipse.gef.mvc.fx.policies.AbstractPolicy

`checkInitialized, getOperation, isInitialized, locallyExecuteOperation, rollback`

### Methods inherited from class org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl

`adaptableProperty, getAdaptable, setAdaptable`

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

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

### Methods inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound

`adaptableProperty, getAdaptable, setAdaptable`

## Constructor Details

### TransformPolicy

public TransformPolicy()

## Method Details

### applyTransform

protected void applyTransform(AffineTransform finalTransform)
Applies the given `AffineTransform` as the new transformation matrix to the `host`. All transformation changes are applied via this method. Therefore, subclasses can override this method to perform adjustments that are necessary for its `host` .

Parameters:
  `finalTransform` - The new transformation matrix for the `host`.

### commit

public ITransactionalOperation commit()
Description copied from class: `AbstractPolicy`
Returns an `ITransactionalOperation` that performs all manipulations applied by the policy since the previous `AbstractPolicy.init()` call.

Specified by:
  `commit` in interface `IPolicy`
Overrides:
  `commit` in class `AbstractPolicy`
Returns:
  An `ITransactionalOperation` that performs all manipulations applied by the policy since the last `AbstractPolicy.init()` call.

### createOperation

protected ITransactionalOperation createOperation()
Description copied from class: `AbstractPolicy`
Creates an `ITransactionalOperation` that is used to encapsulate the changes that are applied by this `AbstractPolicy` through its "work" methods. The created operation should allow for `local execution` at each time.

Specified by:
  `createOperation` in class `AbstractPolicy`
Returns:
  A new `ITransactionalOperation` to encapsulate all applied changes.

### createPostTransform

public int createPostTransform()
Creates a new `AffineTransform` and appends it to the postTransforms list. Therefore, the new `AffineTransform` will affect the host after all other transforms, as shown below:

                --> --> -->  direction of concatenation --> --> -->

                postTransforms  initialTransform  preTransforms
                |------------|                        |-----------|
     postIndex: n, n-1, ...  0              preIndex: 0, 1,  ...  m

                <-- <-- <-- <-- direction of effect <-- <-- <-- <--

A post-transform manipulates the transformed node, while a pre-transform manipulates the coordinate system before the node is transformed.

Returns:
  A new `AffineTransform` that is appended to the postTransforms list.

### createPreTransform

public int createPreTransform()
Creates a new `AffineTransform` and appends it to the preTransforms list. Therefore, the new `AffineTransform` will affect the host before all other transforms, as shown below:

                --> --> -->  direction of concatenation --> --> -->

                postTransforms  initialTransform  preTransforms
                |------------|                        |-----------|
     postIndex: n, n-1, ...  0              preIndex: 0, 1,  ...  m

                <-- <-- <-- <-- direction of effect <-- <-- <-- <--

A post-transform manipulates the transformed node, while a pre-transform manipulates the coordinate system before the node is transformed.

Returns:
  A new `AffineTransform` that is appended to the preTransforms list.

### createTransformContentOperation

protected ITransactionalOperation createTransformContentOperation()
Returns an operation to transform the content.

Returns:
  The ITransactionalOperation to transform the content.

### getCurrentTransform

public AffineTransform getCurrentTransform()
Returns the `AffineTransform` that matches the node transformation of the `host`.

Returns:
  The host's `AffineTransform`.

### getHost

public ITransformableContentPart<? extends javafx.scene.Node> getHost()
Description copied from interface: `IPolicy`
Returns the host of this `IPolicy`, i.e. the `IVisualPart` this `IPolicy` is attached to.

Returns:
  The host of this `IPolicy`.

### getInitialTransform

public AffineTransform getInitialTransform()
Returns a copy of the initial node transformation of the host (obtained via `getCurrentTransform()`).

Returns:
  A copy of the initial node transformation of the host (obtained via `getCurrentTransform()`).

### init

public void init()
Description copied from class: `AbstractPolicy`
Initializes the policy, so that the policy's "work" methods can be used. Calling a "work" method while the policy is not initialized will result in an `IllegalStateException`, as well as re-initializing before committing or rolling back.

Specified by:
  `init` in interface `IPolicy`
Overrides:
  `init` in class `AbstractPolicy`

### isContentTransformable

protected boolean isContentTransformable()
Returns whether the content can be transformed.

Returns:
  `true` if the content can be transformed, `false` otherwise.

### setPostRotate

public void setPostRotate(int index, Angle rotation)
Sets the specified post-transform to a rotation by the given angle.

Parameters:
  `index` - The index of the post-transform to manipulate.
  `rotation` - The counter clock-wise rotation `Angle`.

### setPostScale

public void setPostScale(int index, double sx, double sy)
Sets the specified post-transform to a scaling by the given factors.

Parameters:
  `index` - The index of the post-transform to manipulate.
  `sx` - The horizontal scale factor.
  `sy` - The vertical scale factor.

### setPostTransform

public void setPostTransform(int postTransformIndex, AffineTransform transform)
Sets the specified post-transform to the given `AffineTransform`.

Parameters:
  `postTransformIndex` - The index of the post-transform to manipulate.
  `transform` - The `AffineTransform` that replaces the specified post-transform.

### setPostTranslate

public void setPostTranslate(int index, double tx, double ty)
Sets the specified post-transform to a translation by the given offsets.

Parameters:
  `index` - The index of the post-transform to manipulate.
  `tx` - The horizontal translation offset (in local coordinates).
  `ty` - The vertical translation offset (in local coordinates).

### setPreRotate

public void setPreRotate(int index, Angle rotation)
Sets the specified pre-transform to a rotation by the given angle.

Parameters:
  `index` - The index of the pre-transform to manipulate.
  `rotation` - The counter clock-wise rotation `Angle`.

### setPreScale

public void setPreScale(int index, double sx, double sy)
Sets the specified pre-transform to a scaling by the given factors.

Parameters:
  `index` - The index of the pre-transform to manipulate.
  `sx` - The horizontal scale factor.
  `sy` - The vertical scale factor.

### setPreTransform

public void setPreTransform(int preTransformIndex, AffineTransform transform)
Sets the specified pre-transform to the given `AffineTransform`.

Parameters:
  `preTransformIndex` - The index of the pre-transform to manipulate.
  `transform` - The `AffineTransform` that replaces the specified pre-transform.

### setPreTranslate

public void setPreTranslate(int index, double tx, double ty)
Sets the specified pre-transform to a translation by the given offsets.

Parameters:
  `index` - The index of the pre-transform to manipulate.
  `tx` - The horizontal translation offset (in parent coordinates).
  `ty` - The vertical translation offset (in parent coordinates).

### setTransform

public void setTransform(AffineTransform finalTransform)
Changes the `host's` transformation to the given `AffineTransform`. Clears the pre- and post-transforms lists.

Parameters:
  `finalTransform` - The new `AffineTransform` for the `host`.

### updateTransform

protected void updateTransform()
Composes the pre- and post-transforms lists and the initial node transform to one composite transformation. This composite transformation is then applied to the host using `applyTransform(AffineTransform)`.

                --> --> -->  direction of concatenation --> --> -->

                postTransforms  initialTransform  preTransforms
                |------------|                        |-----------|
     postIndex: n, n-1, ...  0              preIndex: 0, 1,  ...  m

                <-- <-- <-- <-- direction of effect <-- <-- <-- <--

### updateTransformOperation

protected void updateTransformOperation(AffineTransform newTransform)
Updates the operation that was created within `createOperation()` so that it will set the `host's` transformation to match the given `AffineTransform` upon execution.

Parameters:
  `newTransform` - The new transformation for the host.