org.jivesoftware.spark.util
Class ColorUtil

java.lang.Object
  extended by org.jivesoftware.spark.util.ColorUtil

public class ColorUtil
extends java.lang.Object

Common color utilities.

Author:
Jacob Dreyer

Constructor Summary
ColorUtil()
           
 
Method Summary
static java.awt.Color blend(java.awt.Color color1, java.awt.Color color2)
          Make an even blend between two colors.
static java.awt.Color blend(java.awt.Color color1, java.awt.Color color2, double ratio)
          Blend two colors.
static double colorDistance(java.awt.Color color1, java.awt.Color color2)
          Return the "distance" between two colors.
static double colorDistance(double[] color1, double[] color2)
          Return the "distance" between two colors.
static double colorDistance(double r1, double g1, double b1, double r2, double g2, double b2)
          Return the "distance" between two colors.
static java.awt.Color darker(java.awt.Color color, double fraction)
          Make a color darker.
static java.lang.String getHexName(java.awt.Color color)
          Return the hex name of a specified color.
static boolean isDark(java.awt.Color color)
          Check if a color is more dark than light.
static boolean isDark(double r, double g, double b)
          Check if a color is more dark than light.
static java.awt.Color lighter(java.awt.Color color, double fraction)
          Make a color lighter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorUtil

public ColorUtil()
Method Detail

blend

public static java.awt.Color blend(java.awt.Color color1,
                                   java.awt.Color color2,
                                   double ratio)
Blend two colors.

Parameters:
color1 - First color to blend.
color2 - Second color to blend.
ratio - Blend ratio. 0.5 will give even blend, 1.0 will return color1, 0.0 will return color2 and so on.
Returns:
Blended color.

blend

public static java.awt.Color blend(java.awt.Color color1,
                                   java.awt.Color color2)
Make an even blend between two colors.

Parameters:
color1 - First color to blend.
color2 - Second color to blend.
Returns:
Blended color.

darker

public static java.awt.Color darker(java.awt.Color color,
                                    double fraction)
Make a color darker.

Parameters:
color - Color to make darker.
fraction - Darkness fraction.
Returns:
Darker color.

lighter

public static java.awt.Color lighter(java.awt.Color color,
                                     double fraction)
Make a color lighter.

Parameters:
color - Color to make lighter.
fraction - Darkness fraction.
Returns:
Lighter color.

getHexName

public static java.lang.String getHexName(java.awt.Color color)
Return the hex name of a specified color.

Parameters:
color - Color to get hex name of.
Returns:
Hex name of color: "rrggbb".

colorDistance

public static double colorDistance(double r1,
                                   double g1,
                                   double b1,
                                   double r2,
                                   double g2,
                                   double b2)
Return the "distance" between two colors. The rgb entries are taken to be coordinates in a 3D space [0.0-1.0], and this method returnes the distance between the coordinates for the first and second color.

Parameters:
r1, - g1, b1 First color.
r2, - g2, b2 Second color.
Returns:
Distance bwetween colors.

colorDistance

public static double colorDistance(double[] color1,
                                   double[] color2)
Return the "distance" between two colors.

Parameters:
color1 - First color [r,g,b].
color2 - Second color [r,g,b].
Returns:
Distance bwetween colors.

colorDistance

public static double colorDistance(java.awt.Color color1,
                                   java.awt.Color color2)
Return the "distance" between two colors.

Parameters:
color1 - First color.
color2 - Second color.
Returns:
Distance between colors.

isDark

public static boolean isDark(double r,
                             double g,
                             double b)
Check if a color is more dark than light. Useful if an entity of this color is to be labeled: Use white label on a "dark" color and black label on a "light" color.

Parameters:
r,g,b - Color to check.
Returns:
True if this is a "dark" color, false otherwise.

isDark

public static boolean isDark(java.awt.Color color)
Check if a color is more dark than light. Useful if an entity of this color is to be labeled: Use white label on a "dark" color and black label on a "light" color.

Parameters:
color - Color to check.
Returns:
True if this is a "dark" color, false otherwise.