edu.kzoo.util
Class NamedColor.ColorMap

java.lang.Object
  |
  +--edu.kzoo.util.NamedColor.ColorMap
Enclosing class:
NamedColor

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.

Version:
September 1, 2004
Author:
Joel Booth

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

NamedColor.ColorMap

protected NamedColor.ColorMap()
Method Detail

addColor

public void addColor(java.lang.String name,
                     java.awt.Color c)
Adds a color to the map. (Precondition: neither name nor c appears in the map already.

Parameters:
name - the name of the color
c - the color to add
Throws:
IllegalArgumentException - if either c or name are already in the map

changeNameColorMapping

public 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.

Parameters:
name - the name of the color
c - the color

containsName

public boolean containsName(java.lang.String name)
Checks whether or not the mapping contains a color with the given name.

Parameters:
name - the name of the color to look for
Returns:
true if the color is in the map, otherwise false

containsColor

public boolean containsColor(java.awt.Color c)
Checks whether or not the mapping contains a name => color mapping for the given color.

Parameters:
c - the NamedColor to look for
Returns:
true if the color is in the map, otherwise false

getNameFor

public java.lang.String getNameFor(java.awt.Color c)
Gets the name associated with the specified color.

Parameters:
c - a color
Returns:
the name associated with color; null if there is no such association

getNamedColor

public NamedColor getNamedColor(java.lang.String name)
Gets the color associated with the specified name.

Parameters:
name - a color name
Returns:
the color associated with name; null if there is no such association

getAllColorNames

public java.util.Set getAllColorNames()
Gets all of the color names in the map.

Returns:
all the color names in the map (String objects)

getAllNamedColors

public java.util.Set getAllNamedColors()
Gets all of the colors in the map (colors for which there are associated names.

Returns:
a Set of all the NamedColor objects in the map

getRandomNamedColor

public NamedColor getRandomNamedColor()
Gets a random NamedColor from the map.

Returns:
a random NamedColor from the map