de.enough.polish.ui
Class Style

java.lang.Object
  extended by de.enough.polish.ui.Style
All Implemented Interfaces:
Externalizable, Serializable

public class Style
extends Object
implements Externalizable

Style defines the design of any widget.

This class is used by the widgets. If you only use the predefined widgets you do not need to work with this class.

Author:
Robert Virkus, robert@enough.de
 history
        04-Jan-2004 - rob creation
 

Field Summary
 Background background
           
 Border border
           
 String dynamicName
           
static Boolean FALSE
           
 int layout
           
 String name
          The name of this style.
static Boolean TRUE
           
 
Constructor Summary
Style()
          Creates a new style with default settings
Style(int marginLeft, int marginRight, int marginTop, int marginBottom, int paddingLeft, int paddingRight, int paddingTop, int paddingBottom, int paddingVertical, int paddingHorizontal, int layout, int fontColor, Color fontColorObj, Font font, Background background, Border border, short[] attributeKeys, Object[] attributeValues)
          Creates a new Style.
Style(int marginLeft, int marginRight, int marginTop, int marginBottom, int paddingLeft, int paddingRight, int paddingTop, int paddingBottom, int paddingVertical, int paddingHorizontal, int layout, int fontColor, Font font, Background background, Border border, short[] attributeKeys, Object[] attributeValues)
          Creates a new Style.
Style(String name, int layout, Background background, Border border, short[] attributeKeys, Object[] attributeValues)
          Creates a new Style
Style(String name, int layout, Background background, Border border, short[] attributeKeys, Object[] attributeValues, CssAnimation[] animations)
          Creates a new Style when CSS animations are active.
Style(Style style)
          Creates a new style by creating a deep copy of the given style
 
Method Summary
 void addAttribute(int key, Object value)
          Adds the specified attribute to this style, possibly replacing a previous set value
 void addAttribute(String key, Object value)
          Adds the specified attribute to this style, possibly replacing a previous set value.
 Style clone(boolean deepCopy)
          Creates a copy of this style.
 void extendStyle(Style style)
           
 int getAnchor()
          Translates the layout into a Graphics form.
 int getAnchorForText()
          Translates the layout into a Graphics form.
 int getAnchorHorizontal()
          Translates the horizontal layout into a Graphics form.
 CssAnimation[] getAnimations()
          Retrieves all registered animations Note that this method is only defined when css animations are being used.
 Boolean getBooleanProperty(String propName)
          Retrieves a non-standard boolean property of this style.
 Color getColorProperty(String propName)
          Retrieves a non-standard color property of this style.
 Font getFont()
          Retrieves the font associated with this style
 int getFontColor()
          Retrieves the font color that should be used.
 Integer getIntProperty(String propName)
          Retrieves a non-standard integer property of this style.
 int getLayout()
          Retrieves the layout of this style
 int getMarginBottom(int height)
          Looks up the bottom margin value and falls back to the default margin value.
 int getMarginLeft(int width)
          Looks up the left margin value and falls back to the default margin value.
 int getMarginRight(int width)
          Looks up the right margin value and falls back to the default margin value.
 int getMarginTop(int height)
          Looks up the top margin value and falls back to the default margin value.
 Object getObjectProperty(int key)
           
 Object getObjectProperty(String propName)
          Retrieves a non-standard property of this style.
 int getPaddingBottom(int height)
          Looks up the bottom padding value and falls back to the default padding value.
 int getPaddingHorizontal(int width)
          Looks up the horizontal padding value and falls back to the default padding value.
 int getPaddingLeft(int width)
          Looks up the left padding value and falls back to the default padding value.
 int getPaddingRight(int width)
          Looks up the right padding value and falls back to the default padding value.
 int getPaddingTop(int height)
          Looks up the top padding value and falls back to the default padding value.
 int getPaddingVertical(int height)
          Looks up the vertical padding value and falls back to the default padding value.
 String getProperty(String propName)
          Retrieves a non-standard property of this style.
 short[] getRawAttributeKeys()
          Retrieves the internal attribute keys
 Object[] getRawAttributeValues()
          Retrieves the internal attribute values that are defined in this style.
 void read(DataInputStream in)
          Reads this style from an InputStream
 void releaseResources()
          Releases all (memory intensive) resources such as images or RGB arrays of this style.
 void removeAttribute(int key)
          Removes the specified attribute from this style.
 void removeAttribute(String key)
          Removes the specified attribute from this style.
 void write(DataOutputStream out)
          Writes this style to an OutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE

