public class Styles
extends java.lang.Object
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:
For example, an ElementId of "A.B.C" would refer to an Attribute hierarchy from most specific to least specific, as:
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..
Modifier and Type | Field and Description |
---|---|
static ElementId |
DEFAULT_ELEMENT |
static java.lang.String |
ROOT_STYLE |
Constructor and Description |
---|
Styles() |
Modifier and Type | Method and Description |
---|---|
void |
applyStyles(java.lang.Object o,
ElementId elementId) |
void |
applyStyles(java.lang.Object o,
ElementId elementId,
java.lang.String style) |
void |
applyStyles(java.lang.Object o,
java.lang.String elementId)
Deprecated.
|
void |
applyStyles(java.lang.Object o,
java.lang.String elementId,
java.lang.String style)
Deprecated.
|
void |
clearCache() |
protected java.lang.Object |
clone(java.lang.Object value,
com.jme3.util.clone.Cloner cloner) |
protected java.util.List<java.lang.Object> |
cloneList(java.util.List<java.lang.Object> source,
com.jme3.util.clone.Cloner cloner) |
protected java.util.Map<java.lang.Object,java.lang.Object> |
cloneMap(java.util.Map<java.lang.Object,java.lang.Object> source,
com.jme3.util.clone.Cloner cloner) |
Attributes |
getAttributes(ElementId elementId)
Retrieves the compiled attributes for the specified element ID
and default style.
|
Attributes |
getAttributes(ElementId elementId,
java.lang.String style)
Retrieves the compiled attributes for the specified element ID
and style.
|
Attributes |
getAttributes(java.lang.String elementId)
Retrieves the compiled attributes for the specified element ID
and default style.
|
Attributes |
getAttributes(java.lang.String elementId,
java.lang.String style)
Retrieves the compiled attributes for the specified element ID
and style.
|
<T> T |
getDefault(java.lang.Class<T> type) |
java.lang.String |
getDefaultStyle() |
protected java.lang.Object |
getExistingValue(java.lang.Object o,
java.lang.reflect.Method m) |
Attributes |
getSelector(ElementId parent,
ElementId child,
java.lang.String style) |
Attributes |
getSelector(ElementId id,
java.lang.String style) |
Attributes |
getSelector(ElementId parent,
java.lang.String child,
java.lang.String style) |
Attributes |
getSelector(java.lang.String style) |
Attributes |
getSelector(java.lang.String parent,
ElementId child,
java.lang.String style) |
Attributes |
getSelector(java.lang.String id,
java.lang.String style) |
Attributes |
getSelector(java.lang.String parent,
java.lang.String child,
java.lang.String style) |
protected static java.util.List<java.lang.reflect.Method> |
getStyleAttributeMethods(java.lang.Class c) |
protected StyleTree |
getTree(java.lang.String style,
boolean create) |
void |
initializeStyles(java.lang.Class c) |
static void |
main(java.lang.String... args) |
void |
setDefault(java.lang.Object value) |
void |
setDefaultStyle(java.lang.String style)
Sets the default style that is used by GUI elements when no other
style is specified.
|
protected java.lang.String |
styleKey(ElementId elementId,
java.lang.String style) |
public static final java.lang.String ROOT_STYLE
public static final ElementId DEFAULT_ELEMENT
public void setDefaultStyle(java.lang.String style)
public java.lang.String getDefaultStyle()
public void clearCache()
public void setDefault(java.lang.Object value)
public <T> T getDefault(java.lang.Class<T> type)
public Attributes getAttributes(ElementId elementId)
public Attributes getAttributes(ElementId elementId, java.lang.String style)
public Attributes getAttributes(java.lang.String elementId)
public Attributes getAttributes(java.lang.String elementId, java.lang.String style)
protected java.lang.String styleKey(ElementId elementId, java.lang.String style)
protected StyleTree getTree(java.lang.String style, boolean create)
public Attributes getSelector(java.lang.String style)
public Attributes getSelector(ElementId id, java.lang.String style)
public Attributes getSelector(java.lang.String id, java.lang.String style)
public Attributes getSelector(ElementId parent, ElementId child, java.lang.String style)
public Attributes getSelector(ElementId parent, java.lang.String child, java.lang.String style)
public Attributes getSelector(java.lang.String parent, ElementId child, java.lang.String style)
public Attributes getSelector(java.lang.String parent, java.lang.String child, java.lang.String style)
public static void main(java.lang.String... args)
public void initializeStyles(java.lang.Class c)
protected java.lang.Object getExistingValue(java.lang.Object o, java.lang.reflect.Method m)
protected static java.util.List<java.lang.reflect.Method> getStyleAttributeMethods(java.lang.Class c)
@Deprecated public void applyStyles(java.lang.Object o, java.lang.String elementId)
@Deprecated public void applyStyles(java.lang.Object o, java.lang.String elementId, java.lang.String style)
public void applyStyles(java.lang.Object o, ElementId elementId)
public void applyStyles(java.lang.Object o, ElementId elementId, java.lang.String style)
protected java.lang.Object clone(java.lang.Object value, com.jme3.util.clone.Cloner cloner)
protected java.util.Map<java.lang.Object,java.lang.Object> cloneMap(java.util.Map<java.lang.Object,java.lang.Object> source, com.jme3.util.clone.Cloner cloner)
protected java.util.List<java.lang.Object> cloneList(java.util.List<java.lang.Object> source, com.jme3.util.clone.Cloner cloner)