com.bbn.openmap.layer
Class BufferedLayer

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.bbn.openmap.Layer
                          |
                          +--com.bbn.openmap.layer.BufferedLayer
All Implemented Interfaces:
java.awt.event.ActionListener, java.beans.beancontext.BeanContextChild, java.beans.beancontext.BeanContextMembershipListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, ProjectionListener, ProjectionPainter, java.beans.PropertyChangeListener, PropertyConsumer, java.io.Serializable

public class BufferedLayer
extends Layer
implements java.beans.PropertyChangeListener

A BufferedLayer is a layer that buffers a group of layers into an image. When this layer repaints, the image gets rendered. This layer can be used to group a set of layers into one, and was designed with the idea that it is a background layer where a more animated layer would be on top of it.

This layer contains a MapBean, and any layer that gets added to it simply gets added to the MapBean. When a layer needs to redraw itself, it can act normally, and the BufferedLayer will get updated as needed. If the MapBean is a BufferedMapBean (which it is by default), then the layers will get buffered into an image.

There are some special considerations to think about when using this layer if the background is at all transparent. The image buffer will need to be recreated at certain times in order to prevent leftover images from the previous paintings. When the background is set for the layer, the transparency is tested if the background is a Color and the setHasTransparentBackground() method is called accordingly. If a different Paint object is set in the BufferedLayer, it's up to you to set this variable. This causes a new image to be created every time a new projection is provided to the layer. If the layers added to this BufferedLayer are active, meaning that their content could change between projection changes, you should set the hasActiveLayers flag to true. this causes a new image buffer to be created every time a layer repaints itself. Again, this is only important if the background color of the layer is transparent.

The BufferedLayer can be configured in the openmap.properties file:

 
 
  bufLayer.class=com.bbn.openmap.layer.BufferedLayer
  bufLayer.prettyName=My Layer Group
  bufLayer.layers=layer1 layer2 layer3
  bufLayer.visibleLayers=layer1 layer3
  bufLayer.hasActiveLayers=false
 
  
 
layer1, layer2, etc should be defined as any other openmap layer.

See Also:
Serialized Form

Nested Class Summary
 class BufferedLayer.BLMapBean
          An simple extension of the BufferedMapBean that calls a layer, presumably its parent, to call repaint().
protected  class BufferedLayer.VisHelper
          Class that helps track turning on/off layers in the buffered layer.
 
Field Summary
protected  boolean hasActiveLayers
          Used to recreate the buffer on every repaint() call made by every layer.
static java.lang.String HasActiveLayersProperty
           
protected  boolean hasTransparentBackground
          Used to tell the BufferedLayer that the background is transparent.
static java.lang.String LayersProperty
           
static java.lang.String VisibleLayersProperty
           
 
Fields inherited from class com.bbn.openmap.Layer
addAsBackground, AddAsBackgroundProperty, addToBeanContext, AddToBeanContextProperty, autoPalette, AutoPaletteProperty, beanContextChildSupport, DisplayPaletteCmd, DisplayPropertiesCmd, doHack, HidePaletteCmd, i18n, IDListeners, localHackList, lsListeners, palette, paletteListener, PrettyNameProperty, propertyPrefix, RedrawCmd, removable, RemovableProperty, RemoveableProperty, SWING_PACKAGE, windowSupport
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.bbn.openmap.PropertyConsumer
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
BufferedLayer()
           
 
Method Summary
 void addLayer(Layer layer)
          Add a layer to the group.
 void clearLayers()
          Remove all layers from the group.
 void firePaletteEvent(java.awt.event.ComponentEvent event)
          Fire a component event to the Layer component listeners, with the palette as the component, letting them know if it's visible or not.
 java.awt.Color getBackground()
          Get the background color of the image.
 java.awt.Paint getBckgrnd(java.awt.Paint paint)
          Get the background Paint object used for the internal MapBean.
 java.awt.Component getGUI()
          Get the GUI (palettes) for the layers.
 boolean getHasActiveLayers()
           
 boolean getHasTransparentBackground()
           
 java.awt.Component[] getLayers()
          Get the layers assigned to the internal MapBean.
 MapBean getMapBean()
          Get the current MapBean used in the BufferedLayer.
 java.util.Properties getProperties(java.util.Properties props)
          PropertyConsumer method, to fill in a Properties object, reflecting the current values of the layer.
 java.util.Properties getPropertyInfo(java.util.Properties props)
          Not really implemented, because the mechanism for providing a set of properties that let you add a variable number of new objects as children to this one.
 boolean hasLayers()
          Return if there is at least one layer assigned to the group.
 void paint(java.awt.Graphics g)
           
 void projectionChanged(ProjectionEvent pe)
          Part of the Layer/ProjectionListener thing.
 void propertyChange(java.beans.PropertyChangeEvent pce)
          PropertyChangeListener method, to listen for the source map's background changes.
 void removeLayer(Layer layer)
          Remove the layer from group.
 void renderDataForProjection(Projection proj, java.awt.Graphics g)
          Part of the ProjectionPainter interface.
 void resetPalette()
          Should be called if layers are added or removed from the buffer.
 void setBackground(java.awt.Color color)
          Set the background color of the group.
 void setBckgrnd(java.awt.Paint paint)
          Set the background paint of the group.
 void setBeanContext(java.beans.beancontext.BeanContext in_bc)
          Method for BeanContextChild interface.
 void setHasActiveLayers(boolean value)
          If true, will cause a new image buffer to be recreated for every layer.repaint() call.
 void setHasTransparentBackground(boolean value)
          If true, will create a new image buffer when the projection changes.
 void setMapBean(MapBean mb)
          You can change what kind of MapBean is used to hold onto the layers.
 void setProperties(java.lang.String prefix, java.util.Properties props)
          Sets the properties for the Layer.
 
