Class ColorUtils

java.lang.Object
be.gaudry.model.drawing.color.ColorUtils

public final class ColorUtils extends Object
Provided by the broldev.core.model project.
Since:
1.0 Dec 2, 2008, broldev.core.model 0.0.1-SNAPSHOT dependency
Version:
1.2 Nov 9, 2010
Author:
Steph GAUDRY
  • Method Details

    • color2html

      public static String color2html(Color color)
      Use a given Color to get the corresponding HTML string.
      Parameters:
      color - Color to get as string.
      Returns:
      HTML representation #hexvalue of the color
    • decodeHtmlColor

      public static Color decodeHtmlColor(String htmlColor)
      Parses the string argument as a Color.

      An exception of type NumberFormatException is thrown if any of the following situations occurs:

      • The htmlColor argument is null or is a string of length zero.
      • The htmlColor argument does not match to the following pattern # + red hex value on two chars + green hex value on two chars + blue hex value on two chars.

      Examples:

       decodeHtmlColor("#FFFFFF;")       returns Color.WHITE
       decodeHtmlColor("FFFFFF")               returns Color.WHITE
       decodeHtmlColor("FFF")               returns Color.WHITE
       decodeHtmlColor("FFFFFF;")       returns Color.WHITE
       decodeHtmlColor("#OOOOOO")       returns Color.BLACK
       decodeHtmlColor("FFFFFFF")       throws a NumberFormatException
       decodeHtmlColor("#FFG")               throws a NumberFormatException
       decodeHtmlColor("white")               throws a NumberFormatException
       
      Parameters:
      htmlColor - the String containing the HTML color representation to be parsed
      Returns:
      the Color represented by the string argument.
      Throws:
      NumberFormatException - if the String does not contain a parsable Color.
      IllegalArgumentException - if htmlColor is null
    • alpha

      public static Color alpha(Color opaqueColor, float opacity)
      An opacity value of 1.0 means that the color is completely opaque and an alpha value of 0.0 means that the color is completely transparent.
      Parameters:
      opaqueColor - original opaque Color
      opacity - opacity value
      Returns:
      the Color with the desired opacity
      Throws:
      IllegalArgumentException - if opacity is outside of the range 0.0 to 1.0, inclusive