de.matthiasmann.twl.textarea
Class Style

java.lang.Object
  extended by de.matthiasmann.twl.textarea.Style
Direct Known Subclasses:
CSSStyle

public class Style
extends java.lang.Object

Stores the styles which should be applied to a certain element.


Constructor Summary
  Style()
          Creates an empty Style without a parent, class reference and no attributes
protected Style(Style src)
           
  Style(Style parent, StyleSheetKey styleSheetKey)
          Creates an Style with the given parent and class reference.
  Style(Style parent, StyleSheetKey styleSheetKey, java.util.Map<StyleAttribute<?>,java.lang.Object> values)
          Creates an Style with the given parent and class reference and copies the given attributes.
 
Method Summary
protected  void ensureValues()
           
<V> V
get(StyleAttribute<V> attribute, StyleSheetResolver resolver)
          Retrives the value of the specified attribute from the resolved style.
<V> V
getNoResolve(StyleAttribute<V> attribute, StyleSheetResolver resolver)
          Retrives the value of the specified attribute without resolving the style.
 Style getParent()
          Returns the parent of this Style or null.
<V> V
getRaw(StyleAttribute<V> attribute)
          Retrives the value of the specified attribute without resolving the style.
 StyleSheetKey getStyleSheetKey()
          Returns the style sheet key for this Style or null.
protected  void put(StyleAttribute<?> attribute, java.lang.Object value)
           
protected  void putAll(java.util.Map<StyleAttribute<?>,java.lang.Object> values)
           
protected  void putAll(Style src)
           
protected  java.lang.Object rawGet(int idx)
           
 Style resolve(StyleAttribute<?> attribute, StyleSheetResolver resolver)
          Resolves the Style in which the specified attribute is defined.
 java.util.Map<StyleAttribute<?>,java.lang.Object> toMap()
          Creates a map which will contain all set attributes of this Style.
 Style with(java.util.Map<StyleAttribute<?>,java.lang.Object> values)
          Creates a copy of this Style and sets the specified attributes.
<V> Style
with(StyleAttribute<V> attribute, V value)
          Creates a copy of this Style and sets the specified attributes.
 Style withoutNonInheritable()
          Returns a Style which doesn't contain any value for an attribute where StyleAttribute.isInherited() returns false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Style

public Style()
Creates an empty Style without a parent, class reference and no attributes


Style

public Style(Style parent,
             StyleSheetKey styleSheetKey)
Creates an Style with the given parent and class reference.

Parameters:
parent - the parent style. Can be null.
styleSheetKey - key for style sheet lookup. Can be null.

Style

public Style(Style parent,
             StyleSheetKey styleSheetKey,
             java.util.Map<StyleAttribute<?>,java.lang.Object> values)
Creates an Style with the given parent and class reference and copies the given attributes.

Parameters:
parent - the parent style. Can be null.
styleSheetKey - key for style sheet lookup. Can be null.
values - a map with attributes for this Style. Can be null.

Style

protected Style(Style src)
Method Detail

resolve

public Style resolve(StyleAttribute<?> attribute,
                     StyleSheetResolver resolver)
Resolves the Style in which the specified attribute is defined. If a attribute does not cascade then this method does nothing. If a StyleSheetResolver is specified then this method will treat style sheet styles referenced by this Style as if they are part of a Style in this chain.

Parameters:
attribute - The attribute to lookup.
resolver - A StyleSheetResolver to resolve the style sheet key. Can be null.
Returns:
The Style which defined the specified attribute, will never return null.
See Also:
StyleAttribute.isInherited(), getParent()

getNoResolve

public <V> V getNoResolve(StyleAttribute<V> attribute,
                          StyleSheetResolver resolver)
Retrives the value of the specified attribute without resolving the style. If the attribute is not set in this Style and a StyleSheetResolver was specified then the lookup is continued in the style sheet.

Type Parameters:
V - The data type of the attribute
Parameters:
attribute - The attribute to lookup.
resolver - A StyleSheetResolver to resolve the style sheet key. Can be null.
Returns:
The attribute value if it was set, or the default value of the attribute.

get

public <V> V get(StyleAttribute<V> attribute,
                 StyleSheetResolver resolver)
Retrives the value of the specified attribute from the resolved style.

Type Parameters:
V - The data type of the attribute
Parameters:
attribute - The attribute to lookup.
resolver - A StyleSheetResolver to resolve the style sheet key. Can be null.
Returns:
The attribute value if it was set, or the default value of the attribute.
See Also:
resolve(de.matthiasmann.twl.textarea.StyleAttribute, de.matthiasmann.twl.textarea.StyleSheetResolver), getNoResolve(de.matthiasmann.twl.textarea.StyleAttribute, de.matthiasmann.twl.textarea.StyleSheetResolver)

getRaw

public <V> V getRaw(StyleAttribute<V> attribute)
Retrives the value of the specified attribute without resolving the style.

Type Parameters:
V - The data type of the attribute
Parameters:
attribute - The attribute to lookup.
Returns:
the attribute value or null (no default value)

getParent

public Style getParent()
Returns the parent of this Style or null. The parent is used to lookup attributes which can be inherited and are not specified in this Style.

Returns:
the parent of this Style or null.
See Also:
StyleAttribute.isInherited()

getStyleSheetKey

public StyleSheetKey getStyleSheetKey()
Returns the style sheet key for this Style or null. It is used to lookup attributes which are not set in this Style.

Returns:
the style sheet key this Style or null.

with

public Style with(java.util.Map<StyleAttribute<?>,java.lang.Object> values)
Creates a copy of this Style and sets the specified attributes. It is possible to set a attribute to null to 'unset' it.

Parameters:
values - The attributes to set in the new Style.
Returns:
a new Style with the same parent, styleSheetKey and modified attributes.

with

public <V> Style with(StyleAttribute<V> attribute,
                      V value)
Creates a copy of this Style and sets the specified attributes. It is possible to set a attribute to null to 'unset' it.

Type Parameters:
V - The data type of the attribute
Parameters:
attribute - The attribute to set.
value - The new value of that attribute. Can be null.
Returns:
a new Style with the same parent, styleSheetKey and modified attribute.

withoutNonInheritable

public Style withoutNonInheritable()
Returns a Style which doesn't contain any value for an attribute where StyleAttribute.isInherited() returns false.

Returns:
a Style with the same parent, styleSheetKey and modified attribute.

put

protected void put(StyleAttribute<?> attribute,
                   java.lang.Object value)

putAll

protected final void putAll(java.util.Map<StyleAttribute<?>,java.lang.Object> values)

putAll

protected final void putAll(Style src)

ensureValues

protected final void ensureValues()

rawGet

protected final java.lang.Object rawGet(int idx)

toMap

public java.util.Map<StyleAttribute<?>,java.lang.Object> toMap()
Creates a map which will contain all set attributes of this Style. Changes to that map have no impact on this Style.

Returns:
a map which will contain all set attributes of this Style.