public class FXTransformPolicy extends AbstractPolicy<javafx.scene.Node> implements ITransactional
FXTransformPolicy is a transactional
policy 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.
Additionally, the createPostRotate(Point), and
createPostScale(Point) methods can be used to create a rotation or
scaling around a pivot point (in scene coordinates) for convenience.
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. Additionally, the
setPostTranslateInScene(int, double, double) method can be used to
set a translation in scene coordinates for convenience.
ITransactional.NoOperation, ITransactional.UnexecutableOperation| Modifier and Type | Field and Description |
|---|---|
protected boolean |
initialized
Stores the initialized flag for this policy, i.e.
|
protected AffineTransform |
initialNodeTransform
The initial node transformation of the manipulated part.
|
protected java.util.List<AffineTransform> |
postTransforms
The
List of transformations that are applied after the old
transformation. |
protected java.util.List<AffineTransform> |
preTransforms
The
List of transformations that are applied before the old
transformation. |
static java.lang.String |
TRANSFORMATION_PROVIDER_ROLE
The role name for the
Provider<Affine> that will be
used to obtain the host's Affine transformation. |
protected FXTransformOperation |
transformOperation
The
FXTransformOperation that is updated to reflect the
transformation changes that are performed by this policy. |
NOOP, UNEXECUTABLE| Constructor and Description |
|---|
FXTransformPolicy() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
applyTransform(AffineTransform newTransform)
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 last ITransactional.init() call. |
int |
createPostRotate(Point pivotInScene)
Creates three transformations that are used as follows:
Translates the host so that its origin is at the given pivot point.
|
int |
createPostScale(Point pivotInScene)
Creates three transformations that are used as follows:
Translates the host so that its origin is at the given pivot point.
|
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. |
AffineTransform |
getInitialNodeTransform()
Returns a copy of the initial node transformation of the host (obtained
via
getNodeTransform()). |
javafx.scene.transform.Affine |
getNodeTransform()
Returns the
Affine transformation that is returned by the
Provider<Affine> that is installed on the
host under the TRANSFORMATION_PROVIDER_ROLE
role. |
protected static Dimension |
getSnapToGridOffset(GridModel gridModel,
double localX,
double localY,
double gridCellWidthFraction,
double gridCellHeightFraction)
Computes the offset which needs to be added to the given local
coordinates in order to stay on the grid/snap to the grid.
|
void |
init()
Initializes the policy, so that the policy's "work" methods can be used.
|
protected void |
reset()
Resets this
FXTransformPolicy, i.e. clears the pre- and
post-transforms lists and sets the operation and the initial node
transform to null. |
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 |
setPostTranslateInScene(int index,
double tx,
double ty)
Sets the specified pre-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 newTransform)
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.
|
commit, disableRefreshVisuals, enableRefreshVisuals, getAdaptable, getHost, init, setAdaptablepublic static final java.lang.String TRANSFORMATION_PROVIDER_ROLE
Provider<Affine> that will be
used to obtain the host's Affine transformation.protected boolean initialized
protected FXTransformOperation transformOperation
FXTransformOperation that is updated to reflect the
transformation changes that are performed by this policy. The operation
can later be executed on the operation history so that transformation
changes are undoable.protected AffineTransform initialNodeTransform
protected java.util.List<AffineTransform> preTransforms
List of transformations that are applied before the old
transformation.protected java.util.List<AffineTransform> postTransforms
List of transformations that are applied after the old
transformation.protected static Dimension getSnapToGridOffset(GridModel gridModel, double localX, double localY, double gridCellWidthFraction, double gridCellHeightFraction)
gridModel - The GridModel of the host's IViewer.localX - The x-coordinate in host coordinates.localY - The y-coordinate in host coordinates.gridCellWidthFraction - The granularity of the horizontal grid steps.gridCellHeightFraction - The granularity of the vertical grid steps.Dimension representing the offset that needs to be
added to the local coordinates so that they snap to the grid.protected void applyTransform(AffineTransform newTransform)
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
.newTransform - The new transformation matrix for the host.public ITransactionalOperation commit()
ITransactionalITransactionalOperation that performs all
manipulations applied by the policy since the last ITransactional.init() call.
When called multiple times in sequence, only the first call will yield an
operation, the subsequent calls will yield null.
You can return ITransactional.NOOP if no changes have to be applied. The domain
will filter out all ITransactional.NOOPs before their execution.
You can return ITransactional.UNEXECUTABLE to prevent any composite operation
that contains the ITransactional.UNEXECUTABLE from execution.
commit in interface ITransactionalITransactionalOperation that performs all
manipulations applied by the policy since the last
ITransactional.init() call.public int createPostRotate(Point pivotInScene)
setPostRotate(int, Angle)).
--> --> --> direction of concatenation --> --> -->
postTransforms initialNodeTransform preTransforms
|------------| |-----------|
postIndex: n, n-1, ... 0 preIndex: 0, 1, ... m
<-- <-- <-- <-- direction of effect <-- <-- <-- <--
pivotInScene - The pivot Point in scene coordinates.public int createPostScale(Point pivotInScene)
setPreScale(int, double, double)).
--> --> --> direction of concatenation --> --> -->
postTransforms initialNodeTransform preTransforms
|------------| |-----------|
postIndex: n, n-1, ... 0 preIndex: 0, 1, ... m
<-- <-- <-- <-- direction of effect <-- <-- <-- <--
pivotInScene - The pivot Point in scene coordinates.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 initialNodeTransform 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 initialNodeTransform 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.public AffineTransform getInitialNodeTransform()
getNodeTransform()).getNodeTransform()).public javafx.scene.transform.Affine getNodeTransform()
Affine transformation that is returned by the
Provider<Affine> that is installed on the
host under the TRANSFORMATION_PROVIDER_ROLE
role.Affine transformation that is returned by the
Provider<Affine> that is installed on the
host under the
TRANSFORMATION_PROVIDER_ROLE role.public void init()
ITransactionalIllegalStateException. It is safe to call ITransactional.init()
multiple times in sequence.init in interface ITransactionalprotected void reset()
FXTransformPolicy, i.e. clears the pre- and
post-transforms lists and sets the operation and the initial node
transform to null. This method is called by init()
and commit().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 setPostTranslateInScene(int index,
double tx,
double ty)
index - The index of the pre-transform to manipulate.tx - The horizontal translation offset (in scene coordinates).ty - The vertical translation offset (in scene 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 newTransform)
host's transformation to the given
AffineTransform. Clears the pre- and post-transforms lists.newTransform - The new AffineTransform for the host.protected void updateTransform()
applyTransform(AffineTransform).
--> --> --> direction of concatenation --> --> -->
postTransforms initialNodeTransform preTransforms
|------------| |-----------|
postIndex: n, n-1, ... 0 preIndex: 0, 1, ... m
<-- <-- <-- <-- direction of effect <-- <-- <-- <--
Copyright (c) 2014 itemis AG and others. All rights reserved.