Package generic.theme
Class GColor
java.lang.Object
java.awt.Color
generic.theme.GColor
- All Implemented Interfaces:
Paint
,Transparency
,Serializable
- Direct Known Subclasses:
GColorUIResource
A
Color
whose value is dynamically determined by looking up its id into a global
color table that is determined by the active GTheme
.
The idea is for developers to not use specific colors in their code, but to instead use a GColor with an id that hints at its use. For example, instead of hard coding a component's background color to white by coding "component.setBackground(Color.white)", you would do something like "component.setBackground(new GColor("color.mywidget.bg"). Then in a "[module name].theme.properties" file (located in the module's data directory), you would set the default value by adding this line "color.mywidget.bg = white".
- See Also:
-
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
-
Method Summary
Modifier and TypeMethodDescriptionbrighter()
createContext
(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints) darker()
boolean
int
getAlpha()
int
getBlue()
float[]
getColorComponents
(float[] compArray) float[]
getColorComponents
(ColorSpace cspace, float[] compArray) float[]
getComponents
(float[] compArray) float[]
getComponents
(ColorSpace cspace, float[] compArray) int
getGreen()
getId()
Returns the id for this GColor.int
getRed()
int
getRGB()
float[]
getRGBColorComponents
(float[] compArray) float[]
getRGBComponents
(float[] compArray) int
int
hashCode()
boolean
Returns true if this GColor could not find a value for its color id in the current theme and is using the default color as its delegatevoid
refresh
(GThemeValueMap currentValues) Reloads the delegate.static void
refreshAll
(GThemeValueMap currentValues) Static method for notifying all the existing GColors that colors have changed and they should reload their cached indirect color.Generates a more verbose toString()Returns this color as a hex string that starts with '#'toString()
withAlpha
(int newAlpha) Creates a transparent version of this GColor.
-
Constructor Details
-
GColor
Construct a GColor with an id that will be used to look up the current color associated with that id, which can be changed at runtime.- Parameters:
id
- the id used to lookup the current value for this color
-
GColor
Copy constructor. Used primarily to convert a GColorUiResource to a GColor without having to lookup the color which can cause errors during theme transitions.- Parameters:
gColor
- the gColor to copy
-
-
Method Details
-
withAlpha
Creates a transparent version of this GColor. If the underlying value of this GColor changes, the transparent version will also change.- Parameters:
newAlpha
- the transparency level for the new color- Returns:
- a transparent version of this GColor
-
getId
Returns the id for this GColor.- Returns:
- the id for this GColor.
-
getRed
public int getRed() -
getGreen
public int getGreen() -
getBlue
public int getBlue() -
getAlpha
public int getAlpha() -
getRGB
public int getRGB() -
brighter
-
darker
-
isUnresolved
public boolean isUnresolved()Returns true if this GColor could not find a value for its color id in the current theme and is using the default color as its delegate- Returns:
- true if this GColor could not find a value for its color id in the current theme
-
toString
-
toHexString
Returns this color as a hex string that starts with '#'- Returns:
- the hex string
-
toDebugString
Generates a more verbose toString()- Returns:
- a more verbose toString()
-
hashCode
public int hashCode() -
equals
-
getRGBComponents
public float[] getRGBComponents(float[] compArray) - Overrides:
getRGBComponents
in classColor
-
getRGBColorComponents
public float[] getRGBColorComponents(float[] compArray) - Overrides:
getRGBColorComponents
in classColor
-
getComponents
public float[] getComponents(float[] compArray) - Overrides:
getComponents
in classColor
-
getColorComponents
public float[] getColorComponents(float[] compArray) - Overrides:
getColorComponents
in classColor
-
getComponents
- Overrides:
getComponents
in classColor
-
getColorComponents
- Overrides:
getColorComponents
in classColor
-
getColorSpace
- Overrides:
getColorSpace
in classColor
-
createContext
public PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints) - Specified by:
createContext
in interfacePaint
- Overrides:
createContext
in classColor
-
getTransparency
public int getTransparency()- Specified by:
getTransparency
in interfaceTransparency
- Overrides:
getTransparency
in classColor
-
refresh
Reloads the delegate.- Parameters:
currentValues
- the map of current theme values
-
refreshAll
Static method for notifying all the existing GColors that colors have changed and they should reload their cached indirect color.- Parameters:
currentValues
- the map of current theme values
-