Class StyleSheetHandler

java.lang.Object
com.smartgwt.client.core.BaseClass
com.smartgwt.client.browser.StyleSheetHandler
All Implemented Interfaces:
HasHandlers

public class StyleSheetHandler extends BaseClass
This class allows developers to create, modify and load/unload custom CSS stylesheets with simple API calls.
  • Constructor Details

    • StyleSheetHandler

      public StyleSheetHandler()
    • StyleSheetHandler

      public StyleSheetHandler(JavaScriptObject jsObj)
    • StyleSheetHandler

      public StyleSheetHandler(String cssText, boolean autoLoad)
    • StyleSheetHandler

      public StyleSheetHandler(String name, String cssText, boolean autoLoad)
  • Method Details

    • getOrCreateRef

      public static StyleSheetHandler getOrCreateRef(JavaScriptObject jsObj)
    • setJavaScriptObject

      public void setJavaScriptObject(JavaScriptObject jsObj)
      Overrides:
      setJavaScriptObject in class BaseClass
    • create

      public JavaScriptObject create()
      Specified by:
      create in class BaseClass
    • isCreated

      public boolean isCreated()
      Overrides:
      isCreated in class BaseClass
    • getJsObj

      public JavaScriptObject getJsObj()
      Overrides:
      getJsObj in class BaseClass
    • getOrCreateJsObj

      public JavaScriptObject getOrCreateJsObj()
      Overrides:
      getOrCreateJsObj in class BaseClass
    • setAutoLoad

      public StyleSheetHandler setAutoLoad(boolean autoLoad) throws IllegalStateException
      When true, this handler will automatically inject it's stylesheet into the DOM.
      Parameters:
      autoLoad - New autoLoad value. Default value is false
      Returns:
      StyleSheetHandler instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the underlying component has been created
    • getAutoLoad

      public boolean getAutoLoad()
      When true, this handler will automatically inject it's stylesheet into the DOM.
      Returns:
      Current autoLoad value. Default value is false
    • setCssText

      public StyleSheetHandler setCssText(String cssText)
      A string representation of all the CSS styles in this handler's styleSheet.

      If this method is called after the component has been drawn/initialized: Replace the entire CSS in this handler's stylesheet.

      If the stylesheet is already in the DOM, it is first unloaded, the cssText is updated and then the stylesheet is injected back into the DOM. Otherwise, the handler's cssText is updated and no further action is taken.

      Parameters:
      cssText - complete cssText to apply to the stylesheet. Default value is null
      Returns:
      StyleSheetHandler instance, for chaining setter calls
    • getCssText

      public String getCssText()
      A string representation of all the CSS styles in this handler's styleSheet.
      Returns:
      Current cssText value. Default value is null
    • setName

      public StyleSheetHandler setName(String name) throws IllegalStateException
      The name for this handler. This value is applied as both the 'id' and 'title' attributes on the handler's stylesheet.
      Parameters:
      name - New name value. Default value is null
      Returns:
      StyleSheetHandler instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the underlying component has been created
    • getName

      public String getName()
      The name for this handler. This value is applied as both the 'id' and 'title' attributes on the handler's stylesheet.
      Returns:
      Current name value. Default value is null
    • getStyleSheet

      public Element getStyleSheet() throws IllegalStateException
      A reference to this handler's stylesheet-element in the DOM. This attribute cannot be set - see injectSheet() and unload() for details.

      Note : This method should be called only after the underlying component has been created.

      Returns:
      Current styleSheet value. Default value is null
      Throws:
      IllegalStateException - if the underlying component has not yet been created.
    • filterCssText

      public String filterCssText(String className)
      Returns all styles for the passed className or array of classNames. The output is a single compound string in the format ".class1 { css settings; } .class2 { css settings; } ... ".

      This string may then be imported directly into another stylesheet, either replacing content or adding to it.

      Parameters:
      className - one or more CSS-class names to get the declaration for
      Returns:
      the CSS declaration for the passed className
    • filterCssText

      public String filterCssText(String... className)
      Returns all styles for the passed className or array of classNames. The output is a single compound string in the format ".class1 { css settings; } .class2 { css settings; } ... ".

      This string may then be imported directly into another stylesheet, either replacing content or adding to it.

      Parameters:
      className - one or more CSS-class names to get the declaration for
      Returns:
      the CSS declaration for the passed className
    • getClassList

      public String[] getClassList()
      Returns the list of CSS class-names defined in this handler's stylesheet.
      Returns:
      the list of CSS class-names defined in the stylesheet
    • injectCssText

      public boolean injectCssText(String cssText)
      Injects text defining a block of selectors into this handler's stylesheet.

      The passed 'cssText' string should contain one or more selectors, each in the format '.className [, className ...] { css settings; }'. Use modifyClass(className, cssText-without-braces) to apply styles to a specific CSS class.

      Parameters:
      cssText - string of css selectors and their settings to apply to this handler's stylesheet.
      Returns:
      returns true if CSS was injected, false otherwise
    • injectSheet

      public void injectSheet()
      Create this handler's stylesheet element in the DOM.
    • loaded

      public boolean loaded()
      Has this handler's styleSheet been loaded into the DOM?
      Returns:
      true if this handler's stylesheet is currently loaded into the DOM
    • modifyClass

      public boolean modifyClass(String className, String cssText)
      Inject a string of css settings into a single CSS class, via a new rule in this handler's stylesheet.

      The passed 'cssText' should contain semi-colon -separated CSS settings only, not the selector/className or enclosing braces - { }.

      Parameters:
      className - name of the CSS class to apply the cssText to
      cssText - string of css settings to apply to the passed className in this handler's stylesheet.
      Returns:
      returns true if CSS was applied, false otherwise
    • removeClass

      public boolean removeClass(String className)
      Remove the passed CSS class from the stylesheet, by deleting it's rules and pruning it from multi-class selectors.
      Parameters:
      className - name of the CSS class to remove from the stylesheet
      Returns:
      returns true if CSS was removed, false otherwise
    • renameClass

      public boolean renameClass(String oldName, String newName)
      Rename the passed oldClass to newClass in all rules that reference it.
      Parameters:
      oldName - name of the CSS class to rename in the stylesheet
      newName - new name for the CSS class
      Returns:
      returns true if a class was renamed, false otherwise
    • unload

      public void unload()
      Remove this handler's stylesheet from the DOM and destroy it.