public static final Boolean TRUE

FALSE

public static final Boolean FALSE

name

public transient String name
The name of this style.


dynamicName

public transient String dynamicName

background

public Background background

border

public Border border

layout

public int layout
Constructor Detail

Style

public Style()
Creates a new style with default settings


Style

public Style(Style style)
Creates a new style by creating a deep copy of the given style

Parameters:
style - the style

Style

public Style(int marginLeft,
             int marginRight,
             int marginTop,
             int marginBottom,
             int paddingLeft,
             int paddingRight,
             int paddingTop,
             int paddingBottom,
             int paddingVertical,
             int paddingHorizontal,
             int layout,
             int fontColor,
             Font font,
             Background background,
             Border border,
             short[] attributeKeys,
             Object[] attributeValues)
Creates a new Style.

Parameters:
marginLeft - the margin in pixels to the next element on the left
marginRight - the margin in pixels to the next element on the right
marginTop - the margin in pixels to the next element on the top
marginBottom - the margin in pixels to the next element on the bottom
paddingLeft - the padding between the left border and content in pixels
paddingRight - the padding between the right border and content in pixels
paddingTop - the padding between the top border and content in pixels
paddingBottom - the padding between the bottom border and content in pixels
paddingVertical - the vertical padding between internal elements of an item
paddingHorizontal - the horizontal padding between internal elements of an item
layout - the layout for this style, e.g. Item.LAYOUT_CENTER
fontColor - the color of the font
font - the content-font for this style
background - the background for this style
border - the border for this style
attributeKeys - the integer-IDs of any additional attributes. Can be null.
attributeValues - the values of any additional attributes. Can be null.

Style

public Style(int marginLeft,
             int marginRight,
             int marginTop,
             int marginBottom,
             int paddingLeft,
             int paddingRight,
             int paddingTop,
             int paddingBottom,
             int paddingVertical,
             int paddingHorizontal,
             int layout,
             int fontColor,
             Color fontColorObj,
             Font font,
             Background background,
             Border border,
             short[] attributeKeys,
             Object[] attributeValues)
Creates a new Style.

Parameters:
marginLeft - the margin in pixels to the next element on the left
marginRight - the margin in pixels to the next element on the right
marginTop - the margin in pixels to the next element on the top
marginBottom - the margin in pixels to the next element on the bottom
paddingLeft - the padding between the left border and content in pixels
paddingRight - the padding between the right border and content in pixels
paddingTop - the padding between the top border and content in pixels
paddingBottom - the padding between the bottom border and content in pixels
paddingVertical - the vertical padding between internal elements of an item
paddingHorizontal - the horizontal padding between internal elements of an item
layout - the layout for this style, e.g. Item.LAYOUT_CENTER
fontColor - the color of the font
fontColorObj - the color of the font, might be a dynamic color like COLOR_FOREGROUND
font - the content-font for this style
background - the background for this style
border - the border for this style
attributeKeys - the integer-IDs of any additional attributes. Can be null.
attributeValues - the values of any additional attributes. Can be null.

Style

public Style(String name,
             int layout,
             Background background,
             Border border,
             short[] attributeKeys,
             Object[] attributeValues)
Creates a new Style

Parameters:
name - the name of the style
layout - the layout for this style, e.g. Item.LAYOUT_CENTER
background - the background for this style
border - the border for this style
attributeKeys - the integer-IDs of any additional attributes. Can be null.
attributeValues - the values of any additional attributes. Can be null.

Style

public Style(String name,
             int layout,
             Background background,
             Border border,
             short[] attributeKeys,
             Object[] attributeValues,
             CssAnimation[] animations)
Creates a new Style when CSS animations are active.

Parameters:
name - the name of the style
layout - the layout for this style, e.g. Item.LAYOUT_CENTER
background - the background for this style
border - the border for this style
attributeKeys - the integer-IDs of any additional attributes. Can be null.
attributeValues - the values of any additional attributes. Can be null.
animations - CSS animation settings
Method Detail

extendStyle

