nl.lxtreme.ols.util
Class ColorUtils

java.lang.Object
  extended by nl.lxtreme.ols.util.ColorUtils

public final class ColorUtils
extends Object

Provides some utilities for fiddling with colors.


Method Summary
static Color getContrastColor(Color aColor)
          Creates a contrasting color, based on the "perceived luminance" of the given color.
static Color getHighlightColor(Color aColor, float aFactor)
          Calculates a highlight color for the given color.
static double getPerceivedLuminance(Color aColor)
          Returns the Digital CCIR601 luminance value of the given color.
static double getStandardLuminance(Color aColor)
          Returns the Photometric/digital ITU-R luminance value of the given color.
static Color interpolate(Color aBaseColor, Color aSecondaryColor, float aDelta)
          Interpolates a gray-scale color between two given colors.
static Color parseColor(String aColor)
          Parses the given color-string into a valid Color instance.
static String toHexString(Color aColor)
          Returns the given color instance as a string in the form of RR GG BB in which RR, GG, BB are the hexadecimal representations of red, green and blue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getContrastColor

public static Color getContrastColor(Color aColor)
Creates a contrasting color, based on the "perceived luminance" of the given color.

See also: http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color , and http://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color .

Parameters:
aColor - the color to create a contrasting color for, cannot be null.
Returns:
a contrasting color, never null.

getHighlightColor

public static Color getHighlightColor(Color aColor,
                                      float aFactor)
Calculates a highlight color for the given color.

Parameters:
aColor - the color to create a highlight color for, cannot be null;
aFactor - the highlight factor to apply, >= 0.0 && <= 1.0f;
Returns:
a highlighting color, never null.

getPerceivedLuminance

public static double getPerceivedLuminance(Color aColor)
Returns the Digital CCIR601 luminance value of the given color.

Parameters:
aColor - the color to return the luminance value for, cannot be null.
Returns:
a luminance value, 0.0..1.0.

getStandardLuminance

public static double getStandardLuminance(Color aColor)
Returns the Photometric/digital ITU-R luminance value of the given color.

Parameters:
aColor - the color to return the luminance value for, cannot be null.
Returns:
a luminance value, 0.0..1.0.

interpolate

public static Color interpolate(Color aBaseColor,
                                Color aSecondaryColor,
                                float aDelta)
Interpolates a gray-scale color between two given colors.

Parameters:
aBaseColor -
aSecondaryColor -
aDelta -
Returns:

parseColor

public static final Color parseColor(String aColor)
Parses the given color-string into a valid Color instance.

A color-string has the following form: [#]rrggbb where rr, gg and bb are the hexadecimal color values for red, green and blue. The string may optionally start with a hashpound sign.

Parameters:
aColor - the color string to parse as color, cannot be null.
Returns:
the Color-instance matching the given color, never null.

toHexString

public static String toHexString(Color aColor)
Returns the given color instance as a string in the form of RR GG BB in which RR, GG, BB are the hexadecimal representations of red, green and blue.

Parameters:
aColor - the color to return as a string value, cannot be null .
Returns:
the string representing the given color.
See Also:
parseColor(String)


Copyright © 2012 L'Xtreme IT consultancy. All Rights Reserved.