Package com.cedarsoftware.util.geom
Class Color
java.lang.Object
com.cedarsoftware.util.geom.Color
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 -
Constructor Summary
ConstructorsConstructorDescriptionColor(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 TypeMethodDescriptionbooleanintgetAlpha()Returns the alpha component (0-255).intgetBlue()Returns the blue component (0-255).intgetGreen()Returns the green component (0-255).intgetRed()Returns the red component (0-255).intgetRGB()Returns the RGB value representing the color in the default sRGB ColorModel.inthashCode()toString()
-
Field Details
-
BLACK
-
BLUE
-
CYAN
-
DARK_GRAY
-
GRAY
-
GREEN
-
LIGHT_GRAY
-
MAGENTA
-
ORANGE
-
PINK
-
RED
-
WHITE
-
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 valuehasAlpha- 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
-
hashCode
public int hashCode() -
toString
-