com.bbn.openmap.proj
Class ProjectionFactory

java.lang.Object
  extended by com.bbn.openmap.MapHandlerChild
      extended by com.bbn.openmap.OMComponent
          extended by com.bbn.openmap.proj.ProjectionFactory
All Implemented Interfaces:
LightMapHandlerChild, PropertyConsumer, SoloMapComponent, java.beans.beancontext.BeanContextChild, java.beans.beancontext.BeanContextMembershipListener, java.util.EventListener

public class ProjectionFactory
extends OMComponent
implements SoloMapComponent

The ProjectionFactory creates Projections. It used to have Projection classes hard-coded into it which were accessible through static methods, but this paradigm has been changed slightly so the ProjectionFactory is a SoloMapComponent added to the MapHandler. It will attach itself to a MapBean if it finds one in the MapHandler.

The ProjectionFactory can look for ProjectionLoaders in the MapHandler to dynamically add projections to the factory. The ProjectionHandler can also create ProjectionLoaders from property settings. Changes to the available projections can be discovered through property changes.


Field Summary
static java.lang.String AvailableProjectionProperty
          The property name that is fired when the list of available projections has changed.
static java.lang.String CENTER
          Center lat/lon property parameter for new projections passed to ProjectionLoader.
static java.lang.String DATUM
          Datum property parameter for new projections passed to ProjectionLoader.
static java.lang.String HEIGHT
          Projection height (pixels) property parameter for new projections passed to ProjectionLoader.
protected  java.beans.PropertyChangeSupport pcs
          PropertyChangeSupport for letting listeners know about new projections that are available from the factory.
static java.lang.String ProjectionLoadersProperty
          ProjectionFactory property used to designate new projection loaders that should be created from properties.
protected  java.util.Vector<ProjectionLoader> projLoaders
           
static java.lang.String SCALE
          Scale property parameter for new projections passed to ProjectionLoader.
static java.lang.String WIDTH
          Projection width (pixels) property parameter for new projections passed to ProjectionLoader.
 
Fields inherited from class com.bbn.openmap.OMComponent
i18n, propertyPrefix
 
Fields inherited from class com.bbn.openmap.MapHandlerChild
beanContextChildSupport, isolated
 
Fields inherited from interface com.bbn.openmap.PropertyConsumer
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
 
Constructor Summary
ProjectionFactory()
           
 
Method Summary
 void addProjectionLoader(ProjectionLoader loader)
           
 void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
           
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener pcl)
          Method for BeanContextChild interface.
 void clearProjectionLoaders()
           
 void findAndInit(java.lang.Object obj)
          Using the MapHandler to find ProjectionLoaders being added from the application.
 void findAndUndo(java.lang.Object obj)
          Using the MapHandler to find ProjectionLoaders being removed from the application.
protected  void fireLoadersChanged()
           
 java.lang.String[] getAvailableProjections()
          Returns an array of Projection names available from this factory.
 Projection getDefaultProjectionFromEnvironment(Environment e)
          Looks at the Environment settings for the default projection and returns a Projection suited for those settings.
 Projection getDefaultProjectionFromEnvironment(Environment environment, int width, int height)
          Looks at the Environment settings for the default projection and returns a Projection suited for those settings.
 java.lang.Class<? extends Projection> getProjClassForName(java.lang.String name)
          Return the Projection Class with the given pretty name.
 java.util.Collection<ProjectionLoader> getProjectionLoaders()
           
 java.util.Properties getProperties(java.util.Properties props)
          Create the properties to create ProjectionLoaders that this loader created.
 java.util.Iterator<ProjectionLoader> iterator()
           
static ProjectionFactory loadDefaultProjections()
          Convenience method to load default projections into a ProjectionFactory that will be created.
static void loadDefaultProjections(MapHandler mapHandler)
          Convenience method to load a ProjectionFactory and default projections into the provided MapHandler.
static ProjectionFactory loadDefaultProjections(ProjectionFactory pf)
          Convenience method to load default projections into a ProjectionFactory.
 Projection makeProjection(java.lang.Class<? extends Projection> projClass, java.awt.geom.Point2D center, float scale, int width, int height)
          Create a projection.
 Projection makeProjection(ProjectionLoader loader, java.awt.geom.Point2D center, float scale, int width, int height)
          Call the provided ProjectionLoader to create the projection with the given parameters.
 Projection makeProjection(ProjectionLoader loader, java.awt.geom.Point2D center, float scale, int width, int height, java.util.Properties projProps)
          Call the provided ProjectionLoader to create the projection with the given parameters.
 Projection makeProjection(java.lang.String projClassName, java.awt.geom.Point2D center, float scale, int width, int height)
          Create a projection.
 Projection makeProjection(java.lang.String projClassName, Projection p)
          Makes a new projection based on the given projection class name and parameters from the given projection.
 int numProjections()
           
 boolean removeProjectionLoader(ProjectionLoader loader)
           
 void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
           
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener pcl)
          Method for BeanContextChild interface.
 void setProperties(java.lang.String prefix, java.util.Properties props)
          Check the properties for those to create ProjectionLoaders.
 
