Java DTV API 1.3
18-Nov-2009

com.sun.dtv.lwuit.plaf
Class Style

java.lang.Object
  extended by com.sun.dtv.lwuit.plaf.Style

public class Style
extends Object

Represents the look of a given component: colors, fonts, transparency, margin and padding & images.

Each Component contains a Style Object and allows Style modification in Runtime by Using cmp.getStyle() The style is also used in Theming, when a Theme is Changed the Styles Objects are been updated automatically.

When changing a theme the elements changed manually in a style will not be updated by the theme change by default. There are two ways to change that behavior:

  1. Use the set method that accepts a second boolean argument and set it to true.
  2. Create a new style object and pass all the options in the constructor (without invoking setters manually).

The Margin and Padding is inspired by W3 Box Model


       **************************
       *         Margin         *
       *  ********************  *
       *  *      Padding     *  *
       *  *    ***********   *  *
       *  *    * Content *   *  *
       *  *    ***********   *  *
       *  *      Padding     *  *
       *  ********************  *
       *         Margin         *
       **************************


Field Summary
static String BG_COLOR
          Background color attribute name for the theme hashtable.
static String BG_IMAGE
          Background image attribute name for the theme hashtable.
static String BG_SELECTION_COLOR
          Background selection color attribute name for the theme hashtable.
static String BORDER
          Border attribute name for the theme hashtable.
static String FG_COLOR
          Foreground color attribute name for the theme hashtable.
static String FG_SELECTION_COLOR
          Foreground color attribute name for the theme hashtable.
static String FONT
          Font attribute name for the theme hashtable.
static String MARGIN
          Margin attribute name for the theme hashtable.
static String PADDING
          Padding attribute name for the theme hashtable.
static String SCALED_IMAGE
          Scaled image attribute name for the theme hashtable.
static String TRANSPARENCY
          Transparency attribute name for the theme hashtable.
 
Constructor Summary
Style()
          Each component when it draw itself uses this Object to determine in what colors it should use.
Style(Color fgColor, Color bgColor, Color fgSelectionColor, Color bgSelectionColor, Font f, byte transparency)
          Creates a new style with the given attributes.
Style(Color fgColor, Color bgColor, Color fgSelectionColor, Color bgSelectionColor, Font f, byte transparency, Image im, boolean scaledImage)
          Creates a new style with the given attributes.
Style(Style style)
          Creates a full copy of the given style.
 
Method Summary
 void addStyleListener(StyleListener l)
          Adds a Style Listener to the Style Object.
 Color getBgColor()
          Returns the background color for the component.
 Image getBgImage()
          Returns the background image for the component.
 Painter getBgPainter()
          Return the background painter for this style, normally this would be the internal image/color painter but can be user defined.
 Color getBgSelectionColor()
          Returns the background selection color for the component.
 byte getBgTransparency()
          Returns the transparency level of the Component.
 Border getBorder()
          Returns the border for the style.
 Color getFgColor()
          Returns the foreground color for the component.
 Color getFgSelectionColor()
          Returns the foreground selection color for the component.
 Font getFont()
          Returns the font for the component.
 int getMargin(int orientation)
          Returns the Margin.
 int getPadding(int orientation)
          Returns the Padding.
 boolean isModified()
          Returns true if the style was modified manually after it was created by the look and feel.
 boolean isScaleImage()
          Indicates whether the image in the background is scaled.
 void merge(Style style)
          Merges the new style with the current style without changing the elements that were modified.
 void removeStyleListener(StyleListener l)
          Removes a Style Listener from the Style Object.
 void setBgColor(Color bgColor)
          Sets the background color for the component.
 void setBgColor(Color bgColor, boolean override)
          Sets the background color for the component.
 void setBgImage(Image bgImage)
          Sets the background image for the component.
 void setBgImage(Image bgImage, boolean override)
          Sets the background image for the component.
 void setBgPainter(Painter bgPainter)
          Defines the background painter for this style, normally this would be the internal image/color painter but can be user defined.
 void setBgSelectionColor(Color bgSelectionColor)
          Sets the background selection color for the component.
 void setBgSelectionColor(Color bgSelectionColor, boolean override)
          Sets the background selection color for the component.
 void setBgTransparency(byte transparency)
          Sets the Component transparency level.
 void setBgTransparency(int transparency)
          Sets the Component transparency level.
 void setBgTransparency(int transparency, boolean override)
          Sets the Component transparency level.
 void setBorder(Border border)
          Sets the border for the style.
 void setBorder(Border border, boolean override)
          Sets the border for the style.
 void setFgColor(Color fgColor)
          Sets the foreground color for the component.
 void setFgColor(Color fgColor, boolean override)
          Sets the foreground color for the component.
 void setFgSelectionColor(Color fgSelectionColor)
          Sets the foreground selection color for the component.
 void setFgSelectionColor(Color fgSelectionColor, boolean override)
          Sets the foreground selection color for the component.
 void setFont(Font font)
          Sets the font for the component.
 void setFont(Font font, boolean override)
          Sets the font for the component.
 void setMargin(int orientation, int gap)
          Sets the Style Margin.
 void setMargin(int orientation, int gap, boolean override)
          Sets the Style Margin.
 void setMargin(int top, int bottom, int left, int right)
          Sets the Style Margin.
 void setPadding(int orientation, int gap)
          Sets the Style Padding.
 void setPadding(int orientation, int gap, boolean override)
          Sets the Style Padding.
 void setPadding(int top, int bottom, int left, int right)
          Sets the Style Padding.
 void setScaleImage(boolean scaleImage)
          Set to true if the image in the background is scaled, false if it is tiled.
 void setScaleImage(boolean scaleImage, boolean override)
          Set to true if the image in the background is scaled, false if it is tiled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BG_COLOR

