de.caff.util

## Class ColorDecoder

- java.lang.Object
- - de.caff.util.ColorDecoder

-     public class ColorDecoder
      extends java.lang.Object

  ColorDecoder provides enhanced methods to decode color names and values compared to `java.awt.Color.decode()`.

  It understands color names (either from the X11 or the HTML domain) and the following HTML color encodings:

  - `#`rgb with hexadecimal digits r, g, b
  - `#`rrggbb with hexadecimal digits r, g, b
  - `rgb(`r`,`g`,`b`)` with decimal numbers r, g, b
  Author:
    Rammi

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ColorDecoder.Domain` Private class use as a typed enum.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ColorDecoder.Domain` | `DOMAIN_HTML` The color names in the domain of HTML 4.01.
    `static ColorDecoder.Domain` | `DOMAIN_X11` The color names in the domain of X11.
    `static java.lang.Iterable<ColorDecoder.Domain>` | `DOMAINS_HTML_FIRST` The domains sorted in a way that HTML names are tested first.
    `static java.lang.Iterable<ColorDecoder.Domain>` | `DOMAINS_X11_FIRST` The domains sorted in a way that X11 names are tested first.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ColorDecoder()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.awt.Color` | `decode(java.lang.String descr)` Get a color by name or description.
    `static java.awt.Color` | `decode(java.lang.String descr, boolean htmlFirst)` Get a color by name or description.
    `static java.awt.Color` | `decode(java.lang.String descr, ColorDecoder.Domain... domains)` Get a color by name or description.
    `static java.awt.Color` | `decode(java.lang.String descr, ColorDecoder.Domain domain)` Get a color by name or description.
    `static java.awt.Color` | `decode(java.lang.String descr, java.lang.Iterable<? extends ColorDecoder.Domain> domains)` Get a color by name or description.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DOMAIN_X11

          public static final ColorDecoder.Domain DOMAIN_X11

      The color names in the domain of X11.

    - #### DOMAIN_HTML

          public static final ColorDecoder.Domain DOMAIN_HTML

      The color names in the domain of HTML 4.01.

    - #### DOMAINS_HTML_FIRST

          public static final java.lang.Iterable<ColorDecoder.Domain> DOMAINS_HTML_FIRST

      The domains sorted in a way that HTML names are tested first.

    - #### DOMAINS_X11_FIRST

          public static final java.lang.Iterable<ColorDecoder.Domain> DOMAINS_X11_FIRST

      The domains sorted in a way that X11 names are tested first.

  - ### Constructor Detail

    - #### ColorDecoder

          public ColorDecoder()

  - ### Method Detail

    - #### decode

          @Nullable
          public static java.awt.Color decode(@NotNull
                                                        java.lang.String descr)

      Get a color by name or description.

      This method tries X11 first, then HTML.

      Parameters:
        `descr` - color description: either a color name, a HTML-like definition like #0fad78 or rgb(15,178,120) or an integer like expected by Java's Color.decode() method
      Returns:
        decoded color or `null` if the decoding failed.

    - #### decode

          @Nullable
          public static java.awt.Color decode(@NotNull
                                                        java.lang.String descr,
                                                        boolean htmlFirst)

      Get a color by name or description.
      Parameters:
        `descr` - color description: either a color name, a HTML-like definition like #0fad78 or rgb(15,178,120) or an integer like expected by Java's Color.decode() method
        `htmlFirst` - if names are defined differently in different domains, what color is preferred? `true`: HTML, `false`: X11
      Returns:
        decoded color or `null` if the decoding failed.

    - #### decode

          @Nullable
          public static java.awt.Color decode(@NotNull
                                                        java.lang.String descr,
                                                        ColorDecoder.Domain domain)

      Get a color by name or description.
      Parameters:
        `descr` - color description: either a color name, a HTML-like definition like #0fad78 or rgb(15,178,120) or an integer like expected by Java's Color.decode() method
        `domain` - domain to use to resolve named colors
      Returns:
        decoded color or `null` if the decoding failed.

    - #### decode

          @Nullable
          public static java.awt.Color decode(@NotNull
                                                        java.lang.String descr,
                                                        ColorDecoder.Domain... domains)

      Get a color by name or description.
      Parameters:
        `descr` - color description: either a color name, a HTML-like definition like #0fad78 or rgb(15,178,120) or an integer like expected by Java's Color.decode() method
        `domains` - the sequence in which domains are tested for the color if the color is named
      Returns:
        decoded color or `null` if the decoding failed.

    - #### decode

          @Nullable
          public static java.awt.Color decode(@NotNull
                                                        java.lang.String descr,
                                                        @NotNull
                                                        java.lang.Iterable<? extends ColorDecoder.Domain> domains)

      Get a color by name or description.
      Parameters:
        `descr` - color description: either a color name, a HTML-like definition like #0fad78 or rgb(15,178,120) or an integer like expected by Java's Color.decode() method
        `domains` - the sequence in which domains are tested for the color if the color is named
      Returns:
        decoded color or `null` if the decoding failed.