Package de.vatrasoft.vatralib.gfx
Class Color
- java.lang.Object
-
- de.vatrasoft.vatralib.gfx.Color
-
public class Color extends java.lang.ObjectThis class represents colors in the RGB color model.
-
-
Field Summary
Fields Modifier and Type Field Description static ColorBLACKThe color black.static ColorBLUEThe color blue.static ColorCYANThe color cyan.static ColorDARK_GRAYThe color dark gray.static ColorGREENThe color green.static ColorLIGHT_GRAYThe color light gray.static ColorMAGENTAThe color magenta.static ColorORANGEThe color orange.static ColorREDThe color red.static ColorWHITEThe color white.static ColorYELLOWThe color yellow.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)Compares thisColorto the specifiedColor.intgetBlueComponent()Returns the blue component of this color (as an integer between 0 and 255).intgetGreenComponent()Returns the green component of this color (as an integer between 0 and 255).intgetRedComponent()Returns the red component of this color (as an integer between 0 and 255).inthashCode()Returns a hash code for thisColor.static Colorof(int red, int green, int blue)Creates theColorwith the given RGB values.static Colorof(java.lang.String colorString)Creates theColorwith the RGB values contained in the given color string.java.lang.StringtoString()Returns a string representation of thisColor.
-
-
-
Field Detail
-
BLACK
public static final Color BLACK
The color black.
-
DARK_GRAY
public static final Color DARK_GRAY
The color dark gray.
-
LIGHT_GRAY
public static final Color LIGHT_GRAY
The color light gray.
-
WHITE
public static final Color WHITE
The color white.
-
RED
public static final Color RED
The color red.
-
GREEN
public static final Color GREEN
The color green.
-
BLUE
public static final Color BLUE
The color blue.
-
YELLOW
public static final Color YELLOW
The color yellow.
-
MAGENTA
public static final Color MAGENTA
The color magenta.
-
CYAN
public static final Color CYAN
The color cyan.
-
ORANGE
public static final Color ORANGE
The color orange.
-
-
Method Detail
-
of
public static Color of(int red, int green, int blue)
Creates theColorwith the given RGB values.- Parameters:
red- the value for the red component (must be between 0 and 255)green- the value for the green component (must be between 0 and 255)blue- the value for the blue component (must be between 0 and 255)- Returns:
- the
Colorwith the given RGB values - Throws:
java.lang.IllegalArgumentException- if any of the given values is outside the allowed range
-
of
public static Color of(java.lang.String colorString)
Creates theColorwith the RGB values contained in the given color string. The color string must be an "HTML color code", i.e. the RGB values must be formatted as hex triplets preceded with '#' (e.g. "#60DE60"). Hexadecimal values containing letters can be either uppercase or lowercase.- Parameters:
colorString- the RGB values formatted as hex triplets preceded with '#' (e.g. "#60DE60")- Returns:
- the
Colorwith the given RGB values - Throws:
java.lang.IllegalArgumentException- ifcolorStringisnullor not properly formatted
-
getRedComponent
public int getRedComponent()
Returns the red component of this color (as an integer between 0 and 255).- Returns:
- the red component of this color (as an integer between 0 and 255)
-
getGreenComponent
public int getGreenComponent()
Returns the green component of this color (as an integer between 0 and 255).- Returns:
- the green component of this color (as an integer between 0 and 255)
-
getBlueComponent
public int getBlueComponent()
Returns the blue component of this color (as an integer between 0 and 255).- Returns:
- the blue component of this color (as an integer between 0 and 255)
-
toString
public java.lang.String toString()
Returns a string representation of thisColor.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this
Color
-
equals
public boolean equals(java.lang.Object o)
Compares thisColorto the specifiedColor.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to compare with- Returns:
trueif the objects are the same;falseotherwise
-
hashCode
public int hashCode()
Returns a hash code for thisColor.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code for this
Color
-
-