public static final String BG_COLOR
Background color attribute name for the theme hashtable.

See Also:
Constant Field Values

FG_COLOR

public static final String FG_COLOR
Foreground color attribute name for the theme hashtable.

See Also:
Constant Field Values

BG_IMAGE

public static final String BG_IMAGE
Background image attribute name for the theme hashtable.

See Also:
Constant Field Values

BG_SELECTION_COLOR

public static final String BG_SELECTION_COLOR
Background selection color attribute name for the theme hashtable.

See Also:
Constant Field Values

FG_SELECTION_COLOR

public static final String FG_SELECTION_COLOR
Foreground color attribute name for the theme hashtable.

See Also:
Constant Field Values

FONT

public static final String FONT
Font attribute name for the theme hashtable.

See Also:
Constant Field Values

SCALED_IMAGE

public static final String SCALED_IMAGE
Scaled image attribute name for the theme hashtable.

See Also:
Constant Field Values

TRANSPARENCY

public static final String TRANSPARENCY
Transparency attribute name for the theme hashtable.

See Also:
Constant Field Values

MARGIN

public static final String MARGIN
Margin attribute name for the theme hashtable.

See Also:
Constant Field Values

BORDER

public static final String BORDER
Border attribute name for the theme hashtable.

See Also:
Constant Field Values

PADDING

public static final String PADDING
Padding attribute name for the theme hashtable.

See Also:
Constant Field Values
Constructor Detail

Style

public Style()
Each component when it draw itself uses this Object to determine in what colors it should use. When a Component is generated it construct a default Style Object. The Default values for each Component can be changed by using the UIManager class


Style

public Style(Style style)
Creates a full copy of the given style. Notice that if the original style was modified manually (by invoking setters on it) it would not change when changing a theme/look and feel, however this newly created style would change in such a case.

Parameters:
style - the style to be copied

Style

public Style(Color fgColor,
             Color bgColor,
             Color fgSelectionColor,
             Color bgSelectionColor,
             Font f,
             byte transparency)
Creates a new style with the given attributes.

Parameters:
fgColor - foreground color
bgColor - background color
fgSelectionColor - foreground selection color
bgSelectionColor - background selection color
f - font
transparency - transparency level

Style

public Style(Color fgColor,
             Color bgColor,
             Color fgSelectionColor,
             Color bgSelectionColor,
             Font f,
             byte transparency,
             Image im,
             boolean scaledImage)
Creates a new style with the given attributes.

