Package ej.mwt.stylesheet.cascading
Class CascadingStylesheet
- java.lang.Object
-
- ej.mwt.stylesheet.cascading.CascadingStylesheet
-
- All Implemented Interfaces:
Stylesheet
public class CascadingStylesheet extends java.lang.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:
- create an empty result style (no attributes set),
- merge widget with matching selectors rules (set by
getSelectorStyle(Selector)
), - recursively merge with inherited attributes of parents (repeat previous step for parent recursively) (see
Widget.getParent()
), - merge global style (set by
getDefaultStyle()
).
Style
). The result style is complete at the end of the resolution.
-
-
Constructor Summary
Constructors Constructor Description CascadingStylesheet()
Creates a new cascading stylesheet.
-
Method Summary
All 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.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.
-
-
-
Method Detail
-
getStyle
public Style getStyle(Widget widget)
Description copied from interface:Stylesheet
Gets the style for a widget.- Specified by:
getStyle
in interfaceStylesheet
- 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.
-
-