com.miginfocom.util.gfx
Class UIColor

java.lang.Object
  extended by java.awt.Color
      extended by com.miginfocom.util.gfx.UIColor
All Implemented Interfaces:
java.awt.Paint, java.awt.Transparency, java.io.Serializable

public class UIColor
extends java.awt.Color

A subclass to Color that stores it's value as string for later decoding to a Color depending of the UI and platform. Also supports brighter/darker tinting of the named color and the possibility to force the alpha channel to a specific value.
Since a Color is immutable the colorName is converted to a specific color at construction and never changed after that. After Persistence the color is recreated in the new context depending on the Look&Feel and platform when de-persisting.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.awt.Color
black, BLACK, blue, BLUE, cyan, CYAN, DARK_GRAY, darkGray, gray, GRAY, green, GREEN, LIGHT_GRAY, lightGray, magenta, MAGENTA, orange, ORANGE, pink, PINK, red, RED, white, WHITE, yellow, YELLOW
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
UIColor(java.lang.String colorName)
          Creates a color from a string associated with this color.
UIColor(java.lang.String colorName, java.lang.Float tint, java.lang.Integer forcedAlpha)
          Creates a color from a string associated with this color.
 
Method Summary
static java.awt.Color decodeToColor(java.lang.String colorName)
          Uses the text to decode the color.
static java.awt.Color decodeToColor(java.lang.String colorName, java.lang.Float tint, java.lang.Integer forcedAlpha)
          Uses the text to decode the color.
static int decodeToRGBA(java.lang.String colorName)
          Uses the text to decode the color.
static int decodeToRGBA(java.lang.String colorName, java.lang.Float tint, java.lang.Integer forcedAlpha)
          Convert costructor arguments to an int color.
 java.lang.String getColorName()
          Returns the name associated with this color.
static java.lang.String[] getColorStrings()
          Return the color string keys that the current UI stores a Color for.
 java.lang.Integer getForcedAlpha()
          Returns the tint used for making the color darker or brighter.
 java.lang.Float getTint()
          Returns the tint used for making the color darker or brighter.
 
Methods inherited from class java.awt.Color
brighter, createContext, darker, decode, equals, getAlpha, getBlue, getColor, getColor, getColor, getColorComponents, getColorComponents, getColorSpace, getComponents, getComponents, getGreen, getHSBColor, getRed, getRGB, getRGBColorComponents, getRGBComponents, getTransparency, hashCode, HSBtoRGB, RGBtoHSB, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UIColor

public UIColor(java.lang.String colorName)
Creates a color from a string associated with this color. E.g. Button.background or controlDkShadow.

Parameters:
colorName - The color string. Not null.
See Also:
UIManager.getLookAndFeelDefaults()

UIColor

public UIColor(java.lang.String colorName,
               java.lang.Float tint,
               java.lang.Integer forcedAlpha)
Creates a color from a string associated with this color. E.g. Button.background or controlDkShadow.

Parameters:
colorName - The color string. Not null.
tint - The tint used for making the color darker or brighter. Between -1f and 1f, respectively. 0f means unchanged. null leaves the color unchanged (I.e. No tint).
forcedAlpha - The alpha of the color. 0..255. 255 is fully opaque. null leaves the alpha unchanged.
See Also:
GfxUtil.tintColor(java.awt.Color, float), UIManager.getLookAndFeelDefaults()
Method Detail

getColorName

public java.lang.String getColorName()
Returns the name associated with this color. E.g. Button.background or controlDkShadow.

Returns:
The color UI name (key).

getTint

public java.lang.Float getTint()
Returns the tint used for making the color darker or brighter.

Returns:
The tint used for making the color darker or brighter. Between -1f and 1f, respectively. 0f means unchanged.

getForcedAlpha

public java.lang.Integer getForcedAlpha()
Returns the tint used for making the color darker or brighter.

Returns:
The tint used for making the color darker or brighter. Between -1f and 1f, respectively. 0f means unchanged.

decodeToRGBA

public static int decodeToRGBA(java.lang.String colorName,
                               java.lang.Float tint,
                               java.lang.Integer forcedAlpha)
Convert costructor arguments to an int color.

Parameters:
colorName - The color string. Not null.
tint - negative darkens, positive brightens. Between -1f and 1f.
forcedAlpha - The alpha of the color. 0..255. 255 is fully opaque. null leaves the alpha unchanged.
Returns:
The int of the found color or black (not tinted) if unknown (0).

decodeToRGBA

public static final int decodeToRGBA(java.lang.String colorName)
Uses the text to decode the color. Currently the color can be a reference to a UI default and system color.
E.g. Button.background or controlDkShadow.

Parameters:
colorName - The color string. Not null.
Returns:
The int of the found color or black if unknown (0).

decodeToColor

public static final java.awt.Color decodeToColor(java.lang.String colorName)
Uses the text to decode the color. Currently the color can be a reference to a UI default and system color.
E.g. Button.background or controlDkShadow.

Parameters:
colorName - The color string. Not null.
Returns:
The Color for the found color or null if unknown or null is stored.

decodeToColor

public static final java.awt.Color decodeToColor(java.lang.String colorName,
                                                 java.lang.Float tint,
                                                 java.lang.Integer forcedAlpha)
Uses the text to decode the color. Currently the color can be a reference to a UI default and system color.
E.g. Button.background or controlDkShadow.

Parameters:
colorName - The color string. Not null.
forcedAlpha - The alpha of the color. 0..255. 255 is fully opaque. null leaves the alpha unchanged.
Returns:
The Color for the found color or null if unknown or null is stored.

getColorStrings

public static java.lang.String[] getColorStrings()
Return the color string keys that the current UI stores a Color for. Can be used to populate a combo box for instance.

Returns:
Some color strings. E.g. Button.background or controlDkShadow. Never null.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.