NextApp Echo
App Container 1.1.4

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
static int EXPLICIT_SET_ALL
          A constant used in the options attribute of constructors to explicitly determine the font, foreground, and background (based on traversing component hierarchy) and set it using CSS.
static int EXPLICIT_SET_BACKGROUND
          A constant used in the options attribute of constructors to explicitly determine the background color (based on traversing component hierarchy) and set it using CSS.
static int EXPLICIT_SET_FONT
          A constant used in the options attribute of constructors to explicitly determine the font (based on traversing component hierarchy) and set it using CSS.
static int EXPLICIT_SET_FOREGROUND
          A constant used in the options attribute of constructors to explicitly determine the foreground color (based on traversing component hierarchy) and set it using CSS.
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.
 
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.
 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)
          Deprecated. Use the forComponent(ComponentPeer, int) factory method. Invoking it with an options value of EXPLICIT_SET_BACKGROUND will have the same effect as using this constructor with findBackground true.
static ComponentStyle forComponent(ComponentPeer componentPeer, int options)
          Creates and returns a ComponentStyle object for the provided ComponentPeer.
 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
 boolean hasAttributes()
          Returns true if the style has any attributes set.
 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.
 void setVerticalAlignment(int verticalAlignment)
          Sets the vertical text alignment of the style based on a value from the nextapp.echo.EchoConstants class.
 java.lang.String toString()
          Prints state information (for debugging use).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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

EXPLICIT_SET_BACKGROUND

public static final int EXPLICIT_SET_BACKGROUND
A constant used in the options attribute of constructors to explicitly determine the background color (based on traversing component hierarchy) and set it using CSS.

See Also:
Constant Field Values

EXPLICIT_SET_FOREGROUND

public static final int EXPLICIT_SET_FOREGROUND
A constant used in the options attribute of constructors to explicitly determine the foreground color (based on traversing component hierarchy) and set it using CSS.

See Also:
Constant Field Values

EXPLICIT_SET_FONT

public static final int EXPLICIT_SET_FONT
A constant used in the options attribute of constructors to explicitly determine the font (based on traversing component hierarchy) and set it using CSS.

See Also:
Constant Field Values

EXPLICIT_SET_ALL

public static final int EXPLICIT_SET_ALL
A constant used in the options attribute of constructors to explicitly determine the font, foreground, and background (based on traversing component hierarchy) and set it using CSS.

See Also:
Constant Field Values
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)
Deprecated. Use the forComponent(ComponentPeer, int) factory method. Invoking it with an options value of EXPLICIT_SET_BACKGROUND will have the same effect as using this constructor with findBackground true.

Creates and returns a ComponentStyle object for the provided ComponentPeer.

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.

forComponent

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

Parameters:
componentPeer - The peer for which the style is to be generated.
options - A bitmask indicating options to use when creating the style.
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.

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.

hasAttributes

public boolean hasAttributes()
Returns true if the style has any attributes set. This method will return true if the foreground, background, font, backgroundImage, or custom attributes are set.

Returns:
True if the style has any attributes set.

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.

toString

public java.lang.String toString()
Prints state information (for debugging use).

See Also:
Object.toString()

NextApp Echo
App Container 1.1.4