edu.umd.cs.piccolo
Class PCamera

java.lang.Object
  extended by edu.umd.cs.piccolo.PNode
      extended by edu.umd.cs.piccolo.PCamera
All Implemented Interfaces:
java.awt.print.Printable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
PCacheCamera

public class PCamera
extends PNode

PCamera represents a viewport onto a list of layer nodes. Each camera maintains a view transform through which it views these layers. Translating and scaling this view transform is how zooming and panning are implemented.

Cameras are also the point through which all PInputEvents enter Piccolo. The canvas coordinate system, and the local coordinate system of the topmost camera should always be the same.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate
 
Field Summary
static int PROPERTY_CODE_LAYERS
           
static int PROPERTY_CODE_VIEW_TRANSFORM
           
static java.lang.String PROPERTY_LAYERS
          The property name that identifies a change in the set of this camera's layers (see getLayer, getLayerCount, getLayersReference).
static java.lang.String PROPERTY_VIEW_TRANSFORM
          The property name that identifies a change in this camera's view transform (see getViewTransform, getViewTransformReference).
static int VIEW_CONSTRAINT_ALL
           
static int VIEW_CONSTRAINT_CENTER
           
static int VIEW_CONSTRAINT_NONE
           
 
Fields inherited from class edu.umd.cs.piccolo.PNode
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
PCamera()
          Construct a new camera with no layers and a default white color.
 
Method Summary
 void addLayer(int index, PLayer layer)
          Add the layer at the given index in this camera's list of layers.
 void addLayer(PLayer layer)
          Add the layer to the end of this camera's list of layers.
 PTransformActivity animateViewToCenterBounds(java.awt.geom.Rectangle2D centerBounds, boolean shouldScaleToFit, long duration)
          Animate the camera's view from its current transform when the activity starts to a new transform that centers the given bounds in the camera layers coordinate system into the cameras view bounds.
 PTransformActivity animateViewToIncludeBounds(java.awt.geom.Rectangle2D includeBounds, long duration)
          Deprecated. Renamed to animateViewToPanToBounds
 PTransformActivity animateViewToPanToBounds(java.awt.geom.Rectangle2D panToBounds, long duration)
          Pan the camera's view from its current transform when the activity starts to a new transform so that the view bounds will contain (if possible, intersect if not possible) the new bounds in the camera layers coordinate system.
 PTransformActivity animateViewToTransform(java.awt.geom.AffineTransform destination, long duration)
          Animate the cameras view transform from its current value when the activity starts to the new destination transform value.
protected  void applyViewConstraints()
           
 void fullPaint(PPaintContext paintContext)
          Override fullPaint to push the camera onto the paintContext so that it can be later be accessed by PPaintContext.getCamera();
 PComponent getComponent()
          Get the canvas associated with this camera.
 PLayer getLayer(int index)
           
 int getLayerCount()
           
 java.util.List getLayersReference()
          Return a reference to the list of layers managed by this camera.
 PBounds getUnionOfLayerFullBounds()
          Return the total bounds of all the layers that this camera looks at.
 PBounds getViewBounds()
          Return the bounds of this camera in the view coordinate system.
 int getViewConstraint()
           
 double getViewScale()
          Return the scale applied by the view transform to the layers viewed by this camera.
 PAffineTransform getViewTransform()
          Get a copy of the view transform that is applied to the camera's layers.
 PAffineTransform getViewTransformReference()
          Get a reference to the view transform that is applied to the camera's layers.
 int indexOfLayer(PLayer layer)
           
 java.awt.geom.Dimension2D localToView(java.awt.geom.Dimension2D localDimension)
          Convert the dimension from the camera's local coordinate system to the camera's view coordinate system.
 java.awt.geom.Point2D localToView(java.awt.geom.Point2D localPoint)
          Convert the point from the camera's local coordinate system to the camera's view coordinate system.
 java.awt.geom.Rectangle2D localToView(java.awt.geom.Rectangle2D localRectangle)
          Convert the rectangle from the camera's local coordinate system to the camera's view coordinate system.
protected  void paint(PPaintContext paintContext)
          Paint this camera (default background color is white) and then paint the cameras view through the view transform.
protected  void paintCameraView(PPaintContext paintContext)
          Paint all the layers that the camera is looking at, this method is only called when the cameras view transform and clip are applied to the paintContext.
protected  void paintDebugInfo(PPaintContext paintContext)
           
 PPickPath pick(double x, double y, double halo)
          Generate and return a PPickPath for the point x,y specified in the local coord system of this camera.
protected  boolean pickAfterChildren(PPickPath pickPath)
          After the direct children of the camera have been given a chance to be picked objects viewed by the camera are given a chance to be picked.
protected  boolean pickCameraView(PPickPath pickPath)
          Pick all the layers that the camera is looking at, this method is only called when the cameras view transform and clip are applied to the pickPath.
 PLayer removeLayer(int index)
          Remove the layer at the given index from the list of layers managed by this camera.
 PLayer removeLayer(PLayer layer)
          Remove the given layer from the list of layers managed by this camera.
 void repaintFrom(PBounds localBounds, PNode descendentOrThis)
          Repaint this camera, and forward the repaint request to the camera's canvas if it is not null.
 void repaintFromLayer(PBounds viewBounds, PNode repaintedLayer)
          Repaint from one of the cameras layers.
 void scaleView(double scale)
          Scale the view transform that is applied to the layers viewed by this camera by the given amount.
 void scaleViewAboutPoint(double scale, double x, double y)
          Scale the view transform that is applied to the layers viewed by this camera by the given amount about the given point.
 void setComponent(PComponent aComponent)
          Set the canvas associated with this camera.
 void setViewBounds(java.awt.geom.Rectangle2D centerBounds)
          Translates and scales the camera's view transform so that the given bounds (in camera layer's coordinate system)are centered withing the cameras view bounds.
 void setViewConstraint(int constraint)
           
 void setViewOffset(double x, double y)
          Sets the offset of the view transform that is applied to the camera's layers.
 void setViewScale(double scale)
          Set the scale of the view transform that is applied to the layers viewed by this camera.
 void setViewTransform(java.awt.geom.AffineTransform aTransform)
          Set the view transform that is applied to the views layers.
 void translateView(double dx, double dy)
          Translate the view transform that is applied to the camera's layers.
 java.awt.geom.Dimension2D viewToLocal(java.awt.geom.Dimension2D viewDimension)
          Convert the dimension from the camera's view coordinate system to the camera's local coordinate system.
 java.awt.geom.Point2D viewToLocal(java.awt.geom.Point2D viewPoint)
          Convert the point from the camera's view coordinate system to the camera's local coordinate system.
 java.awt.geom.Rectangle2D viewToLocal(java.awt.geom.Rectangle2D viewRectangle)
          Convert the rectangle from the camera's view coordinate system to the camera's local coordinate system.
 
Methods inherited from class edu.umd.cs.piccolo.PNode
addActivity, addAttribute, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, 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, getIntegerAttribute, getInverseTransform, getListenerList, getLocalToGlobalTransform, 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, invalidatePaint, isAncestorOf, isDescendentOf, isDescendentOfRoot, isOpaque, layoutChildren, lerp, localToGlobal, localToGlobal, localToGlobal, localToParent, localToParent, localToParent, moveInBackOf, moveInFrontOf, moveToBack, moveToFront, offset, 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, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setPropertyChangeParentMask, setRotation, setScale, setTransform, setTransparency, setVisible, setWidth, setX, setY, signalBoundsChanged, startResizeBounds, toImage, toImage, toImage, toString, transformBy, translate, validateFullBounds, validateFullPaint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_LAYERS

public static final java.lang.String PROPERTY_LAYERS
The property name that identifies a change in the set of this camera's layers (see getLayer, getLayerCount, getLayersReference). A property change event's new value will be a reference to the list of this nodes layers, but old value will always be null.

See Also:
Constant Field Values

PROPERTY_CODE_LAYERS

public static final int PROPERTY_CODE_LAYERS
See Also:
Constant Field Values

PROPERTY_VIEW_TRANSFORM

public static final java.lang.String PROPERTY_VIEW_TRANSFORM
The property name that identifies a change in this camera's view transform (see getViewTransform, getViewTransformReference). A property change event's new value will be a reference to the view transform, but old value will always be null.

See Also:
Constant Field Values

PROPERTY_CODE_VIEW_TRANSFORM

public static final int PROPERTY_CODE_VIEW_TRANSFORM
See Also:
Constant Field Values

