com.bbn.openmap
Class Environment

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by com.bbn.openmap.Environment
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class Environment
extends java.util.Properties

An Environment is a set of property lists that together specify the runtime environment for this process.

There is only one Environment, and it is accessed through static member functions.

The environment is comprised of at least three property lists:

When Environment.get() is called, all lists are searched until the property is found. System properties are searched first, then runtime properties, and then hardcoded properties.

This search pattern allows system properties and properties specified as applet parameters or command line properties (using -DProperty=value Java flag) to override more hardcoded properties specified elsewhere, say in a user preferences file.

See Also:
 
 
 
    # metanames of the names of the variables used in the OpenMap
    # system to configure the Environment class from the properties.
    openmap.Title - String for title of application window.
    openmap.Version - Version number of application.
    openmap.BuildDate - Build data of code base.
    openmap.WebBrowser - The launch command to launch a browser.
    openmap.TempDirectory - A path to a directory to use for temporary files.
    openmap.UseInternalFrames - For an application, to direct it to use InternalFrames for other windows.
    openmap.Latitude - Starting latitude for map projection.
    openmap.Longitude - Starting longitude for map projection.
    openmap.Scale - Starting scale for map projection.
    openmap.Projection - Starting projection type for map projection.
    openmap.Width - Pixel width for map.
    openmap.Height - Pixel height for map.
    openmap.HelpURL - The URL to use for OpenMap/Application help pages.
    openmap.BackgroundColor - An ARGB integer to use for the background (sea) color.
    openmap.Debug - Debug tokens to activate for printout.  @see com.bbn.openmap.util.Debug
   
    openmap.UniqueID String for unique identification of OpenMap instance (calculated)
 
 
 
 
, Serialized Form

Field Summary
protected static java.applet.Applet applet
           
static java.lang.String BackgroundColor
           
static java.lang.String build
           
static java.lang.String BuildDate
           
static java.lang.String DebugList
           
protected  javax.swing.JLayeredPane desktop
           
static boolean doingXWindowsWorkaround
           
protected static Environment env
           
protected  java.util.Properties hardcodedProps
           
static java.lang.String Height
           
static java.lang.String HelpURL
           
static java.lang.String Latitude
           
static java.lang.String Longitude
           
static java.lang.String OpenMapPrefix
           
static java.lang.String PreferencesURL
           
static java.lang.String Projection
           
protected  java.util.Properties runtimeProps
           
static java.lang.String Scale
           
static java.lang.String ThreadPool
           
static java.lang.String title
           
static java.lang.String Title
           
static java.lang.String TmpDir
           
static java.lang.String UniqueID
           
static java.lang.String UseInternalFrames
           
static java.lang.String version
           
static java.lang.String Version
           
static java.lang.String WebBrowser
           
static java.lang.String Width
           
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
protected Environment(java.applet.Applet applet)
          Creates an Environment based on applet properties.
protected Environment(java.util.Properties sysProps)
          Creates an Environment with the specified system properties.
 
Method Summary
static void addPathToClasspaths(java.lang.String path)
          Add a resource path to internal Vector.
static void addRuntimeProperty(java.lang.String key, java.lang.String value)
          Adds a key/value pair to the Environment's runtime properties list.
static void addSystemProperty(java.lang.String key, java.lang.String value)
          Adds a key/value pair to the Environment's system properties list.
protected  void commonInit()
          Adds runtime, user, and base properties to the Environment.
static java.lang.String generateUniqueString()
          Generate a unique string.
static java.lang.String get(java.lang.String key)
          Searches for the named property in the environment.
static java.lang.String get(java.lang.String key, java.lang.String defaultValue)
          Searches for the named property in the environment.
static java.applet.Applet getApplet()
          Gets the applet associated with this process.
static boolean getBoolean(java.lang.String key)
          Gets a boolean value out of the Environment.
static boolean getBoolean(java.lang.String key, boolean defaultValue)
          Gets a boolean value out of the Environment.
static java.util.Vector<java.lang.String> getClasspathDirs()
          Returns elements of the CLASSPATH that are directories.
