public interface Stylesheet
A stylesheet associates a style to an element.
The style of an element is computed from a set a rules. A rule is the combination of a partial style with a selector.
A partial style means that all its attributes may not be set.
The selector is used to choose on which elements the style is applied based on their Java type, state, etc and a combination of these parameters.
Finally, the style of an element computed by the stylesheet is complete and may be built from several rules partial styles.
By default, every element has the same style (initial style):
Style.isComplete()
Modifier and Type | Method and Description |
---|---|
void |
addRule(Selector selector,
Style style)
Adds a rule: a style applied to the elements matching a selector.
|
Style |
getRuleStyle(Selector selector)
Gets the style associated with a selector.
|
Style |
getStyle(Element element)
Gets the style for the given element.
|
void |
removeRule(Selector selector)
Removes a rule associated with a selector.
|
void |
reset()
Resets the stylesheet to its initial state.
|
void |
resetDefaultStyle()
Resets the default style attributes to their initial value.
|
void |
setDefaultStyle(Style style)
Sets the default style.
|
@NonNull Style getStyle(@NonNull Element element)
This method should be called in the display thread to avoid concurrency issues.
element
- the element to get the style for.void setDefaultStyle(@NonNull Style style)
It will be used as the root style of the cascading resolution.
If the given style is not complete, only its set attributes override the ones in the current default style.
This method should be called in the display thread to avoid concurrency issues.
style
- the style.java.lang.NullPointerException
- if the given style is null
.void resetDefaultStyle()
This method should be called in the display thread to avoid concurrency issues.
void addRule(@NonNull Selector selector, @NonNull Style style)
If a rule already exists with the same selector, the styles are merged (the attributes of the new one override the attributes of the previous one).
This method should be called in the display thread to avoid concurrency issues.
selector
- the selector.style
- the style.java.lang.NullPointerException
- if a parameter is null
.@NonNull Style getRuleStyle(@NonNull Selector selector)
Any modification on the returned style will not affect the style in the stylesheet.
This method should be called in the display thread to avoid concurrency issues.
selector
- the selector.java.lang.NullPointerException
- if the given selector is null
.void removeRule(@NonNull Selector selector)
This method should be called in the display thread to avoid concurrency issues.
selector
- the selector.java.lang.NullPointerException
- if the given selector is null
.void reset()
This method should be called in the display thread to avoid concurrency issues.