com.bbn.openmap.layer.util
Class LayerUtils

java.lang.Object
  |
  +--com.bbn.openmap.layer.util.LayerUtils

public class LayerUtils
extends java.lang.Object

A Class that provides some static methods useful for generic tasks within the layer, like changing a single string of File.separator paths into an array of Strings, and creating java.awt.Colors from a hex string.

To merge all of the functions that deal with handling properties, these methods have been moved to the com.bbn.openmap.util.PropUtils class. If you call these methods, they now simply call the same PropUtils method.


Constructor Summary
LayerUtils()
           
 
Method Summary
static boolean booleanFromProperties(java.util.Properties p, java.lang.String propName, boolean defaultValue)
          Gets an boolean out of a properties object.
static double doubleFromProperties(java.util.Properties p, java.lang.String propName, double defaultValue)
          Gets a double out of a properties object.
static float floatFromProperties(java.util.Properties p, java.lang.String propName, float defaultValue)
          Gets an float out of a properties object.
static java.lang.String[] getPropertiesAsStringArray(java.util.Properties props)
          Converts a properties object to an array of Strings.
static java.net.URL getResourceOrFileOrURL(java.lang.Class askingClass, java.lang.String name)
          Returns a URL that names either a resource, a local file, or an internet URL.
static java.net.URL getResourceOrFileOrURL(java.lang.Object askingClass, java.lang.String name)
          Returns a URL that names either a resource, a local file, or an internet URL.
static java.net.URL getResourceOrFileOrURL(java.lang.String name)
          Returns a URL that names either a resource, a local file, or an internet URL.
static java.lang.String[] initPathsFromProperties(java.util.Properties p, java.lang.String propName)
          Takes a string of `;' separated paths and returns an array of parsed strings.
static int intFromProperties(java.util.Properties p, java.lang.String propName, int defaultValue)
          Gets an integer out of a properties object.
static java.lang.Object objectFromProperties(java.util.Properties p, java.lang.String propName)
          Creates an object out of a property name.
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.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.lang.String[] stringArrayFromProperties(java.util.Properties p, java.lang.String propName, java.lang.String tok)
          Takes a string of representing token separated properties and returns an array of parsed strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LayerUtils

public LayerUtils()
Method Detail

initPathsFromProperties

public static java.lang.String[] initPathsFromProperties(java.util.Properties p,
                                                         java.lang.String propName)
Takes a string of `;' separated paths and returns an array of parsed strings. NOTE: this method currently doesn't support appropriate quoting of the `;' character, although it probably should...

Parameters:
p - properties
propName - the name of the property
Returns:
Array of strings representing paths.

intFromProperties

public static int intFromProperties(java.util.Properties p,
                                    java.lang.String propName,
                                    int defaultValue)
Gets an integer out of a properties object. Returns the default value if something goes wrong.

Parameters:
p - properties
propName - name of the property associated with the wanted value.
defaultValue - what to return if the property name doesn't exist, or if the value isn't a numerical value.
Returns:
integer value associated with the property.

floatFromProperties

public static float floatFromProperties(java.util.Properties p,
                                        java.lang.String propName,
                                        float defaultValue)
Gets an float out of a properties object. Returns the default value if something goes wrong.

Parameters:
p - properties
propName - name of the property associated with the wanted value.
defaultValue - what to return if the property name doesn't exist, or if the value isn't a numerical value.
Returns:
float value associated with the property.

booleanFromProperties

public static boolean booleanFromProperties(java.util.Properties p,
                                            java.lang.String propName,
                                            boolean defaultValue)
Gets an boolean out of a properties object. Returns the default value if something goes wrong.

Parameters:
p - properties
propName - name of the property associated with the wanted value.
defaultValue - what to return if the property name doesn't exist, or if the value isn't a numerical value.
Returns:
boolean value associated with the property.

objectFromProperties

public static java.lang.Object objectFromProperties(java.util.Properties p,
                                                    java.lang.String propName)
Creates an object out of a property name. If anything fails, return null.

Parameters:
p - properties
propName - name of class to instantiate.
Returns:
null on failure, otherwise, a default constructed instance of the class named in the property.

stringArrayFromProperties

public static java.lang.String[] stringArrayFromProperties(java.util.Properties p,
                                                           java.lang.String propName,
                                                           java.lang.String tok)
Takes a string of representing token separated properties and returns an array of parsed strings. NOTE: this method currently doesn't support appropriate quoting of the token, although it probably should...

Parameters:
p - properties
propName - the name of the property
tok - the characters separating the strings.
Returns:
Array of strings between the tokens.

doubleFromProperties

public static double doubleFromProperties(java.util.Properties p,
                                          java.lang.String propName,
                                          double defaultValue)
Gets a double out of a properties object. Returns the default value if something goes wrong.

Parameters:
p - properties
propName - name of the property associated with the wanted value.
defaultValue - what to return if the property name doesn't exist, or if the value isn't a numerical value.
Returns:
double value associated with the property.

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:
ColorFactory.parseColorFromProperties(Properties, String, String, boolean)

parseColorFromProperties

public static java.awt.Paint parseColorFromProperties(java.util.Properties p,
                                                      java.lang.String propName,
                                                      java.awt.Paint 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:
ColorFactory.parseColorFromProperties(Properties, String, 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. NOTE:

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:
ColorFactory.parseColor(String, boolean)

getPropertiesAsStringArray

public static java.lang.String[] getPropertiesAsStringArray(java.util.Properties props)
Converts a properties object to an array of Strings. The resulting array will consist of alternating key-value strings.

Parameters:
props - the properties object to convert.
Returns:
an array of Strings representing key-value pairs.

getResourceOrFileOrURL

public static java.net.URL getResourceOrFileOrURL(java.lang.String name)
                                           throws java.net.MalformedURLException
Returns a URL that names either a resource, a local file, or an internet URL. Resources are checked for in the general classpath.

Parameters:
name - name of the resource, file or URL.
Returns:
URL
Throws:
java.net.MalformedURLException

getResourceOrFileOrURL

public static java.net.URL getResourceOrFileOrURL(java.lang.Object askingClass,
                                                  java.lang.String name)
                                           throws java.net.MalformedURLException
Returns a URL that names either a resource, a local file, or an internet URL.

Parameters:
askingClass - the object asking for the URL.
name - name of the resource, file or URL.
Returns:
URL
Throws:
java.net.MalformedURLException

getResourceOrFileOrURL

public static java.net.URL getResourceOrFileOrURL(java.lang.Class askingClass,
                                                  java.lang.String name)
                                           throws java.net.MalformedURLException
Returns a URL that names either a resource, a local file, or an internet URL.

Parameters:
askingClass - the class asking for the URL. Can be null.
name - name of the resource, file or URL.
Returns:
URL
Throws:
java.net.MalformedURLException


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