static java.awt.Color getCustomBackgroundColor()
          Checks the Environment to see if a BackgroundColor string, set as a hex ARGB string, has been set.
static double getDouble(java.lang.String key)
          Gets a double value out of the Environment.
static double getDouble(java.lang.String key, double defaultValue)
          Gets a double value out of the Environment.
static float getFloat(java.lang.String key)
          Gets a float value out of the Environment.
static float getFloat(java.lang.String key, float defaultValue)
          Gets a float value out of the Environment.
static I18n getI18n()
          Get the Internationalization instance.
static Environment getInstance()
           
static int getInteger(java.lang.String key)
          Gets an integer value out of the Environment.
static int getInteger(java.lang.String key, int defaultValue)
          Gets an integer value out of the Environment.
static int getInteger(java.lang.String key, int defaultValue, int radix)
          Gets an integer value out of the Environment.
static javax.swing.JLayeredPane getInternalFrameDesktop()
          Get the JLayeredPane to use for Internal Frames.
static java.util.Properties getProperties()
          Returns the toplevel Properties list of the Environment.
static void init()
          Initializes the OpenMap environment.
static void init(java.applet.Applet applet)
          Initializes the environment of an applet.
static void init(java.util.Properties sysProps)
          Initializes the environment of an application.
protected static void initHardCodedProperties(java.util.Properties p)
          Hardcoded default properties.
protected static void initRuntimeProperties(java.util.Properties p)
          Initializes the runtime properties list.
static boolean isApplet()
          Indicates whether the current process is an applet.
static boolean isApplication()
          Indicates whether the current process is an application.
static boolean isXWindowSystem()
          Check if this is an XWindows-based VM.
static java.lang.String set(java.lang.String key, java.lang.String value)
          Puts a property into the environment.
protected static void setApplet(java.applet.Applet applet)
           
protected  void setAppletProperties(java.applet.Applet applet, java.util.Properties props)
          Populates the system properties for an applet.
static java.lang.String timestamp()
          Returns a stringified value of the current time.
static void useInternalFrames(javax.swing.JLayeredPane layeredPane)
          A method to set the Environment to be able to tell other components to InternalFrames.
static void useInternalFrames(javax.swing.JRootPane rootPane)
          A method to set the Environment to be able to tell other components to InternalFrames.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

env

protected static Environment env

hardcodedProps

protected java.util.Properties hardcodedProps

runtimeProps

protected java.util.Properties runtimeProps

desktop

protected javax.swing.JLayeredPane desktop

applet

protected static java.applet.Applet applet

OpenMapPrefix

public static final transient java.lang.String OpenMapPrefix
See Also:
Constant Field Values

PreferencesURL

public static final transient java.lang.String PreferencesURL
See Also:
Constant Field Values

Title

public static final transient java.lang.String Title
See Also:
Constant Field Values

Version

public static final transient java.lang.String Version
See Also:
Constant Field Values

BuildDate

public static final transient java.lang.String BuildDate
See Also:
Constant Field Values

UniqueID

public static final transient java.lang.String UniqueID
See Also:
Constant Field Values

WebBrowser

public static final transient java.lang.String WebBrowser
See Also:
Constant Field Values

TmpDir

public static final transient java.lang.String TmpDir
See Also:
Constant Field Values

UseInternalFrames

public static final transient java.lang.String UseInternalFrames
See Also:
Constant Field Values

Latitude

public static final transient java.lang.String Latitude
See Also:
Constant Field Values

Longitude

public static final transient java.lang.String Longitude
See Also:
Constant Field Values

Scale

public static final transient java.lang.String Scale
See Also:
Constant Field Values

Projection

public static final transient java.lang.String Projection
See Also:
Constant Field Values

Width

public static final transient java.lang.String Width
See Also:
Constant Field Values

Height

public static final transient java.lang.String Height
See Also:
Constant Field Values

HelpURL

public static final transient java.lang.String HelpURL
See Also:
Constant Field Values

BackgroundColor

public static final transient java.lang.String BackgroundColor
See Also:
Constant Field Values

