|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectus.zuercher.gpx2map.plotter.Color
public class Color
Color represents an RGB color. The static getColor(String)
and
getColors()
methods obtain the default set of colors from a copy
of rgb.txt taken from Netpbm 10.29.
The rgb.txt file may contain multiple names for a given RGB triplet. For example, "Black", "Gray0", and "Grey0" all map to (0, 0, 0). Also, rgb.txt sometimes contains multiple RGB triplets for a single color name. Examples include "Black" which appears twice as (0, 0, 0) and "Navy" which appears first as (0, 0, 142) and again as (0, 0, 128).
The static internal mapping of color name to Color object maintained by this class uses the first appearance of each color name, so requests for the color "Navy" will return a Color with an RGB value of (0, 0, 142). However, Color also maintains a static internal mapping of RGB value to Color objects. Both versions of "Navy" appear in this map.
Field Summary | |
---|---|
private int |
blue
Blue value. |
private String |
colorName
Color's name. |
private static Map<String,Color> |
colors
Map of color names to Colors. |
private static Map<Integer,Color> |
colorsByValue
Map of color values to Colors. |
private int |
green
Green value. |
private int |
red
Red value. |
Constructor Summary | |
---|---|
private |
Color(String colorName,
int red,
int green,
int blue)
Constructs a new Color object. |
Method Summary | |
---|---|
boolean |
equalByColorValue(Color other)
Tests to see if this Color has the same color value as another Color. |
boolean |
equals(Object other)
Tests to see if this Color is the same as another Color by both name and RGB value. |
int |
getBlue()
Returns the color's blue value. |
static Color |
getColor(String colorName)
Returns the Color associated with the given name. |
String |
getColorName()
Returns the Color's name. |
static Collection<Color> |
getColors()
Returns an unordered collection of all known Color objects. |
int |
getGreen()
Returns the color's green value. |
int |
getRed()
Returns the color's red value. |
int |
hashCode()
Computes the hashcode of the color's name. |
private static void |
loadColors()
Load the standard color name/value to Color mappings. |
private static int |
makeColorValueKey(int red,
int green,
int blue)
Computes a "color value key" for a given RGB value. |
static void |
resetColors()
Resets the color name/value to Color mappings to their startup defaults. |
String |
toString()
Returns the color's name. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static Map<String,Color> colors
private static Map<Integer,Color> colorsByValue
private final String colorName
private final int red
private final int green
private final int blue
Constructor Detail |
---|
private Color(String colorName, int red, int green, int blue)
colorName
- color's namered
- red valuegreen
- green valueblue
- blue valueMethod Detail |
---|
public static Collection<Color> getColors() throws ColorDataError
ColorDataError
- if there's an error loading color data from
rgb.txt (only on first call or after
resetColors()
)public static Color getColor(String colorName) throws ColorDataError
Example results, assuming that getColor(String)
is called
repeatedly with each name. Note the unexpected behavior with respect
to "Navy" in the last three examples (see class description for an
explanation).
Name | Result |
---|---|
Red | rgb.txt Color("Red", 255, 0, 0) |
red | rgb.txt Color("Red", 255, 0, 0) |
#ff0000 | rgb.txt Color("Red", 255, 0, 0) |
#FF0000 | rgb.txt Color("Red", 255, 0, 0) |
#00008D | new Color ("#00008D", 0, 0, 141) |
#00008d | Color("#00008D", 0, 0, 141) |
Navy | rgb.txt Color("Navy", 0, 0, 142) |
#00008e | rgb.txt Color("Navy", 0, 0, 142) |
#000080 | rgb.txt Color("Navy", 0, 0, 128) |
colorName
- case-insensitive color name
ColorDataError
- if there's an error loading color data from
rgb.txt (only on first call or after
resetColors()
)public String getColorName()
public int getRed()
public int getGreen()
public int getBlue()
public String toString()
toString
in class Object
public int hashCode()
hashCode
in class Object
public boolean equals(Object other)
equals
in class Object
other
- another Color object
ClassCastException
- if other
is not a
Color
equalByColorValue(Color)
public boolean equalByColorValue(Color other)
other
- another Color
public static void resetColors()
getColor(String)
or getColors()
is called.
private static int makeColorValueKey(int red, int green, int blue)
red
- red valuegreen
- green valueblue
- blue value
private static void loadColors() throws ColorDataError
ColorDataError
- if there's an error loading Color data.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |