public class CascadingStylesheet extends Object implements Stylesheet
This stylesheet contains:
The style of a widget is determined following these steps:
getSelectorStyle(Selector)
),Widget.getParent()
),getDefaultStyle()
).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()
).
Modifier and Type | Field and 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 and Description |
---|
CascadingStylesheet()
Creates a new cascading stylesheet.
|
Modifier and Type | Method and 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.
|
public static final int BACKGROUND_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int BORDER_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int COLOR_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic 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.
public static final int DIMENSION_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int EXTRA_FIELD_1_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int EXTRA_FIELD_2_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int EXTRA_FIELD_3_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int EXTRA_FIELD_4_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int EXTRA_FIELD_5_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int EXTRA_FIELD_6_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int EXTRA_FIELD_7_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int FONT_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int HORIZONTAL_ALIGNMENT_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int MARGIN_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int PADDING_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic static final int VERTICAL_ALIGNMENT_INDEX
getStyleSources(Style)
,
Constant Field Valuespublic CascadingStylesheet()
public EditableStyle getDefaultStyle()
This style is used as the root style of the cascading resolution. Its initial attributes are equal to the values
defined in DefaultStyle
.
public EditableStyle getSelectorStyle(Selector selector)
This style is applied to the widgets matching the selector.
selector
- the selector.public Style getStyle(Widget widget)
Stylesheet
getStyle
in interface Stylesheet
widget
- the widget to get the style for.@Nullable public static Selector[] getStyleSources(Style 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).
style
- the style to get the sources forIllegalArgumentException
- if the given style does not come from a CascadingStylesheet
public void reset()
public void resetDefaultStyle()
public void resetSelectorStyle(Selector selector)
selector
- the selector.