|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.umd.cs.piccolo.PNode
edu.umd.cs.piccolo.PCamera
public class PCamera
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.
PLayer
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode |
---|
PNode.PSceneGraphDelegate |
Field Summary | |
---|---|
static int |
PROPERTY_CODE_LAYERS
The property code that identifies a change in the set of this camera's layers (see getLayer , getLayerCount , getLayersReference ). |
static int |
PROPERTY_CODE_VIEW_TRANSFORM
The property code that identifies a change in this camera's view transform (see getViewTransform ,
getViewTransformReference ). |
static String |
PROPERTY_LAYERS
The property name that identifies a change in the set of this camera's layers (see getLayer , getLayerCount , getLayersReference ). |
static 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
Enforces that the view be able to see all nodes in the scene. |
static int |
VIEW_CONSTRAINT_CENTER
Constrains the the view to be centered on the scene's full bounds. |
static int |
VIEW_CONSTRAINT_NONE
Denotes that the view has no constraints. |
Fields inherited from interface java.awt.print.Printable |
---|
NO_SUCH_PAGE, PAGE_EXISTS |
Constructor Summary | |
---|---|
PCamera()
Create a new camera with an empy list of layers. |
Method Summary | |
---|---|
void |
addLayer(int index,
PLayer layer)
Inserts the specified layer at the specified position in the list of layers viewed by this camera. |
void |
addLayer(PLayer layer)
Inserts the specified layer at the end of the list of layers viewed by this camera. |
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. |
PTransformActivity |
animateViewToIncludeBounds(Rectangle2D includeBounds,
long duration)
Deprecated. Renamed to animateViewToPanToBounds |
PTransformActivity |
animateViewToPanToBounds(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(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()
Transforms the view so that it conforms to the given constraint. |
void |
fullPaint(PPaintContext paintContext)
Paint this node and all of its descendants. |
PComponent |
getComponent()
Return the component for this camera, or null if no
component has been associated with this camera, as may be the case for
internal cameras. |
PLayer |
getLayer(int index)
Return the layer at the specified position in the list of layers viewed by this camera. |
int |
getLayerCount()
Return the number of layers in the list of layers viewed by this camera. |
List |
getLayersReference()
Return a reference to the list of layers viewed by this camera. |
PBounds |
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. |
PBounds |
getViewBounds()
Return the bounds of this camera in the view coordinate system. |
int |
getViewConstraint()
Return the constraint applied to the view. |
double |
getViewScale()
Return the scale applied by the view transform to the list of layers viewed by this camera. |
PAffineTransform |
getViewTransform()
Return a copy of the view transform applied to the list of layers viewed by this camera. |
PAffineTransform |
getViewTransformReference()
Return a reference to the view transform applied to the list of layers viewed by this camera. |
int |
indexOfLayer(PLayer layer)
Return the index of the first occurrence of the specified layer in the list of layers viewed by this camera, or -1 if the list of layers
viewed by this camera does not contain the specified layer. |
Dimension2D |
localToView(Dimension2D localDimension)
Convert the dimension from the camera's local coordinate system to the camera's view coordinate system. |
Point2D |
localToView(Point2D localPoint)
Convert the point from the camera's local coordinate system to the camera's view coordinate system. |
Rectangle2D |
localToView(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 and then paint this camera's view through its view transform. |
protected void |
paintCameraView(PPaintContext paintContext)
Paint all the layers in the list of layers viewed by this camera. |
protected void |
paintDebugInfo(PPaintContext paintContext)
Renders debug info onto the newly painted scene. |
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)
Try to pick this node after its children have had a chance to be picked. |
protected boolean |
pickCameraView(PPickPath pickPath)
Try to pick all of the layers in the list of layers viewed by this camera. |
PLayer |
removeLayer(int index)
Removes the element at the specified position from the list of layers viewed by this camera. |
PLayer |
removeLayer(PLayer layer)
Removes the first occurrence of the specified layer from the list of layers viewed by this camera, if it is present. |
void |
repaintFrom(PBounds localBounds,
PNode sourceNode)
Repaint this camera and forward the repaint request to the component for this camera, if it is non-null. |
void |
repaintFromLayer(PBounds viewBounds,
PLayer repaintedLayer)
Repaint from one of the camera's layers. |
void |
repaintFromLayer(PBounds viewBounds,
PNode repaintedLayer)
Deprecated. by repaintFromLayer(PBounds, PLayer) . Will be removed
in version 2.0. |
void |
scaleView(double scale)
Scale the view transform applied to the list of layers viewed by this camera by scale about the point [0, 0] . |
void |
scaleViewAboutPoint(double scale,
double x,
double y)
Scale the view transform applied to the list of layers viewed by this camera by scale about the specified point
[x, y] . |
void |
setComponent(PComponent component)
Set the component for this camera to component . |
void |
setViewBounds(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. |
void |
setViewConstraint(int viewConstraint)
Set the view constraint to apply to the view to viewConstraint . |
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] . |
void |
setViewScale(double scale)
Set the scale applied by the view transform to the list of layers viewed by this camera to scale . |
void |
setViewTransform(AffineTransform viewTransform)
Set the view transform applied to the list of layers viewed by this camera to viewTransform . |
void |
translateView(double dx,
double dy)
Translate the view transform applied to the list of layers viewed by this camera by [dx, dy] . |
Dimension2D |
viewToLocal(Dimension2D viewDimension)
Convert the dimension from the camera's view coordinate system to the camera's local coordinate system. |
Point2D |
viewToLocal(Point2D viewPoint)
Convert the point from the camera's view coordinate system to the camera's local coordinate system. |
Rectangle2D |
viewToLocal(Rectangle2D viewRectangle)
Convert the rectangle from the camera's view coordinate system to the camera's local coordinate system. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PROPERTY_LAYERS
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.
public static final int PROPERTY_CODE_LAYERS
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.
public static final String PROPERTY_VIEW_TRANSFORM
getViewTransform
,
getViewTransformReference
). A property
change event's new value will be a reference to the view transform, but
old value will always be null.
public static final int PROPERTY_CODE_VIEW_TRANSFORM
getViewTransform
,
getViewTransformReference
). A property
change event's new value will be a reference to the view transform, but
old value will always be null.
public static final int VIEW_CONSTRAINT_NONE
public static final int VIEW_CONSTRAINT_ALL
public static final int VIEW_CONSTRAINT_CENTER
Constructor Detail |
---|
public PCamera()
Method Detail |
---|
public PComponent getComponent()
null
if no
component has been associated with this camera, as may be the case for
internal cameras.
null
if no such
component existspublic void setComponent(PComponent component)
component
. The
component, if non-null, receives repaint notification from this camera.
component
- component for this camerapublic void repaintFrom(PBounds localBounds, PNode sourceNode)
repaintFrom
in class PNode
localBounds
- bounds that require repainting, in local coordinatessourceNode
- node from which the repaint message originates, may
be the camera itselfpublic void repaintFromLayer(PBounds viewBounds, PLayer repaintedLayer)
viewBounds
parameter.
viewBounds
- bounds that require repainting, in view coordinatesrepaintedLayer
- layer dispatching the repaint notificationpublic void repaintFromLayer(PBounds viewBounds, PNode repaintedLayer)
repaintFromLayer(PBounds, PLayer)
. Will be removed
in version 2.0.
viewBounds
- bounds that require repainting, in view coordinatesrepaintedLayer
- layer dispatching the repaint notificationpublic List getLayersReference()
public int getLayerCount()
public PLayer getLayer(int index)
index
- index of the layer to return
IndexOutOfBoundsException
- if the specified index is out of range
(index < 0 || index >= getLayerCount()
)public int indexOfLayer(PLayer layer)
-1
if the list of layers
viewed by this camera does not contain the specified layer.
layer
- layer to search for
-1
if the list of
layers viewed by this camera does not contain the specified layerpublic void addLayer(PLayer layer)
layer
- layer to addpublic void addLayer(int index, PLayer layer)
index
- index at which the specified layer is to be insertedlayer
- layer to add
IndexOutOfBoundsException
- if the specified index is out of range
(index < 0 || index >= getLayerCount()
)public PLayer removeLayer(PLayer layer)
layer
- layer to be removed
public PLayer removeLayer(int index)
index
- index of the layer to remove
IndexOutOfBoundsException
- if the specified index is out of range
(index < 0 || index >= getLayerCount()
)public PBounds getUnionOfLayerFullBounds()
protected void paint(PPaintContext paintContext)
paint
in class PNode
paintContext
- context in which painting occursprotected void paintCameraView(PPaintContext paintContext)
paintContext
- context in which painting occursprotected void paintDebugInfo(PPaintContext paintContext)
paintContext
- context in which painting occurspublic void fullPaint(PPaintContext paintContext)
paint
or
paintAfterChildren
instead.
Pushes this camera onto the specified paint context so that it
can be accessed later by PPaintContext.getCamera()
.
fullPaint
in class PNode
paintContext
- the paint context to use for painting this node and
its childrenpublic PPickPath pick(double x, double y, double halo)
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
protected boolean pickAfterChildren(PPickPath pickPath)
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.
pickAfterChildren
in class PNode
pickPath
- the pick path used for the pick operation
protected boolean pickCameraView(PPickPath pickPath)
pickPath
- pick path
public PBounds getViewBounds()
public void setViewBounds(Rectangle2D centerBounds)
centerBounds
- the targetBoundspublic double getViewScale()
public void scaleView(double scale)
scale
about the point [0, 0]
.
scale
- view transform scalepublic void scaleViewAboutPoint(double scale, double x, double y)
scale
about the specified point
[x, y]
.
scale
- view transform scalex
- scale about point, x coordinatey
- scale about point, y coordinatepublic void setViewScale(double scale)
scale
.
scale
- view transform scalepublic void translateView(double dx, double dy)
[dx, dy]
.
dx
- translate delta xdy
- translate delta ypublic void setViewOffset(double x, double y)
[x, y]
.
x
- offset xy
- offset ypublic PAffineTransform getViewTransform()
public PAffineTransform getViewTransformReference()
public void setViewTransform(AffineTransform viewTransform)
viewTransform
.
viewTransform
- view transform applied to the list of layers
viewed by this camerapublic PTransformActivity animateViewToCenterBounds(Rectangle2D centerBounds, boolean shouldScaleToFit, long duration)
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
public PTransformActivity animateViewToPanToBounds(Rectangle2D panToBounds, long duration)
panToBounds
- the bounds to which the view will animate toduration
- the duration of the animation given in milliseconds
public PTransformActivity animateViewToIncludeBounds(Rectangle2D includeBounds, long duration)
includeBounds
- the bounds to which the view will animate toduration
- the duration of the animation given in milliseconds
public PTransformActivity animateViewToTransform(AffineTransform destination, long duration)
destination
- the transform to which the view should be transformed
intoduration
- the duraiton in milliseconds the animation should take
public int getViewConstraint()
VIEW_CONSTRAINT_NONE
,
VIEW_CONSTRAINT_CENTER
, or VIEW_CONSTRAINT_CENTER
. Defaults to VIEW_CONSTRAINT_NONE
.
public void setViewConstraint(int viewConstraint)
viewConstraint
. The view constraint must be one of
VIEW_CONSTRAINT_NONE
, VIEW_CONSTRAINT_CENTER
, or VIEW_CONSTRAINT_CENTER
.
viewConstraint
- constraint to apply to the view
IllegalArgumentException
- if viewConstraint
is not one of VIEW_CONSTRAINT_NONE
,
VIEW_CONSTRAINT_CENTER
, or VIEW_CONSTRAINT_CENTER
protected void applyViewConstraints()
public Point2D viewToLocal(Point2D viewPoint)
viewPoint
- the point to transform to the local coordinate system
from the view's coordinate system
public Dimension2D viewToLocal(Dimension2D viewDimension)
viewDimension
- the dimension to transform from the view system to
the local coordinate system
public Rectangle2D viewToLocal(Rectangle2D viewRectangle)
viewRectangle
- the rectangle to transform from view to local
coordinate System
public Point2D localToView(Point2D localPoint)
localPoint
- point to transform from local to view coordinate system
public Dimension2D localToView(Dimension2D localDimension)
localDimension
- the dimension to transform from local to view
coordinate systems
public Rectangle2D localToView(Rectangle2D localRectangle)
localRectangle
- the rectangle to transform from local to view
coordinate system
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |