NextApp Echo
App Container 1.0.5

nextapp.echoservlet
Class ComponentStyle

java.lang.Object
  extended bynextapp.echoservlet.ComponentStyle
All Implemented Interfaces:
java.io.Serializable

public class ComponentStyle
extends java.lang.Object
implements java.io.Serializable

A CSS style handler for a ComponentPeer.

This class has an unusual design as it is intended to minimize the number of CSS style definitions generated for a given HTML document. Minimizing the number of styles is necessary as, if an independent style were to be generated for each and every component, more complex documents would have a ridiculous quantity of CSS code.

To create a ComponentPeer that will render a component using a CSS style generated by ComponentStyle you must follow this procedure:

  1. Create a ComponentStyle for your ComponentPeer:
  2. Add additional attributes to the style if necessary:
  3. Add any element types that will use the style:
  4. Add the style to the HtmlDocument in which your component's HTML code will be rendered (and take note of its resulting assigned name):
  5. Reference the style from elements that use it by setting the "class" attribute:
Styles must be added using this sequence of operations. Once a style has been added to a document it may not be modified. The reason for this is that the container will attempt to reuse styles for other components.

See Also:
Serialized Form

Field Summary
private  java.util.Map attributes
           
private  nextapp.echo.Color background
           
private  java.lang.String backgroundImage
           
private  java.util.Set elements
           
private  nextapp.echo.Font font
           
private  nextapp.echo.Color foreground
           
private  ComponentStyle forwardingStyle
           
private  int id
           
static java.lang.String PERCENT_UNITS
          A unit suffix for percent units.
static java.lang.String PIXEL_UNITS
          A unit suffix for pixel units.
static java.lang.String POINT_UNITS
          A unit suffix for point units.
private  java.util.Map pseudonyms
           
private static java.lang.String STYLE_PREFIX
          A prefix which will be appended to all style names.
 
Constructor Summary
ComponentStyle()
           
 
Method Summary
 void addAttribute(java.lang.String name, int value)
          Adds an integer attribute to the style.
 void addAttribute(java.lang.String name, int value, java.lang.String units)
          Adds an integer attribute and units to the style.
 void addAttribute(java.lang.String name, java.lang.String value)
          Adds a text attribute to the style.
 void addElementType(java.lang.String name)
          Adds an element type to the style.
(package private)  void addElementTypesOfStyle(ComponentStyle style)
          Adds all element types that are present in another style.
 void addPseudoAttribute(java.lang.String pseudonym, java.lang.String name, int value)
          Adds an integer attribute to a pseudoclass of the style.
 void addPseudoAttribute(java.lang.String pseudonym, java.lang.String name, java.lang.String value)
          Adds an attribute to a pseudoclass of the style.
 boolean equals(java.lang.Object o)
           
static ComponentStyle forComponent(ComponentPeer componentPeer)
          Creates and returns a ComponentStyle object for the provided ComponentPeer.
static ComponentStyle forComponent(ComponentPeer componentPeer, boolean findBackground)
          Creates and returns a ComponentStyle object for the provided ComponentPeer, optionally searching its ancestors to find a background color if it does not provide one.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of the specified attribute.
static java.lang.String getColorHexValue(nextapp.echo.Color color)
          Converts a color to a seven character hexadecimal string of the form #RRGGBB
(package private)  java.lang.String getName()
          Returns the name of the style.
 int hashCode()
           
 void setBackground(nextapp.echo.Color background)
          Sets the background color of the style.
 void setBackgroundImage(java.lang.String backgroundImage)
          Sets the background image of the style.
 void setFont(nextapp.echo.Font font)
          Sets the font of the style.
 void setForeground(nextapp.echo.Color foreground)
          Sets the foreground color of the style.
 void setHorizontalAlignment(int horizontalAlignment)
          Sets the horizontal text alignment of the style based on a value from the nextapp.echo.EchoConstants class.
(package private)  void setId(int id)
          Sets the identifier of the style.
 void setVerticalAlignment(int verticalAlignment)
          Sets the vertical text alignment of the style based on a value from the nextapp.echo.EchoConstants class.
(package private)  Style toStyle()
          Renders a CSS representation of the style.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STYLE_PREFIX

private static final java.lang.String STYLE_PREFIX
A prefix which will be appended to all style names. Style names will consist of this prefix supplemented by an Id.

See Also:
Constant Field Values

PERCENT_UNITS

public static final java.lang.String PERCENT_UNITS
A unit suffix for percent units.

See Also:
Constant Field Values

PIXEL_UNITS

public static final java.lang.String PIXEL_UNITS
A unit suffix for pixel units.

See Also:
Constant Field Values

POINT_UNITS

public static final java.lang.String POINT_UNITS
A unit suffix for point units.

See Also:
Constant Field Values

font

private nextapp.echo.Font font

foreground

private nextapp.echo.Color foreground

background

private nextapp.echo.Color background

backgroundImage

private java.lang.String backgroundImage