VIEW_CONSTRAINT_NONE

public static final int VIEW_CONSTRAINT_NONE
See Also:
Constant Field Values

VIEW_CONSTRAINT_ALL

public static final int VIEW_CONSTRAINT_ALL
See Also:
Constant Field Values

VIEW_CONSTRAINT_CENTER

public static final int VIEW_CONSTRAINT_CENTER
See Also:
Constant Field Values
Constructor Detail

PCamera

public PCamera()
Construct a new camera with no layers and a default white color.

Method Detail

getComponent

public PComponent getComponent()
Get the canvas associated with this camera. This will return null if not canvas has been associated, as may be the case for internal cameras.


setComponent

public void setComponent(PComponent aComponent)
Set the canvas associated with this camera. When the camera is repainted it will request repaints on this canvas.


repaintFrom

public void repaintFrom(PBounds localBounds,
                        PNode descendentOrThis)
Repaint this camera, and forward the repaint request to the camera's canvas if it is not null.

Overrides:
repaintFrom in class PNode
Parameters:
localBounds - the bounds to repaint
descendentOrThis - if childOrThis does not equal this then this nodes transform will be applied to the localBounds param

repaintFromLayer

public void repaintFromLayer(PBounds viewBounds,
                             PNode repaintedLayer)
Repaint from one of the cameras layers. The repaint region needs to be transformed from view to local in this case. Unlike most repaint methods in piccolo this one must not modify the viewBounds parameter.


getLayersReference

public java.util.List getLayersReference()
Return a reference to the list of layers managed by this camera.


getLayerCount

public int getLayerCount()

getLayer

public PLayer getLayer(int index)

indexOfLayer

public int indexOfLayer(PLayer layer)

addLayer

public void addLayer(PLayer layer)
Add the layer to the end of this camera's list of layers. Layers may be viewed by multiple cameras at once.


addLayer

public void addLayer(int index,
                     PLayer layer)
Add the layer at the given index in this camera's list of layers. Layers may be viewed by multiple cameras at once.


removeLayer

public PLayer removeLayer(PLayer layer)
Remove the given layer from the list of layers managed by this camera.


removeLayer

public PLayer removeLayer(int index)
Remove the layer at the given index from the list of layers managed by this camera.


getUnionOfLayerFullBounds

public PBounds getUnionOfLayerFullBounds()
Return the total bounds of all the layers that this camera looks at.


paint

protected void paint(PPaintContext paintContext)
Paint this camera (default background color is white) and then paint the cameras view through the view transform.

Overrides:
paint in class PNode
Parameters:
paintContext - the paint context to use for painting the node

paintCameraView

protected void paintCameraView(PPaintContext paintContext)
Paint all the layers that the camera is looking at, this method is only called when the cameras view transform and clip are applied to the paintContext.


paintDebugInfo

protected void paintDebugInfo(PPaintContext paintContext)

fullPaint

public void fullPaint(PPaintContext paintContext)
Override fullPaint to push the camera onto the paintContext so that it can be later be accessed by PPaintContext.getCamera();

Overrides:
fullPaint in class PNode
Parameters:
paintContext - the paint context to use for painting this node and its children

pick

public PPickPath pick(double x,
                      double y,
                      double halo)
Generate and return a PPickPath for the point x,y specified in the local coord system of this camera. Picking is done with a rectangle, halo specifies how large that rectangle will be.


pickAfterChildren

protected boolean pickAfterChildren(PPickPath pickPath)
After the direct children of the camera have been given a chance to be picked objects viewed by the camera are given a chance to be picked.

Overrides:
pickAfterChildren in class PNode
Parameters:
pickPath - the pick path used for the pick operation
Returns:
true if this node was picked

pickCameraView

protected boolean pickCameraView(PPickPath pickPath)
Pick all the layers that the camera is looking at, this method is only called when the cameras view transform and clip are applied to the pickPath.


getViewBounds

public PBounds getViewBounds()
Return the bounds of this camera in the view coordinate system.


setViewBounds

public void setViewBounds(java.awt.geom.Rectangle2D centerBounds)
Translates and scales the camera's view transform so that the given bounds (in camera layer's coordinate system)are centered withing the cameras view bounds. Use this method to point the camera at a given location.


