Class ClassRule

All Implemented Interfaces:
AnimationIntf<CssRule>, BackgroundIntf<CssRule>, com.oorian.css.BasicBoxIntf<CssRule>, com.oorian.css.BasicUserInterfaceIntf<CssRule>, BorderIntf<CssRule>, com.oorian.css.ColorIntf<CssRule>, CountersIntf<CssRule>, com.oorian.css.CssStyleIntf<CssRule>, com.oorian.css.FilterEffectsIntf<CssRule>, com.oorian.css.FlexibleBoxLayoutIntf<CssRule>, com.oorian.css.FontIntf<CssRule>, com.oorian.css.GeneratedContentForPagedMediaIntf<CssRule>, com.oorian.css.ImageValuesAndReplacedContentIntf<CssRule>, com.oorian.css.ListIntf<CssRule>, com.oorian.css.MarqueeIntf<CssRule>, com.oorian.css.MaskingIntf<CssRule>, com.oorian.css.MultiColumnLayoutIntf<CssRule>, PagedMediaIntf<CssRule>, com.oorian.css.SpeechIntf<CssRule>, com.oorian.css.TableIntf<CssRule>, com.oorian.css.TextDecorationIntf<CssRule>, com.oorian.css.TextIntf<CssRule>, com.oorian.css.TransformIntf<CssRule>, com.oorian.css.TransitionIntf<CssRule>, com.oorian.css.WritingModeIntf<CssRule>

public class ClassRule extends CssRule
Represents a CSS rule that targets elements by their class attribute.

ClassRule provides multiple ways to create class-based CSS selectors:

  • By explicit class name string
  • By Java Class object (converts package.ClassName to package-classname)
  • By the rule's own class (for self-referencing component styles)

Example usage:

 ClassRule buttonStyle = new ClassRule("btn-primary");
 buttonStyle.setBackgroundColor(Color.BLUE);
 buttonStyle.setColor(Color.WHITE);
 // Generates: .btn-primary { background-color: blue; color: white; }
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ClassRule

      public ClassRule(String className)
      Constructs a class rule targeting elements with the specified CSS class.
      Parameters:
      className - The CSS class name to target (without the "." prefix).
    • ClassRule

      public ClassRule(Class cls)
      Constructs a class rule using a Java Class object's canonical name.

      The class name is converted to CSS format by replacing dots with dashes and converting to lowercase (e.g., com.example.MyClass becomes com-example-myclass).

      Parameters:
      cls - The Java Class whose name will be converted to a CSS class selector.
    • ClassRule

      public ClassRule(Class cls, String classSuffix)
      Constructs a class rule using a Java Class object's canonical name with a suffix.

      The class name is converted to CSS format and appended with the specified suffix.

      Parameters:
      cls - The Java Class whose name will be converted to a CSS class selector.
      classSuffix - A suffix to append to the generated class name.
    • ClassRule

      public ClassRule()
      Constructs a class rule using this object's own class name.

      Useful for creating self-referencing component styles where the CSS class name matches the Java class name.

  • Method Details

    • getName

      public String getName()
      Returns the CSS class name for this rule.
      Returns:
      The class name (without the "." prefix).