Package com.actelion.research.util
Class ColorHelper
- java.lang.Object
-
- com.actelion.research.util.ColorHelper
-
public class ColorHelper extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ColorHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.Color
brighter(java.awt.Color c, float factor)
Creates a newColor
that is a brighter version of thisColor
.static java.awt.Color
createColor(java.awt.Color c, float perceivedBrightness)
Creates a new color with the hue taken from colorc
, but adjusted in brightness to match the desired perceived brightness.static java.awt.Color
darker(java.awt.Color c, float factor)
Creates a newColor
that is a darker version of thisColor
.static java.awt.Color
getContrastColor(java.awt.Color fg, java.awt.Color bg)
Based on the differences of hue and perceived brightness of foreground colorfg
and background colorbg
, this method checks and possibly adjusts the given foreground colorfg
such that its hue stays unchanged, but its brightness is adapted to make it better perceivable on the background.static java.awt.Color
intermediateColor(java.awt.Color c1, java.awt.Color c2, float ratio)
Creates an intermediate color between color c1 and color c2 in the RGB color space.static float
perceivedBrightness(java.awt.Color c)
This is a color's perceived brightness by the human eye
-
-
-
Method Detail
-
intermediateColor
public static java.awt.Color intermediateColor(java.awt.Color c1, java.awt.Color c2, float ratio)
Creates an intermediate color between color c1 and color c2 in the RGB color space.- Parameters:
c1
-c2
-ratio
- 0.0 -> returns c1; 1.0 -> returns c2- Returns:
- color in between c1 and c2
-
brighter
public static java.awt.Color brighter(java.awt.Color c, float factor)
Creates a newColor
that is a brighter version of thisColor
. This is a copy of Color.brighter(), but lets you choose the factor.- Parameters:
c
- the color to be brightenedfactor
- value < 1.0; Color.brighter() uses 0.7- Returns:
- a new
Color
object that is a brighter version of thisColor
with the samealpha
value.
-
darker
public static java.awt.Color darker(java.awt.Color c, float factor)
Creates a newColor
that is a darker version of thisColor
. This is a copy of Color.darker(), but lets you choose the factor.- Parameters:
c
- the color to be darkenedfactor
- value < 1.0; Color.darker() uses 0.7- Returns:
- a new
Color
object that is a darker version of thisColor
with the samealpha
value.
-
perceivedBrightness
public static float perceivedBrightness(java.awt.Color c)
This is a color's perceived brightness by the human eye- Parameters:
c
-- Returns:
- brightness from 0.0 to 1.0
-
createColor
public static java.awt.Color createColor(java.awt.Color c, float perceivedBrightness)
Creates a new color with the hue taken from colorc
, but adjusted in brightness to match the desired perceived brightness.- Parameters:
c
-perceivedBrightness
-- Returns:
-
getContrastColor
public static java.awt.Color getContrastColor(java.awt.Color fg, java.awt.Color bg)
Based on the differences of hue and perceived brightness of foreground colorfg
and background colorbg
, this method checks and possibly adjusts the given foreground colorfg
such that its hue stays unchanged, but its brightness is adapted to make it better perceivable on the background.- Parameters:
fg
- foreground colorbg
- background color // * @param minContrast the minimum desired contrast (0 to 0.5)- Returns:
- unchanged or adjusted fg
-
-