com.davisor.graphics.data
Class ColorType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.graphics.data.PaintType
              extended bycom.davisor.graphics.data.ColorType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, java.io.Serializable

public class ColorType
extends PaintType

ColorType defines a solid color data type. In particular, color type provides a convenient conversion tool for conversion from color specification strings to color objects. Color types also define a set of Color utility methods that extend and improve standard Java color utilities.

ColorType uses a color definition resource bundle file to map color names to color definitions. The resource bundle name is:

com.davisor.graphics.data.colors

The default resource bundle defines a set of default colors. Overriding and extending this bundle allows system administrator to define custom and localized color sets.

Since:
JDK1.1
See Also:
createColor(String,ParsePosition), ColorData, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
static java.lang.String TYPENAME
          Type name ("COLOR").
 
Fields inherited from class com.davisor.graphics.data.PaintType
DEFAULT
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS
 
Constructor Summary
  ColorType()
          Default constructor.
  ColorType(ColorType ct)
          Copy constructor.
  ColorType(java.lang.String dataName)
          Creates a new default type with no identity.
  ColorType(java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.net.URL context)
          Creates a new type.
  ColorType(java.lang.String dataName, java.lang.String id, java.lang.String format)
          Constructs a new type with given spesification.
protected ColorType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.net.URL context)
          Creates a new type.
 
Method Summary
static java.awt.Color createColor(java.lang.String format)
          Creates a new color.
static java.awt.Color createColor(java.lang.String format, java.text.ParsePosition status)
          Convert a string to a color value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
static java.util.Hashtable getColors()
          Gets a reference to the internal hashtable that holds the currently available colors.
 java.lang.Class getValueClass()
          Gets value container class.
 DataValue one()
          Gets the unit data value for this type.
 DataValue toData(java.lang.Object value)
          Converts the object to a color value.
 DataValue toData(java.lang.String value, java.text.ParsePosition status)
          Converts the string to a color value.
static java.lang.String toString(java.awt.Color color)
          Convert a color to a string value in the standard "#rrggbb" format.
 DataValue zero()
          Gets zero data value for this type.
 
Methods inherited from class com.davisor.graphics.data.PaintType
createColor, createPaint, createPaint, getContext, getPaints, setContext, toData
 
Methods inherited from class com.davisor.data.Type
ceil, check, check, compare, create, create, create, create, create, dup, floor, format, getCompatibility, getDataName, getFormat, getId, getID, getMetaData, getMetaData, getSpecs, getSQLCode, getSQLName, getSQLName, getTypeName, hashCode, isNull, parseObject, register, register, setDataName, setFormat, setId, setID, setMetaData, setMetaData, setSpecs, toData, toData, toString, toXML, xmlEnd, xmlStart
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPENAME

public static final java.lang.String TYPENAME
Type name ("COLOR").

See Also:
Constant Field Values
Constructor Detail

ColorType

public ColorType()
Default constructor.


ColorType

public ColorType(ColorType ct)
Copy constructor.


ColorType

public ColorType(java.lang.String dataName)
Creates a new default type with no identity.

Parameters:
dataName - data name (may be null)

ColorType

public ColorType(java.lang.String dataName,
                 java.lang.String id,
                 java.lang.String format)
Constructs a new type with given spesification.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
format - type spesification (may be null)
See Also:
Type.setFormat(java.lang.String)

ColorType

public ColorType(java.lang.String dataName,
                 java.lang.String id,
                 java.util.Map metaData,
                 java.net.URL context)
Creates a new type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
context - context for partially specified URL addesses (may be null)

ColorType

protected ColorType(java.lang.String typeName,
                    java.lang.String dataName,
                    java.lang.String id,
                    java.util.Map metaData,
                    java.net.URL context)
Creates a new type.

Parameters:
typeName - type name
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
context - context for partially specified URL addesses (may be null)
Method Detail

dup

public com.davisor.core.Dupable dup()
Makes a deep copy of this object.

Specified by:
dup in interface com.davisor.core.Dupable
Overrides:
dup in class PaintType

equals

public boolean equals(java.lang.Object o)
Tests if this object is equal with another object.

Color type objects are equal if their superclasses are.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class PaintType

createColor

public static java.awt.Color createColor(java.lang.String format)
                                  throws InvalidDataException
Creates a new color. This is only an convenience method to call the actual color creator. Please see creteColor(String,ParsePosition).

Throws:
InvalidDataException
See Also:
createColor(String,ParsePosition)

createColor

public static java.awt.Color createColor(java.lang.String format,
                                         java.text.ParsePosition status)
                                  throws InvalidDataException
Convert a string to a color value. The string is first assumed to contain a known color name. If no matching known color is found, the string is assumed to define color RGB values as:

where 'red', 'green' and 'blue' are integer values between 0-255, and 'rr', 'gg' and 'bb' are the corresponding hexadecimal values.

Parameters:
format - color spesification string
status - parse status
Returns:
a color object
Throws:
InvalidDataException - if the string cannot be parsed as a color
See Also:
getColors()

toString

public static java.lang.String toString(java.awt.Color color)
Convert a color to a string value in the standard "#rrggbb" format.

Parameters:
color - the color to be encoded
Returns:
String representation of the given color
See Also:
createColor(java.lang.String)

getColors

public static java.util.Hashtable getColors()
Gets a reference to the internal hashtable that holds the currently available colors. The hashtable has lowercase color names as keys, and Color objects as values. The hashtable initial content is taken from the color resource file, as described in the class documentation.

Any modifications to the exposed hashtable will have immediate global effect on the services of this class. If modifications are made, they should be synchronized with the returned Hashtable object.

See Also:
createColor(String,ParsePosition)

getValueClass

public java.lang.Class getValueClass()
Gets value container class.

Overrides:
getValueClass in class PaintType

one

public DataValue one()
Gets the unit data value for this type.

Overrides:
one in class PaintType
See Also:
zero()

toData

public DataValue toData(java.lang.String value,
                        java.text.ParsePosition status)
                 throws InvalidDataException
Converts the string to a color value.

Overrides:
toData in class PaintType
Parameters:
value - a color data string
status - parse status
Returns:
a new color data object
Throws:
InvalidDataException - String cannot be converted to a color value.
See Also:
ColorData

toData

public DataValue toData(java.lang.Object value)
                 throws InvalidDataException
Converts the object to a color value.

Overrides:
toData in class PaintType
Parameters:
value - the object to be converted
Returns:
a new color data object
Throws:
InvalidDataException - if the object cannot be converted
See Also:
ColorData

zero

public DataValue zero()
Gets zero data value for this type.

Overrides:
zero in class PaintType
See Also:
one()


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.