public class IlvContrastingColor extends Color implements Composite
Note: This class can only be used in graphic objects and renderers that have explicit support for it. Most graphic objects and renderers in JViews do not support it.
Note: In order to add support for IlvContrastingColor
to a drawing routine with a background filled entirely with a known color,
the following code template can be used:
Color backgroundColor = ...; Graphics2D g = ...; Color oldPaint = g.getPaint(); try { g.setPaint(contrastingColor.chooseColor(backgroundColor); ... } finally { g.setPaint(oldPaint); }
Note: In order to add support for IlvContrastingColor
to a drawing routine with an unknown background, the following code template
can be used:
Color backgroundColor = ...; Graphics2D g = ...; Color oldPaint = g.getPaint(); Composite oldComposite = g.getComposite(); try { g.setPaint(Color.black); g.setComposite(contrastingColor); ... } finally { g.setPaint(oldPaint); g.setComposite(oldComposite); }
Note: IlvContrastingColor
is a custom implementation of
Composite
. Due to Sun JRE bug #4833528, custom
Composite
s work only when rendering into a
BufferedImage
. This is the case
sun.java2d.pmoffscreen
is set to false
,
orBufferedImage
.
Modifier and Type | Field and Description |
---|---|
static RenderingHints.Key |
KNOWN_BACKGROUND_COLOR
This rendering hint can be set on a
Graphics2D to indicate
a known background 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
BITMASK, OPAQUE, TRANSLUCENT
Constructor and Description |
---|
IlvContrastingColor()
Creates a contrasting color with default settings.
|
IlvContrastingColor(Color darkColor,
Color brightColor,
float threshold)
Creates a contrasting color with the given dark and bright color.
|
Modifier and Type | Method and Description |
---|---|
Color |
chooseColor(Color backgroundColor)
Returns the appropriate color for a given background color.
|
CompositeContext |
createContext(ColorModel srcColorModel,
ColorModel dstColorModel,
RenderingHints hints)
This method implements the
Composite interface. |
Color |
getBrightColor()
Returns the color used in front of dark background.
|
Color |
getDarkColor()
Returns the color used in front of bright background.
|
float |
getThreshold()
Returns the brightness limit used to distinguish whether the background
is considered as bright or dark.
|
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
public static final RenderingHints.Key KNOWN_BACKGROUND_COLOR
Graphics2D
to indicate
a known background color. The possible values are instances of
java.awt.Color
and null
.public IlvContrastingColor(Color darkColor, Color brightColor, float threshold)
darkColor
- The color to use in front of bright background.brightColor
- The color to use in front of dark background.threshold
- The brightness limit used to distinguish whether the
background is considered as bright or dark. This is
a value between 0 and 1.public IlvContrastingColor()
public Color getDarkColor()
public Color getBrightColor()
public float getThreshold()
public Color chooseColor(Color backgroundColor)
getDarkColor()
, getBrightColor()
.public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints)
Composite
interface.createContext
in interface Composite
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.