Class Transform


  • public class Transform
    extends Resource
    Instances of this class represent transformation matrices for points expressed as (x, y) pairs of floating point numbers.

    Application code must explicitly invoke the Transform.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

    This class requires the operating system's advanced graphics subsystem which may not be available on some platforms.

    Since:
    3.1
    See Also:
    SWT Example: GraphicsExample, Sample code and further information
    • Field Summary

      Fields 
      Modifier and Type Field Description
      long handle
      the OS resource for the Transform (Warning: This field is platform dependent)
    • Constructor Summary

      Constructors 
      Constructor Description
      Transform​(Device device)
      Constructs a new identity Transform.
      Transform​(Device device, float[] elements)
      Constructs a new Transform given an array of elements that represent the matrix that describes the transformation.
      Transform​(Device device, float m11, float m12, float m21, float m22, float dx, float dy)
      Constructs a new Transform given all of the elements that represent the matrix that describes the transformation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void getElements​(float[] elements)
      Fills the parameter with the values of the transformation matrix that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
      void identity()
      Modifies the receiver such that the matrix it represents becomes the identity matrix.
      void invert()
      Modifies the receiver such that the matrix it represents becomes the mathematical inverse of the matrix it previously represented.
      boolean isDisposed()
      Returns true if the Transform has been disposed, and false otherwise.
      boolean isIdentity()
      Returns true if the Transform represents the identity matrix and false otherwise.
      void multiply​(Transform matrix)
      Modifies the receiver such that the matrix it represents becomes the the result of multiplying the matrix it previously represented by the argument.
      void rotate​(float angle)
      Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation rotated by the specified angle.
      void scale​(float scaleX, float scaleY)
      Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation scaled by (scaleX, scaleY).
      void setElements​(float m11, float m12, float m21, float m22, float dx, float dy)
      Modifies the receiver to represent a new transformation given all of the elements that represent the matrix that describes that transformation.
      void shear​(float shearX, float shearY)
      Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation sheared by (shearX, shearY).
      String toString()
      Returns a string containing a concise, human-readable description of the receiver.
      void transform​(float[] pointArray)
      Given an array containing points described by alternating x and y values, modify that array such that each point has been replaced with the result of applying the transformation represented by the receiver to that point.
      void translate​(float offsetX, float offsetY)
      Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation translated by (offsetX, offsetY).
    • Field Detail

      • handle

        public long handle
        the OS resource for the Transform (Warning: This field is platform dependent)

        IMPORTANT: This field is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code.

        Restriction:
        This field is not intended to be referenced by clients.
    • Constructor Detail

      • Transform

        public Transform​(Device device)
        Constructs a new identity Transform.

        This operation requires the operating system's advanced graphics subsystem which may not be available on some platforms.

        You must dispose the transform when it is no longer required.

        Parameters:
        device - the device on which to allocate the Transform
        Throws:
        IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if device is null and there is no current device
        SWTException -
        • ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
        SWTError -
        • ERROR_NO_HANDLES if a handle for the Transform could not be obtained
        See Also:
        Resource.dispose()
      • Transform

        public Transform​(Device device,
                         float[] elements)
        Constructs a new Transform given an array of elements that represent the matrix that describes the transformation.

        This operation requires the operating system's advanced graphics subsystem which may not be available on some platforms.

        You must dispose the transform when it is no longer required.

        Parameters:
        device - the device on which to allocate the Transform
        elements - an array of floats that describe the transformation matrix
        Throws:
        IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null
        • ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values
        SWTException -
        • ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
        SWTError -
        • ERROR_NO_HANDLES if a handle for the Transform could not be obtained
        See Also:
        Resource.dispose()
      • Transform

        public Transform​(Device device,
                         float m11,
                         float m12,
                         float m21,
                         float m22,
                         float dx,
                         float dy)
        Constructs a new Transform given all of the elements that represent the matrix that describes the transformation.

        This operation requires the operating system's advanced graphics subsystem which may not be available on some platforms.

        You must dispose the transform when it is no longer required.

        Parameters:
        device - the device on which to allocate the Transform
        m11 - the first element of the first row of the matrix
        m12 - the second element of the first row of the matrix
        m21 - the first element of the second row of the matrix
        m22 - the second element of the second row of the matrix
        dx - the third element of the first row of the matrix
        dy - the third element of the second row of the matrix
        Throws:
        IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if device is null and there is no current device
        SWTException -
        • ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
        SWTError -
        • ERROR_NO_HANDLES if a handle for the Transform could not be obtained
        See Also:
        Resource.dispose()
    • Method Detail

      • getElements

        public void getElements​(float[] elements)
        Fills the parameter with the values of the transformation matrix that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
        Parameters:
        elements - array to hold the matrix values
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
        IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the parameter is null
        • ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values
      • identity

        public void identity()
        Modifies the receiver such that the matrix it represents becomes the identity matrix.
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
        Since:
        3.4
      • invert

        public void invert()
        Modifies the receiver such that the matrix it represents becomes the mathematical inverse of the matrix it previously represented.
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
        • ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible
      • isDisposed

        public boolean isDisposed()
        Returns true if the Transform has been disposed, and false otherwise.

        This method gets the dispose state for the Transform. When a Transform has been disposed, it is an error to invoke any other method (except Resource.dispose()) using the Transform.

        Specified by:
        isDisposed in class Resource
        Returns:
        true when the Transform is disposed, and false otherwise
      • isIdentity

        public boolean isIdentity()
        Returns true if the Transform represents the identity matrix and false otherwise.
        Returns:
        true if the receiver is an identity Transform, and false otherwise
      • multiply

        public void multiply​(Transform matrix)
        Modifies the receiver such that the matrix it represents becomes the the result of multiplying the matrix it previously represented by the argument.
        Parameters:
        matrix - the matrix to multiply the receiver by
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
        IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the parameter is null
        • ERROR_INVALID_ARGUMENT - if the parameter has been disposed
      • rotate

        public void rotate​(float angle)
        Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation rotated by the specified angle. The angle is specified in degrees and for the identity transform 0 degrees is at the 3 o'clock position. A positive value indicates a clockwise rotation while a negative value indicates a counter-clockwise rotation.
        Parameters:
        angle - the angle to rotate the transformation by
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • scale

        public void scale​(float scaleX,
                          float scaleY)
        Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation scaled by (scaleX, scaleY).
        Parameters:
        scaleX - the amount to scale in the X direction
        scaleY - the amount to scale in the Y direction
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • setElements

        public void setElements​(float m11,
                                float m12,
                                float m21,
                                float m22,
                                float dx,
                                float dy)
        Modifies the receiver to represent a new transformation given all of the elements that represent the matrix that describes that transformation.
        Parameters:
        m11 - the first element of the first row of the matrix
        m12 - the second element of the first row of the matrix
        m21 - the first element of the second row of the matrix
        m22 - the second element of the second row of the matrix
        dx - the third element of the first row of the matrix
        dy - the third element of the second row of the matrix
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • shear

        public void shear​(float shearX,
                          float shearY)
        Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation sheared by (shearX, shearY).
        Parameters:
        shearX - the shear factor in the X direction
        shearY - the shear factor in the Y direction
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
        Since:
        3.4
      • transform

        public void transform​(float[] pointArray)
        Given an array containing points described by alternating x and y values, modify that array such that each point has been replaced with the result of applying the transformation represented by the receiver to that point.
        Parameters:
        pointArray - an array of alternating x and y values to be transformed
        Throws:
        IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the point array is null
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • translate

        public void translate​(float offsetX,
                              float offsetY)
        Modifies the receiver so that it represents a transformation that is equivalent to its previous transformation translated by (offsetX, offsetY).
        Parameters:
        offsetX - the distance to translate in the X direction
        offsetY - the distance to translate in the Y direction
        Throws:
        SWTException -
        • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • toString

        public String toString()
        Returns a string containing a concise, human-readable description of the receiver.
        Overrides:
        toString in class Object
        Returns:
        a string representation of the receiver