DebugList

public static final transient java.lang.String DebugList
See Also:
Constant Field Values

doingXWindowsWorkaround

public static transient boolean doingXWindowsWorkaround

title

public static final transient java.lang.String title
See Also:
Constant Field Values

version

public static final transient java.lang.String version
See Also:
Constant Field Values

build

public static final transient java.lang.String build
See Also:
Constant Field Values

ThreadPool

public static final transient java.lang.String ThreadPool
See Also:
Constant Field Values
Constructor Detail

Environment

protected Environment(java.applet.Applet applet)
Creates an Environment based on applet properties.

Parameters:
applet - an Applet

Environment

protected Environment(java.util.Properties sysProps)
Creates an Environment with the specified system properties.

Parameters:
sysProps - system properties
Method Detail

initHardCodedProperties

protected static final void initHardCodedProperties(java.util.Properties p)
Hardcoded default properties.

These should be edited before each new version/installation of OpenMap. They are declared in such a way that they can be easily edited from a build script.

Parameters:
p - Properties

init

public static void init(java.applet.Applet applet)
Initializes the environment of an applet.

Parameters:
applet - An applet
See Also:
Applet

init

public static void init(java.util.Properties sysProps)
Initializes the environment of an application.

Parameters:
sysProps - Runtime/System Properties (Toplevel)

init

public static void init()
Initializes the OpenMap environment. Installs the default System Properties into the Environment.


getInstance

public static Environment getInstance()

commonInit

protected void commonInit()
Adds runtime, user, and base properties to the Environment.


setAppletProperties

protected void setAppletProperties(java.applet.Applet applet,
                                   java.util.Properties props)
Populates the system properties for an applet. Currently this property list contains the ten system properties available to applets and any applet parameters specified in Applet.getParameterInfo().

Parameters:
applet - the applet
See Also:
Applet.getParameterInfo()

initRuntimeProperties

protected static void initRuntimeProperties(java.util.Properties p)
Initializes the runtime properties list. Runtime properties are those properties that exist only while the program is running. They are not persistent. Persistent properties should be stored in the user properties list.

Parameters:
p - The runtime properties list

isApplet

public static boolean isApplet()
Indicates whether the current process is an applet.

Returns:
true if process is an applet; false otherwise.

setApplet

protected static void setApplet(java.applet.Applet applet)

isApplication

public static boolean isApplication()
Indicates whether the current process is an application.

Returns:
true if process is an application; false otherwise.

get

public static java.lang.String get(java.lang.String key)
Searches for the named property in the environment. If the key is not found, null is returned. All three property lists, runtime, user, and system are searched in that order.

Parameters:
key - the property key
Returns:
the value of the property with the specified key or null if there is no property with that key.

get

public static java.lang.String get(java.lang.String key,
                                   java.lang.String defaultValue)
Searches for the named property in the environment. If the key is not found, the default value is returned. All three property lists, runtime, user, and system are searched in that order.

Parameters:
key - the property key
defaultValue - a default value
Returns:
the value of the property with the specified key or defaultValue if there is no property with that key.

set

public static java.lang.String set(java.lang.String key,
                                   java.lang.String value)
Puts a property into the environment.

Parameters:
key - the property key.
value - the value to the key.
Returns:
the value of the property set, or null if the environment isn't ready for it.

getBoolean

public static boolean getBoolean(java.lang.String key)
Gets a boolean value out of the Environment.

Parameters:
key - the property key
Returns:
the boolean value of the property or false if there is no property with that key

getBoolean

public static boolean getBoolean(java.lang.String key,
                                 boolean defaultValue)
Gets a boolean value out of the Environment.

Parameters:
key - the property key
defaultValue - a default value
Returns:
the boolean value of the property or defaultValue if there is no property with that key

getInteger

public static int getInteger(java.lang.String key)
Gets an integer value out of the Environment.

Parameters:
key - the property key
Returns:
the integer value of the property or defaultValue if there is no property with that key

getInteger

public static int getInteger(java.lang.String key,
                             int defaultValue)
Gets an integer value out of the Environment.

