|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.kzoo.util.NamedColor.ColorMap
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.
Constructor Summary | |
protected |
NamedColor.ColorMap()
|
Method Summary | |
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 |
getAllColorNames()
Gets all of the color names in the map. |
java.util.Set |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected NamedColor.ColorMap()
Method Detail |
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 add
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 for
true
if the color is in the map,
otherwise false
public boolean containsColor(java.awt.Color c)
c
- the NamedColor
to look for
true
if the color is in the map,
otherwise false
public java.lang.String getNameFor(java.awt.Color c)
c
- a color
color
;
null if there is no such associationpublic NamedColor getNamedColor(java.lang.String name)
name
- a color name
name
;
null if there is no such associationpublic java.util.Set getAllColorNames()
String
objects)public java.util.Set getAllNamedColors()
Set
of all the NamedColor
objects in the mappublic NamedColor getRandomNamedColor()
NamedColor
from the map.
NamedColor
from the map
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |