Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.bbn.openmap.util
Class ColorFactory

    java.lang.Object
      com.bbn.openmap.util.ColorFactory

public class ColorFactory
extends java.lang.Object

ColorFactory creates instances of colors. This class has methods which create `java.awt.Color` or `com.bbn.openmap.omGraphics.OMColor` objects. This class handles creation of Color objects in a Java version-neutral way by using reflection to create the java.awt.Color object. This way we support the extended Java 2 platform without sacrificing support for JDK 1.1.X.

NOTE: For general RGB-colored graphics, you should directly use the java.awt.Color 1.1.X constructors. If you are interested in using alpha-valued colors, or using colors in a (JDK) version-neutral way, then read on...

You may want to use this class because:

- You want to use alpha-valued colors in your images under both JDK 1.1 and JDK 1.2. (JDK1.1 has limited support for alpha-valued images). You can use the appropriate `createColor()` methods in this class with the `forceAlpha` set to `true` and you are guaranteed (almost!) to get back an alpha-valued color.

- You want to use alpha-valued colors for generic graphics, but only in a version-neutral way and if the support is available (e.g., you're running under the Java 2 platform). In this case you can call the appropriate `createColor()` methods without the `forceAlpha` argument, or with `forceAlpha` set to false.

See Also:
  `OMColor`

Constructor Summary
`ColorFactory()`

Method Summary
`static java.awt.Color` | `createColor(float red, float green, float blue, float alpha)` Create a Color.
`static java.awt.Color` | `createColor(float red, float green, float blue, float alpha, boolean forceAlpha)` Create a Color.
`static java.awt.Color` | `createColor(int value)` Create a Color.
`static java.awt.Color` | `createColor(int value, boolean forceAlpha)` Create a Color.
`static java.awt.Color` | `createColor(int red, int green, int blue, int alpha)` Create a Color.
`static java.awt.Color` | `createColor(int red, int green, int blue, int alpha, boolean forceAlpha)` Create a Color.
`static java.lang.String` | `getHexColorString(java.awt.Color color)`
`static java.awt.Color` | `getNamedColor(java.lang.String name, java.awt.Color defaultColor)` Method that returns a java.awt.Color object given the name of the color.
`static java.awt.Color` | `parseColor(java.lang.String colorString)` Convert a string representing a 24/32bit hex color value into a Color value.
`static java.awt.Color` | `parseColor(java.lang.String colorString, boolean forceAlpha)` Convert a string representing a 24/32bit hex color value into a Color value.
`static java.awt.Paint` | `parseColorFromProperties(java.util.Properties p, java.lang.String propName, java.awt.Paint dfault)` Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a color, and convert it to a java.awt.Color.
`static java.awt.Color` | `parseColorFromProperties(java.util.Properties p, java.lang.String propName, java.lang.String dfault)` Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a color, and convert it to a java.awt.Color.
`static java.awt.Color` | `parseColorFromProperties(java.util.Properties p, java.lang.String propName, java.lang.String dfault, boolean forceAlpha)` Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a color, and convert it to a java.awt.Color.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ColorFactory

    public ColorFactory()

Method Detail

### parseColorFromProperties

    public static java.awt.Color parseColorFromProperties(java.util.Properties p,
                                                          java.lang.String propName,
                                                          java.lang.String dfault)
                                                   throws java.lang.NumberFormatException

  Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a color, and convert it to a java.awt.Color.

  Parameters:
    `p` - properties
    `propName` - the name of the property
    `dfault` - color to use if the property value doesn't work
  Returns:
    java.awt.Color
  Throws:
    `java.lang.NumberFormatException` - if the specified string cannot be interpreted as a hexidecimal integer
  See Also:
    `parseColor(String, boolean)`

### parseColorFromProperties

    public static java.awt.Color parseColorFromProperties(java.util.Properties p,
                                                          java.lang.String propName,
                                                          java.lang.String dfault,
                                                          boolean forceAlpha)
                                                   throws java.lang.NumberFormatException

  Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a color, and convert it to a java.awt.Color.

  Parameters:
    `p` - properties
    `propName` - the name of the property
    `dfault` - color to use if the property value doesn't work
    `forceAlpha` - force using alpha value
  Returns:
    java.awt.Color
  Throws:
    `java.lang.NumberFormatException` - if the specified string cannot be interpreted as a hexidecimal integer
  See Also:
    `parseColor(String, boolean)`

### parseColorFromProperties

    public static java.awt.Paint parseColorFromProperties(java.util.Properties p,
                                                          java.lang.String propName,
                                                          java.awt.Paint dfault)

  Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a color, and convert it to a java.awt.Color.

  Parameters:
    `p` - properties
    `propName` - the name of the property
    `dfault` - color to use if the property value doesn't work
  Returns:
    java.awt.Color
  See Also:
    `parseColor(String, boolean)`

### parseColor

    public static java.awt.Color parseColor(java.lang.String colorString)
                                     throws java.lang.NumberFormatException

  Convert a string representing a 24/32bit hex color value into a Color value.

  Parameters:
    `colorString` - the 24/32bit hex string value (ARGB)
  Returns:
    java.awt.Color (24bit RGB on JDK 1.1, 24/32bit ARGB on JDK1.2)
  Throws:
    `java.lang.NumberFormatException` - if the specified string cannot be interpreted as a hexidecimal integer
  See Also:
    `parseColor(String, boolean)`

### parseColor

    public static java.awt.Color parseColor(java.lang.String colorString,
                                            boolean forceAlpha)
                                     throws java.lang.NumberFormatException

  Convert a string representing a 24/32bit hex color value into a Color value. NOTE:
  - Only 24bit (RGB) java.awt.Color is supported on the JDK 1.1 platform.
  - Both 24/32bit (ARGB) java.awt.Color is supported on the Java 2 platform.

  Parameters:
    `colorString` - the 24/32bit hex string value (ARGB)
    `forceAlpha` - force using alpha value
  Returns:
    java.awt.Color (24bit RGB on JDK 1.1, 24/32bit ARGB on JDK1.2)
  Throws:
    `java.lang.NumberFormatException` - if the specified string cannot be interpreted as a hexidecimal integer
  See Also:
    `createColor(int, boolean)`

### createColor

    public static java.awt.Color createColor(float red,
                                             float green,
                                             float blue,
                                             float alpha)

  Create a Color.

  Parameters:
    `red` - red component (0.0-1.0)
    `green` - green component (0.0-1.0)
    `blue` - blue component (0.0-1.0)
    `alpha` - alpha component (0.0-1.0)
  Returns:
    Color or OMColor that has an ARGB value
  See Also:
    `createColor(int, boolean)`

### createColor

    public static java.awt.Color createColor(float red,
                                             float green,
                                             float blue,
                                             float alpha,
                                             boolean forceAlpha)

  Create a Color.

  Parameters:
    `red` - red component (0.0-1.0)
    `green` - green component (0.0-1.0)
    `blue` - blue component (0.0-1.0)
    `alpha` - alpha component (0.0-1.0)
    `forceAlpha` - force using alpha value
  Returns:
    Color or OMColor that has an ARGB value
  See Also:
    `createColor(int, boolean)`

### createColor

    public static java.awt.Color createColor(int red,
                                             int green,
                                             int blue,
                                             int alpha)

  Create a Color.

  Parameters:
    `red` - red component (0-255)
    `green` - green component (0-255)
    `blue` - blue component (0-255)
    `alpha` - alpha component (0-255)
  Returns:
    Color or OMColor that has an ARGB value
  See Also:
    `createColor(int, boolean)`

### createColor

    public static java.awt.Color createColor(int red,
                                             int green,
                                             int blue,
                                             int alpha,
                                             boolean forceAlpha)

  Create a Color.

  Parameters:
    `red` - red component (0-255)
    `green` - green component (0-255)
    `blue` - blue component (0-255)
    `alpha` - alpha component (0-255)
    `forceAlpha` - force using alpha value
  Returns:
    Color or OMColor that has an ARGB value
  See Also:
    `createColor(int, boolean)`

### createColor

    public static java.awt.Color createColor(int value)

  Create a Color.

  Parameters:
    `value` - 32bit ARGB color value
  Returns:
    Color or OMColor that has an ARGB value
  See Also:
    `createColor(int, boolean)`

### createColor

    public static java.awt.Color createColor(int value,
                                             boolean forceAlpha)

  Create a Color.

  Parameters:
    `value` - 32bit ARGB color value
    `forceAlpha` - force using alpha value the underlying java.awt.Color supports it
  Returns:
    Color or OMColor that has an ARGB value

### getHexColorString

    public static java.lang.String getHexColorString(java.awt.Color color)

### getNamedColor

    public static java.awt.Color getNamedColor(java.lang.String name,
                                               java.awt.Color defaultColor)

  Method that returns a java.awt.Color object given the name of the color. Depends on the static instances of color provided by the java.awt.Color class.

  Parameters:
    `name` -
    `defaultColor` -
  Returns:
    Color that reflects the name, or the default color.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details