org.formaria.aria.style
Class Style

java.lang.Object
  extended by org.formaria.aria.style.Style
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
StyleEx

public class Style
extends java.lang.Object
implements java.lang.Cloneable

A style for storing information about the look of a component. Information such as font (face, size, bold, italic), color (fore, back).

Copyright (c) Formaria Ltd., 2008
License: see license.txt $Revision: 2.5 $


Field Summary
static int COLOR_BACK
          The component back color style
static int COLOR_FORE
          The component fore color style
static int FONT_FACE
          The font face/family style
static int FONT_ITALIC
          The font italic style
static int FONT_SIZE
          The font size style
static int FONT_WEIGHT
          The font weight (bold) style
static int NUM_DEFAULT_STYLES
           
protected  java.lang.Object[] values
           
 
Constructor Summary
Style()
          Create a new style object
 
Method Summary
 java.lang.Object clone()
          Create a copy of this component
 java.lang.Integer getFontHashcode()
          Gets the font hashcode
 int getNumStyles()
          Get the number of styles managed by this style object
 java.awt.Color getStyleAsColor(int key)
          Retrieve a style element as a Color.
 int getStyleAsInt(int key)
          Retrieve a style element as an int.
 java.lang.String getStyleAsString(int key)
          Retrieve a style element as a String.
 int getStyleIndex(java.lang.String name)
          Gets a integer constant corresponding to a style name
 java.lang.String getStyleName(int idx)
          Get the name of a style
 java.lang.Object getStyleValue(int key)
          Retrieve a style element as an object.
 void mergeStyle(Style newStyle)
          For applying a hierarchy of styles to a new Style.
static java.lang.Object parseColor(java.lang.String temp)
          Parse a color string
 void setClosed(boolean state)
          Mark the style as closed.
 void setNumStyles(int num)
          Set the number of styles.
 void setStyle(int key, int value)
          Set a style element.
 void setStyle(int key, java.lang.Object value)
          Set a style element.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FONT_FACE

public static final int FONT_FACE
The font face/family style

See Also:
Constant Field Values

FONT_SIZE

public static final int FONT_SIZE
The font size style

See Also:
Constant Field Values

FONT_WEIGHT

public static final int FONT_WEIGHT
The font weight (bold) style

See Also:
Constant Field Values

FONT_ITALIC

public static final int FONT_ITALIC
The font italic style

See Also:
Constant Field Values

COLOR_BACK

public static final int COLOR_BACK
The component back color style

See Also:
Constant Field Values

COLOR_FORE

public static final int COLOR_FORE
The component fore color style

See Also:
Constant Field Values

NUM_DEFAULT_STYLES

public static final int NUM_DEFAULT_STYLES
See Also:
Constant Field Values

values

protected java.lang.Object[] values
Constructor Detail

Style

public Style()
Create a new style object

Method Detail

setNumStyles

public void setNumStyles(int num)
Set the number of styles. The current data is copied to the new style array. The number of styles can only be increased with this method so as to prevent any loss of data.

Parameters:
num - the number of new parameters

getNumStyles

public int getNumStyles()
Get the number of styles managed by this style object

Returns:
The number of styles being managed

setClosed

public void setClosed(boolean state)
Mark the style as closed. A closed style cannot accept any more style attributes


getStyleIndex

public int getStyleIndex(java.lang.String name)
Gets a integer constant corresponding to a style name

Parameters:
name - the style name e.g. "font_face"
Returns:
the style constant e.g. Style.FONT_FACE

getStyleName

public java.lang.String getStyleName(int idx)
Get the name of a style

Parameters:
idx - the style index
Returns:
the style name

clone

public java.lang.Object clone()
Create a copy of this component

Overrides:
clone in class java.lang.Object
Returns:
the copy

setStyle

public void setStyle(int key,
                     java.lang.Object value)
Set a style element.

Parameters:
key - The index of the element
value - The Object value of the element

setStyle

public void setStyle(int key,
                     int value)
Set a style element.

Parameters:
key - The index of the element
value - The int value of the element

getStyleAsInt

public int getStyleAsInt(int key)
Retrieve a style element as an int.

Parameters:
key - The index of the style required
Returns:
The style converted to an int

getStyleAsString

public java.lang.String getStyleAsString(int key)
Retrieve a style element as a String.

Parameters:
key - The index of the style required
Returns:
The style converted to a String

getStyleValue

public java.lang.Object getStyleValue(int key)
Retrieve a style element as an object.

Parameters:
key - The index of the style required
Returns:
The style value

getStyleAsColor

public java.awt.Color getStyleAsColor(int key)
Retrieve a style element as a Color.

Parameters:
key - The index of the style required
Returns:
The style converted to a Color

mergeStyle

public void mergeStyle(Style newStyle)
For applying a hierarchy of styles to a new Style. Only apply the style if it's found.

Parameters:
newStyle - the style to merge with the current object.

getFontHashcode

public java.lang.Integer getFontHashcode()
Gets the font hashcode

Returns:
the hashcode

parseColor

public static java.lang.Object parseColor(java.lang.String temp)
Parse a color string

Parameters:
temp - the color string as either hex or decimal rgb
Returns:
the color.