Methods inherited from class com.bbn.openmap.Layer
actionPerformed, addComponentListener, added, addInfoDisplayListener, addLayerStatusListener, addMouseListener, addVetoableChangeListener, childrenAdded, childrenRemoved, clearListeners, connectToBeanContext, createWindowSupport, finalize, findAndInit, findAndInit, findAndUndo, fireHideToolTip, fireHideToolTip, fireRequestBrowserContent, fireRequestBrowserContent, fireRequestCursor, fireRequestInfoLine, fireRequestInfoLine, fireRequestInfoLine, fireRequestMessage, fireRequestMessage, fireRequestToolTip, fireRequestToolTip, fireRequestToolTip, fireRequestToolTip, fireRequestURL, fireRequestURL, fireStatusUpdate, fireStatusUpdate, fireVetoableChange, getAddAsBackground, getAddToBeanContext, getBeanContext, getMapMouseListener, getPackage, getPalette, getProjection, getPropertyPrefix, getWindowSupport, hidePalette, isRemovable, isRemoveable, notifyHideHack, removeComponentListener, removeConfirmed, removed, removeInfoDisplayListener, removeLayerStatusListener, removeVetoableChangeListener, repaint, setAddAsBackground, setAddToBeanContext, setName, setPaletteVisible, setProjection, setProjection, setProperties, setPropertyPrefix, setRemovable, setRemoveable, setVisible, setWindowSupport, showPalette
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.beans.beancontext.BeanContextChild
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

LayersProperty

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

VisibleLayersProperty

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

HasActiveLayersProperty

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

hasActiveLayers

protected boolean hasActiveLayers
Used to recreate the buffer on every repaint() call made by every layer. Makes for a lot of image buffer creation. If the layers may call repaint() and change what they present between projection changes, then this needs to be set to true. Otherwise, the old graphics will still be visible. This only needs to be set if the background is at all transparent. If the background of the internal MapBean is opaque, set this to false, which is the default.


hasTransparentBackground

protected boolean hasTransparentBackground
Used to tell the BufferedLayer that the background is transparent. Will cause a new image buffer to be created when the projection changes, in order to cover up what was already there. This is set to true but default, since the internal MapBean color is set to OMColor.clear.

Constructor Detail

BufferedLayer

public BufferedLayer()
Method Detail

setProperties

public void setProperties(java.lang.String prefix,
                          java.util.Properties props)
Description copied from class: Layer
Sets the properties for the Layer. Part of the PropertyConsumer interface. Layers which override this method should do something like:
 public void setProperties(String prefix, Properties props) {
     super.setProperties(prefix, props);
     // do local stuff
 }
 
If the addToBeanContext property is not defined, it maintains the same state.

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

getProperties

public java.util.Properties getProperties(java.util.Properties props)
Description copied from class: Layer
PropertyConsumer method, to fill in a Properties object, reflecting the current values of the layer. If the layer has a propertyPrefix set, the property keys should have that prefix plus a separating '.' prepended to each propery key it uses for configuration.

Specified by:
getProperties in interface PropertyConsumer
Overrides:
getProperties in class Layer
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.

getPropertyInfo

