Package com.oorian.css
Class BoxShadow
java.lang.Object
com.oorian.css.BoxShadow
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(int offsetX, int offsetY) Adds a shadow with pixel offsets only.add(int offsetX, int offsetY, int blur) Adds a shadow with pixel offsets and blur radius.Adds a shadow with pixel offsets, blur, spread, and aColorobject.Adds a shadow with pixel offsets, blur radius, and aColorobject.Adds a shadow with horizontal and vertical offsets only.Adds a shadow with offsets and blur radius.Adds a shadow with offsets, blur radius, and color.Adds a shadow with offsets, blur radius, spread radius, and color.Adds an inset shadow with pixel values and aColorobject.Adds an inset shadow with offsets, blur radius, spread radius, and color.toString()Returns the CSS shadow string.
-
Constructor Details
-
BoxShadow
public BoxShadow()Constructs an empty BoxShadow.
-
-
Method Details
-
add
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
Adds a shadow with pixel offsets only.- Parameters:
offsetX- the horizontal offset in pixelsoffsetY- the vertical offset in pixels- Returns:
- this BoxShadow for method chaining
-
add
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
Adds a shadow with pixel offsets and blur radius.- Parameters:
offsetX- the horizontal offset in pixelsoffsetY- the vertical offset in pixelsblur- the blur radius in pixels- Returns:
- this BoxShadow for method chaining
-
add
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
Adds a shadow with pixel offsets, blur radius, and aColorobject.- Parameters:
offsetX- the horizontal offset in pixelsoffsetY- the vertical offset in pixelsblur- the blur radius in pixelscolor- the shadow Color object- Returns:
- this BoxShadow for method chaining
-
add
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
Adds a shadow with pixel offsets, blur, spread, and aColorobject.- Parameters:
offsetX- the horizontal offset in pixelsoffsetY- the vertical offset in pixelsblur- the blur radius in pixelsspread- the spread radius in pixelscolor- the shadow Color object- Returns:
- this BoxShadow for method chaining
-
add
- Parameters:
offsetX- the horizontal offset as a Units valueoffsetY- the vertical offset as a Units valueblur- the blur radius as a Units valuespread- the spread radius as a Units valuecolor- the shadow Color object- Returns:
- this BoxShadow for method chaining
-
addInset
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, nottext-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
Adds an inset shadow with pixel values and aColorobject.Inset shadows appear inside the element's box. Note that inset shadows are only valid for
box-shadow, nottext-shadow.- Parameters:
offsetX- the horizontal offset in pixelsoffsetY- the vertical offset in pixelsblur- the blur radius in pixelsspread- the spread radius in pixelscolor- the shadow Color object- Returns:
- this BoxShadow for method chaining
-
addInset
Adds an inset shadow withUnitsvalues and aColorobject.Inset shadows appear inside the element's box. Note that inset shadows are only valid for
box-shadow, nottext-shadow.- Parameters:
offsetX- the horizontal offset as a Units valueoffsetY- the vertical offset as a Units valueblur- the blur radius as a Units valuespread- the spread radius as a Units valuecolor- the shadow Color object- Returns:
- this BoxShadow for method chaining
-
toString
Returns the CSS shadow string.
-