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.Colorbrighter(java.awt.Color c, float factor)Creates a newColorthat is a brighter version of thisColor.static java.awt.ColorcreateColor(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.Colordarker(java.awt.Color c, float factor)Creates a newColorthat is a darker version of thisColor.static java.awt.ColorgetContrastColor(java.awt.Color fg, java.awt.Color bg)Based on the differences of hue and perceived brightness of foreground colorfgand background colorbg, this method checks and possibly adjusts the given foreground colorfgsuch that its hue stays unchanged, but its brightness is adapted to make it better perceivable on the background.static java.awt.ColorintermediateColor(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 floatperceivedBrightness(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 newColorthat 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
Colorobject that is a brighter version of thisColorwith the samealphavalue.
-
darker
public static java.awt.Color darker(java.awt.Color c, float factor)Creates a newColorthat 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
Colorobject that is a darker version of thisColorwith the samealphavalue.
-
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 colorfgand background colorbg, this method checks and possibly adjusts the given foreground colorfgsuch 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
-
-