VR
- The visual root node of the UI toolkit used, e.g.
javafx.scene.Node in case of JavaFX.public abstract class AbstractTransformPolicy<VR> extends AbstractTransactionPolicy<VR>
AbstractTransformPolicy
is a AbstractTransactionPolicy
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 initialTransform 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.
Subclasses need to override the following methods to implement transformations for their host:
AbstractTransactionPolicy.createOperation()
- Creates an ITransactionalOperation
that can be used to change the host's transformation.
getCurrentTransform()
- Extracts the host's transformation and
converts it to an AffineTransform
.
updateTransformOperation(AffineTransform)
- Updates the
operation that was created within AbstractTransactionPolicy.createOperation()
so that the
host's transformation is changed to match the given AffineTransform
.
Constructor and Description |
---|
AbstractTransformPolicy() |
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 last AbstractTransactionPolicy.init() call. |
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.
|
abstract AffineTransform |
getCurrentTransform()
Returns the
AffineTransform that matches the node transformation
of the host . |
AffineTransform |
getInitialTransform()
Returns a copy of the initial node transformation of the host (obtained
via
getCurrentTransform() ). |
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 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 abstract void |
updateTransformOperation(AffineTransform finalTransform)
Updates the operation that was created within
AbstractTransactionPolicy.createOperation()
so that it will set the host's transformation to match
the given AffineTransform upon execution. |
checkInitialized, createOperation, getOperation, isInitialized, locallyExecuteOperation, rollback
getAdaptable, getHost, setAdaptable
public 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 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()
AbstractTransactionPolicy
ITransactionalOperation
that performs all
manipulations applied by the policy since the last AbstractTransactionPolicy.init()
call.
When called multiple times in sequence, only the first call will yield an
operation, the subsequent calls will yield null
.commit
in class AbstractTransactionPolicy<VR>
ITransactionalOperation
that performs all
manipulations applied by the policy since the last
AbstractTransactionPolicy.init()
call.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 abstract AffineTransform getCurrentTransform()
AffineTransform
that matches the node transformation
of the host
.AffineTransform
.public AffineTransform getInitialTransform()
getCurrentTransform()
).getCurrentTransform()
).public void init()
AbstractTransactionPolicy
IllegalStateException
. It is safe to call AbstractTransactionPolicy.init()
multiple times in sequence.init
in class AbstractTransactionPolicy<VR>
protected 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 abstract void updateTransformOperation(AffineTransform finalTransform)
AbstractTransactionPolicy.createOperation()
so that it will set the host's
transformation to match
the given AffineTransform
upon execution.finalTransform
- The new transformation for the host.Copyright (c) 2014 itemis AG and others. All rights reserved.