Class CssStyleSheet

java.lang.Object
com.oorian.css.CssStyleSheet

public class CssStyleSheet extends Object
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 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

      public final CssStyleSheet addStyleSheet(CssStyleSheet styleSheet)
      Adds a child stylesheet to this stylesheet.
      Parameters:
      styleSheet - the child stylesheet to add
      Returns:
      This CssStyleSheet for method chaining.
    • addRule

      public final CssStyleSheet addRule(CssRule rule)
      Adds a CSS rule to this stylesheet.
      Parameters:
      rule - the CSS rule to add
      Returns:
      This CssStyleSheet for method chaining.
    • addKeyFrames

      public final CssStyleSheet addKeyFrames(KeyFrames keyFrames)
      Adds keyframes animation definition to this stylesheet.
      Parameters:
      keyFrames - the keyframes animation to add
      Returns:
      This CssStyleSheet for method chaining.
    • addMediaQuery

      public final CssStyleSheet addMediaQuery(CssMediaQuery mediaQuery)
      Adds a media query to this stylesheet.
      Parameters:
      mediaQuery - the media query to add
      Returns:
      This CssStyleSheet for method chaining.
    • toString

      public final String toString()
      Generates and returns the complete CSS string representation of this stylesheet. Triggers lazy initialization if not already initialized.
      Overrides:
      toString in class Object
      Returns:
      the CSS string