Class Color

java.lang.Object
com.cedarsoftware.util.geom.Color

public final class Color extends Object
Zero-dependency geometric primitive - Immutable Color class representing RGB or RGBA color values.

This class provides an API-compatible replacement for java.awt.Color without requiring the java.desktop module (~8MB), making it ideal for headless servers, microservices, and modular applications.

No AWT dependency - This class is completely independent and does not require java.awt.

Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

License

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
    static final Color
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Color(int rgb)
    Creates a color from a packed RGB integer value (0xRRGGBB).
    Color(int rgb, boolean hasAlpha)
    Creates a color from a packed integer value.
    Color(int red, int green, int blue)
    Creates an opaque RGB color with the specified red, green, and blue values.
    Color(int red, int green, int blue, int alpha)
    Creates an RGBA color with the specified red, green, blue, and alpha values.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    int
    Returns the alpha component (0-255).
    int
    Returns the blue component (0-255).
    int
    Returns the green component (0-255).
    int
    Returns the red component (0-255).
    int
    Returns the RGB value representing the color in the default sRGB ColorModel.
    int
     
     

    Methods inherited from class java.lang.Object

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

    • BLACK

      public static final Color BLACK
    • BLUE

      public static final Color BLUE
    • CYAN

      public static final Color CYAN
    • DARK_GRAY

      public static final Color DARK_GRAY
    • GRAY

      public static final Color GRAY
    • GREEN

      public static final Color GREEN
    • LIGHT_GRAY

      public static final Color LIGHT_GRAY
    • MAGENTA

      public static final Color MAGENTA
    • ORANGE

      public static final Color ORANGE
    • PINK

      public static final Color PINK
    • RED

      public static final Color RED
    • WHITE

      public static final Color WHITE
    • YELLOW

      public static final Color YELLOW
  • Constructor Details

    • Color

      public Color(int red, int green, int blue)
      Creates an opaque RGB color with the specified red, green, and blue values.
      Parameters:
      red - the red component (0-255)
      green - the green component (0-255)
      blue - the blue component (0-255)
      Throws:
      IllegalArgumentException - if any value is out of range 0-255
    • Color

      public Color(int red, int green, int blue, int alpha)
      Creates an RGBA color with the specified red, green, blue, and alpha values.
      Parameters:
      red - the red component (0-255)
      green - the green component (0-255)
      blue - the blue component (0-255)
      alpha - the alpha component (0-255)
      Throws:
      IllegalArgumentException - if any value is out of range 0-255
    • Color

      public Color(int rgb)
      Creates a color from a packed RGB integer value (0xRRGGBB).
      Parameters:
      rgb - the packed RGB value (alpha is set to 255)
    • Color

      public Color(int rgb, boolean hasAlpha)
      Creates a color from a packed integer value.
      Parameters:
      rgb - the packed RGB or ARGB value
      hasAlpha - if true, treats rgb as ARGB (0xAARRGGBB); if false, treats as RGB (0xRRGGBB) with alpha=255
  • Method Details

    • getRed

      public int getRed()
      Returns the red component (0-255).
    • getGreen

      public int getGreen()
      Returns the green component (0-255).
    • getBlue

      public int getBlue()
      Returns the blue component (0-255).
    • getAlpha

      public int getAlpha()
      Returns the alpha component (0-255).
    • getRGB

      public int getRGB()
      Returns the RGB value representing the color in the default sRGB ColorModel. The alpha value is in bits 24-31, red in bits 16-23, green in bits 8-15, and blue in bits 0-7.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object