Class Filter

java.lang.Object
com.oorian.css.Filter

public class Filter extends Object
A builder for composing CSS filter property values.

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

Usage:


 // Compose multiple filters
 element.setFilter(new Filter()
     .blur("5px")
     .brightness(1.2f)
     .contrast(1.1f));
 // Result: filter: blur(5px) brightness(1.2) contrast(1.1)

 // Use with CssRule
 CssRule rule = new CssRule(".faded");
 rule.setFilter(new Filter().grayscale(1.0f).opacity(0.8f));
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Filter

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

    • blur

      public Filter blur(String value)
      Adds a blur() function.
      Parameters:
      value - the CSS length value (e.g., "5px", "0.5rem")
      Returns:
      this Filter for method chaining
    • blur

      public Filter blur(int px)
      Adds a blur() function with a pixel value.
      Parameters:
      px - the blur radius in pixels
      Returns:
      this Filter for method chaining
    • blur

      public Filter blur(Units units)
      Adds a blur() function with a Units value.
      Parameters:
      units - the blur radius as a Units value (e.g., new Px(5), new Rem(0.5f))
      Returns:
      this Filter for method chaining
    • brightness

      public Filter brightness(float value)
      Adds a brightness() function.
      Parameters:
      value - the brightness factor (e.g., 1.5f for 150%, 0.5f for 50%)
      Returns:
      this Filter for method chaining
    • contrast

      public Filter contrast(float value)
      Adds a contrast() function.
      Parameters:
      value - the contrast factor (e.g., 1.5f for 150%, 0.5f for 50%)
      Returns:
      this Filter for method chaining
    • dropShadow

      public Filter dropShadow(String value)
      Adds a drop-shadow() function with a raw CSS value.
      Parameters:
      value - the drop-shadow value (e.g., "2px 2px 4px rgba(0,0,0,0.3)")
      Returns:
      this Filter for method chaining
    • dropShadow

      public Filter dropShadow(String offsetX, String offsetY, String blurRadius, String color)
      Adds a drop-shadow() function with individual parameters.
      Parameters:
      offsetX - the horizontal offset (e.g., "2px")
      offsetY - the vertical offset (e.g., "2px")
      blurRadius - the blur radius (e.g., "4px")
      color - the shadow color (e.g., "rgba(0,0,0,0.3)")
      Returns:
      this Filter for method chaining
    • dropShadow

      public Filter dropShadow(int offsetX, int offsetY, int blurRadius, Color color)
      Adds a drop-shadow() function with pixel values and a Color object.
      Parameters:
      offsetX - the horizontal offset in pixels
      offsetY - the vertical offset in pixels
      blurRadius - the blur radius in pixels
      color - the shadow Color object
      Returns:
      this Filter for method chaining
    • dropShadow

      public Filter dropShadow(Units offsetX, Units offsetY, Units blurRadius, Color color)
      Adds a drop-shadow() function with Units values and a Color object.
      Parameters:
      offsetX - the horizontal offset as a Units value
      offsetY - the vertical offset as a Units value
      blurRadius - the blur radius as a Units value
      color - the shadow Color object
      Returns:
      this Filter for method chaining
    • grayscale

      public Filter grayscale(float value)
      Adds a grayscale() function.
      Parameters:
      value - the grayscale amount from 0.0f (none) to 1.0f (full grayscale)
      Returns:
      this Filter for method chaining
    • hueRotate

      public Filter hueRotate(float degrees)
      Adds a hue-rotate() function.
      Parameters:
      degrees - the rotation angle in degrees (e.g., 90 for 90deg)
      Returns:
      this Filter for method chaining
    • hueRotate

      public Filter hueRotate(String value)
      Adds a hue-rotate() function with a raw CSS angle value.
      Parameters:
      value - the CSS angle value (e.g., "90deg", "0.5turn")
      Returns:
      this Filter for method chaining
    • invert

      public Filter invert(float value)
      Adds an invert() function.
      Parameters:
      value - the inversion amount from 0.0f (none) to 1.0f (full inversion)
      Returns:
      this Filter for method chaining
    • opacity

      public Filter opacity(float value)
      Adds an opacity() function.
      Parameters:
      value - the opacity amount from 0.0f (transparent) to 1.0f (opaque)
      Returns:
      this Filter for method chaining
    • saturate

      public Filter saturate(float value)
      Adds a saturate() function.
      Parameters:
      value - the saturation factor (e.g., 1.5f for 150%, 0.5f for 50%)
      Returns:
      this Filter for method chaining
    • sepia

      public Filter sepia(float value)
      Adds a sepia() function.
      Parameters:
      value - the sepia amount from 0.0f (none) to 1.0f (full sepia)
      Returns:
      this Filter for method chaining
    • toString

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