public void extendStyle(Style style)

clone

public Style clone(boolean deepCopy)
Creates a copy of this style. A shallow copy will use the same internal arrays for CSS attributes and animations, so adding an attribute will also add the attribute to this style. Note that even with a deep copy, the border and background, as well as embedded CSS attribute and animation references are kept the same.

Parameters:
deepCopy - true when arrays should be copied instead of referenced
Returns:
a style copy

getProperty

public String getProperty(String propName)
Retrieves a non-standard property of this style.

Parameters:
propName - the name of the property
Returns:
the value of this property as a String. If none has been defined, null will be returned.

getObjectProperty

public Object getObjectProperty(String propName)
Retrieves a non-standard property of this style.

Parameters:
propName - the name of the property
Returns:
the value of this property. If none has been defined, null will be returned.

getIntProperty

public Integer getIntProperty(String propName)
Retrieves a non-standard integer property of this style.

Parameters:
propName - the name of the property
Returns:
the value of this property as an Integer object. If none has been defined, null will be returned.

getColorProperty

public Color getColorProperty(String propName)
Retrieves a non-standard color property of this style.

Parameters:
propName - the name of the property
Returns:
the value of this property as an Color object. If none has been defined, null will be returned.

getBooleanProperty

public Boolean getBooleanProperty(String propName)
Retrieves a non-standard boolean property of this style.

Parameters:
propName - the name of the property
Returns:
the value of this property as an Boolean object. If none has been defined, null will be returned.

getObjectProperty

public Object getObjectProperty(int key)

getAnimations

public CssAnimation[] getAnimations()
Retrieves all registered animations Note that this method is only defined when css animations are being used. You can test this with the preprocessing symbol 'polish.css.animations'

Returns:
an array of registered animations for this style, can be null

releaseResources

public void releaseResources()
Releases all (memory intensive) resources such as images or RGB arrays of this style.


getFontColor

public int getFontColor()
Retrieves the font color that should be used. The color can be dynamic like Display.COLOR_FOREGROUND and should always be retrieved using this method instead of using the public field fontColor.

Returns:
the color for the font.

getFont

public Font getFont()
Retrieves the font associated with this style

Returns:
the font of this style, can be null if none is defined

removeAttribute

public void removeAttribute(int key)
Removes the specified attribute from this style.

Parameters:
key - the integer key of the attribute

removeAttribute

public void removeAttribute(String key)
Removes the specified attribute from this style.

Parameters:
key - the key name of the attribute

addAttribute

public void addAttribute(String key,
                         Object value)
Adds the specified attribute to this style, possibly replacing a previous set value. This method expects the property name referenced directly like "padding-top", not as a variable like propName, since the property name is converted to an integer value in the preprocessing phase.

Parameters:
key - the integer key of the attribute
value - the value of the attribute

addAttribute

public void addAttribute(int key,
                         Object value)
Adds the specified attribute to this style, possibly replacing a previous set value

Parameters:
key - the integer key of the attribute
value - the value of the attribute

getMarginLeft

public int getMarginLeft(int width)
Looks up the left margin value and falls back to the default margin value.

Parameters:
width - the corresponding available width
Returns:
the left margin or 0 if neither the left nor the normal margin is defined

getMarginRight

public int getMarginRight(int width)
Looks up the right margin value and falls back to the default margin value.

Parameters:
width - the corresponding available width
Returns:
the right margin or 0 if neither the right nor the normal margin is defined

getMarginTop

public int getMarginTop(int height)
Looks up the top margin value and falls back to the default margin value.

Parameters:
height - the corresponding available height or width - note that the CSS standard uses the width (so will J2ME Polish items) for calculating percentage values for all margins
Returns:
the top margin or 0 if neither the top nor the normal margin is defined

getMarginBottom

public int getMarginBottom(int height)
Looks up the bottom margin value and falls back to the default margin value.

Parameters:
height - the corresponding available height or width - note that the CSS standard uses the width (so will J2ME Polish items) for calculating percentage values for all margins
Returns:
the bottom margin or 0 if neither the bottom nor the normal margin is defined

getPaddingLeft

public int getPaddingLeft(int width)
Looks up the left padding value and falls back to the default padding value.

Parameters:
width - the corresponding available width
Returns:
the left padding or 0 if neither the left nor the normal padding is defined

