Package com.oorian.css
Class CssStyleSheet
java.lang.Object
com.oorian.css.CssStyleSheet
Represents a dynamic CSS stylesheet that can contain rules, keyframes, media queries, and nested stylesheets.
This class provides a programmatic way to build CSS stylesheets in Java. It supports hierarchical organization with nested stylesheets and can generate complete CSS output as a string. The stylesheet is lazily initialized when first converted to a string.
Features:
- Add CSS rules with selectors and style declarations
- Define keyframe animations
- Create media queries for responsive design
- Nest child stylesheets for modular organization
- Lazy initialization for optimal performance
Usage:
CssStyleSheet sheet = new CssStyleSheet();
CssRule rule = new CssRule(".myClass");
rule.setColor(Color.BLUE);
sheet.addRule(rule);
String css = sheet.toString();
- Since:
- 2016
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal CssStyleSheetaddKeyFrames(KeyFrames keyFrames) Adds keyframes animation definition to this stylesheet.final CssStyleSheetaddMediaQuery(CssMediaQuery mediaQuery) Adds a media query to this stylesheet.final CssStyleSheetAdds a CSS rule to this stylesheet.final CssStyleSheetaddStyleSheet(CssStyleSheet styleSheet) Adds a child stylesheet to this stylesheet.protected voidcreate()Template method for subclasses to add rules and elements during initialization.final StringtoString()Generates and returns the complete CSS string representation of this stylesheet.
-
Constructor Details
-
CssStyleSheet
public CssStyleSheet()Constructs an empty CssStyleSheet.
-
-
Method Details
-
create
protected void create()Template method for subclasses to add rules and elements during initialization. Override this method to programmatically populate the stylesheet. -
addStyleSheet
Adds a child stylesheet to this stylesheet.- Parameters:
styleSheet- the child stylesheet to add- Returns:
- This CssStyleSheet for method chaining.
-
addRule
Adds a CSS rule to this stylesheet.- Parameters:
rule- the CSS rule to add- Returns:
- This CssStyleSheet for method chaining.
-
addKeyFrames
Adds keyframes animation definition to this stylesheet.- Parameters:
keyFrames- the keyframes animation to add- Returns:
- This CssStyleSheet for method chaining.
-
addMediaQuery
Adds a media query to this stylesheet.- Parameters:
mediaQuery- the media query to add- Returns:
- This CssStyleSheet for method chaining.
-
toString
Generates and returns the complete CSS string representation of this stylesheet. Triggers lazy initialization if not already initialized.
-