Class Color

java.lang.Object
org.odftoolkit.odfdom.type.Color
All Implemented Interfaces:
OdfDataType

public class Color extends Object implements OdfDataType
This class represents the in OpenDocument format used data type color See W3C CSS specification for further details.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Color
    The color aqua in sRGB space.
    static final Color
    The color black in sRGB space.
    static final Color
    The color blue in sRGB space.
    static final Color
    The color fuchsia in sRGB space.
    static final Color
    The color gray in sRGB space.
    static final Color
    The color green in sRGB space.
    static final Color
    The color lime in sRGB space.
    static final Color
    The color maroon in sRGB space.
    static final Color
    The color navy in sRGB space.
    static final Color
    The color olive in sRGB space.
    static final Color
    The color orange in sRGB space.
    static final Color
    The color purple in sRGB space.
    static final Color
    The color red in sRGB space.
    static final Color
    The color silver in sRGB space.
    static final Color
    The color teal in sRGB space.
    static final Color
    The color white in sRGB space.
    static final Color
    The color yellow in sRGB space.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Color(float red, float green, float blue)
    Construct Color using the specified red, green, and blue values in the range (0.0 - 1.0).
    Color(int red, int green, int blue)
    Construct Color using the specified red, green and blue values in the range (0 - 255).
    Color(Color color)
    Construct Color using java.awt.Color.
    Color(String color)
    Construct Color by the parsing the given string.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Return the corresponding java.awt.Color instance of the Color data type.
    int
     
    static boolean
    isValid(String colorValue)
    Check if the specified String is a valid color data type.
    static Color
    Map a Color data type to java.awt.Color.
    static String
    Convert RGB color formats to six-digit hex RGB format.
    Returns the Color in six HEX sRGB notation. format.
    static Color
    valueOf(String colorValue)
    Returns a Color instance representing the specified String value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • AQUA

      public static final Color AQUA
      The color aqua in sRGB space.
    • BLACK

      public static final Color BLACK
      The color black in sRGB space.
    • BLUE

      public static final Color BLUE
      The color blue in sRGB space.
    • FUCHSIA

      public static final Color FUCHSIA
      The color fuchsia in sRGB space.
    • GRAY

      public static final Color GRAY
      The color gray in sRGB space.
    • GREEN

      public static final Color GREEN
      The color green in sRGB space.
    • LIME

      public static final Color LIME
      The color lime in sRGB space.
    • MAROON

      public static final Color MAROON
      The color maroon in sRGB space.
    • OLIVE

      public static final Color OLIVE
      The color olive in sRGB space.
    • ORANGE

      public static final Color ORANGE
      The color orange in sRGB space.
    • PURPLE

      public static final Color PURPLE
      The color purple in sRGB space.
    • RED

      public static final Color RED
      The color red in sRGB space.
    • SILVER

      public static final Color SILVER
      The color silver in sRGB space.
    • TEAL

      public static final Color TEAL
      The color teal in sRGB space.
    • WHITE

      public static final Color WHITE
      The color white in sRGB space.
    • YELLOW

      public static final Color YELLOW
      The color yellow in sRGB space.
  • Constructor Details

    • Color

      public Color(String color)
      Construct Color by the parsing the given string. The string should be observed sRGB color standard which starts with "#" and following with six numbers or three numbers in Hex format. For example, "#FFFFFF" is a valid argument and white color will be constructed.

      For further information on sRGB, see http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .

      Parameters:
      color - represented using the 3 or 6 HEX sRGB notation.
      Throws:
      IllegalArgumentException - if the given argument is not a valid Color in sRGB HEX notation.
    • Color

      public Color(int red, int green, int blue)
      Construct Color using the specified red, green and blue values in the range (0 - 255).
      Parameters:
      red - the red component.
      green - the green component.
      blue - the blue component.
      Throws:
      IllegalArgumentException - if red, green or blue are outside of the range 0 to 255, inclusive.
    • Color

      public Color(float red, float green, float blue)
      Construct Color using the specified red, green, and blue values in the range (0.0 - 1.0).
      Parameters:
      red - the red component
      green - the green component
      blue - the blue component
      Throws:
      IllegalArgumentException - if red, green or blue are outside of the range 0.0 to 1.0, inclusive.
    • Color

      public Color(Color color)
      Construct Color using java.awt.Color.
      Parameters:
      color - the specified java.awt.Color.
      Throws:
      IllegalArgumentException - if the given argument is not a valid Color.
      See Also:
  • Method Details

    • toString

      public String toString()
      Returns the Color in six HEX sRGB notation. format.
      Overrides:
      toString in class Object
      Returns:
      a six number hexadecimal string representation of the Color
    • valueOf

      public static Color valueOf(String colorValue)
      Returns a Color instance representing the specified String value.
      Parameters:
      colorValue - a six (or three) number hexadecimal string representation of the Color
      Returns:
      return a Color instance representing stringValue.
      Throws:
      IllegalArgumentException - if the given argument is not a valid Color.
    • isValid

      public static boolean isValid(String colorValue)
      Check if the specified String is a valid color data type.
      Parameters:
      colorValue - a six (or three) number hexadecimal string representation of the Color
      Returns:
      true if the value of argument is valid forcolor data type false otherwise.
    • toSixDigitHexRGB

      public static String toSixDigitHexRGB(String colorValue)
      Convert RGB color formats to six-digit hex RGB format.

      The RGB mapping works as follows: rgb(110%, 0%, 0%)----clipped to rgb(100%,0%,0%), return #ff0000 maroon----one of the seventeen fixed labeled numbers, return #800000 #ff0000----six-digit notation #rrggbb, returns the input #f00----three-digit notation #rgb, return #ff0000 rgb(255,0,0)----integer range 0 - 255, return #ff0000 rgb(300,0,0)----clipped to rgb(255,0,0), return #ff0000 rgb(255,-10,0)----clipped to rgb(255,0,0), return #ff0000

      Parameters:
      colorValue - The sRGB color value to be converted.
      Returns:
      the converted color.
    • getAWTColor

      public Color getAWTColor()
      Return the corresponding java.awt.Color instance of the Color data type.
      Returns:
      the converted java.awt.Color instance..
    • mapColorToAWTColor

      public static Color mapColorToAWTColor(Color color)
      Map a Color data type to java.awt.Color.
      Parameters:
      color - The color data type to be mapped..
      Returns:
      the converted java.awt.Color instance.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object