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
TheTransformPolicyis a JavaFX-specificAbstractPolicythat handles the transformation of itshost.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()andcreatePostTransform()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), andsetPreTranslate(int, double, double)methods can be used to change a previously created pre- or post-transform.
-
-
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapplyTransform(AffineTransform finalTransform)Applies the givenAffineTransformas the new transformation matrix to thehost.ITransactionalOperationcommit()Returns anITransactionalOperationthat performs all manipulations applied by the policy since the previousAbstractPolicy.init()call.protected ITransactionalOperationcreateOperation()Creates anITransactionalOperationthat is used to encapsulate the changes that are applied by thisAbstractPolicythrough its "work" methods.intcreatePostTransform()Creates a newAffineTransformand appends it to the postTransforms list.intcreatePreTransform()Creates a newAffineTransformand appends it to the preTransforms list.protected ITransactionalOperationcreateTransformContentOperation()Returns an operation to transform the content.AffineTransformgetCurrentTransform()Returns theAffineTransformthat matches the node transformation of thehost.ITransformableContentPart<? extends javafx.scene.Node>getHost()AffineTransformgetInitialTransform()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 booleanisContentTransformable()Returns 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 voidupdateTransform()Composes 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, 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
-
-
-
-
Method Detail
-
applyTransform
protected void applyTransform(AffineTransform finalTransform)
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
public ITransactionalOperation 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
protected ITransactionalOperation 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
protected ITransactionalOperation createTransformContentOperation()
Returns an operation to transform the content.- Returns:
- The ITransactionalOperation to transform the content.
-
getCurrentTransform
public AffineTransform getCurrentTransform()
Returns theAffineTransformthat matches the node transformation of thehost.- Returns:
- The host's
AffineTransform.
-
getHost
public ITransformableContentPart<? extends javafx.scene.Node> getHost()
Description copied from interface:IPolicy- Returns:
- The host of this
IPolicy.
-
getInitialTransform
public AffineTransform 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
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 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
public void setPostTransform(int postTransformIndex, AffineTransform transform)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
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 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
public void setPreTransform(int preTransformIndex, AffineTransform transform)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
public void setTransform(AffineTransform finalTransform)
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
protected void updateTransformOperation(AffineTransform newTransform)
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.
-
-