Class TransformPolicy

  • All Implemented Interfaces:
    IAdaptable.Bound<IVisualPart<? extends javafx.scene.Node>>, IPolicy

    public class TransformPolicy
    extends AbstractPolicy
    The 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:

    1. Translate the coordinate system, so that the pivot point is in the origin (-px, -py).
    2. Rotate the coordinate system.
    3. Translate back to the original position (px, py).
    But the corresponding transformations have to be concatenated in reverse order, i.e. translate back first, rotate then, translate pivot to origin last. This is easy to confuse, that's why this policy manages a list of pre-transforms and a list of post-transforms. These transformations (as well as the initial node transformation) are concatenated as follows to yield the new node transformation for the host:
                --> --> -->  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.

    • Constructor Detail

      • TransformPolicy

        public TransformPolicy()
    • Method Detail

      • applyTransform

        protected void applyTransform​(AffineTransform finalTransform)
        Applies the given 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 .
        Parameters:
        finalTransform - The new transformation matrix for the host.
      • createPostTransform

        public int createPostTransform()
        Creates a new 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.
        Returns:
        A new AffineTransform that is appended to the postTransforms list.
      • createPreTransform

        public int createPreTransform()
        Creates a new 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.
        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.
      • 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 an IllegalStateException, as well as re-initializing before committing or rolling back.
        Specified by:
        init in interface IPolicy
        Overrides:
        init in class AbstractPolicy
      • 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 rotation Angle.
      • 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 given AffineTransform.
        Parameters:
        postTransformIndex - The index of the post-transform to manipulate.
        transform - The AffineTransform 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 rotation Angle.
      • 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 given AffineTransform.
        Parameters:
        preTransformIndex - The index of the pre-transform to manipulate.
        transform - The AffineTransform 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).
      • 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 using applyTransform(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 within createOperation() so that it will set the host's transformation to match the given AffineTransform upon execution.
        Parameters:
        newTransform - The new transformation for the host.