public java.util.Properties getPropertyInfo(java.util.Properties props)
Not really implemented, because the mechanism for providing a set of properties that let you add a variable number of new objects as children to this one.

Specified by:
getPropertyInfo in interface PropertyConsumer
Overrides:
getPropertyInfo in class Layer
Parameters:
props - a Properties object to load the PropertyConsumer properties into. If getList 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.

setHasActiveLayers

public void setHasActiveLayers(boolean value)
If true, will cause a new image buffer to be recreated for every layer.repaint() call. Should only be set to true if the background is at all transparent, and if the layers could change between projection changes.


getHasActiveLayers

public boolean getHasActiveLayers()

setHasTransparentBackground

public void setHasTransparentBackground(boolean value)
If true, will create a new image buffer when the projection changes. Should be set to true if the background has any transparency.


getHasTransparentBackground

public boolean getHasTransparentBackground()

clearLayers

public void clearLayers()
Remove all layers from the group.


setBeanContext

public void setBeanContext(java.beans.beancontext.BeanContext in_bc)
                    throws java.beans.PropertyVetoException
Method for BeanContextChild interface. Gets an iterator from the BeanContext to call findAndInit() over. Sets BeanContext on sub-layers.

Specified by:
setBeanContext in interface java.beans.beancontext.BeanContextChild
Overrides:
setBeanContext in class Layer
java.beans.PropertyVetoException

addLayer

public void addLayer(Layer layer)
Add a layer to the group. Sets the BeanContext on the added layer.


removeLayer

public void removeLayer(Layer layer)
Remove the layer from group.


hasLayers

public boolean hasLayers()
Return if there is at least one layer assigned to the group.


getLayers

public java.awt.Component[] getLayers()
Get the layers assigned to the internal MapBean.

Returns:
a Component[].

firePaletteEvent

public void firePaletteEvent(java.awt.event.ComponentEvent event)
Description copied from class: Layer
Fire a component event to the Layer component listeners, with the palette as the component, letting them know if it's visible or not.

Overrides:
firePaletteEvent in class Layer

setMapBean

public void setMapBean(MapBean mb)
You can change what kind of MapBean is used to hold onto the layers. This method just sets the new MapBean into the layer, as is. If there was a previous MapBean with layers, they're gone and replaces with whatever is attached to the new MapBean.

Parameters:
mb - new MapBean

getMapBean

public MapBean getMapBean()
Get the current MapBean used in the BufferedLayer.

Returns:
MapBean

setBackground

public void setBackground(java.awt.Color color)
Set the background color of the group. Actually sets the background color of the projection used by the internal MapBean, and which then forces a repaint() on it.

Overrides:
setBackground in class javax.swing.JComponent
Parameters:
color - java.awt.Color.

setBckgrnd

public void setBckgrnd(java.awt.Paint paint)
Set the background paint of the group. Actually sets the background paint of the projection used by the internal MapBean.

Parameters:
paint - java.awt.Paint

getBackground

public java.awt.Color getBackground()
Get the background color of the image. Actually returns the background color of the projection of the internal MapBean.

Overrides:
getBackground in class java.awt.Component
Returns:
color java.awt.Color

getBckgrnd

public java.awt.Paint getBckgrnd(java.awt.Paint paint)
Get the background Paint object used for the internal MapBean.

Returns:
java.awt.Paint

projectionChanged

public void projectionChanged(ProjectionEvent pe)
Part of the Layer/ProjectionListener thing. The internal MapBean's projection gets set here, which forces the group layers to receive it as well.

Specified by:
projectionChanged in interface ProjectionListener
Parameters:
pe - ProjectionEvent

resetPalette

public void resetPalette()
Should be called if layers are added or removed from the buffer.

Overrides:
resetPalette in class Layer

getGUI

public java.awt.Component getGUI()
Get the GUI (palettes) for the layers. The BufferedLayer actually creates a JTabbedPane holding the palettes for all of its layers, and also has a pane for itself that provides visibility control for the group layers.

Overrides:
getGUI in class Layer
Returns:
java.awt.Component or null

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class javax.swing.JComponent

renderDataForProjection

public void renderDataForProjection(Projection proj,
                                    java.awt.Graphics g)
Part of the ProjectionPainter interface. The group layers are given the projection and the graphics to paint into.

Specified by:
renderDataForProjection in interface ProjectionPainter
Overrides:
renderDataForProjection in class Layer
Parameters:
proj - Projection of the map.
g - java.awt.Graphics to draw into.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent pce)
PropertyChangeListener method, to listen for the source map's background changes. Act on if necessary.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener


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