Class Styles
The attributes that are available for a given GUI element are based on the StyleAttribute annotations specified on the class. StyleAttribute setters expose style attributes that can be set in an Attributes set.
Attributes are accessed by selector that is a simplified version of the way cascading style sheets work. A selector can either by the raw style name, a specific element ID for a style, or a parent/child relationship for a style. A particular element may inherit from one or more of these depending on how its element ID is setup.
In normal cascading style sheets, the parent/child relationship between elements is based on the full page hierarchy. In Lemur's Style system, parent/child relationships are limited to the dotted notation with an element ID itself. So an element ID of "button" has no parent/child relationship. An element ID of "slider.thumb.button" has direct parent/child relationships between "slider"/"thumb" and "thumb"/"button", and an intrinsic parent/child relationship between "slider"/"button".
Attribute sets are built in such a way that they inherit attributes up this parent/child hierarchy. Most specific styles override less specific ones. The precendence goes roughly in the following order:
- Specific element ID, fully qualified
- For every dotted part, from right to left, all parent/child relationships and then the element ID for that dotted part.
- The global settings for the particular style.
For example, an ElementId of "A.B.C" would refer to an Attribute hierarchy from most specific to least specific, as:
- A.B.C
- B contains C
- A contains C
- C
- A contains B
- B
- style-defaults
This is "font" is accessed for "A.B.C" the configured Attribute sets are checked for a "font" attribute in the order listed above. The first one found wins.
The values of the attributes are set based on a selector similar to the specific steps listed above. For example, a style's attributes can be specifically set for "A.B.C" or can be set for any case of "A contains C". These attribute sets are accessed using the getSelector() methods and return a non-hierarchical, selector-specific attribute set.
To retrieve attributes for a GUI element, the getAttributes() methods are used. These return a full hierarchy of attribute sets as described above.
Using this system, an application could easily configure style-global attributes while also overriding the defaults for specific cases. For example, if the application is defining a "beveled" style, it might set the default "font" for all style="beveled" elements. It might then set the default background for all style="beveled", element="button" elements. At that point, all labels, text fields, and text entry fields would be using the specified font. All buttons, whether they are in sliders, scroll bars, or on their own, would have the specified background. The application could then define settings for "any button in a slider" with getSelector( "slider", "button", "beveled" ) or even get more specific and target "slider"/"thumb" directly or any "thumb"/"button" that might exist in sliders or scrollbars, etc..
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyStyles
(Object o, ElementId elementId) void
applyStyles
(Object o, ElementId elementId, String style) void
applyStyles
(Object o, String elementId) Deprecated.void
applyStyles
(Object o, String elementId, String style) Deprecated.void
protected Object
getAttributes
(ElementId elementId) Retrieves the compiled attributes for the specified element ID and default style.getAttributes
(ElementId elementId, String style) Retrieves the compiled attributes for the specified element ID and style.getAttributes
(String elementId) Retrieves the compiled attributes for the specified element ID and default style.getAttributes
(String elementId, String style) Retrieves the compiled attributes for the specified element ID and style.<T> T
getDefault
(Class<T> type) protected Object
getExistingValue
(Object o, Method m) getSelector
(ElementId parent, ElementId child, String style) getSelector
(ElementId id, String style) getSelector
(ElementId parent, String child, String style) getSelector
(String style) getSelector
(String parent, ElementId child, String style) getSelector
(String id, String style) getSelector
(String parent, String child, String style) protected StyleTree
void
static void
void
setDefault
(Object value) void
setDefaultStyle
(String style) Sets the default style that is used by GUI elements when no other style is specified.protected String
-
Field Details
-
ROOT_STYLE
- See Also:
-
DEFAULT_ELEMENT
-
-
Constructor Details
-
Styles
public Styles()
-
-
Method Details
-
setDefaultStyle
Sets the default style that is used by GUI elements when no other style is specified. This is an easy way to provide a common look to the entire user interface without having to pass styles to every created component. Defaults to the root style. -
getDefaultStyle
-
clearCache
public void clearCache() -
setDefault
-
getDefault
-
getAttributes
Retrieves the compiled attributes for the specified element ID and default style. The attributes are compiled based on the selector rules and attributes setup prior to this call. -
getAttributes
Retrieves the compiled attributes for the specified element ID and style. The attributes are compiled based on the selector rules and attributes setup prior to this call. -
getAttributes
Retrieves the compiled attributes for the specified element ID and default style. The attributes are compiled based on the selector rules and attributes setup prior to this call. -
getAttributes
Retrieves the compiled attributes for the specified element ID and style. The attributes are compiled based on the selector rules and attributes setup prior to this call. -
styleKey
-
getTree
-
getSelector
-
getSelector
-
getSelector
-
getSelector
-
getSelector
-
getSelector
-
getSelector
-
main
-
initializeStyles
-
getExistingValue
-
getStyleAttributeMethods
-
applyStyles
Deprecated. -
applyStyles
Deprecated. -
applyStyles
-
applyStyles
-
clone
-
cloneMap
-
cloneList
-