Class Transform

java.lang.Object
com.oorian.css.Transform

public class Transform extends Object
A builder for composing CSS transform property values.

Transform provides a type-safe, fluent API for building CSS transform strings that contain multiple functions. Functions are maintained in insertion order, and setting the same function again replaces the previous value.

Usage:


 // Compose multiple transforms
 element.setTransform(new Transform()
     .translateX("50px")
     .rotate(45)
     .scale(1.5f));
 // Result: transform: translateX(50px) rotate(45deg) scale(1.5)

 // Order matters — transforms apply right to left
 element.setTransform(new Transform()
     .scale(2)
     .translateX("50px"));
 // Result: transform: scale(2.0) translateX(50px)

 // Use with CssRule
 CssRule rule = new CssRule(".rotated");
 rule.setTransform(new Transform().rotate(45).scale(0.8f));
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Transform

      public Transform()
      Constructs an empty Transform.
  • Method Details

    • translateX

      public Transform translateX(String value)
      Adds a translateX() function.
      Parameters:
      value - the CSS length value (e.g., "50px", "10%", "2rem")
      Returns:
      this Transform for method chaining
    • translateX

      public Transform translateX(int pixels)
      Adds a translateX() function with a pixel value.
      Parameters:
      pixels - the horizontal translation in pixels
      Returns:
      this Transform for method chaining
    • translateX

      public Transform translateX(Units units)
      Adds a translateX() function with a Units value.
      Parameters:
      units - the horizontal translation as a Units value (e.g., new Px(50), new Percent(10))
      Returns:
      this Transform for method chaining
    • translateY

      public Transform translateY(String value)
      Adds a translateY() function.
      Parameters:
      value - the CSS length value (e.g., "50px", "10%", "2rem")
      Returns:
      this Transform for method chaining
    • translateY

      public Transform translateY(int pixels)
      Adds a translateY() function with a pixel value.
      Parameters:
      pixels - the vertical translation in pixels
      Returns:
      this Transform for method chaining
    • translateY

      public Transform translateY(Units units)
      Adds a translateY() function with a Units value.
      Parameters:
      units - the vertical translation as a Units value (e.g., new Px(50), new Percent(10))
      Returns:
      this Transform for method chaining
    • translateZ

      public Transform translateZ(String value)
      Adds a translateZ() function.
      Parameters:
      value - the CSS length value (e.g., "50px", "100px")
      Returns:
      this Transform for method chaining
    • translateZ

      public Transform translateZ(int pixels)
      Adds a translateZ() function with a pixel value.
      Parameters:
      pixels - the depth translation in pixels
      Returns:
      this Transform for method chaining
    • translateZ

      public Transform translateZ(Units units)
      Adds a translateZ() function with a Units value.
      Parameters:
      units - the depth translation as a Units value
      Returns:
      this Transform for method chaining
    • translate

      public Transform translate(String x, String y)
      Adds a translate() function for 2D translation.
      Parameters:
      x - the horizontal CSS length value
      y - the vertical CSS length value
      Returns:
      this Transform for method chaining
    • translate

      public Transform translate(int x, int y)
      Adds a translate() function for 2D translation with pixel values.
      Parameters:
      x - the horizontal translation in pixels
      y - the vertical translation in pixels
      Returns:
      this Transform for method chaining
    • translate

      public Transform translate(Units x, Units y)
      Adds a translate() function for 2D translation with Units values.
      Parameters:
      x - the horizontal translation as a Units value
      y - the vertical translation as a Units value
      Returns:
      this Transform for method chaining
    • translate3d

      public Transform translate3d(String x, String y, String z)
      Adds a translate3d() function for 3D translation.
      Parameters:
      x - the horizontal CSS length value
      y - the vertical CSS length value
      z - the depth CSS length value
      Returns:
      this Transform for method chaining
    • translate3d

      public Transform translate3d(int x, int y, int z)
      Adds a translate3d() function for 3D translation with pixel values.
      Parameters:
      x - the horizontal translation in pixels
      y - the vertical translation in pixels
      z - the depth translation in pixels
      Returns:
      this Transform for method chaining
    • translate3d

      public Transform translate3d(Units x, Units y, Units z)
      Adds a translate3d() function for 3D translation with Units values.
      Parameters:
      x - the horizontal translation as a Units value
      y - the vertical translation as a Units value
      z - the depth translation as a Units value
      Returns:
      this Transform for method chaining
    • rotate

      public Transform rotate(float degrees)
      Adds a rotate() function.
      Parameters:
      degrees - the rotation angle in degrees
      Returns:
      this Transform for method chaining
    • rotate

      public Transform rotate(String value)
      Adds a rotate() function with a CSS angle value.
      Parameters:
      value - the CSS angle value (e.g., "45deg", "0.5turn", "1.57rad")
      Returns:
      this Transform for method chaining
    • rotateX

      public Transform rotateX(float degrees)
      Adds a rotateX() function for 3D rotation around the X axis.
      Parameters:
      degrees - the rotation angle in degrees
      Returns:
      this Transform for method chaining
    • rotateX

      public Transform rotateX(String value)
      Adds a rotateX() function with a CSS angle value.
      Parameters:
      value - the CSS angle value (e.g., "45deg", "0.5turn", "1.57rad")
      Returns:
      this Transform for method chaining
    • rotateY

      public Transform rotateY(float degrees)
      Adds a rotateY() function for 3D rotation around the Y axis.
      Parameters:
      degrees - the rotation angle in degrees
      Returns:
      this Transform for method chaining
    • rotateY

      public Transform rotateY(String value)
      Adds a rotateY() function with a CSS angle value.
      Parameters:
      value - the CSS angle value (e.g., "45deg", "0.5turn", "1.57rad")
      Returns:
      this Transform for method chaining
    • rotateZ

      public Transform rotateZ(float degrees)
      Adds a rotateZ() function for 3D rotation around the Z axis.
      Parameters:
      degrees - the rotation angle in degrees
      Returns:
      this Transform for method chaining
    • rotateZ

      public Transform rotateZ(String value)
      Adds a rotateZ() function with a CSS angle value.
      Parameters:
      value - the CSS angle value (e.g., "45deg", "0.5turn", "1.57rad")
      Returns:
      this Transform for method chaining
    • rotate3d

      public Transform rotate3d(float x, float y, float z, String angle)
      Adds a rotate3d() function.
      Parameters:
      x - the X component of the rotation axis vector
      y - the Y component of the rotation axis vector
      z - the Z component of the rotation axis vector
      angle - the CSS angle value (e.g., "45deg")
      Returns:
      this Transform for method chaining
    • scale

      public Transform scale(float value)
      Adds a uniform scale() function.
      Parameters:
      value - the scale factor (e.g., 1.5f for 150%)
      Returns:
      this Transform for method chaining
    • scale

      public Transform scale(float x, float y)
      Adds a non-uniform scale() function.
      Parameters:
      x - the horizontal scale factor
      y - the vertical scale factor
      Returns:
      this Transform for method chaining
    • scaleX

      public Transform scaleX(float value)
      Adds a scaleX() function.
      Parameters:
      value - the horizontal scale factor
      Returns:
      this Transform for method chaining
    • scaleY

      public Transform scaleY(float value)
      Adds a scaleY() function.
      Parameters:
      value - the vertical scale factor
      Returns:
      this Transform for method chaining
    • scaleZ

      public Transform scaleZ(float value)
      Adds a scaleZ() function.
      Parameters:
      value - the depth scale factor
      Returns:
      this Transform for method chaining
    • scale3d

      public Transform scale3d(float x, float y, float z)
      Adds a scale3d() function.
      Parameters:
      x - the horizontal scale factor
      y - the vertical scale factor
      z - the depth scale factor
      Returns:
      this Transform for method chaining
    • skewX

      public Transform skewX(String value)
      Adds a skewX() function.
      Parameters:
      value - the CSS angle value (e.g., "15deg")
      Returns:
      this Transform for method chaining
    • skewX

      public Transform skewX(float degrees)
      Adds a skewX() function with an angle in degrees.
      Parameters:
      degrees - the skew angle in degrees
      Returns:
      this Transform for method chaining
    • skewY

      public Transform skewY(String value)
      Adds a skewY() function.
      Parameters:
      value - the CSS angle value (e.g., "15deg")
      Returns:
      this Transform for method chaining
    • skewY

      public Transform skewY(float degrees)
      Adds a skewY() function with an angle in degrees.
      Parameters:
      degrees - the skew angle in degrees
      Returns:
      this Transform for method chaining
    • skew

      public Transform skew(String x, String y)
      Adds a skew() function for 2D skewing.
      Parameters:
      x - the CSS angle value for the X axis
      y - the CSS angle value for the Y axis
      Returns:
      this Transform for method chaining
    • skew

      public Transform skew(float xDegrees, float yDegrees)
      Adds a skew() function for 2D skewing with angles in degrees.
      Parameters:
      xDegrees - the X-axis skew angle in degrees
      yDegrees - the Y-axis skew angle in degrees
      Returns:
      this Transform for method chaining
    • perspective

      public Transform perspective(String value)
      Adds a perspective() function.
      Parameters:
      value - the CSS length value (e.g., "500px")
      Returns:
      this Transform for method chaining
    • perspective

      public Transform perspective(int pixels)
      Adds a perspective() function with a pixel value.
      Parameters:
      pixels - the perspective distance in pixels
      Returns:
      this Transform for method chaining
    • perspective

      public Transform perspective(Units units)
      Adds a perspective() function with a Units value.
      Parameters:
      units - the perspective distance as a Units value
      Returns:
      this Transform for method chaining
    • toString

      public String toString()
      Returns the CSS transform string.
      Overrides:
      toString in class Object
      Returns:
      the space-separated list of transform functions, or "none" if empty