Class BoxShadow

java.lang.Object
com.oorian.css.BoxShadow

public class BoxShadow extends Object
A builder for composing CSS box-shadow and text-shadow property values.

BoxShadow provides a type-safe, fluent API for building shadow strings that support multiple layered shadows. CSS allows comma-separated shadow values, and this builder makes it easy to compose them. The same builder can be used for both box-shadow and text-shadow properties.

Usage:


 // Single box shadow
 element.setBoxShadow(new BoxShadow()
     .add("2px", "2px", "4px", "0px", "rgba(0,0,0,0.3)"));
 // Result: box-shadow: 2px 2px 4px 0px rgba(0,0,0,0.3)

 // Multiple layered shadows
 element.setBoxShadow(new BoxShadow()
     .add("2px", "2px", "4px", "#000")
     .addInset("0", "0", "10px", "5px", "rgba(0,0,0,0.2)"));
 // Result: box-shadow: 2px 2px 4px #000, inset 0 0 10px 5px rgba(0,0,0,0.2)

 // Text shadow with Color objects
 element.setTextShadow(new BoxShadow()
     .add(1, 1, 3, 0, Color.BLACK));
 // Result: text-shadow: 1px 1px 3px 0px #000000

 // Use with CssRule
 CssRule rule = new CssRule(".elevated");
 rule.setBoxShadow(new BoxShadow()
     .add("0", "4px", "6px", "-1px", "rgba(0,0,0,0.1)")
     .add("0", "2px", "4px", "-2px", "rgba(0,0,0,0.1)"));
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • BoxShadow

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

    • add

      public BoxShadow add(String offsetX, String offsetY)
      Adds a shadow with horizontal and vertical offsets only.
      Parameters:
      offsetX - the horizontal offset (e.g., "2px")
      offsetY - the vertical offset (e.g., "2px")
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(int offsetX, int offsetY)
      Adds a shadow with pixel offsets only.
      Parameters:
      offsetX - the horizontal offset in pixels
      offsetY - the vertical offset in pixels
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(String offsetX, String offsetY, String blur)
      Adds a shadow with offsets and blur radius.
      Parameters:
      offsetX - the horizontal offset (e.g., "2px")
      offsetY - the vertical offset (e.g., "2px")
      blur - the blur radius (e.g., "4px")
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(int offsetX, int offsetY, int blur)
      Adds a shadow with pixel offsets and blur radius.
      Parameters:
      offsetX - the horizontal offset in pixels
      offsetY - the vertical offset in pixels
      blur - the blur radius in pixels
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(String offsetX, String offsetY, String blur, String color)
      Adds a shadow with offsets, blur radius, and color.
      Parameters:
      offsetX - the horizontal offset (e.g., "2px")
      offsetY - the vertical offset (e.g., "2px")
      blur - the blur radius (e.g., "4px")
      color - the shadow color (e.g., "rgba(0,0,0,0.3)", "#000")
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(int offsetX, int offsetY, int blur, Color color)
      Adds a shadow with pixel offsets, blur radius, and a Color object.
      Parameters:
      offsetX - the horizontal offset in pixels
      offsetY - the vertical offset in pixels
      blur - the blur radius in pixels
      color - the shadow Color object
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(String offsetX, String offsetY, String blur, String spread, String color)
      Adds a shadow with offsets, blur radius, spread radius, and color.
      Parameters:
      offsetX - the horizontal offset (e.g., "2px")
      offsetY - the vertical offset (e.g., "2px")
      blur - the blur radius (e.g., "4px")
      spread - the spread radius (e.g., "0px", "-1px")
      color - the shadow color (e.g., "rgba(0,0,0,0.3)")
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(int offsetX, int offsetY, int blur, int spread, Color color)
      Adds a shadow with pixel offsets, blur, spread, and a Color object.
      Parameters:
      offsetX - the horizontal offset in pixels
      offsetY - the vertical offset in pixels
      blur - the blur radius in pixels
      spread - the spread radius in pixels
      color - the shadow Color object
      Returns:
      this BoxShadow for method chaining
    • add

      public BoxShadow add(Units offsetX, Units offsetY, Units blur, Units spread, Color color)
      Adds a shadow with Units offsets, blur, spread, and a Color object.
      Parameters:
      offsetX - the horizontal offset as a Units value
      offsetY - the vertical offset as a Units value
      blur - the blur radius as a Units value
      spread - the spread radius as a Units value
      color - the shadow Color object
      Returns:
      this BoxShadow for method chaining
    • addInset

      public BoxShadow addInset(String offsetX, String offsetY, String blur, String spread, String color)
      Adds an inset shadow with offsets, blur radius, spread radius, and color.

      Inset shadows appear inside the element's box. Note that inset shadows are only valid for box-shadow, not text-shadow.

      Parameters:
      offsetX - the horizontal offset (e.g., "0")
      offsetY - the vertical offset (e.g., "0")
      blur - the blur radius (e.g., "10px")
      spread - the spread radius (e.g., "5px")
      color - the shadow color (e.g., "rgba(0,0,0,0.2)")
      Returns:
      this BoxShadow for method chaining
    • addInset

      public BoxShadow addInset(int offsetX, int offsetY, int blur, int spread, Color color)
      Adds an inset shadow with pixel values and a Color object.

      Inset shadows appear inside the element's box. Note that inset shadows are only valid for box-shadow, not text-shadow.

      Parameters:
      offsetX - the horizontal offset in pixels
      offsetY - the vertical offset in pixels
      blur - the blur radius in pixels
      spread - the spread radius in pixels
      color - the shadow Color object
      Returns:
      this BoxShadow for method chaining
    • addInset

      public BoxShadow addInset(Units offsetX, Units offsetY, Units blur, Units spread, Color color)
      Adds an inset shadow with Units values and a Color object.

      Inset shadows appear inside the element's box. Note that inset shadows are only valid for box-shadow, not text-shadow.

      Parameters:
      offsetX - the horizontal offset as a Units value
      offsetY - the vertical offset as a Units value
      blur - the blur radius as a Units value
      spread - the spread radius as a Units value
      color - the shadow Color object
      Returns:
      this BoxShadow for method chaining
    • toString

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