Methods inherited from class com.bbn.openmap.OMComponent
getPropertyInfo, getPropertyPrefix, setProperties, setPropertyPrefix
 
Methods inherited from class com.bbn.openmap.MapHandlerChild
addVetoableChangeListener, childrenAdded, childrenRemoved, findAndInit, firePropertyChange, fireVetoableChange, getBeanContext, isIsolated, removeVetoableChangeListener, setBeanContext, setIsolated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENTER

public static final java.lang.String CENTER
Center lat/lon property parameter for new projections passed to ProjectionLoader.

See Also:
Constant Field Values

SCALE

public static final java.lang.String SCALE
Scale property parameter for new projections passed to ProjectionLoader.

See Also:
Constant Field Values

HEIGHT

public static final java.lang.String HEIGHT
Projection height (pixels) property parameter for new projections passed to ProjectionLoader.

See Also:
Constant Field Values

WIDTH

public static final java.lang.String WIDTH
Projection width (pixels) property parameter for new projections passed to ProjectionLoader.

See Also:
Constant Field Values

DATUM

public static final java.lang.String DATUM
Datum property parameter for new projections passed to ProjectionLoader.

See Also:
Constant Field Values

AvailableProjectionProperty

public static final java.lang.String AvailableProjectionProperty
The property name that is fired when the list of available projections has changed.

See Also:
Constant Field Values

ProjectionLoadersProperty

public static final java.lang.String ProjectionLoadersProperty
ProjectionFactory property used to designate new projection loaders that should be created from properties.

See Also:
Constant Field Values

pcs

protected java.beans.PropertyChangeSupport pcs
PropertyChangeSupport for letting listeners know about new projections that are available from the factory.


projLoaders

protected java.util.Vector<ProjectionLoader> projLoaders
Constructor Detail

ProjectionFactory

public ProjectionFactory()
Method Detail

setProperties

public void setProperties(java.lang.String prefix,
                          java.util.Properties props)
Check the properties for those to create ProjectionLoaders.

Specified by:
setProperties in interface PropertyConsumer
Overrides:
setProperties in class OMComponent
Parameters:
prefix - the token to prefix the property names
props - the Properties object

getProperties

public java.util.Properties getProperties(java.util.Properties props)
Create the properties to create ProjectionLoaders that this loader created.

Specified by:
getProperties in interface PropertyConsumer
Overrides:
getProperties in class OMComponent
Parameters:
props - a Properties object to load the PropertyConsumer properties into. If props equals null, then a new Properties object should be created.
Returns:
Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.

getAvailableProjections

public java.lang.String[] getAvailableProjections()
Returns an array of Projection names available from this factory.


getProjClassForName

public java.lang.Class<? extends Projection> getProjClassForName(java.lang.String name)
Return the Projection Class with the given pretty name.

Parameters:
name - the name of the projection, set in the pretty name of it's ProjectionLoader.
Returns:
Class of Projection, or null if not found.

makeProjection

public Projection makeProjection(java.lang.String projClassName,
                                 Projection p)
Makes a new projection based on the given projection class name and parameters from the given projection.


makeProjection

public Projection makeProjection(java.lang.String projClassName,
                                 java.awt.geom.Point2D center,
                                 float scale,
                                 int width,
                                 int height)
Create a projection. If the Class for the classname can't be found, a Mercator projection will be returned.

Parameters:
projClassName - the classname of the projection.
center - Point2D center of the projection.
scale - float scale.
width - pixel width of projection.
height - pixel height of projection.
Returns:
Projection

makeProjection

public Projection makeProjection(java.lang.Class<? extends Projection> projClass,
                                 java.awt.geom.Point2D center,
                                 float scale,
                                 int width,
                                 int height)
Create a projection. If the class can't be found, a Mercator projection will be returned.

Parameters:
projClass - the class of the projection.
center - Point2D center of the projection.
scale - float scale.
width - pixel width of projection.
height - pixel height of projection.
Returns:
Projection

getDefaultProjectionFromEnvironment