Parameters:
key - the property key
defaultValue - a default value
Returns:
the integer value of the property or defaultValue if there is no property with that key

getInteger

public static int getInteger(java.lang.String key,
                             int defaultValue,
                             int radix)
Gets an integer value out of the Environment.

Parameters:
key - the property key
defaultValue - a default value
radix - base value
Returns:
the integer value of the property or defaultValue if there is no property with that key

getFloat

public static float getFloat(java.lang.String key)
Gets a float value out of the Environment.

Parameters:
key - the property key
Returns:
the float value of the property or defaultValue if there is no property with that key

getFloat

public static float getFloat(java.lang.String key,
                             float defaultValue)
Gets a float value out of the Environment.

Parameters:
key - the property key
defaultValue - a default value
Returns:
the float value of the property or defaultValue if there is no property with that key

getDouble

public static double getDouble(java.lang.String key)
Gets a double value out of the Environment.

Parameters:
key - the property key
Returns:
the double value of the property or defaultValue if there is no property with that key

getDouble

public static double getDouble(java.lang.String key,
                               double defaultValue)
Gets a double value out of the Environment.

Parameters:
key - the property key
defaultValue - a default value
Returns:
the double value of the property or defaultValue if there is no property with that key

getApplet

public static java.applet.Applet getApplet()
Gets the applet associated with this process.

Returns:
the applet, or null if process is an application

addSystemProperty

public static void addSystemProperty(java.lang.String key,
                                     java.lang.String value)
Adds a key/value pair to the Environment's system properties list.

Parameters:
key - the key, used later for retrieval
value - the associate value
See Also:
get(java.lang.String)

addRuntimeProperty

public static void addRuntimeProperty(java.lang.String key,
                                      java.lang.String value)
Adds a key/value pair to the Environment's runtime properties list.

Parameters:
key - the key, used later for retrieval
value - the associate value
See Also:
get(java.lang.String)

getProperties

public static java.util.Properties getProperties()
Returns the toplevel Properties list of the Environment.

Returns:
Properties system properties

timestamp

public static java.lang.String timestamp()
Returns a stringified value of the current time.

Note: you probably don't want to call this in a tight loop.

Returns:
String timestamp YYYYMMDDhhmmss

isXWindowSystem

public static final boolean isXWindowSystem()
Check if this is an XWindows-based VM.

Note: this only returns a valid result if the Environment has been initialized.

Returns:
boolean

generateUniqueString

public static java.lang.String generateUniqueString()
Generate a unique string. This should be unique compared to other strings generated this way.

Returns:
String
See Also:
timestamp()

getClasspathDirs

public static final java.util.Vector<java.lang.String> getClasspathDirs()
Returns elements of the CLASSPATH that are directories. CLASSPATH elements that are not directories are not returned.

Returns:
Vector of Strings

addPathToClasspaths

public static void addPathToClasspaths(java.lang.String path)
Add a resource path to internal Vector. This path will get added to the classpath, if the Environment is asked for classpaths.


getCustomBackgroundColor

public static java.awt.Color getCustomBackgroundColor()
Checks the Environment to see if a BackgroundColor string, set as a hex ARGB string, has been set. If it hasn't or if it doesn't represent a valid color number, then null is returned, which should be interpreted as an excuse to use the default pretty blue embedded in the projection.


useInternalFrames

public static void useInternalFrames(javax.swing.JRootPane rootPane)
A method to set the Environment to be able to tell other components to InternalFrames.

Parameters:
rootPane - to use for the internal frames - the method gets the LayeredPane from the rootPane.

useInternalFrames

public static void useInternalFrames(javax.swing.JLayeredPane layeredPane)
A method to set the Environment to be able to tell other components to InternalFrames.

Parameters:
layeredPane - to use for the internal frames.

getInternalFrameDesktop

public static javax.swing.JLayeredPane getInternalFrameDesktop()
Get the JLayeredPane to use for Internal Frames. May be null if the Environment hasn't be set with the root pane.


getI18n

public static I18n getI18n()
Get the Internationalization instance.



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