com.bbn.openmap.layer.policy
Class StandardPCPolicy

java.lang.Object
  |
  +--com.bbn.openmap.layer.policy.StandardPCPolicy
All Implemented Interfaces:
ProjectionChangePolicy

public class StandardPCPolicy
extends java.lang.Object
implements ProjectionChangePolicy

ProjectionChangePolicy that uses a Layer SwingWorker to kick off a thread to call layer.prepare() and doesn't delete the OMGraphicList between projection changes. The standard behavior for simple layers that maintain a constant list of OMGraphics.


Field Summary
protected  boolean alwaysSpawnThread
          A flag to tell the policy to always spawn a thread.
protected  int graphicCutoff
          The number of OMGraphics that have to be on the layer's OMGraphicList before a thread is spawned.
protected  OMGraphicHandlerLayer layer
          The OMGraphicHandlerLayer using this policy.
 
Constructor Summary
StandardPCPolicy()
          You must set a layer at some point before using this class.
StandardPCPolicy(OMGraphicHandlerLayer layer)
          Don't pass in a null layer.
StandardPCPolicy(OMGraphicHandlerLayer layer, boolean alwaysSpawnThreadForPrepare)
          Don't pass in a null layer.
 
Method Summary
 boolean getAlwaysSpawnThread()
           
 int getGraphicCutoff()
           
 OMGraphicHandlerLayer getLayer()
          Get the OMGraphicHandlerLayer to work with.
 void projectionChanged(ProjectionEvent pe)
          When the projection changes, the StandardPCPolicy sets the current projection on the layer, and calls prepare() on the layer.
 void setAlwaysSpawnThread(boolean val)
          Tell the policy whether to spawn a thread when projectionChanged() is called with a new projection.
 void setGraphicCutoff(int number)
          Set the number of OMGraphics that have to be on the list before a thread gets spawned to call generate() on them.
 void setLayer(OMGraphicHandlerLayer l)
          Set the OMGraphicHandlerLayer to work with.
protected  boolean shouldSpawnThreadForPrepare()
          We're assuming that the list is somewhat constant for the layer.
 void workerComplete(OMGraphicList aList)
          This is a subtle call, that dictates what should happen when the LayerWorker has completed working in it's thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

layer

protected OMGraphicHandlerLayer layer
The OMGraphicHandlerLayer using this policy. Don't let this be null.


graphicCutoff

protected int graphicCutoff
The number of OMGraphics that have to be on the layer's OMGraphicList before a thread is spawned. The default is 50;


alwaysSpawnThread

protected boolean alwaysSpawnThread
A flag to tell the policy to always spawn a thread.

Constructor Detail

StandardPCPolicy

public StandardPCPolicy()
You must set a layer at some point before using this class.


StandardPCPolicy

public StandardPCPolicy(OMGraphicHandlerLayer layer)
Don't pass in a null layer.


StandardPCPolicy

public StandardPCPolicy(OMGraphicHandlerLayer layer,
                        boolean alwaysSpawnThreadForPrepare)
Don't pass in a null layer.

Parameters:
layer - layer to work for
alwaysSpawnThreadForPrepare - should be true if the layer's prepare method takes a while. Normally, the policy looks at the number of OMGraphics on the list to determine if a thread should be spawned. True by default.
Method Detail

setLayer

public void setLayer(OMGraphicHandlerLayer l)
Description copied from interface: ProjectionChangePolicy
Set the OMGraphicHandlerLayer to work with.

Specified by:
setLayer in interface ProjectionChangePolicy

getLayer

public OMGraphicHandlerLayer getLayer()
Description copied from interface: ProjectionChangePolicy
Get the OMGraphicHandlerLayer to work with.

Specified by:
getLayer in interface ProjectionChangePolicy

setAlwaysSpawnThread

public void setAlwaysSpawnThread(boolean val)
Tell the policy whether to spawn a thread when projectionChanged() is called with a new projection.


getAlwaysSpawnThread

public boolean getAlwaysSpawnThread()

projectionChanged

public void projectionChanged(ProjectionEvent pe)
When the projection changes, the StandardPCPolicy sets the current projection on the layer, and calls prepare() on the layer. repaint() will be automatically called. This method does not generate the OMGraphics in the list. The layer is still expected to do that in prepare().

Specified by:
projectionChanged in interface ProjectionChangePolicy

workerComplete

public void workerComplete(OMGraphicList aList)
This is a subtle call, that dictates what should happen when the LayerWorker has completed working in it's thread. The LayerWorker.get() method returns whatever was returned in the OMGraphicHandler.prepare() method, an OMGraphicList. In most cases, this object should be set as the Layer's list at this time. Some Layers, working asynchronously with their data sources, might want nothing to happen.

Specified by:
workerComplete in interface ProjectionChangePolicy

shouldSpawnThreadForPrepare

protected boolean shouldSpawnThreadForPrepare()
We're assuming that the list is somewhat constant for the layer. If the number of OMGraphics on the layer's list is more than the cutoff number, thena thread should be launched to generate them with the new projection. You can extend this method so that different criteria may be considered.


setGraphicCutoff

public void setGraphicCutoff(int number)
Set the number of OMGraphics that have to be on the list before a thread gets spawned to call generate() on them.


getGraphicCutoff

public int getGraphicCutoff()


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