Class TransformPolicy
- All Implemented Interfaces:
IAdaptable.Bound<IVisualPart<? extends javafx.scene.Node>>,IPolicy
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:
- Translate the coordinate system, so that the pivot point is in the origin
(-px, -py). - Rotate the coordinate system.
- Translate back to the original position
(px, py).
--> --> --> 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
adaptableProperties 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyTransform(AffineTransform finalTransform) Applies the givenAffineTransformas the new transformation matrix to thehost.commit()Returns anITransactionalOperationthat performs all manipulations applied by the policy since the previousAbstractPolicy.init()call.protected ITransactionalOperationCreates anITransactionalOperationthat is used to encapsulate the changes that are applied by thisAbstractPolicythrough its "work" methods.intCreates a newAffineTransformand appends it to the postTransforms list.intCreates a newAffineTransformand appends it to the preTransforms list.protected ITransactionalOperationReturns an operation to transform the content.Returns theAffineTransformthat matches the node transformation of thehost.ITransformableContentPart<? extends javafx.scene.Node>getHost()Returns a copy of the initial node transformation of the host (obtained viagetCurrentTransform()).voidinit()Initializes the policy, so that the policy's "work" methods can be used.protected booleanReturns whether the content can be transformed.voidsetPostRotate(int index, Angle rotation) Sets the specified post-transform to a rotation by the given angle.voidsetPostScale(int index, double sx, double sy) Sets the specified post-transform to a scaling by the given factors.voidsetPostTransform(int postTransformIndex, AffineTransform transform) Sets the specified post-transform to the givenAffineTransform.voidsetPostTranslate(int index, double tx, double ty) Sets the specified post-transform to a translation by the given offsets.voidsetPreRotate(int index, Angle rotation) Sets the specified pre-transform to a rotation by the given angle.voidsetPreScale(int index, double sx, double sy) Sets the specified pre-transform to a scaling by the given factors.voidsetPreTransform(int preTransformIndex, AffineTransform transform) Sets the specified pre-transform to the givenAffineTransform.voidsetPreTranslate(int index, double tx, double ty) Sets the specified pre-transform to a translation by the given offsets.voidsetTransform(AffineTransform finalTransform) Changes thehost'stransformation to the givenAffineTransform.protected voidComposes the pre- and post-transforms lists and the initial node transform to one composite transformation.protected voidupdateTransformOperation(AffineTransform newTransform) Updates the operation that was created withincreateOperation()so that it will set thehost'stransformation to match the givenAffineTransformupon execution.Methods inherited from class org.eclipse.gef.mvc.fx.policies.AbstractPolicy
checkInitialized, getOperation, isInitialized, locallyExecuteOperation, rollbackMethods inherited from class org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl
adaptableProperty, getAdaptable, setAdaptableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound
adaptableProperty, getAdaptable, setAdaptable
-
Constructor Details
-
TransformPolicy
public TransformPolicy()
-
-
Method Details
-
applyTransform
Applies the givenAffineTransformas the new transformation matrix to thehost. All transformation changes are applied via this method. Therefore, subclasses can override this method to perform adjustments that are necessary for itshost.- Parameters:
finalTransform- The new transformation matrix for thehost.
-
commit
Description copied from class:AbstractPolicyReturns anITransactionalOperationthat performs all manipulations applied by the policy since the previousAbstractPolicy.init()call.- Specified by:
commitin interfaceIPolicy- Overrides:
commitin classAbstractPolicy- Returns:
- An
ITransactionalOperationthat performs all manipulations applied by the policy since the lastAbstractPolicy.init()call.
-
createOperation
Description copied from class:AbstractPolicyCreates anITransactionalOperationthat is used to encapsulate the changes that are applied by thisAbstractPolicythrough its "work" methods. The created operation should allow forlocal executionat each time.- Specified by:
createOperationin classAbstractPolicy- Returns:
- A new
ITransactionalOperationto encapsulate all applied changes.
-
createPostTransform
public int createPostTransform()Creates a newAffineTransformand appends it to the postTransforms list. Therefore, the newAffineTransformwill 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
AffineTransformthat is appended to the postTransforms list.
-
createPreTransform
public int createPreTransform()Creates a newAffineTransformand appends it to the preTransforms list. Therefore, the newAffineTransformwill 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
AffineTransformthat is appended to the preTransforms list.
-
createTransformContentOperation
Returns an operation to transform the content.- Returns:
- The ITransactionalOperation to transform the content.
-
getCurrentTransform
Returns theAffineTransformthat matches the node transformation of thehost.- Returns:
- The host's
AffineTransform.
-
getHost
Description copied from interface:IPolicy- Returns:
- The host of this
IPolicy.
-
getInitialTransform
Returns a copy of the initial node transformation of the host (obtained viagetCurrentTransform()).- Returns:
- A copy of the initial node transformation of the host (obtained
via
getCurrentTransform()).
-
init
public void init()Description copied from class:AbstractPolicyInitializes 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 anIllegalStateException, as well as re-initializing before committing or rolling back.- Specified by:
initin interfaceIPolicy- Overrides:
initin classAbstractPolicy
-
isContentTransformable
protected boolean isContentTransformable()Returns whether the content can be transformed.- Returns:
trueif the content can be transformed,falseotherwise.
-
setPostRotate
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 rotationAngle.
-
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
Sets the specified post-transform to the givenAffineTransform.- Parameters:
postTransformIndex- The index of the post-transform to manipulate.transform- TheAffineTransformthat 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
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 rotationAngle.
-
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
Sets the specified pre-transform to the givenAffineTransform.- Parameters:
preTransformIndex- The index of the pre-transform to manipulate.transform- TheAffineTransformthat 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
Changes thehost'stransformation to the givenAffineTransform. Clears the pre- and post-transforms lists.- Parameters:
finalTransform- The newAffineTransformfor thehost.
-
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 usingapplyTransform(AffineTransform).--> --> --> direction of concatenation --> --> --> postTransforms initialTransform preTransforms |------------| |-----------| postIndex: n, n-1, ... 0 preIndex: 0, 1, ... m <-- <-- <-- <-- direction of effect <-- <-- <-- <-- -
updateTransformOperation
Updates the operation that was created withincreateOperation()so that it will set thehost'stransformation to match the givenAffineTransformupon execution.- Parameters:
newTransform- The new transformation for the host.
-