getPaddingRight

public int getPaddingRight(int width)
Looks up the right padding value and falls back to the default padding value.

Parameters:
width - the corresponding available width
Returns:
the right padding or 0 if neither the right nor the normal padding is defined

getPaddingTop

public int getPaddingTop(int height)
Looks up the top padding value and falls back to the default padding value.

Parameters:
height - the corresponding available height or width - note that the CSS standard uses the width (so will J2ME Polish items) for calculating percentage values for all paddings
Returns:
the top padding or 0 if neither the top nor the normal padding is defined

getPaddingBottom

public int getPaddingBottom(int height)
Looks up the bottom padding value and falls back to the default padding value.

Parameters:
height - the corresponding available height or width - note that the CSS standard uses the width (so will J2ME Polish items) for calculating percentage values for all paddings
Returns:
the bottom padding or 0 if neither the bottom nor the normal padding is defined

getPaddingHorizontal

public int getPaddingHorizontal(int width)
Looks up the horizontal padding value and falls back to the default padding value.

Parameters:
width - the corresponding available width
Returns:
the horizontal padding or 0 if neither the horizontal nor the normal padding is defined

getPaddingVertical

public int getPaddingVertical(int height)
Looks up the vertical padding value and falls back to the default padding value.

Parameters:
height - the corresponding available height or width - note that the CSS standard uses the width (so will J2ME Polish items) for calculating percentage values for all paddings
Returns:
the vertical padding or 0 if neither the vertical nor the normal padding is defined

getLayout

public int getLayout()
Retrieves the layout of this style

Returns:
the layout
See Also:
Item.LAYOUT_LEFT, Item.LAYOUT_RIGHT, Item.LAYOUT_TOP, Item.LAYOUT_BOTTOM, Item.LAYOUT_CENTER, Item.LAYOUT_VCENTER, Item.LAYOUT_EXPAND, Item.LAYOUT_VEXPAND, Item.LAYOUT_SHRINK, Item.LAYOUT_VSHRINK

getAnchor

public int getAnchor()
Translates the layout into a Graphics form. Item.LAYOUT_LEFT is translated to Graphics.LEFT, for example. This method translates Item.LAYOUT_VCENTER into Graphics.VCENTER, so the resulting anchor CANNOT be used for text.

Returns:
the layout in Graphics anchor format.
See Also:
getAnchorForText(), Graphics.LEFT, Graphics.RIGHT, Graphics.HCENTER, Graphics.TOP, Graphics.BOTTOM, Graphics.VCENTER

getAnchorForText

public int getAnchorForText()
Translates the layout into a Graphics form. Item.LAYOUT_LEFT is translated to Graphics.LEFT, for example. This method translates Item.LAYOUT_VCENTER into Graphics.BASELINE, so the resulting anchor CAN be used for text.

Returns:
the layout in Graphics anchor format.
See Also:
getAnchor(), Graphics.LEFT, Graphics.RIGHT, Graphics.HCENTER, Graphics.TOP, Graphics.BOTTOM, Graphics.BASELINE

getAnchorHorizontal

public int getAnchorHorizontal()
Translates the horizontal layout into a Graphics form. Item.LAYOUT_LEFT is translated to Graphics.LEFT, for example.

Returns:
the horizontal layout in Graphics anchor format, either Graphics.LEFT, Graphics.RIGHT or Graphics.HCENTER
See Also:
getAnchor(), Graphics.LEFT, Graphics.RIGHT, Graphics.HCENTER

read

public void read(DataInputStream in)
          throws IOException
Reads this style from an InputStream

Specified by:
read in interface Externalizable
Parameters:
in - the input stream
Throws:
IOException - when reading fails

write

public void write(DataOutputStream out)
           throws IOException
Writes this style to an OutputStream

Specified by:
write in interface Externalizable
Parameters:
out - the output stream
Throws:
IOException - when writing fails

getRawAttributeKeys

public short[] getRawAttributeKeys()
Retrieves the internal attribute keys

Returns:
a short array with all the keys or null when this style has no attributes

getRawAttributeValues

public Object[] getRawAttributeValues()
Retrieves the internal attribute values that are defined in this style.

Returns:
the attribute values or none in case no attributes are defined for this style