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
TheTransformPolicy
is a JavaFX-specificAbstractPolicy
that 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 void
applyTransform(AffineTransform finalTransform)
Applies the givenAffineTransform
as the new transformation matrix to thehost
.ITransactionalOperation
commit()
Returns anITransactionalOperation
that performs all manipulations applied by the policy since the previousAbstractPolicy.init()
call.protected ITransactionalOperation
createOperation()
Creates anITransactionalOperation
that is used to encapsulate the changes that are applied by thisAbstractPolicy
through its "work" methods.int
createPostTransform()
Creates a newAffineTransform
and appends it to the postTransforms list.int
createPreTransform()
Creates a newAffineTransform
and appends it to the preTransforms list.protected ITransactionalOperation
createTransformContentOperation()
Returns an operation to transform the content.AffineTransform
getCurrentTransform()
Returns theAffineTransform
that matches the node transformation of thehost
.ITransformableContentPart<? extends javafx.scene.Node>
getHost()
AffineTransform
getInitialTransform()
Returns a copy of the initial node transformation of the host (obtained viagetCurrentTransform()
).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 givenAffineTransform
.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 givenAffineTransform
.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 thehost's
transformation to the givenAffineTransform
.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 withincreateOperation()
so that it will set thehost's
transformation to match the givenAffineTransform
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
-
-
-
-
Method Detail
-
applyTransform
protected void applyTransform(AffineTransform finalTransform)
Applies the givenAffineTransform
as 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:AbstractPolicy
Returns anITransactionalOperation
that performs all manipulations applied by the policy since the previousAbstractPolicy.init()
call.- Specified by:
commit
in interfaceIPolicy
- Overrides:
commit
in classAbstractPolicy
- Returns:
- An
ITransactionalOperation
that performs all manipulations applied by the policy since the lastAbstractPolicy.init()
call.
-
createOperation
protected ITransactionalOperation createOperation()
Description copied from class:AbstractPolicy
Creates anITransactionalOperation
that is used to encapsulate the changes that are applied by thisAbstractPolicy
through its "work" methods. The created operation should allow forlocal execution
at each time.- Specified by:
createOperation
in classAbstractPolicy
- Returns:
- A new
ITransactionalOperation
to encapsulate all applied changes.
-
createPostTransform
public int createPostTransform()
Creates a newAffineTransform
and appends it to the postTransforms list. Therefore, the newAffineTransform
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 newAffineTransform
and appends it to the preTransforms list. Therefore, the newAffineTransform
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 theAffineTransform
that 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: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 anIllegalStateException
, as well as re-initializing before committing or rolling back.- Specified by:
init
in interfaceIPolicy
- Overrides:
init
in classAbstractPolicy
-
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 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
- TheAffineTransform
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 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
- TheAffineTransform
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 thehost's
transformation to the givenAffineTransform
. Clears the pre- and post-transforms lists.- Parameters:
finalTransform
- The newAffineTransform
for 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's
transformation to match the givenAffineTransform
upon execution.- Parameters:
newTransform
- The new transformation for the host.
-
-