getViewScale

public double getViewScale()
Return the scale applied by the view transform to the layers viewed by this camera.


scaleView

public void scaleView(double scale)
Scale the view transform that is applied to the layers viewed by this camera by the given amount.


scaleViewAboutPoint

public void scaleViewAboutPoint(double scale,
                                double x,
                                double y)
Scale the view transform that is applied to the layers viewed by this camera by the given amount about the given point.


setViewScale

public void setViewScale(double scale)
Set the scale of the view transform that is applied to the layers viewed by this camera.


translateView

public void translateView(double dx,
                          double dy)
Translate the view transform that is applied to the camera's layers.


setViewOffset

public void setViewOffset(double x,
                          double y)
Sets the offset of the view transform that is applied to the camera's layers.


getViewTransform

public PAffineTransform getViewTransform()
Get a copy of the view transform that is applied to the camera's layers.


getViewTransformReference

public PAffineTransform getViewTransformReference()
Get a reference to the view transform that is applied to the camera's layers.


setViewTransform

public void setViewTransform(java.awt.geom.AffineTransform aTransform)
Set the view transform that is applied to the views layers.


animateViewToCenterBounds

public PTransformActivity animateViewToCenterBounds(java.awt.geom.Rectangle2D centerBounds,
                                                    boolean shouldScaleToFit,
                                                    long duration)
Animate the camera's view from its current transform when the activity starts to a new transform that centers the given bounds in the camera layers coordinate system into the cameras view bounds. If the duration is 0 then the view will be transformed immediately, and null will be returned. Else a new PTransformActivity will get returned that is set to animate the camera's view transform to the new bounds. If shouldScale is true, then the camera will also scale its view so that the given bounds fit fully within the cameras view bounds, else the camera will maintain its original scale.


animateViewToPanToBounds

public PTransformActivity animateViewToPanToBounds(java.awt.geom.Rectangle2D panToBounds,
                                                   long duration)
Pan the camera's view from its current transform when the activity starts to a new transform so that the view bounds will contain (if possible, intersect if not possible) the new bounds in the camera layers coordinate system. If the duration is 0 then the view will be transformed immediately, and null will be returned. Else a new PTransformActivity will get returned that is set to animate the camera's view transform to the new bounds.


animateViewToIncludeBounds

public PTransformActivity animateViewToIncludeBounds(java.awt.geom.Rectangle2D includeBounds,
                                                     long duration)
Deprecated. Renamed to animateViewToPanToBounds


animateViewToTransform

public PTransformActivity animateViewToTransform(java.awt.geom.AffineTransform destination,
                                                 long duration)
Animate the cameras view transform from its current value when the activity starts to the new destination transform value.


getViewConstraint

public int getViewConstraint()

setViewConstraint

public void setViewConstraint(int constraint)

applyViewConstraints

protected void applyViewConstraints()

viewToLocal

public java.awt.geom.Point2D viewToLocal(java.awt.geom.Point2D viewPoint)
Convert the point from the camera's view coordinate system to the camera's local coordinate system. The given point is modified by this.


viewToLocal

public java.awt.geom.Dimension2D viewToLocal(java.awt.geom.Dimension2D viewDimension)
Convert the dimension from the camera's view coordinate system to the camera's local coordinate system. The given dimension is modified by this.


viewToLocal

public java.awt.geom.Rectangle2D viewToLocal(java.awt.geom.Rectangle2D viewRectangle)
Convert the rectangle from the camera's view coordinate system to the camera's local coordinate system. The given rectangle is modified by this method.


localToView

public java.awt.geom.Point2D localToView(java.awt.geom.Point2D localPoint)
Convert the point from the camera's local coordinate system to the camera's view coordinate system. The given point is modified by this method.


localToView

public java.awt.geom.Dimension2D localToView(java.awt.geom.Dimension2D localDimension)
Convert the dimension from the camera's local coordinate system to the camera's view coordinate system. The given dimension is modified by this method.


localToView

public java.awt.geom.Rectangle2D localToView(java.awt.geom.Rectangle2D localRectangle)
Convert the rectangle from the camera's local coordinate system to the camera's view coordinate system. The given rectangle is modified by this method.



Copyright 2005 by University of Maryland, College Park, MD 20742, USA All rights reserved.

Web Accessibility