edu.umd.cs.piccolox.nodes
Class PNodeCache

java.lang.Object
  extended by edu.umd.cs.piccolo.PNode
      extended by edu.umd.cs.piccolox.nodes.PNodeCache
All Implemented Interfaces:
Printable, Serializable, Cloneable

public class PNodeCache
extends PNode

PNodeCache caches a visual representation of it's children into an image and uses this cached image for painting instead of painting it's children directly. This is intended to be used in two ways.

First it can be used as a simple optimization technique. If a node has many descendents it may be faster to paint the cached image representation instead of painting each node.

Second PNodeCache provides a place where "image" effects such as blurring and drop shadows can be added to the Piccolo scene graph. This can be done by overriding the method createImageCache and returing an image with the desired effect applied.

Version:
1.0
Author:
Jesse Grosjean
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate
 
Field Summary
 
Fields inherited from class edu.umd.cs.piccolo.PNode
FILL_STRATEGY_ASPECT_COVER, FILL_STRATEGY_ASPECT_FIT, FILL_STRATEGY_EXACT_FIT, PROPERTY_BOUNDS, PROPERTY_CHILDREN, PROPERTY_CHILDREN_PICKABLE, PROPERTY_CLIENT_PROPERTIES, PROPERTY_CODE_BOUNDS, PROPERTY_CODE_CHILDREN, PROPERTY_CODE_CHILDREN_PICKABLE, PROPERTY_CODE_CLIENT_PROPERTIES, PROPERTY_CODE_FULL_BOUNDS, PROPERTY_CODE_PAINT, PROPERTY_CODE_PARENT, PROPERTY_CODE_PICKABLE, PROPERTY_CODE_TRANSFORM, PROPERTY_CODE_TRANSPARENCY, PROPERTY_CODE_VISIBLE, PROPERTY_FULL_BOUNDS, PROPERTY_PAINT, PROPERTY_PARENT, PROPERTY_PICKABLE, PROPERTY_TRANSFORM, PROPERTY_TRANSPARENCY, PROPERTY_VISIBLE, SCENE_GRAPH_DELEGATE
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PNodeCache()
           
 
Method Summary
 Image createImageCache(Dimension2D cacheOffsetRef)
          Override this method to customize the image cache creation process.
 void fullPaint(PPaintContext paintContext)
          Repaints this node, using the cached result if possible.
 Image getImageCache()
          Returns an image that is a cached representation of its children.
 void invalidateCache()
          Clears the cache, forcing it to be recalculated on the next call to getImageCache.
 void invalidatePaint()
          Intercepts the normal invalidatePaint mechanism so that the node will not be repainted unless it's cache has been invalidated.
protected  boolean pickAfterChildren(PPickPath pickPath)
          By always returning false, makes the PNodeCache instance NOT pickable.
 void repaintFrom(PBounds localBounds, PNode childOrThis)
          Handles a repaint event issued from a node in this node's tree.
 
Methods inherited from class edu.umd.cs.piccolo.PNode
addActivity, addAttribute, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, animateToRelativePosition, animateToTransform, animateToTransparency, animateTransformToBounds, centerBoundsOnPoint, centerFullBoundsOnPoint, clone, computeFullBounds, endResizeBounds, findIntersectingNodes, fireChildPropertyChange, firePropertyChange, fullIntersects, fullPick, getAllNodes, getAllNodes, getAttribute, getAttribute, getBooleanAttribute, getBounds, getBoundsChanged, getBoundsReference, getBoundsVolatile, getChild, getChildBoundsInvalid, getChildBoundsVolatile, getChildPaintInvalid, getChildrenCount, getChildrenIterator, getChildrenPickable, getChildrenReference, getClientProperties, getClientProperty, getClientPropertyKeysEnumeration, getClientPropertyKeysIterator, getDoubleAttribute, getFullBounds, getFullBoundsInvalid, getFullBoundsReference, getGlobalBounds, getGlobalFullBounds, getGlobalRotation, getGlobalScale, getGlobalToLocalTransform, getGlobalTranslation, getHeight, getInputEventListeners, getIntegerAttribute, getInverseTransform, getListenerList, getLocalToGlobalTransform, getName, getOccluded, getOffset, getPaint, getPaintInvalid, getParent, getPickable, getPropertyChangeParentMask, getRoot, getRotation, getScale, getTransform, getTransformReference, getTransparency, getUnionOfChildrenBounds, getVisible, getWidth, getX, getXOffset, getY, getYOffset, globalToLocal, globalToLocal, globalToLocal, indexOfChild, internalUpdateBounds, intersects, invalidateFullBounds, invalidateLayout, isAncestorOf, isDescendentOf, isDescendentOfRoot, isOpaque, layoutChildren, lerp, localToGlobal, localToGlobal, localToGlobal, localToParent, localToParent, localToParent, moveInBackOf, moveInFrontOf, moveToBack, moveToFront, offset, paint, paintAfterChildren, paramString, parentBoundsChanged, parentToLocal, parentToLocal, parentToLocal, pick, position, print, print, removeAllChildren, removeChild, removeChild, removeChildren, removeFromParent, removeInputEventListener, removePropertyChangeListener, removePropertyChangeListener, repaint, reparent, replaceWith, resetBounds, rotate, rotateAboutPoint, rotateAboutPoint, rotateInPlace, scale, scaleAboutPoint, scaleAboutPoint, setBounds, setBounds, setBoundsChanged, setChildBoundsInvalid, setChildBoundsVolatile, setChildPaintInvalid, setChildrenPickable, setFullBoundsInvalid, setGlobalRotation, setGlobalScale, setGlobalTranslation, setHeight, setName, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setPropertyChangeParentMask, setRotation, setScale, setTransform, setTransparency, setVisible, setWidth, setX, setY, signalBoundsChanged, startResizeBounds, toImage, toImage, toImage, toImage, transformBy, translate, validateFullBounds, validateFullPaint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PNodeCache

public PNodeCache()
Method Detail

createImageCache

public Image createImageCache(Dimension2D cacheOffsetRef)
Override this method to customize the image cache creation process. For example if you want to create a shadow effect you would do that here. Fill in the cacheOffsetRef if needed to make your image cache line up with the nodes children.

Parameters:
cacheOffsetRef - output parameter that can be changed to make the cached offset line up with the node's children
Returns:
an image representing this node

getImageCache

public Image getImageCache()
Returns an image that is a cached representation of its children.

Returns:
image representation of its children

invalidateCache

public void invalidateCache()
Clears the cache, forcing it to be recalculated on the next call to getImageCache.


invalidatePaint

public void invalidatePaint()
Intercepts the normal invalidatePaint mechanism so that the node will not be repainted unless it's cache has been invalidated.

Overrides:
invalidatePaint in class PNode

repaintFrom

public void repaintFrom(PBounds localBounds,
                        PNode childOrThis)
Handles a repaint event issued from a node in this node's tree.

Overrides:
repaintFrom in class PNode
Parameters:
localBounds - local bounds of this node that need repainting
childOrThis - the node that emitted the repaint notification

fullPaint

public void fullPaint(PPaintContext paintContext)
Repaints this node, using the cached result if possible.

Overrides:
fullPaint in class PNode
Parameters:
paintContext - context in which painting should occur

pickAfterChildren

protected boolean pickAfterChildren(PPickPath pickPath)
By always returning false, makes the PNodeCache instance NOT pickable.

Overrides:
pickAfterChildren in class PNode
Parameters:
pickPath - path which this node is being tested for inclusion
Returns:
always returns false


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.