elements

private java.util.Set elements

attributes

private java.util.Map attributes

pseudonyms

private java.util.Map pseudonyms

id

private int id

forwardingStyle

private ComponentStyle forwardingStyle
Constructor Detail

ComponentStyle

public ComponentStyle()
Method Detail

forComponent

public static ComponentStyle forComponent(ComponentPeer componentPeer)
Creates and returns a ComponentStyle object for the provided ComponentPeer.

Parameters:
componentPeer - The peer for which the style is to be generated.
Returns:
A ComponentStyle instance suitable for the given ComponentPeer.

forComponent

public static ComponentStyle forComponent(ComponentPeer componentPeer,
                                          boolean findBackground)
Creates and returns a ComponentStyle object for the provided ComponentPeer, optionally searching its ancestors to find a background color if it does not provide one. The handling of background colors is a special case because most of the time styles will only specify a background color if a component explicitly has its own background color set. This is necessary for proper aesthetics.

Parameters:
componentPeer - The peer for which the style is to be generated.
findBackground - If true, the component's ancestors will be searched upward from the specified component until a background color is found. This background color will be explicitly specified in the style's CSS output.
Returns:
A ComponentStyle instance suitable for the given ComponentPeer.

getColorHexValue

public static java.lang.String getColorHexValue(nextapp.echo.Color color)
Converts a color to a seven character hexadecimal string of the form #RRGGBB

Parameters:
color - The color to be converted.
Returns:
A presentation of the color in the format #RRGGBB.

addAttribute

public void addAttribute(java.lang.String name,
                         java.lang.String value)
Adds a text attribute to the style.

Parameters:
name - The name of the attribute.
value - The attribute's value.

addAttribute

public void addAttribute(java.lang.String name,
                         int value)
Adds an integer attribute to the style.

Parameters:
name - The name of the attribute.
value - The attribute's value.

addAttribute

public void addAttribute(java.lang.String name,
                         int value,
                         java.lang.String units)
Adds an integer attribute and units to the style.

Parameters:
name - The name of the attribute.
value - The attribute's value.
units - The units of the value.

addElementType

public void addElementType(java.lang.String name)
Adds an element type to the style.

Parameters:
name - The name of the element type to add. Common element type names are available from the nextapp.echoservlet.html.ElemenetNames class.

addElementTypesOfStyle

void addElementTypesOfStyle(ComponentStyle style)
Adds all element types that are present in another style.

Parameters:
style - The style whose element types are to be retrieved and added to this style's list of element types.

addPseudoAttribute

public void addPseudoAttribute(java.lang.String pseudonym,
                               java.lang.String name,
                               java.lang.String value)
Adds an attribute to a pseudoclass of the style.

Parameters:
pseudonym - The name of the pseudoclass (e.g. hover, visited, etc).
name - The name of the attribute.
value - The attribute's value.

addPseudoAttribute

public void addPseudoAttribute(java.lang.String pseudonym,
                               java.lang.String name,
                               int value)
Adds an integer attribute to a pseudoclass of the style.

Parameters:
pseudonym - The name of the pseudoclass (e.g. hover, visited, etc).
name - The name of the attribute.
value - The attribute's value.

equals

public boolean equals(java.lang.Object o)
See Also:
Object.equals(java.lang.Object)

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value of the specified attribute.

Parameters:
name - The name of an attribute.
Returns:
The named attribute's value, or null if the attribute is not set.

getName

java.lang.String getName()
Returns the name of the style.


hashCode

public int hashCode()
See Also:
Object.hashCode()

setBackground

public void setBackground(nextapp.echo.Color background)
Sets the background color of the style.

Parameters:
background - The new background color.

setBackgroundImage

public void setBackgroundImage(java.lang.String backgroundImage)
Sets the background image of the style.

Parameters:
backgroundImage - The new background image.

setFont

public void setFont(nextapp.echo.Font font)
Sets the font of the style.

Parameters:
font - The new font.

setHorizontalAlignment

public void setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal text alignment of the style based on a value from the nextapp.echo.EchoConstants class.

Parameters:
horizontalAlignment - The horizontal text alignment, one of the following values:
  • EchoConstants.LEFT
  • EchoConstants.CENTER
  • EchoConstants.RIGHT

setVerticalAlignment

public void setVerticalAlignment(int verticalAlignment)
Sets the vertical text alignment of the style based on a value from the nextapp.echo.EchoConstants class.

Parameters:
verticalAlignment - The vertical text alignment, one of the following values:
  • EchoConstants.TOP
  • EchoConstants.CENTER
  • EchoConstants.BOTTOM

setForeground

public void setForeground(nextapp.echo.Color foreground)
Sets the foreground color of the style.

Parameters:
foreground - The new foreground color.

setId

void setId(int id)
Sets the identifier of the style.


toStyle

Style toStyle()
Renders a CSS representation of the style.

Returns:
A CSS representation of the style.

NextApp Echo
App Container 1.0.5