public class TransformPolicy extends AbstractPolicy
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:
(-px, -py).
(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.
adaptableadaptableIAdaptable.Bound.Impl<T extends IAdaptable>| Constructor and Description |
|---|
TransformPolicy() |
| Modifier and Type | Method and 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()
|
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. |
checkInitialized, getOperation, isInitialized, locallyExecuteOperation, rollbackadaptableProperty, getAdaptable, setAdaptableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitadaptableProperty, getAdaptable, setAdaptableprotected void applyTransform(AffineTransform finalTransform)
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
.finalTransform - The new transformation matrix for the host.public ITransactionalOperation commit()
AbstractPolicyITransactionalOperation that performs all
manipulations applied by the policy since the previous AbstractPolicy.init()
call.commit in interface IPolicycommit in class AbstractPolicyITransactionalOperation that performs all
manipulations applied by the policy since the last
AbstractPolicy.init() call.protected ITransactionalOperation createOperation()
AbstractPolicyITransactionalOperation 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.createOperation in class AbstractPolicyITransactionalOperation to encapsulate all applied
changes.public int createPostTransform()
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.AffineTransform that is appended to the
postTransforms list.public int createPreTransform()
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.AffineTransform that is appended to the
preTransforms list.protected ITransactionalOperation createTransformContentOperation()
public AffineTransform getCurrentTransform()
AffineTransform that matches the node transformation
of the host.AffineTransform.public ITransformableContentPart<? extends javafx.scene.Node> getHost()
IPolicyIPolicy.public AffineTransform getInitialTransform()
getCurrentTransform()).getCurrentTransform()).public void init()
AbstractPolicyIllegalStateException, as well as re-initializing before
committing or rolling back.init in interface IPolicyinit in class AbstractPolicyprotected boolean isContentTransformable()
true if the content can be transformed,
false otherwise.public void setPostRotate(int index,
Angle rotation)
index - The index of the post-transform to manipulate.rotation - The counter clock-wise rotation Angle.public void setPostScale(int index,
double sx,
double sy)
index - The index of the post-transform to manipulate.sx - The horizontal scale factor.sy - The vertical scale factor.public void setPostTransform(int postTransformIndex,
AffineTransform transform)
AffineTransform.postTransformIndex - The index of the post-transform to manipulate.transform - The AffineTransform that replaces the specified
post-transform.public void setPostTranslate(int index,
double tx,
double ty)
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).public void setPreRotate(int index,
Angle rotation)
index - The index of the pre-transform to manipulate.rotation - The counter clock-wise rotation Angle.public void setPreScale(int index,
double sx,
double sy)
index - The index of the pre-transform to manipulate.sx - The horizontal scale factor.sy - The vertical scale factor.public void setPreTransform(int preTransformIndex,
AffineTransform transform)
AffineTransform.preTransformIndex - The index of the pre-transform to manipulate.transform - The AffineTransform that replaces the specified
pre-transform.public void setPreTranslate(int index,
double tx,
double ty)
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).public void setTransform(AffineTransform finalTransform)
host's transformation to the given
AffineTransform. Clears the pre- and post-transforms lists.finalTransform - The new AffineTransform for the host.protected void updateTransform()
applyTransform(AffineTransform).
--> --> --> direction of concatenation --> --> -->
postTransforms initialTransform preTransforms
|------------| |-----------|
postIndex: n, n-1, ... 0 preIndex: 0, 1, ... m
<-- <-- <-- <-- direction of effect <-- <-- <-- <--
protected void updateTransformOperation(AffineTransform newTransform)
createOperation()
so that it will set the host's transformation to match
the given AffineTransform upon execution.newTransform - The new transformation for the host.Copyright (c) 2014, 2016 itemis AG and others. All rights reserved.