Package ej.mwt.stylesheet.cascading

## Class CascadingStylesheet

- java.lang.Object
- - ej.mwt.stylesheet.cascading.CascadingStylesheet

- All Implemented Interfaces:
    `Stylesheet`

      public class CascadingStylesheet
      extends Object
      implements Stylesheet

  Cascading stylesheet implementation strongly inspired by CSS.

  This stylesheet contains:

  - a default style that defines all the attributes,
  - a set of rules with a selector and a partial style.

  The style of a widget is determined following these steps:

  1. create an empty result style (no attributes set),
  2. merge widget with matching selectors rules (set by `getSelectorStyle(Selector)`),
  3. recursively merge with inherited attributes of parents (repeat previous step for parent recursively) (see `Widget.getParent()`),
  4. merge global style (set by `getDefaultStyle()`).
  The merge consists in completing the result style with all the set attributes of another style (see `Style`). The result style is complete at the end of the resolution.

  The implementation assumes that the style of the parent is resolved prior to the resolution of its children. It simplifies the cascading resolution because it avoids recursive resolution upward. In other words, that means that the resolution of the styles in a hierarchy must be done from top to bottom. That is the case for the widgets since `Widget.updateStyle()` is recursive (see `Container.updateStyle()`).

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `BACKGROUND_INDEX` | Background field position in the array of selectors.
    `static int` | `BORDER_INDEX` | Border field position in the array of selectors.
    `static int` | `COLOR_INDEX` | Color field position in the array of selectors.
    `static String` | `DEBUG_CASCADINGSTYLE_ENABLED_CONSTANT` | `BON boolean constant` to enable/disable the cascading stylesheet debug.
    `static int` | `DIMENSION_INDEX` | Dimension field position in the array of selectors.
    `static int` | `EXTRA_FIELD_1_INDEX` | First extra field position in the array of selectors.
    `static int` | `EXTRA_FIELD_2_INDEX` | Second extra field position in the array of selectors.
    `static int` | `EXTRA_FIELD_3_INDEX` | Third extra field position in the array of selectors.
    `static int` | `EXTRA_FIELD_4_INDEX` | Fourth extra field position in the array of selectors.
    `static int` | `EXTRA_FIELD_5_INDEX` | Fifth extra field position in the array of selectors.
    `static int` | `EXTRA_FIELD_6_INDEX` | Sixth extra field position in the array of selectors.
    `static int` | `EXTRA_FIELD_7_INDEX` | Seventh extra field position in the array of selectors.
    `static int` | `FONT_INDEX` | Font field position in the array of selectors.
    `static int` | `HORIZONTAL_ALIGNMENT_INDEX` | Horizontal alignment field position in the array of selectors.
    `static int` | `MARGIN_INDEX` | Margin field position in the array of selectors.
    `static int` | `PADDING_INDEX` | Padding field position in the array of selectors.
    `static int` | `VERTICAL_ALIGNMENT_INDEX` | Vertical alignment field position in the array of selectors.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CascadingStylesheet()` | Creates a new cascading stylesheet.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `EditableStyle` | `getDefaultStyle()` | Gets the default style.
    `EditableStyle` | `getSelectorStyle​(Selector selector)` | Gets the style for a selector.
    `Style` | `getStyle​(Widget widget)` | Gets the style for a widget.
    `static Selector[]` | `getStyleSources​(Style style)` | Gets the selectors used to create the given style.
    `void` | `reset()` | Resets the stylesheet to its initial state.
    `void` | `resetDefaultStyle()` | Resets the default style attributes to their initial value.
    `void` | `resetSelectorStyle​(Selector selector)` | Resets the style attributes for a selector.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DIMENSION_INDEX

          public static final int DIMENSION_INDEX

      Dimension field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### HORIZONTAL_ALIGNMENT_INDEX

          public static final int HORIZONTAL_ALIGNMENT_INDEX

      Horizontal alignment field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### VERTICAL_ALIGNMENT_INDEX

          public static final int VERTICAL_ALIGNMENT_INDEX

      Vertical alignment field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### MARGIN_INDEX

          public static final int MARGIN_INDEX

      Margin field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### BORDER_INDEX

          public static final int BORDER_INDEX

      Border field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### PADDING_INDEX

          public static final int PADDING_INDEX

      Padding field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### BACKGROUND_INDEX

          public static final int BACKGROUND_INDEX

      Background field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### COLOR_INDEX

          public static final int COLOR_INDEX

      Color field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### FONT_INDEX

          public static final int FONT_INDEX

      Font field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### EXTRA_FIELD_1_INDEX

          public static final int EXTRA_FIELD_1_INDEX

      First extra field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### EXTRA_FIELD_2_INDEX

          public static final int EXTRA_FIELD_2_INDEX

      Second extra field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### EXTRA_FIELD_3_INDEX

          public static final int EXTRA_FIELD_3_INDEX

      Third extra field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### EXTRA_FIELD_4_INDEX

          public static final int EXTRA_FIELD_4_INDEX

      Fourth extra field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### EXTRA_FIELD_5_INDEX

          public static final int EXTRA_FIELD_5_INDEX

      Fifth extra field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### EXTRA_FIELD_6_INDEX

          public static final int EXTRA_FIELD_6_INDEX

      Sixth extra field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### EXTRA_FIELD_7_INDEX

          public static final int EXTRA_FIELD_7_INDEX

      Seventh extra field position in the array of selectors.
      See Also:
        `getStyleSources(Style)`, Constant Field Values

    - #### DEBUG_CASCADINGSTYLE_ENABLED_CONSTANT

          public static final String DEBUG_CASCADINGSTYLE_ENABLED_CONSTANT

      `BON boolean constant` to enable/disable the cascading stylesheet debug.

      If enabled, "ej.mwt.debug.cascadingstyle.enabled" must also be set.

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CascadingStylesheet

          public CascadingStylesheet()

      Creates a new cascading stylesheet.

  - ### Method Detail

    - #### getStyle

          public Style getStyle​(Widget widget)

      Description copied from interface: `Stylesheet`
      Gets the style for a widget.
      Specified by:
        `getStyle` in interface `Stylesheet`
      Parameters:
        `widget` - the widget to get the style for.
      Returns:
        the style applied to the widget.

    - #### getDefaultStyle

          public EditableStyle getDefaultStyle()

      Gets the default style. The style can be modified.

      This style is used as the root style of the cascading resolution. Its initial attributes are equal to the values defined in `DefaultStyle`.

      Returns:
        the editable default style.

    - #### resetDefaultStyle

          public void resetDefaultStyle()

      Resets the default style attributes to their initial value.

    - #### getSelectorStyle

          public EditableStyle getSelectorStyle​(Selector selector)

      Gets the style for a selector. The style can be modified.

      This style is applied to the widgets matching the selector.

      Parameters:
        `selector` - the selector.
      Returns:
        the editable style for the given selector.

    - #### resetSelectorStyle

          public void resetSelectorStyle​(Selector selector)

      Resets the style attributes for a selector.
      Parameters:
        `selector` - the selector.

    - #### reset

          public void reset()

      Resets the stylesheet to its initial state.

    - #### getStyleSources

          @Nullable
          public static Selector[] getStyleSources​(Style style)

      Gets the selectors used to create the given style.

      The returned array contains 16 entries: one for each parameter of the style. For each entry, the selector belongs to the rule selected to fill the matching parameter. A `null` entry means that the parameter is from the default style.

      The BON boolean constant `DEBUG_CASCADINGSTYLE_ENABLED_CONSTANT` must be set to `true` for this method to work. Beware that enabling that feature may downgrade the performances (more time to compute a style and more Java heap used).

      Parameters:
        `style` - the style to get the sources for
      Returns:
        the array of selectors
      Throws:
        `IllegalArgumentException` - if the given style does not come from a `CascadingStylesheet`