Package edu.umd.cs.piccolo
Class PCamera
java.lang.Object
edu.umd.cs.piccolo.PNode
edu.umd.cs.piccolo.PCamera
- All Implemented Interfaces:
Printable,Serializable,Cloneable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe property code that identifies a change in the set of this camera's layers (seegetLayer,getLayerCount,getLayersReference).static final intThe property code that identifies a change in this camera's view transform (seegetViewTransform,getViewTransformReference).static final StringThe property name that identifies a change in the set of this camera's layers (seegetLayer,getLayerCount,getLayersReference).static final StringThe property name that identifies a change in this camera's view transform (seegetViewTransform,getViewTransformReference).static final intEnforces that the view be able to see all nodes in the scene.static final intConstrains the the view to be centered on the scene's full bounds.static final intDenotes that the view has no constraints.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_DELEGATEFields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts the specified layer at the specified position in the list of layers viewed by this camera.voidInserts the specified layer at the end of the list of layers viewed by this camera.animateViewToCenterBounds(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 layer's coordinate system into the cameras view bounds.animateViewToIncludeBounds(Rectangle2D includeBounds, long duration) Deprecated.Renamed to animateViewToPanToBoundsanimateViewToPanToBounds(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.animateViewToTransform(AffineTransform destination, long duration) Animate the cameras view transform from its current value when the activity starts to the new destination transform value.protected voidTransforms the view so that it conforms to the given constraint.voidfullPaint(PPaintContext paintContext) Paint this node and all of its descendants.Return the component for this camera, ornullif no component has been associated with this camera, as may be the case for internal cameras.getLayer(int index) Return the layer at the specified position in the list of layers viewed by this camera.intReturn the number of layers in the list of layers viewed by this camera.Return a reference to the list of layers viewed by this camera.Return the union of the full bounds of each layer in the list of layers viewed by this camera, or empty bounds if the list of layers viewed by this camera is empty.Return the bounds of this camera in the view coordinate system.intReturn the constraint applied to the view.doubleReturn the scale applied by the view transform to the list of layers viewed by this camera.Return a copy of the view transform applied to the list of layers viewed by this camera.Return a reference to the view transform applied to the list of layers viewed by this camera.intindexOfLayer(PLayer layer) Return the index of the first occurrence of the specified layer in the list of layers viewed by this camera, or-1if the list of layers viewed by this camera does not contain the specified layer.localToView(Dimension2D localDimension) Convert the dimension from the camera's local coordinate system to the camera's view coordinate system.localToView(Point2D localPoint) Convert the point from the camera's local coordinate system to the camera's view coordinate system.localToView(Rectangle2D localRectangle) Convert the rectangle from the camera's local coordinate system to the camera's view coordinate system.protected voidpaint(PPaintContext paintContext) Paint this camera and then paint this camera's view through its view transform.protected voidpaintCameraView(PPaintContext paintContext) Paint all the layers in the list of layers viewed by this camera.protected voidpaintDebugInfo(PPaintContext paintContext) Renders debug info onto the newly painted scene.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 booleanpickAfterChildren(PPickPath pickPath) Try to pick this node after its children have had a chance to be picked.protected booleanpickCameraView(PPickPath pickPath) Try to pick all of the layers in the list of layers viewed by this camera.removeLayer(int index) Removes the element at the specified position from the list of layers viewed by this camera.removeLayer(PLayer layer) Removes the first occurrence of the specified layer from the list of layers viewed by this camera, if it is present.voidrepaintFrom(PBounds localBounds, PNode sourceNode) Repaint this camera and forward the repaint request to the component for this camera, if it is non-null.voidrepaintFromLayer(PBounds viewBounds, PLayer repaintedLayer) Repaint from one of the camera's layers.voidrepaintFromLayer(PBounds viewBounds, PNode repaintedLayer) Deprecated.voidscaleView(double scale) Scale the view transform applied to the list of layers viewed by this camera byscaleabout the point[0, 0].voidscaleViewAboutPoint(double scale, double x, double y) Scale the view transform applied to the list of layers viewed by this camera byscaleabout the specified point[x, y].voidsetComponent(PComponent component) Set the component for this camera tocomponent.voidsetViewBounds(Rectangle2D centerBounds) Animates the camera's view so that the given bounds (in camera layer's coordinate system) are centered within the cameras view bounds.voidsetViewConstraint(int viewConstraint) Set the view constraint to apply to the view toviewConstraint.voidsetViewOffset(double x, double y) Set the offset for the view transform applied to the list of layers viewed by this camera to[x, y].voidsetViewScale(double scale) Set the scale applied by the view transform to the list of layers viewed by this camera toscale.voidsetViewTransform(AffineTransform viewTransform) Set the view transform applied to the list of layers viewed by this camera toviewTransform.voidtranslateView(double dx, double dy) Translate the view transform applied to the list of layers viewed by this camera by[dx, dy].viewToLocal(Dimension2D viewDimension) Convert the dimension from the camera's view coordinate system to the camera's local coordinate system.viewToLocal(Point2D viewPoint) Convert the point from the camera's view coordinate system to the camera's local coordinate system.viewToLocal(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, 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, 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, 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
-
Field Details
-
PROPERTY_LAYERS
The property name that identifies a change in the set of this camera's layers (seegetLayer,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:
-
PROPERTY_CODE_LAYERS
public static final int PROPERTY_CODE_LAYERSThe property code that identifies a change in the set of this camera's layers (seegetLayer,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:
-
PROPERTY_VIEW_TRANSFORM
The property name that identifies a change in this camera's view transform (seegetViewTransform,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:
-
PROPERTY_CODE_VIEW_TRANSFORM
public static final int PROPERTY_CODE_VIEW_TRANSFORMThe property code that identifies a change in this camera's view transform (seegetViewTransform,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:
-
VIEW_CONSTRAINT_NONE
public static final int VIEW_CONSTRAINT_NONEDenotes that the view has no constraints.- See Also:
-
VIEW_CONSTRAINT_ALL
public static final int VIEW_CONSTRAINT_ALLEnforces that the view be able to see all nodes in the scene.- See Also:
-
VIEW_CONSTRAINT_CENTER
public static final int VIEW_CONSTRAINT_CENTERConstrains the the view to be centered on the scene's full bounds.- See Also:
-
-
Constructor Details
-
PCamera
public PCamera()Create a new camera with an empy list of layers.
-
-
Method Details
-
getComponent
Return the component for this camera, ornullif no component has been associated with this camera, as may be the case for internal cameras.- Returns:
- the component for this camera, or
nullif no such component exists
-
setComponent
Set the component for this camera tocomponent. The component, if non-null, receives repaint notification from this camera.- Parameters:
component- component for this camera
-
repaintFrom
Repaint this camera and forward the repaint request to the component for this camera, if it is non-null.- Overrides:
repaintFromin classPNode- Parameters:
localBounds- bounds that require repainting, in local coordinatessourceNode- node from which the repaint message originates, may be the camera itself
-
repaintFromLayer
Repaint from one of the camera's layers. The repaint region needs to be transformed from view to local in this case. Unlike most repaint methods in Piccolo2D this one must not modify theviewBoundsparameter.- Parameters:
viewBounds- bounds that require repainting, in view coordinatesrepaintedLayer- layer dispatching the repaint notification- Since:
- 1.3
-
repaintFromLayer
Deprecated.byrepaintFromLayer(PBounds, PLayer). Will be removed in version 2.0.- Parameters:
viewBounds- bounds that require repainting, in view coordinatesrepaintedLayer- layer dispatching the repaint notification
-
getLayersReference
Return a reference to the list of layers viewed by this camera.- Returns:
- the list of layers viewed by this camera
-
getLayerCount
public int getLayerCount()Return the number of layers in the list of layers viewed by this camera.- Returns:
- the number of layers in the list of layers viewed by this camera
-
getLayer
Return the layer at the specified position in the list of layers viewed by this camera.- Parameters:
index- index of the layer to return- Returns:
- the layer at the specified position in the list of layers viewed by this camera
- Throws:
IndexOutOfBoundsException- if the specified index is out of range (index < 0 || index >= getLayerCount())
-
indexOfLayer
Return the index of the first occurrence of the specified layer in the list of layers viewed by this camera, or-1if the list of layers viewed by this camera does not contain the specified layer.- Parameters:
layer- layer to search for- Returns:
- the index of the first occurrence of the specified layer in the
list of layers viewed by this camera, or
-1if the list of layers viewed by this camera does not contain the specified layer
-
addLayer
Inserts the specified layer at the end of the list of layers viewed by this camera. Layers may be viewed by multiple cameras at once.- Parameters:
layer- layer to add
-
addLayer
Inserts the specified layer at the specified position in the list of layers viewed by this camera. Layers may be viewed by multiple cameras at once.- Parameters:
index- index at which the specified layer is to be insertedlayer- layer to add- Throws:
IndexOutOfBoundsException- if the specified index is out of range (index < 0 || index >= getLayerCount())
-
removeLayer
Removes the first occurrence of the specified layer from the list of layers viewed by this camera, if it is present.- Parameters:
layer- layer to be removed- Returns:
- the specified layer
-
removeLayer
Removes the element at the specified position from the list of layers viewed by this camera.- Parameters:
index- index of the layer to remove- Returns:
- the layer previously at the specified position
- Throws:
IndexOutOfBoundsException- if the specified index is out of range (index < 0 || index >= getLayerCount())
-
getUnionOfLayerFullBounds
Return the union of the full bounds of each layer in the list of layers viewed by this camera, or empty bounds if the list of layers viewed by this camera is empty.- Returns:
- the union of the full bounds of each layer in the list of layers viewed by this camera, or empty bounds if the list of layers viewed by this camera is empty
-
paint
Paint this camera and then paint this camera's view through its view transform. -
paintCameraView
Paint all the layers in the list of layers viewed by this camera. This method is called after the view transform and clip have been applied to the specified paint context.- Parameters:
paintContext- context in which painting occurs
-
paintDebugInfo
Renders debug info onto the newly painted scene. Things like full bounds and bounds are painted as filled and outlines.- Parameters:
paintContext- context in which painting occurs
-
fullPaint
Paint this node and all of its descendants. Most subclasses do not need to override this method, they should overridepaintorpaintAfterChildreninstead.Pushes this camera onto the specified paint context so that it can be accessed later by
PPaintContext.getCamera(). -
pick
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.- Parameters:
x- the x coordinate of the pick path given in local coordinatesy- the y coordinate of the pick path given in local coordinateshalo- the distance from the x,y coordinate that is considered for inclusion in the pick path- Returns:
- the picked path
-
pickAfterChildren
Try to pick this node after its children have had a chance to be picked. Most subclasses the define a different geometry will need to override this method.After the direct children of this camera have been given a chance to be picked all of the layers in the list of layers viewed by this camera are given a chance to be picked.
- Overrides:
pickAfterChildrenin classPNode- Parameters:
pickPath- the pick path used for the pick operation- Returns:
- true if any of the layers in the list of layers viewed by this camera were picked
-
pickCameraView
Try to pick all of the layers in the list of layers viewed by this camera. This method is called after the view transform has been applied to the specified pick path.- Parameters:
pickPath- pick path- Returns:
- true if any of the layers in the list of layers viewed by this camera were picked
-
getViewBounds
Return the bounds of this camera in the view coordinate system.- Returns:
- the bounds of this camera in the view coordinate system
-
setViewBounds
Animates the camera's view so that the given bounds (in camera layer's coordinate system) are centered within the cameras view bounds. Use this method to point the camera at a given location.- Parameters:
centerBounds- the targetBounds
-
getViewScale
public double getViewScale()Return the scale applied by the view transform to the list of layers viewed by this camera.- Returns:
- the scale applied by the view transform to the list of layers viewed by this camera
-
scaleView
public void scaleView(double scale) Scale the view transform applied to the list of layers viewed by this camera byscaleabout the point[0, 0].- Parameters:
scale- view transform scale
-
scaleViewAboutPoint
public void scaleViewAboutPoint(double scale, double x, double y) Scale the view transform applied to the list of layers viewed by this camera byscaleabout the specified point[x, y].- Parameters:
scale- view transform scalex- scale about point, x coordinatey- scale about point, y coordinate
-
setViewScale
public void setViewScale(double scale) Set the scale applied by the view transform to the list of layers viewed by this camera toscale.- Parameters:
scale- view transform scale
-
translateView
public void translateView(double dx, double dy) Translate the view transform applied to the list of layers viewed by this camera by[dx, dy].- Parameters:
dx- translate delta xdy- translate delta y
-
setViewOffset
public void setViewOffset(double x, double y) Set the offset for the view transform applied to the list of layers viewed by this camera to[x, y].- Parameters:
x- offset xy- offset y
-
getViewTransform
Return a copy of the view transform applied to the list of layers viewed by this camera.- Returns:
- a copy of the view transform applied to the list of layers viewed by this camera
-
getViewTransformReference
Return a reference to the view transform applied to the list of layers viewed by this camera.- Returns:
- the view transform applied to the list of layers viewed by this camera
-
setViewTransform
Set the view transform applied to the list of layers viewed by this camera toviewTransform.- Parameters:
viewTransform- view transform applied to the list of layers viewed by this camera
-
animateViewToCenterBounds
public PTransformActivity animateViewToCenterBounds(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 layer's 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.- Parameters:
centerBounds- the bounds which the animation will pace at the center of the viewshouldScaleToFit- whether the camera should scale the view while animating to itduration- how many milliseconds the animations should take- Returns:
- the scheduled PTransformActivity
-
animateViewToPanToBounds
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.- Parameters:
panToBounds- the bounds to which the view will animate toduration- the duration of the animation given in milliseconds- Returns:
- the scheduled PTransformActivity
-
animateViewToIncludeBounds
Deprecated.Renamed to animateViewToPanToBoundsPan 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.- Parameters:
includeBounds- the bounds to which the view will animate toduration- the duration of the animation given in milliseconds- Returns:
- the scheduled PTransformActivity
-
animateViewToTransform
Animate the cameras view transform from its current value when the activity starts to the new destination transform value.- Parameters:
destination- the transform to which the view should be transformed intoduration- the duraiton in milliseconds the animation should take- Returns:
- the scheduled PTransformActivity
-
getViewConstraint
public int getViewConstraint()Return the constraint applied to the view. The view constraint will be one ofVIEW_CONSTRAINT_NONE,VIEW_CONSTRAINT_CENTER, orVIEW_CONSTRAINT_CENTER. Defaults toVIEW_CONSTRAINT_NONE.- Returns:
- the view constraint being applied to the view
-
setViewConstraint
public void setViewConstraint(int viewConstraint) Set the view constraint to apply to the view toviewConstraint. The view constraint must be one ofVIEW_CONSTRAINT_NONE,VIEW_CONSTRAINT_CENTER, orVIEW_CONSTRAINT_CENTER.- Parameters:
viewConstraint- constraint to apply to the view- Throws:
IllegalArgumentException- ifviewConstraintis not one ofVIEW_CONSTRAINT_NONE,VIEW_CONSTRAINT_CENTER, orVIEW_CONSTRAINT_CENTER
-
applyViewConstraints
protected void applyViewConstraints()Transforms the view so that it conforms to the given constraint. -
viewToLocal
Convert the point from the camera's view coordinate system to the camera's local coordinate system. The given point is modified by this.- Parameters:
viewPoint- the point to transform to the local coordinate system from the view's coordinate system- Returns:
- the transformed point
-
viewToLocal
Convert the dimension from the camera's view coordinate system to the camera's local coordinate system. The given dimension is modified by this.- Parameters:
viewDimension- the dimension to transform from the view system to the local coordinate system- Returns:
- returns the transformed dimension
-
viewToLocal
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.- Parameters:
viewRectangle- the rectangle to transform from view to local coordinate System- Returns:
- the transformed rectangle
-
localToView
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.- Parameters:
localPoint- point to transform from local to view coordinate system- Returns:
- the transformed point
-
localToView
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.- Parameters:
localDimension- the dimension to transform from local to view coordinate systems- Returns:
- the transformed dimension
-
localToView
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.- Parameters:
localRectangle- the rectangle to transform from local to view coordinate system- Returns:
- the transformed rectangle
-