public Projection getDefaultProjectionFromEnvironment(Environment e)
Looks at the Environment settings for the default projection and returns a Projection suited for those settings. If there is a problem creating the projection, the default projection of the MapBean will be returned. The ProjectionFactory needs to be loaded with the Projection class described in the properties before this will return an expected projection.

Returns:
Projection from Environment settings.

getDefaultProjectionFromEnvironment

public Projection getDefaultProjectionFromEnvironment(Environment environment,
                                                      int width,
                                                      int height)
Looks at the Environment settings for the default projection and returns a Projection suited for those settings. If there is a problem creating the projection, the default projection of the MapBean will be returned. The ProjectionFactory needs to be loaded with the Projection class described in the properties before this will return an expected projection.

Parameters:
width - pixel height of projection. If 0 or less, the Environment.Width value will be used.
height - pixel height of projection. If 0 or less, the Environment.Height value will be used.
Returns:
Projection from Environment settings, fit for the pixel height and width provided.

makeProjection

public Projection makeProjection(ProjectionLoader loader,
                                 java.awt.geom.Point2D center,
                                 float scale,
                                 int width,
                                 int height)
Call the provided ProjectionLoader to create the projection with the given parameters. The parameters are converted to Properties before being passed to the ProjectionLoader.

Parameters:
loader - ProjectionLoader for projection type
center - center coordinate for projection
scale - scale for projection
width - pixel width of projection
height - pixel height of projection
Returns:
Projection

makeProjection

public Projection makeProjection(ProjectionLoader loader,
                                 java.awt.geom.Point2D center,
                                 float scale,
                                 int width,
                                 int height,
                                 java.util.Properties projProps)
Call the provided ProjectionLoader to create the projection with the given parameters. The parameters are converted to Properties before being passed to the ProjectionLoader. The ProjectionLoader should throw a ProjectionException from here if it has a problem creating the projection with the provided parameters.

Parameters:
loader - projection loader to use.
center - Point2D center of the projection.
scale - float scale.
width - pixel width of projection.
height - pixel height of projection.
projProps - a Properties object to add the parameters to, which can include extra parameters that are needed by this particular projection loader. If null, a Properties object will be created.
Returns:
projection, or null if the projection can't be created.

addProjectionLoader

public void addProjectionLoader(ProjectionLoader loader)

removeProjectionLoader

public boolean removeProjectionLoader(ProjectionLoader loader)

clearProjectionLoaders

public void clearProjectionLoaders()

iterator

public java.util.Iterator<ProjectionLoader> iterator()

numProjections

public int numProjections()

getProjectionLoaders

public java.util.Collection<ProjectionLoader> getProjectionLoaders()

fireLoadersChanged

protected void fireLoadersChanged()

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener pcl)
Description copied from class: MapHandlerChild
Method for BeanContextChild interface. Uses the BeanContextChildSupport to add a listener to this object's property. You don't need this function for objects that extend java.awt.Component.

Specified by:
addPropertyChangeListener in interface java.beans.beancontext.BeanContextChild
Overrides:
addPropertyChangeListener in class MapHandlerChild

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener pcl)
Description copied from class: MapHandlerChild
Method for BeanContextChild interface. Uses the BeanContextChildSupport to remove a listener to this object's property. You don't need this function for objects that extend java.awt.Component.

Specified by:
removePropertyChangeListener in interface java.beans.beancontext.BeanContextChild
Overrides:
removePropertyChangeListener in class MapHandlerChild

findAndInit

public void findAndInit(java.lang.Object obj)
Using the MapHandler to find ProjectionLoaders being added from the application.

Specified by:
findAndInit in interface LightMapHandlerChild
Overrides:
findAndInit in class MapHandlerChild

findAndUndo

public void findAndUndo(java.lang.Object obj)
Using the MapHandler to find ProjectionLoaders being removed from the application.

Specified by:
findAndUndo in interface LightMapHandlerChild
Overrides:
findAndUndo in class MapHandlerChild

loadDefaultProjections

public static void loadDefaultProjections(MapHandler mapHandler)
Convenience method to load a ProjectionFactory and default projections into the provided MapHandler.

Parameters:
mapHandler - the MapHandler to receive the default ProjectionFactory

loadDefaultProjections

public static ProjectionFactory loadDefaultProjections()
Convenience method to load default projections into a ProjectionFactory that will be created.

Returns:
ProjectionFactory

loadDefaultProjections

public static ProjectionFactory loadDefaultProjections(ProjectionFactory pf)
Convenience method to load default projections into a ProjectionFactory.

Parameters:
pf -
Returns:
ProjectionFactory


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