protected static class NamedColor.ColorMap
extends java.lang.Object
ColorMap is a protected static class that represents a
mapping of colors to names and names to colors. It uses two HashMaps
to implement this 1 - 1 mapping, ensuring quick lookups in either
direction. All names are held in all uppercase format to avoid the
problem different capitilizations cause for hashing on the keys.
All colors in the map are NamedColor objects.
| Modifier | Constructor and Description |
|---|---|
protected |
ColorMap() |
| Modifier and Type | Method and Description |
|---|---|
void |
addColor(java.lang.String name,
java.awt.Color c)
Adds a color to the map.
|
void |
changeNameColorMapping(java.lang.String name,
java.awt.Color c)
Adds a named color to the map, removing any previous mapping
involving either
name or c. |
boolean |
containsColor(java.awt.Color c)
Checks whether or not the mapping contains a name => color
mapping for the given color.
|
boolean |
containsName(java.lang.String name)
Checks whether or not the mapping contains a color with the given
name.
|
java.util.Set<java.lang.String> |
getAllColorNames()
Gets all of the color names in the map.
|
java.util.Set<NamedColor> |
getAllNamedColors()
Gets all of the colors in the map (colors for which there are
associated names.
|
NamedColor |
getNamedColor(java.lang.String name)
Gets the color associated with the specified name.
|
java.lang.String |
getNameFor(java.awt.Color c)
Gets the name associated with the specified color.
|
NamedColor |
getRandomNamedColor()
Gets a random
NamedColor from the map. |
public void addColor(java.lang.String name,
java.awt.Color c)
name nor c
appears in the map already.name - the name of the colorc - the color to addjava.lang.IllegalArgumentException - if either
c or name are already in the
mappublic void changeNameColorMapping(java.lang.String name,
java.awt.Color c)
name or c.name - the name of the colorc - the colorpublic boolean containsName(java.lang.String name)
name - the name of the color to look fortrue if the color is in the map,
otherwise falsepublic boolean containsColor(java.awt.Color c)
c - the NamedColor to look fortrue if the color is in the map,
otherwise falsepublic java.lang.String getNameFor(java.awt.Color c)
c - a colorcolor;
null if there is no such associationpublic NamedColor getNamedColor(java.lang.String name)
name - a color namename;
null if there is no such associationpublic java.util.Set<java.lang.String> getAllColorNames()
String
objects)public java.util.Set<NamedColor> getAllNamedColors()
Set of all the NamedColor
objects in the mappublic NamedColor getRandomNamedColor()
NamedColor from the map.NamedColor from the map