Parameters:
fgColor - foreground color
bgColor - background color
fgSelectionColor - foreground selection color
bgSelectionColor - background selection color
f - font
transparency - transparency level
im - underlying image
scaledImage - indicates whether image is scaled
Method Detail

merge

public void merge(Style style)
Merges the new style with the current style without changing the elements that were modified.

Parameters:
style - new values of styles from the current theme

isModified

public boolean isModified()
Returns true if the style was modified manually after it was created by the look and feel. If the style was modified manually (by one of the set methods) then it should be merged rather than overwritten.

Returns:
true if modified, false otherwise

getBgColor

public Color getBgColor()
Returns the background color for the component.

Returns:
the background color for the component
See Also:
setBgColor(java.awt.Color)

getBgImage

public Image getBgImage()
Returns the background image for the component.

Returns:
the background image for the component
See Also:
setBgImage(com.sun.dtv.lwuit.Image)

getFgColor

public Color getFgColor()
Returns the foreground color for the component.

Returns:
the foreground color for the component
See Also:
setFgColor(java.awt.Color)

getFont

public Font getFont()
Returns the font for the component.

Returns:
the font for the component
See Also:
setFont(com.sun.dtv.lwuit.Font)

setBgColor

public void setBgColor(Color bgColor)
Sets the background color for the component.

Parameters:
bgColor - RRGGBB color that ignores the alpha component
See Also:
getBgColor()

setBgImage

public void setBgImage(Image bgImage)
Sets the background image for the component.

Parameters:
bgImage - the image
See Also:
getBgImage()

setFgColor

public void setFgColor(Color fgColor)
Sets the foreground color for the component.

Parameters:
fgColor - the color
See Also:
getFgColor()

setFont

public void setFont(Font font)
Sets the font for the component.

Parameters:
font - the font
See Also:
getFont()

getBgSelectionColor

public Color getBgSelectionColor()
Returns the background selection color for the component.

Returns:
the background selection color for the component
See Also:
setBgSelectionColor(java.awt.Color)

setBgSelectionColor

public void setBgSelectionColor(Color bgSelectionColor)
Sets the background selection color for the component.

Parameters:
bgSelectionColor - the color
See Also:
getBgSelectionColor()

getFgSelectionColor

public Color getFgSelectionColor()
Returns the foreground selection color for the component.

Returns:
the foreground selection color for the component
See Also:
setFgSelectionColor(java.awt.Color)

setFgSelectionColor

public void setFgSelectionColor(Color fgSelectionColor)
Sets the foreground selection color for the component.

Parameters:
fgSelectionColor - the color
See Also:
getFgSelectionColor()

isScaleImage

public boolean isScaleImage()
Indicates whether the image in the background is scaled.

Returns:
true if the image in the background is scaled, false if it is tiled
See Also:
setScaleImage(boolean)

setScaleImage

public void setScaleImage(boolean scaleImage)
Set to true if the image in the background is scaled, false if it is tiled.

Parameters:
scaleImage - value indicating whether the image in the background is scaled
See Also:
isScaleImage()

getBgTransparency

public byte getBgTransparency()
Returns the transparency level of the Component.

Returns:
the transparency level of the Component
See Also:
setBgTransparency(byte)

setBgTransparency

public void setBgTransparency(byte transparency)
Sets the Component transparency level.

Parameters:
transparency - transparency level as byte
See Also:
getBgTransparency()

setBgTransparency

public void setBgTransparency(int transparency)
Sets the Component transparency level. Valid values should be a number between 0-255.

Parameters:
transparency - int value between 0-255
See Also:
getBgTransparency()

setPadding

public void setPadding(int top,
                       int bottom,
                       int left,
                       int right)
Sets the Style Padding.

Parameters:
top - number of pixels to pad
bottom - number of pixels to pad
left - number of pixels to pad
right - number of pixels to pad
See Also:
getPadding(int)

setPadding

public void setPadding(int orientation,
                       int gap)
Sets the Style Padding.

Parameters:
orientation - one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
gap - number of pixels to pad
See Also:
getPadding(int)

setMargin

public void setMargin(int top,
                      int bottom,
                      int left,
                      int right)
Sets the Style Margin.

Parameters:
top - number of margin pixels
bottom - number of margin pixels
left - number of margin pixels
right - number of margin pixels
See Also:
getMargin(int)

setMargin

public void setMargin(int orientation,
                      int gap)
Sets the Style Margin.

Parameters:
orientation - one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
gap - number of margin pixels
See Also:
getMargin(int)

getPadding

public int getPadding(int orientation)
Returns the Padding.

Parameters:
orientation - one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
Returns:
number of padding pixels in the given orientation
See Also:
setPadding(int, int)

getMargin

public int getMargin(int orientation)
Returns the Margin.

Parameters:
orientation - one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
Returns:
number of margin pixels in the given orientation
See Also:
setMargin(int, int)

setBgColor

public void setBgColor(Color bgColor,
                       boolean override)
Sets the background color for the component.

Parameters:
bgColor - RRGGBB color that ignores the alpha component
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getBgColor()

setBgImage

public void setBgImage(Image bgImage,
                       boolean override)
Sets the background image for the component.

Parameters:
bgImage - the image
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getBgImage()

setFgColor

public void setFgColor(Color fgColor,
                       boolean override)
Sets the foreground color for the component.

Parameters:
fgColor - the color
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getFgColor()

setFont

public void setFont(Font font,
                    boolean override)
Sets the font for the component.

Parameters:
font - the font
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getFont()

setBgSelectionColor

public void setBgSelectionColor(Color bgSelectionColor,
                                boolean override)
Sets the background selection color for the component.

Parameters:
bgSelectionColor - the color
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getBgSelectionColor()

setFgSelectionColor

public void setFgSelectionColor(Color fgSelectionColor,
                                boolean override)
Sets the foreground selection color for the component.

Parameters:
fgSelectionColor - the color
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getFgSelectionColor()

setScaleImage

public void setScaleImage(boolean scaleImage,
                          boolean override)
Set to true if the image in the background is scaled, false if it is tiled.

Parameters:
scaleImage - value indicating whether the image in the background is scaled
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
isScaleImage()

setBgTransparency

public void setBgTransparency(int transparency,
                              boolean override)
Sets the Component transparency level. Valid values should be a number between 0-255.

Parameters:
transparency - the transparency level
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getBgTransparency()

setPadding

public void setPadding(int orientation,
                       int gap,
                       boolean override)
Sets the Style Padding.

Parameters:
orientation - one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
gap - number of pixels to pad
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getPadding(int)

setMargin

public void setMargin(int orientation,
                      int gap,
                      boolean override)
Sets the Style Margin.

Parameters:
orientation - one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
gap - number of margin pixels
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getMargin(int)

addStyleListener

public void addStyleListener(StyleListener l)
Adds a Style Listener to the Style Object.

Parameters:
l - a style listener
See Also:
removeStyleListener(com.sun.dtv.lwuit.events.StyleListener)

removeStyleListener

public void removeStyleListener(StyleListener l)
Removes a Style Listener from the Style Object.

Parameters:
l - a style listener
See Also:
addStyleListener(com.sun.dtv.lwuit.events.StyleListener)

setBorder

public void setBorder(Border border)
Sets the border for the style.

Parameters:
border - new border object for the component
See Also:
getBorder()

setBorder

public void setBorder(Border border,
                      boolean override)
Sets the border for the style.

Parameters:
border - new border object for the component
override - If set to true allows the look and feel/theme to override the value in this attribute when changing a theme/look and feel
See Also:
getBorder()

getBorder

public Border getBorder()
Returns the border for the style.

Returns:
the border
See Also:
setBorder(com.sun.dtv.lwuit.plaf.Border)

getBgPainter

public Painter getBgPainter()
Return the background painter for this style, normally this would be the internal image/color painter but can be user defined.

Returns:
the painter
See Also:
setBgPainter(com.sun.dtv.lwuit.Painter)

setBgPainter

public void setBgPainter(Painter bgPainter)
Defines the background painter for this style, normally this would be the internal image/color painter but can be user defined.

Parameters:
bgPainter - new painter to install into the style
See Also:
getBgPainter()

Java DTV API 1.3
18-Nov-2009

Copyright © 2008-2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Use of this document is subject to license terms.