edu.umd.cs.piccolo
Class PNode

java.lang.Object
  extended byedu.umd.cs.piccolo.PNode
All Implemented Interfaces:
java.lang.Cloneable, java.awt.print.Printable, java.io.Serializable
Direct Known Subclasses:
P3DRect, PCamera, PComposite, PImage, PLayer, PLens, PLine, PNodeCache, PPath, PRoot, PStickyHandleManager, PStyledText, PSWTImage, PSWTPath, PSWTText, PText

public class PNode
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, java.awt.print.Printable

PNode is the central abstraction in Piccolo. All objects that are visible on the screen are instances of the node class. All nodes may have other "child" nodes added to them.

See edu.umd.piccolo.examples.NodeExample.java for demonstrations of how nodes can be used and how new types of nodes can be created.

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

Field Summary
static java.lang.String PROPERTY_BOUNDS
          The property name that identifies a change of this node's bounds (see getBounds, getBoundsReference).
static java.lang.String PROPERTY_CHILDREN
          The property name that identifies a change in the set of this node's direct children (see getChildrenReference, getChildrenIterator).
static java.lang.String PROPERTY_CHILDREN_PICKABLE
          The property name that identifies a change of this node's children pickable status (see getChildrenPickable).
static java.lang.String PROPERTY_CLIENT_PROPERTIES
          The property name that identifies a change in this node's client propertie (see getClientProperty).
static java.lang.String PROPERTY_FULL_BOUNDS
          The property name that identifies a change of this node's full bounds (see getFullBounds, getFullBoundsReference).
static java.lang.String PROPERTY_PAINT
          The property name that identifies a change of this node's paint (see getPaint).
static java.lang.String PROPERTY_PARENT
          The property name that identifies a change of this node's parent (see getParent).
static java.lang.String PROPERTY_PICKABLE
          The property name that identifies a change of this node's pickable status (see getPickable).
static java.lang.String PROPERTY_TRANSFORM
          The property name that identifies a change of this node's transform (see getTransform, getTransformReference).
static java.lang.String PROPERTY_TRANSPARENCY
          The property name that identifies a change of this node's transparency (see getTransparency).
static java.lang.String PROPERTY_VISIBLE
          The property name that identifies a change of this node's visibility (see getVisible).
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PNode()
          Constructs a new PNode.
 
Method Summary
 boolean addActivity(PActivity activity)
          Schedule the given activity with the root, note that only scheduled activities will be stepped.
 void addChild(int index, PNode child)
          Add a node to be a new child of this node at the specified index.
 void addChild(PNode child)
          Add a node to be a new child of this node.
 void addChildren(java.util.Collection nodes)
          Add a collection of nodes to be children of this node.
 void addClientProperty(java.lang.Object key, java.lang.Object value)
          Add an arbitrary key/value "client property" to this node.
 void addInputEventListener(PInputEventListener listener)
          Adds the specified input event listener to receive input events from this node.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener for a specific property.
 PInterpolatingActivity animateToBounds(double x, double y, double width, double height, long duration)
          Animate this node's bounds from their current location when the activity starts to the specified bounds.
 PInterpolatingActivity animateToColor(java.awt.Color destColor, long duration)
          Animate this node's color from its current value to the new value specified.
 PTransformActivity animateToPositionScaleRotation(double x, double y, double scale, double theta, long duration)
          Animate this node's transform from its current location when the activity starts to the specified location, scale, and rotation.
 PTransformActivity animateToTransform(java.awt.geom.AffineTransform destTransform, long duration)
          Animate this node's transform from its current values when the activity starts to the new values specified in the given transform.
 PInterpolatingActivity animateToTransparency(float zeroToOne, long duration)
          Animate this node's transparency from its current value to the new value specified.
 boolean centerBoundsOnPoint(double localX, double localY)
          Center the bounds of this node so that they are centered on the given point specified on the local coords of this node.
 void centerFullBoundsOnPoint(double parentX, double parentY)
          Center the ffull bounds of this node so that they are centered on the given point specified on the local coords of this nodes parent.
 java.lang.Object clone()
          The copy method copies this node and all of its descendents.
 PBounds computeFullBounds(PBounds dstBounds)
          Compute and return the full bounds of this node.
 void endResizeBounds()
          Notify this node that you have finished a resize bounds sequence.
 void findIntersectingNodes(java.awt.geom.Rectangle2D fullBounds, java.util.ArrayList results)
           
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Report a bound property update to any registered listeners.
 boolean fullIntersects(java.awt.geom.Rectangle2D parentBounds)
          Return true if the full bounds of this node intersects with the specified bounds.
 void fullPaint(PPaintContext paintContext)
          Paint this node and all of its descendents.
 boolean fullPick(PPickPath pickPath)
          Try to pick this node and all of its descendents.
 java.util.Collection getAllNodes()
          Return a collection containing this node and all of its descendent nodes.
 java.util.Collection getAllNodes(PNodeFilter filter, java.util.Collection results)
          Return a collection containing the subset of this node and all of its descendent nodes that are accepted by the given node filter.
 PBounds getBounds()
          Return a copy of this node's bounds.
protected  boolean getBoundsChanged()
          Return true if this node's bounds have recently changed.
 PBounds getBoundsReference()
          Return a direct reference to this node's bounds.
protected  boolean getBoundsVolatile()
          Return true if this nodes bounds may change at any time.
 PNode getChild(int index)
          Return the child node at the specified index.
protected  boolean getChildBoundsInvalid()
          Return true if one of this node's descendents has invalid bounds.
protected  boolean getChildBoundsVolatile()
          Return true if this node has a child with volatile bounds.
 boolean getChildPaintInvalid()
          Return true if this node has a child with invalid paint.
 int getChildrenCount()
          Return the number of children that this node has.
 java.util.ListIterator getChildrenIterator()
          Return an iterator over this nodeís direct descendent children.
 boolean getChildrenPickable()
          Return true if the children of this node should be picked.
 java.util.List getChildrenReference()
          Return a reference to the list used to manage this nodeís children.
 java.lang.Object getClientProperty(java.lang.Object key)
          Returns the value of the property with the specified key.
 java.util.Iterator getClientPropertyKeysIterator()
          Returns an Iterator that will traverse all of the keys maped to client values.
 PBounds getFullBounds()
          Return a copy of this node's full bounds.
protected  boolean getFullBoundsInvalid()
          Return true if the full bounds of this node are invalid.
 PBounds getFullBoundsReference()
          Return a reference to this node's full bounds cache.
 PBounds getGlobalBounds()
          Return a copy of the bounds of this node in the global coordinate system.
 PBounds getGlobalFullBounds()
          Return a copy of the full bounds of this node in the global coordinate system.
 double getGlobalRotation()
          Return the total amount of rotation applied to this node by its own transform together with the transforms of all its ancestors.
 double getGlobalScale()
          Return the global scale that is being applied to this node by its transform together with the transforms of all its ancestors.
 PAffineTransform getGlobalToLocalTransform(PAffineTransform dest)
          Return the transform that converts global coordinates to local coordinates of this node.
 java.awt.geom.Point2D getGlobalTranslation()
          Return the global translation that is being applied to this node by its transform together with the transforms of all its ancestors.
 double getHeight()
          Return the height (in local coords) of this node's bounds.
 PAffineTransform getInverseTransform()
          Return an inverted copy of the transform associated with this node.
 javax.swing.event.EventListenerList getListenerList()
          Return the list of event listeners associated with this node.
 PAffineTransform getLocalToGlobalTransform(PAffineTransform dest)
          Return the transform that converts local coordinates at this node to the global coordinate system.
 boolean getOccluded()
           
 java.awt.geom.Point2D getOffset()
          Return the offset that is being applied to this node by its transform.
 java.awt.Paint getPaint()
          Return the paint used to paint this node.
 boolean getPaintInvalid()
          Return true if this nodes paint is invalid, in which case the node needs to be repainted.
 PNode getParent()
          Return the parent of this node.
 boolean getPickable()
          Return true if this node is pickable.
 PRoot getRoot()
          Return the root node (instance of PRoot).
 double getRotation()
          Returns the rotation applied by this node's transform in radians.
 double getScale()
          Return the scale applied by this node's transform.
 PAffineTransform getTransform()
          Return a copy of the transform associated with this node.
 PAffineTransform getTransformReference(boolean createNewTransformIfNull)
          Return a reference to the transform associated with this node.
 float getTransparency()
          Return the transparency used when painting this node.
 PBounds getUnionOfChildrenBounds(PBounds dstBounds)
          Compute and return the union of the full bounds of all the children of this node.
 boolean getVisible()
          Return true if this node is visible, that is if it will paint itself and descendents.
 double getWidth()
          Return the width (in local coords) of this node's bounds.
 double getX()
          Return the x position (in local coords) of this node's bounds.
 double getXOffset()
           
 double getY()
          Return the y position (in local coords) of this node's bounds.
 double getYOffset()
           
 java.awt.geom.Dimension2D globalToLocal(java.awt.geom.Dimension2D globalDimension)
          Transform the given dimension from global coordinates to this node's local coordinate system.
 java.awt.geom.Point2D globalToLocal(java.awt.geom.Point2D globalPoint)
          Transform the given point from global coordinates to this node's local coordinate system.
 java.awt.geom.Rectangle2D globalToLocal(java.awt.geom.Rectangle2D globalRectangle)
          Transform the given rectangle from global coordinates to this node's local coordinate system.
 int indexOfChild(PNode child)
          Return the index where the given child is stored.
protected  void internalUpdateBounds(double x, double y, double width, double height)
          Gives nodes a chance to update their internal structure before bounds changed notifications are sent.
 boolean intersects(java.awt.geom.Rectangle2D localBounds)
          Return true if this node intersects the given rectangle specified in local bounds.
 void invalidateFullBounds()
          Invalidates the full bounds of this node, and sets the child bounds invalid flag on each of this node's ancestors.
 void invalidateLayout()
          Invalidate this node's layout, so that later layoutChildren will get called.
 void invalidatePaint()
          Invalidate this node's paint, and mark all of its ancestors as having a node with invalid paint.
 boolean isAncestorOf(PNode node)
          Return true if this node is an ancestor of the parameter node.
 boolean isDescendentOf(PNode node)
          Return true if this node is a descendent of the parameter node.
 boolean isDescendentOfRoot()
          Return true if this node descends from the root.
 boolean isOpaque(java.awt.geom.Rectangle2D boundary)
           
protected  void layoutChildren()
          Nodes that apply layout constraints to their children should override this method and do the layout there.
static double lerp(double t, double a, double b)
          Linearly interpolates between a and b, based on t.
 java.awt.geom.Dimension2D localToGlobal(java.awt.geom.Dimension2D localDimension)
          Transform the given dimension from this node's local coordinate system to the global coordinate system.
 java.awt.geom.Point2D localToGlobal(java.awt.geom.Point2D localPoint)
          Transform the given point from this node's local coordinate system to the global coordinate system.
 java.awt.geom.Rectangle2D localToGlobal(java.awt.geom.Rectangle2D localRectangle)
          Transform the given rectangle from this node's local coordinate system to the global coordinate system.
 java.awt.geom.Dimension2D localToParent(java.awt.geom.Dimension2D localDimension)
          Transform the given dimension from this node's local coordinate system to its parent's local coordinate system.
 java.awt.geom.Point2D localToParent(java.awt.geom.Point2D localPoint)
          Transform the given point from this node's local coordinate system to its parent's local coordinate system.
 java.awt.geom.Rectangle2D localToParent(java.awt.geom.Rectangle2D localRectangle)
          Transform the given rectangle from this node's local coordinate system to its parent's local coordinate system.
 void moveInBackOf(PNode sibling)
          Change the order of this node in its parent's children list so that it will draw after the given sibling node.
 void moveInFrontOf(PNode sibling)
          Change the order of this node in its parent's children list so that it will draw before the given sibling node.
 void moveToBack()
          Change the order of this node in its parent's children list so that it will draw in back of all of its other sibling nodes.
 void moveToFront()
          Change the order of this node in its parent's children list so that it will draw in front of all of its other sibling nodes.
 void offset(double dx, double dy)
          Offset this node relative to the parents coordinate system, and is NOT effected by this nodes current scale or rotation.
protected  void paint(PPaintContext paintContext)
          Paint this node behind any of its children nodes.
protected  void paintAfterChildren(PPaintContext paintContext)
          Subclasses that wish to do additional painting after their children are painted should override this method and do that painting here.
protected  java.lang.String paramString()
          Returns a string representing the state of this node.
protected  void parentBoundsChanged()
          A notification that the bounds of this node's parent have changed.
 java.awt.geom.Dimension2D parentToLocal(java.awt.geom.Dimension2D parentDimension)
          Transform the given dimension from this node's parent's local coordinate system to the local coordinate system of this node.
 java.awt.geom.Point2D parentToLocal(java.awt.geom.Point2D parentPoint)
          Transform the given point from this node's parent's local coordinate system to the local coordinate system of this node.
 java.awt.geom.Rectangle2D parentToLocal(java.awt.geom.Rectangle2D parentRectangle)
          Transform the given rectangle from this node's parent's local coordinate system to the local coordinate system of this node.
protected  boolean pick(PPickPath pickPath)
          Try to pick this node before its children have had a chance to be picked.
protected  boolean pickAfterChildren(PPickPath pickPath)
          Try to pick this node after its children have had a chance to be picked.
 void position(java.awt.geom.Point2D srcPt, java.awt.geom.Point2D destPt, java.awt.geom.Rectangle2D destBounds, int millis)
          This will calculate the necessary transform in order to make this node appear at a particular position relative to the specified bounding box.
 void print()
          Constructs a new PrinterJob, allows the user to select which printer to print to, And then prints the node.
 int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Prints the node into the given Graphics context using the specified format.
 void removeAllChildren()
          Remove all the children from this node.
 PNode removeChild(int index)
          Remove the child at the specified position of this group node's children.
 PNode removeChild(PNode child)
          Remove the given child from this node's children list.
 void removeChildren(java.util.Collection childrenNodes)
          Remove all the children in the given collection from this nodeís list of children.
 void removeFromParent()
          Delete this node by removing it from its parentís list of children.
 void removeInputEventListener(PInputEventListener listener)
          Removes the specified input event listener so that it no longer receives input events from this node.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener for a specific property.
 void repaint()
          Mark the area on the screen represented by this nodes full bounds as needing a repaint.
 void repaintFrom(PBounds localBounds, PNode childOrThis)
          Pass the given repaint request up the tree, so that any cameras can invalidate that region on their associated canvas.
 void reparent(PNode newParent)
          Set the parent of this node, and transform the node in such a way that it doesn't move in global coordinates.
 void replaceWith(PNode replacementNode)
          Swaps this node out of the scene graph tree, and replaces it with the specified replacement node.
 void resetBounds()
          Set the empty bit of this bounds to true.
 void rotate(double theta)
          Rotates this node by theta (in radians) about the 0,0 point.
 void rotateAboutPoint(double theta, double x, double y)
          Rotates this node by theta (in radians) about the given point.
 void rotateAboutPoint(double theta, java.awt.geom.Point2D point)
          Rotates this node by theta (in radians) about the given point.
 void rotateInPlace(double theta)
          Rotates this node by theta (in radians), and then translates the node so that the x, y position of its fullBounds stays constant.
 void scale(double scale)
          Scale this nodes transform by the given amount.
 void scaleAboutPoint(double scale, double x, double y)
          Scale this nodes transform by the given amount about the specified point.
 void scaleAboutPoint(double scale, java.awt.geom.Point2D point)
          Scale this nodes transform by the given amount about the specified point.
 boolean setBounds(double x, double y, double width, double height)
          Set the bounds of this node to the given value.
 boolean setBounds(java.awt.geom.Rectangle2D newBounds)
          Set the bounds of this node to the given value.
protected  void setBoundsChanged(boolean boundsChanged)
          Set the bounds chnaged flag.
protected  void setChildBoundsInvalid(boolean childBoundsInvalid)
          Set the flag indicating that one of this node's descendents has invalid bounds.
protected  void setChildBoundsVolatile(boolean childBoundsVolatile)
          Set if this node has a child with volatile bounds.
 void setChildPaintInvalid(boolean childPaintInvalid)
          Mark this node as having a child with invalid paint.
 void setChildrenPickable(boolean areChildrenPickable)
          Set the children pickable flag.
protected  void setFullBoundsInvalid(boolean fullBoundsInvalid)
          Set the full bounds invalid flag.
 void setGlobalRotation(double theta)
          Set the global rotation (in radians) of this node.
 void setGlobalScale(double scale)
          Set the global scale of this node.
 void setGlobalTranslation(java.awt.geom.Point2D globalPoint)
          Set the global translation of this node.
 boolean setHeight(double height)
           
 void setOccluded(boolean isOccluded)
           
 void setOffset(double x, double y)
          Set the offset that is being applied to this node by its transform.
 void setOffset(java.awt.geom.Point2D point)
          Set the offset that is being applied to this node by its transform.
 void setPaint(java.awt.Paint newPaint)
          Set the paint used to paint this node.
 void setPaintInvalid(boolean paintInvalid)
          Mark this node as having invalid paint.
 void setParent(PNode newParent)
          Set the parent of this node.
 void setPickable(boolean isPickable)
          Set the pickable flag for this node.
 void setRotation(double theta)
          Sets the rotation of this nodes transform in radians.
 void setScale(double scale)
          Set the scale of this node's transform.
 void setTransform(java.awt.geom.AffineTransform newTransform)
          Set the transform applied to this node.
 void setTransparency(float zeroToOne)
          Set the transparency used to paint this node.
 void setVisible(boolean isVisible)
          Set the visibility of this node and its descendents.
 boolean setWidth(double width)
           
 boolean setX(double x)
           
 boolean setY(double y)
           
 void signalBoundsChanged()
          This method should be called when the bounds of this node are changed.
 void startResizeBounds()
          Notify this node that you will beging to repeadily call setBounds.
 java.awt.Image toImage()
          Return a new Image representing this node and all of its children.
 java.awt.Image toImage(int width, int height, java.awt.Paint backGroundPaint)
          Return a new Image of the requested size representing this node and all of its children.
 java.lang.String toString()
          Returns a string representation of this object for debugging purposes.
 void transformBy(java.awt.geom.AffineTransform aTransform)
          Transform this nodes transform by the given transform.
 void translate(double dx, double dy)
          Translate this node's transform by the given amount, using the standard affine transform translate method.
protected  boolean validateFullBounds()
          This method is called to validate the bounds of this node and all of its descendents.
 void validateFullPaint()
          Repaint this node and any of its descendents if they have invalid paint.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_CLIENT_PROPERTIES

public static final java.lang.String PROPERTY_CLIENT_PROPERTIES
The property name that identifies a change in this node's client propertie (see getClientProperty). In an property change event the new value will be a reference to the map of client properties but old value will always be null.

See Also:
Constant Field Values

PROPERTY_BOUNDS

public static final java.lang.String PROPERTY_BOUNDS
The property name that identifies a change of this node's bounds (see getBounds, getBoundsReference). In any property change event the new value will be a reference to this node's bounds, but old value will always be null.

See Also:
Constant Field Values

PROPERTY_FULL_BOUNDS

public static final java.lang.String PROPERTY_FULL_BOUNDS
The property name that identifies a change of this node's full bounds (see getFullBounds, getFullBoundsReference). In any property change event the new value will be a reference to this node's full bounds cache, but old value will always be null.

See Also:
Constant Field Values

PROPERTY_TRANSFORM

public static final java.lang.String PROPERTY_TRANSFORM
The property name that identifies a change of this node's transform (see getTransform, getTransformReference). In any property change event the new value will be a reference to this node's transform, but old value will always be null.

See Also:
Constant Field Values

PROPERTY_VISIBLE

public static final java.lang.String PROPERTY_VISIBLE
The property name that identifies a change of this node's visibility (see getVisible). Both old value and new value will be null in any property change event.

See Also:
Constant Field Values

PROPERTY_PAINT

public static final java.lang.String PROPERTY_PAINT
The property name that identifies a change of this node's paint (see getPaint). Both old value and new value will be set correctly in any property change event.

See Also:
Constant Field Values

PROPERTY_TRANSPARENCY

public static final java.lang.String PROPERTY_TRANSPARENCY
The property name that identifies a change of this node's transparency (see getTransparency). Both old value and new value will be null in any property change event.

See Also:
Constant Field Values

PROPERTY_PICKABLE

public static final java.lang.String PROPERTY_PICKABLE
The property name that identifies a change of this node's pickable status (see getPickable). Both old value and new value will be null in any property change event.

See Also:
Constant Field Values

PROPERTY_CHILDREN_PICKABLE

public static final java.lang.String PROPERTY_CHILDREN_PICKABLE
The property name that identifies a change of this node's children pickable status (see getChildrenPickable). Both old value and new value will be null in any property change event.

See Also:
Constant Field Values

PROPERTY_CHILDREN

public static final java.lang.String PROPERTY_CHILDREN
The property name that identifies a change in the set of this node's direct children (see getChildrenReference, getChildrenIterator). In any property change event the new value will be a reference to this node's children, but old value will always be null.

See Also:
Constant Field Values

PROPERTY_PARENT

public static final java.lang.String PROPERTY_PARENT
The property name that identifies a change of this node's parent (see getParent). Both old value and new value will be set correctly in any property change event.

See Also:
Constant Field Values
Constructor Detail

PNode

public PNode()
Constructs a new PNode.

By default a node's paint is null, and bounds are empty. These values must be set for the node to show up on the screen once it's added to a scene graph.

Method Detail

animateToBounds

public PInterpolatingActivity animateToBounds(double x,
                                              double y,
                                              double width,
                                              double height,
                                              long duration)
Animate this node's bounds from their current location when the activity starts to the specified bounds. If this node descends from the root then the activity will be scheduled, else the returned activity should be scheduled manually. If two different transform activities are scheduled for the same node at the same time, they will both be applied to the node, but the last one scheduled will be applied last on each frame, so it will appear to have replaced the original. Generally you will not want to do that.

Parameters:
duration - amount of time that the animation should take
Returns:
the newly scheduled activity

animateToPositionScaleRotation

public PTransformActivity animateToPositionScaleRotation(double x,
                                                         double y,
                                                         double scale,
                                                         double theta,
                                                         long duration)
Animate this node's transform from its current location when the activity starts to the specified location, scale, and rotation. If this node descends from the root then the activity will be scheduled, else the returned activity should be scheduled manually. If two different transform activities are scheduled for the same node at the same time, they will both be applied to the node, but the last one scheduled will be applied last on each frame, so it will appear to have replaced the original. Generally you will not want to do that.

Parameters:
duration - amount of time that the animation should take
theta - final theta value (in radians) for the animation
Returns:
the newly scheduled activity

animateToTransform

public PTransformActivity animateToTransform(java.awt.geom.AffineTransform destTransform,
                                             long duration)
Animate this node's transform from its current values when the activity starts to the new values specified in the given transform. If this node descends from the root then the activity will be scheduled, else the returned activity should be scheduled manually. If two different transform activities are scheduled for the same node at the same time, they will both be applied to the node, but the last one scheduled will be applied last on each frame, so it will appear to have replaced the original. Generally you will not want to do that.

Parameters:
destTransform - the final transform value
duration - amount of time that the animation should take
Returns:
the newly scheduled activity

animateToColor

public PInterpolatingActivity animateToColor(java.awt.Color destColor,
                                             long duration)
Animate this node's color from its current value to the new value specified. This meathod assumes that this nodes paint property is of type color. If this node descends from the root then the activity will be scheduled, else the returned activity should be scheduled manually. If two different color activities are scheduled for the same node at the same time, they will both be applied to the node, but the last one scheduled will be applied last on each frame, so it will appear to have replaced the original. Generally you will not want to do that.

Parameters:
destColor - final color value.
duration - amount of time that the animation should take
Returns:
the newly scheduled activity

animateToTransparency

public PInterpolatingActivity animateToTransparency(float zeroToOne,
                                                    long duration)
Animate this node's transparency from its current value to the new value specified. Transparency values must range from zero to one. If this node descends from the root then the activity will be scheduled, else the returned activity should be scheduled manually. If two different transparency activities are scheduled for the same node at the same time, they will both be applied to the node, but the last one scheduled will be applied last on each frame, so it will appear to have replaced the original. Generally you will not want to do that.

Parameters:
zeroToOne - final transparency value.
duration - amount of time that the animation should take
Returns:
the newly scheduled activity

addActivity

public boolean addActivity(PActivity activity)
Schedule the given activity with the root, note that only scheduled activities will be stepped. If the activity is successfully added true is returned, else false.

Parameters:
activity - new activity to schedule
Returns:
true if the activity is successfully scheduled.

getClientProperty

public java.lang.Object getClientProperty(java.lang.Object key)
Returns the value of the property with the specified key. Only properties added with addClientProperty will return a non-null value.

Returns:
the value of this property or null

addClientProperty

public void addClientProperty(java.lang.Object key,
                              java.lang.Object value)
Add an arbitrary key/value "client property" to this node.

The get/addClientProperty methods provide access to a small per-instance hashtable. Callers can use get/addClientProperty to annotate nodes that were created by another module.

If value is null this method will remove the property.


getClientPropertyKeysIterator

public java.util.Iterator getClientPropertyKeysIterator()
Returns an Iterator that will traverse all of the keys maped to client values.

Returns:
an Iterator over client property keys

clone

public java.lang.Object clone()
The copy method copies this node and all of its descendents. Note that copying is implemented in terms of java serialization. See the serialization notes for more information.

Returns:
new copy of this node or null if the node was not serializable

localToParent

public java.awt.geom.Point2D localToParent(java.awt.geom.Point2D localPoint)
Transform the given point from this node's local coordinate system to its parent's local coordinate system. Note that this will modify the point parameter.

Parameters:
localPoint - point in local coordinate system to be transformed.
Returns:
point in parent's local coordinate system

localToParent

public java.awt.geom.Dimension2D localToParent(java.awt.geom.Dimension2D localDimension)
Transform the given dimension from this node's local coordinate system to its parent's local coordinate system. Note that this will modify the dimension parameter.

Parameters:
localDimension - dimension in local coordinate system to be transformed.
Returns:
dimension in parent's local coordinate system

localToParent

public java.awt.geom.Rectangle2D localToParent(java.awt.geom.Rectangle2D localRectangle)
Transform the given rectangle from this node's local coordinate system to its parent's local coordinate system. Note that this will modify the rectangle parameter.

Parameters:
localRectangle - rectangle in local coordinate system to be transformed.
Returns:
rectangle in parent's local coordinate system

parentToLocal

public java.awt.geom.Point2D parentToLocal(java.awt.geom.Point2D parentPoint)
Transform the given point from this node's parent's local coordinate system to the local coordinate system of this node. Note that this will modify the point parameter.

Parameters:
parentPoint - point in parent's coordinate system to be transformed.
Returns:
point in this node's local coordinate system

parentToLocal

public java.awt.geom.Dimension2D parentToLocal(java.awt.geom.Dimension2D parentDimension)
Transform the given dimension from this node's parent's local coordinate system to the local coordinate system of this node. Note that this will modify the dimension parameter.

Parameters:
parentDimension - dimension in parent's coordinate system to be transformed.
Returns:
dimension in this node's local coordinate system

parentToLocal

public java.awt.geom.Rectangle2D parentToLocal(java.awt.geom.Rectangle2D parentRectangle)
Transform the given rectangle from this node's parent's local coordinate system to the local coordinate system of this node. Note that this will modify the rectangle parameter.

Parameters:
parentRectangle - rectangle in parent's coordinate system to be transformed.
Returns:
rectangle in this node's local coordinate system

localToGlobal

public java.awt.geom.Point2D localToGlobal(java.awt.geom.Point2D localPoint)
Transform the given point from this node's local coordinate system to the global coordinate system. Note that this will modify the point parameter.

Parameters:
localPoint - point in local coordinate system to be transformed.
Returns:
point in global coordinates

localToGlobal

public java.awt.geom.Dimension2D localToGlobal(java.awt.geom.Dimension2D localDimension)
Transform the given dimension from this node's local coordinate system to the global coordinate system. Note that this will modify the dimension parameter.

Parameters:
localDimension - dimension in local coordinate system to be transformed.
Returns:
dimension in global coordinates

localToGlobal

public java.awt.geom.Rectangle2D localToGlobal(java.awt.geom.Rectangle2D localRectangle)
Transform the given rectangle from this node's local coordinate system to the global coordinate system. Note that this will modify the rectangle parameter.

Parameters:
localRectangle - rectangle in local coordinate system to be transformed.
Returns:
rectangle in global coordinates

globalToLocal

public java.awt.geom.Point2D globalToLocal(java.awt.geom.Point2D globalPoint)
Transform the given point from global coordinates to this node's local coordinate system. Note that this will modify the point parameter.

Parameters:
globalPoint - point in global coordinates to be transformed.
Returns:
point in this node's local coordinate system.

globalToLocal

public java.awt.geom.Dimension2D globalToLocal(java.awt.geom.Dimension2D globalDimension)
Transform the given dimension from global coordinates to this node's local coordinate system. Note that this will modify the dimension parameter.

Parameters:
globalDimension - dimension in global coordinates to be transformed.
Returns:
dimension in this node's local coordinate system.

globalToLocal

public java.awt.geom.Rectangle2D globalToLocal(java.awt.geom.Rectangle2D globalRectangle)
Transform the given rectangle from global coordinates to this node's local coordinate system. Note that this will modify the rectangle parameter.

Parameters:
globalRectangle - rectangle in global coordinates to be transformed.
Returns:
rectangle in this node's local coordinate system.

getLocalToGlobalTransform

public PAffineTransform getLocalToGlobalTransform(PAffineTransform dest)
Return the transform that converts local coordinates at this node to the global coordinate system.

Returns:
The concatenation of transforms from the top node down to this node.

getGlobalToLocalTransform

public PAffineTransform getGlobalToLocalTransform(PAffineTransform dest)
Return the transform that converts global coordinates to local coordinates of this node.

Returns:
The inverse of the concatenation of transforms from the root down to this node.

getListenerList

public javax.swing.event.EventListenerList getListenerList()
Return the list of event listeners associated with this node.

Returns:
event listener list or null

addInputEventListener

public void addInputEventListener(PInputEventListener listener)
Adds the specified input event listener to receive input events from this node.

Parameters:
listener - the new input listener

removeInputEventListener

public void removeInputEventListener(PInputEventListener listener)
Removes the specified input event listener so that it no longer receives input events from this node.

Parameters:
listener - the input listener to remove

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties. See the fields in PNode and subclasses that start with PROPERTY_ to find out which properties exist.

Parameters:
listener - The PropertyChangeListener to be added

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property. See the fields in PNode and subclasses that start with PROPERTY_ to find out which properties are supported.

Parameters:
propertyName - The name of the property to listen on.
listener - The PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - The PropertyChangeListener to be removed

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific property.

Parameters:
propertyName - The name of the property that was listened on.
listener - The PropertyChangeListener to be removed

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.

Parameters:
propertyName - The programmatic name of the property that was changed.
oldValue - The old value of the property.
newValue - The new value of the property.

getBounds

public PBounds getBounds()
Return a copy of this node's bounds. These bounds are stored in the local coordinate system of this node and do not include the bounds of any of this node's children.


getBoundsReference

public PBounds getBoundsReference()
Return a direct reference to this node's bounds. These bounds are stored in the local coordinate system of this node and do not include the bounds of any of this node's children. The value returned should not be modified.


startResizeBounds

public void startResizeBounds()
Notify this node that you will beging to repeadily call setBounds. When you are done call endResizeBounds to let the node know that you are done.


endResizeBounds

public void endResizeBounds()
Notify this node that you have finished a resize bounds sequence.


setX

public boolean setX(double x)

setY

public boolean setY(double y)

setWidth

public boolean setWidth(double width)

setHeight

public boolean setHeight(double height)

setBounds

public boolean setBounds(java.awt.geom.Rectangle2D newBounds)
Set the bounds of this node to the given value. These bounds are stored in the local coordinate system of this node.

Returns:
true if the bounds changed.

setBounds

public boolean setBounds(double x,
                         double y,
                         double width,
                         double height)
Set the bounds of this node to the given value. These bounds are stored in the local coordinate system of this node. If the width or height is less then or equal to zero then the bound's emtpy bit will be set to true. Subclasses must call the super.setBounds() method.

Returns:
true if the bounds changed.

internalUpdateBounds

protected void internalUpdateBounds(double x,
                                    double y,
                                    double width,
                                    double height)
Gives nodes a chance to update their internal structure before bounds changed notifications are sent. When this message is recived the nodes bounds field will contain the new value. See PPath for an example that uses this method.


resetBounds

public void resetBounds()
Set the empty bit of this bounds to true.


getX

public double getX()
Return the x position (in local coords) of this node's bounds.


getY

public double getY()
Return the y position (in local coords) of this node's bounds.


getWidth

public double getWidth()
Return the width (in local coords) of this node's bounds.


getHeight

public double getHeight()
Return the height (in local coords) of this node's bounds.


getGlobalBounds

public PBounds getGlobalBounds()
Return a copy of the bounds of this node in the global coordinate system.

Returns:
the bounds in global coordinate system.

centerBoundsOnPoint

public boolean centerBoundsOnPoint(double localX,
                                   double localY)
Center the bounds of this node so that they are centered on the given point specified on the local coords of this node. Note that this meathod will modify the nodes bounds, while centerFullBoundsOnPoint will modify the nodes transform.

Returns:
true if the bounds changed.

centerFullBoundsOnPoint

public void centerFullBoundsOnPoint(double parentX,
                                    double parentY)
Center the ffull bounds of this node so that they are centered on the given point specified on the local coords of this nodes parent. Note that this meathod will modify the nodes transform, while centerBoundsOnPoint will modify the nodes bounds.


intersects

public boolean intersects(java.awt.geom.Rectangle2D localBounds)
Return true if this node intersects the given rectangle specified in local bounds. If the geometry of this node is complex this method can become expensive, it is therefore recommended that fullIntersects is used for quick rejects before calling this method.

Parameters:
localBounds - the bounds to test for intersection against
Returns:
true if the given rectangle intersects this nodes geometry.

getFullBounds

public PBounds getFullBounds()
Return a copy of this node's full bounds. These bounds are stored in the parent coordinate system of this node and they include the union of this node's bounds and all the bounds of it's descendents.

Returns:
a copy of this node's full bounds.

getFullBoundsReference

public PBounds getFullBoundsReference()
Return a reference to this node's full bounds cache. These bounds are stored in the parent coordinate system of this node and they include the union of this node's bounds and all the bounds of it's descendents. The bounds returned by this method should not be modified.

Returns:
a reference to this node's full bounds cache.

computeFullBounds

public PBounds computeFullBounds(PBounds dstBounds)
Compute and return the full bounds of this node. If the dstBounds parameter is not null then it will be used to return the results instead of creating a new PBounds.

Parameters:
dstBounds - if not null the new bounds will be stored here
Returns:
the full bounds in the parent coordinate system of this node

getUnionOfChildrenBounds

public PBounds getUnionOfChildrenBounds(PBounds dstBounds)
Compute and return the union of the full bounds of all the children of this node. If the dstBounds parameter is not null then it will be used to return the results instead of creating a new PBounds.

Parameters:
dstBounds - if not null the new bounds will be stored here

getGlobalFullBounds

public PBounds getGlobalFullBounds()
Return a copy of the full bounds of this node in the global coordinate system.

Returns:
the full bounds in global coordinate system.

fullIntersects

public boolean fullIntersects(java.awt.geom.Rectangle2D parentBounds)
Return true if the full bounds of this node intersects with the specified bounds.

Parameters:
parentBounds - the bounds to test for intersection against (specified in parent's coordinate system)
Returns:
true if this nodes full bounds intersect the given bounds.

getBoundsVolatile

protected boolean getBoundsVolatile()
Return true if this nodes bounds may change at any time. The default behavior is to return false, subclasses that override this method to return true should also override getBoundsReference() and compute their volatile bounds there before returning the reference.

Returns:
true if this node has volatile bounds

getChildBoundsVolatile

protected boolean getChildBoundsVolatile()
Return true if this node has a child with volatile bounds.

Returns:
true if this node has a child with volatile bounds

setChildBoundsVolatile

protected void setChildBoundsVolatile(boolean childBoundsVolatile)
Set if this node has a child with volatile bounds. This should normally be managed automatically by the bounds validation process.

Parameters:
childBoundsVolatile - true if this node has a descendent with volatile bounds

getBoundsChanged

protected boolean getBoundsChanged()
Return true if this node's bounds have recently changed. This flag will be reset on the next call of validateFullBounds.

Returns:
true if this node's bounds have changed.

setBoundsChanged

protected void setBoundsChanged(boolean boundsChanged)
Set the bounds chnaged flag. This flag will be reset on the next call of validateFullBounds.

Parameters:
boundsChanged - true if this nodes bounds have changed.

getFullBoundsInvalid

protected boolean getFullBoundsInvalid()
Return true if the full bounds of this node are invalid. This means that the full bounds of this node have changed and need to be recomputed.

Returns:
true if the full bounds of this node are invalid

setFullBoundsInvalid

protected void setFullBoundsInvalid(boolean fullBoundsInvalid)
Set the full bounds invalid flag. This flag is set when the full bounds of this node need to be recomputed as is the case when this node is transformed or when one of this node's children changes geometry.


getChildBoundsInvalid

protected boolean getChildBoundsInvalid()
Return true if one of this node's descendents has invalid bounds.


setChildBoundsInvalid

protected void setChildBoundsInvalid(boolean childBoundsInvalid)
Set the flag indicating that one of this node's descendents has invalid bounds.


signalBoundsChanged

public void signalBoundsChanged()
This method should be called when the bounds of this node are changed. It invalidates the full bounds of this node, and also notifies each of this nodes children that their parent's bounds have changed. As a result of this method getting called this nodes layoutChildren will be called.


invalidateLayout

public void invalidateLayout()
Invalidate this node's layout, so that later layoutChildren will get called.


parentBoundsChanged

protected void parentBoundsChanged()
A notification that the bounds of this node's parent have changed.


invalidateFullBounds

public void invalidateFullBounds()
Invalidates the full bounds of this node, and sets the child bounds invalid flag on each of this node's ancestors.


validateFullBounds

protected boolean validateFullBounds()
This method is called to validate the bounds of this node and all of its descendents. It returns true if this nodes bounds or the bounds of any of its descendents are marked as volatile.

Returns:
true if this node or any of its descendents have volatile bounds

layoutChildren

protected void layoutChildren()
Nodes that apply layout constraints to their children should override this method and do the layout there.


getRotation

public double getRotation()
Returns the rotation applied by this node's transform in radians. This rotation affects this node and all its descendents. The value returned will be between 0 and 2pi radians.

Returns:
rotation in radians.

setRotation

public void setRotation(double theta)
Sets the rotation of this nodes transform in radians. This will affect this node and all its descendents.

Parameters:
theta - rotation in radians

rotate

public void rotate(double theta)
Rotates this node by theta (in radians) about the 0,0 point. This will affect this node and all its descendents.

Parameters:
theta - the amount to rotate by in radians

rotateInPlace

public void rotateInPlace(double theta)
Rotates this node by theta (in radians), and then translates the node so that the x, y position of its fullBounds stays constant.

Parameters:
theta - the amount to rotate by in radians

rotateAboutPoint

public void rotateAboutPoint(double theta,
                             java.awt.geom.Point2D point)
Rotates this node by theta (in radians) about the given point. This will affect this node and all its descendents.

Parameters:
theta - the amount to rotate by in radians

rotateAboutPoint

public void rotateAboutPoint(double theta,
                             double x,
                             double y)
Rotates this node by theta (in radians) about the given point. This will affect this node and all its descendents.

Parameters:
theta - the amount to rotate by in radians

getGlobalRotation

public double getGlobalRotation()
Return the total amount of rotation applied to this node by its own transform together with the transforms of all its ancestors. The value returned will be between 0 and 2pi radians.

Returns:
the total amount of rotation applied to this node in radians

setGlobalRotation

public void setGlobalRotation(double theta)
Set the global rotation (in radians) of this node. This is implemented by rotating this nodes transform the required amount so that the nodes global rotation is as requested.

Parameters:
theta - the amount to rotate by in radians relative to the global coord system.

getScale

public double getScale()
Return the scale applied by this node's transform. The scale is effecting this node and all its descendents.

Returns:
scale applied by this nodes transform.

setScale

public void setScale(double scale)
Set the scale of this node's transform. The scale will affect this node and all its descendents.

Parameters:
scale - the scale to set the transform to

scale

public void scale(double scale)
Scale this nodes transform by the given amount. This will affect this node and all of its descendents.

Parameters:
scale - the amount to scale by

scaleAboutPoint

public void scaleAboutPoint(double scale,
                            java.awt.geom.Point2D point)
Scale this nodes transform by the given amount about the specified point. This will affect this node and all of its descendents.

Parameters:
scale - the amount to scale by
point - the point to scale about

scaleAboutPoint

public void scaleAboutPoint(double scale,
                            double x,
                            double y)
Scale this nodes transform by the given amount about the specified point. This will affect this node and all of its descendents.

Parameters:
scale - the amount to scale by

getGlobalScale

public double getGlobalScale()
Return the global scale that is being applied to this node by its transform together with the transforms of all its ancestors.


setGlobalScale

public void setGlobalScale(double scale)
Set the global scale of this node. This is implemented by scaling this nodes transform the required amount so that the nodes global scale is as requested.

Parameters:
scale - the desired global scale

getXOffset

public double getXOffset()

getYOffset

public double getYOffset()

getOffset

public java.awt.geom.Point2D getOffset()
Return the offset that is being applied to this node by its transform. This offset effects this node and all of its descendents and is specified in the parent coordinate system. This returns the values that are in the m02 and m12 positions in the affine transform.

Returns:
a point representing the x and y offset

setOffset

public void setOffset(java.awt.geom.Point2D point)
Set the offset that is being applied to this node by its transform. This offset effects this node and all of its descendents and is specified in the nodes parent coordinate system. This directly sets the values of the m02 and m12 positions in the affine transform. Unlike "PNode.translate()" it is not effected by the transforms scale.

Parameters:
point - a point representing the x and y offset

setOffset

public void setOffset(double x,
                      double y)
Set the offset that is being applied to this node by its transform. This offset effects this node and all of its descendents and is specified in the nodes parent coordinate system. This directly sets the values of the m02 and m12 positions in the affine transform. Unlike "PNode.translate()" it is not effected by the transforms scale.

Parameters:
x - amount of x offset
y - amount of y offset

offset

public void offset(double dx,
                   double dy)
Offset this node relative to the parents coordinate system, and is NOT effected by this nodes current scale or rotation. This is implemented by directly adding dx to the m02 position and dy to the m12 position in the affine transform.


translate

public void translate(double dx,
                      double dy)
Translate this node's transform by the given amount, using the standard affine transform translate method. This translation effects this node and all of its descendents.


getGlobalTranslation

public java.awt.geom.Point2D getGlobalTranslation()
Return the global translation that is being applied to this node by its transform together with the transforms of all its ancestors.


setGlobalTranslation

public void setGlobalTranslation(java.awt.geom.Point2D globalPoint)
Set the global translation of this node. This is implemented by translating this nodes transform the required amount so that the nodes global scale is as requested.

Parameters:
globalPoint - the desired global translation

transformBy

public void transformBy(java.awt.geom.AffineTransform aTransform)
Transform this nodes transform by the given transform.

Parameters:
aTransform - the transform to apply.

lerp

public static double lerp(double t,
                          double a,
                          double b)
Linearly interpolates between a and b, based on t. Specifically, it computes lerp(a, b, t) = a + t*(b - a). This produces a result that changes from a (when t = 0) to b (when t = 1).

Parameters:
a - from point
b - to Point
t - variable 'time' parameter

position

public void position(java.awt.geom.Point2D srcPt,
                     java.awt.geom.Point2D destPt,
                     java.awt.geom.Rectangle2D destBounds,
                     int millis)
This will calculate the necessary transform in order to make this node appear at a particular position relative to the specified bounding box. The source point specifies a point in the unit square (0, 0) - (1, 1) that represents an anchor point on the corresponding node to this transform. The destination point specifies an anchor point on the reference node. The position method then computes the transform that results in transforming this node so that the source anchor point coincides with the reference anchor point. This can be useful for layout algorithms as it is straightforward to position one object relative to another.

For example, If you have two nodes, A and B, and you call

     Point2D srcPt = new Point2D.Double(1.0, 0.0);
     Point2D destPt = new Point2D.Double(0.0, 0.0);
     A.position(srcPt, destPt, B.getGlobalBounds(), 750, null);
 
The result is that A will move so that its upper-right corner is at the same place as the upper-left corner of B, and the transition will be smoothly animated over a period of 750 milliseconds.

Parameters:
srcPt - The anchor point on this transform's node (normalized to a unit square)
destPt - The anchor point on destination bounds (normalized to a unit square)
destBounds - The bounds (in global coordinates) used to calculate this transform's node
millis - Number of milliseconds over which to perform the animation

getTransform

public PAffineTransform getTransform()
Return a copy of the transform associated with this node.

Returns:
copy of this node's transform

getTransformReference

public PAffineTransform getTransformReference(boolean createNewTransformIfNull)
Return a reference to the transform associated with this node. This returned transform should not be modified. PNode transforms are created lazily when needed. If you access the transform reference before the transform has been created it may return null. The createNewTransformIfNull parameter is used to specify that the PNode should create a new transform (and assign that transform to the nodes local transform variable) instead of returning null.

Returns:
reference to this node's transform

getInverseTransform

public PAffineTransform getInverseTransform()
Return an inverted copy of the transform associated with this node.

Returns:
inverted copy of this node's transform

setTransform

public void setTransform(java.awt.geom.AffineTransform newTransform)
Set the transform applied to this node.

Parameters:
newTransform - the new transform value

getPaintInvalid

public boolean getPaintInvalid()
Return true if this nodes paint is invalid, in which case the node needs to be repainted.

Returns:
true if this node needs to be repainted

setPaintInvalid

public void setPaintInvalid(boolean paintInvalid)
Mark this node as having invalid paint. If this is set the node will later be repainted. Node this method is most often used internally.

Parameters:
paintInvalid - true if this node should be repainted

getChildPaintInvalid

public boolean getChildPaintInvalid()
Return true if this node has a child with invalid paint.

Returns:
true if this node has a child with invalid paint

setChildPaintInvalid

public void setChildPaintInvalid(boolean childPaintInvalid)
Mark this node as having a child with invalid paint.

Parameters:
childPaintInvalid - true if this node has a child with invalid paint

invalidatePaint

public void invalidatePaint()
Invalidate this node's paint, and mark all of its ancestors as having a node with invalid paint.


validateFullPaint

public void validateFullPaint()
Repaint this node and any of its descendents if they have invalid paint.


repaint

public void repaint()
Mark the area on the screen represented by this nodes full bounds as needing a repaint.


repaintFrom

public void repaintFrom(PBounds localBounds,
                        PNode childOrThis)
Pass the given repaint request up the tree, so that any cameras can invalidate that region on their associated canvas.

Parameters:
localBounds - the bounds to repaint
childOrThis - if childOrThis does not equal this then this nodes transform will be applied to the localBounds param

isOpaque

public boolean isOpaque(java.awt.geom.Rectangle2D boundary)

getOccluded

public boolean getOccluded()

setOccluded

public void setOccluded(boolean isOccluded)

getVisible

public boolean getVisible()
Return true if this node is visible, that is if it will paint itself and descendents.

Returns:
true if this node and its descendents are visible.

setVisible

public void setVisible(boolean isVisible)
Set the visibility of this node and its descendents.

Parameters:
isVisible - true if this node and its descendents are visible

getPaint

public java.awt.Paint getPaint()
Return the paint used to paint this node. This value may be null.


setPaint

public void setPaint(java.awt.Paint newPaint)
Set the paint used to paint this node. This value may be set to null.


getTransparency

public float getTransparency()
Return the transparency used when painting this node. Note that this transparency is also applied to all of the nodeís descendents.


setTransparency

public void setTransparency(float zeroToOne)
Set the transparency used to paint this node. Note that this transparency applies to this node and all of its descendents.


paint

protected void paint(PPaintContext paintContext)
Paint this node behind any of its children nodes. Subclasses that define a different appearance should override this method and paint themselves there.

Parameters:
paintContext - the paint context to use for painting the node

fullPaint

public void fullPaint(PPaintContext paintContext)
Paint this node and all of its descendents. Most subclasses do not need to override this method, they should override paint or paintAfterChildren instead.

Parameters:
paintContext - the paint context to use for painting this node and its children

paintAfterChildren

protected void paintAfterChildren(PPaintContext paintContext)
Subclasses that wish to do additional painting after their children are painted should override this method and do that painting here.

Parameters:
paintContext - the paint context to sue for painting after the children are painted

toImage

public java.awt.Image toImage()
Return a new Image representing this node and all of its children. The image size will be equal to the size of this nodes full bounds.

Returns:
a new image representing this node and its descendents

toImage

public java.awt.Image toImage(int width,
                              int height,
                              java.awt.Paint backGroundPaint)
Return a new Image of the requested size representing this node and all of its children. If backGroundPaint is null the resulting image will have transparent regions, else those regions will be filled with the backgroundPaint.

Returns:
a new image representing this node and its descendents

print

public void print()
Constructs a new PrinterJob, allows the user to select which printer to print to, And then prints the node.


print

public int print(java.awt.Graphics graphics,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
Prints the node into the given Graphics context using the specified format. The zero based index of the requested page is specified by pageIndex. If the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. If the printable object aborts the print job then it throws a PrinterException.

Specified by:
print in interface java.awt.print.Printable
Parameters:
graphics - the context into which the node is drawn
pageFormat - the size and orientation of the page
pageIndex - the zero based index of the page to be drawn

getPickable

public boolean getPickable()
Return true if this node is pickable. Only pickable nodes can receive input events. Nodes are pickable by default.

Returns:
true if this node is pickable

setPickable

public void setPickable(boolean isPickable)
Set the pickable flag for this node. Only pickable nodes can receive input events. Nodes are pickable by default.

Parameters:
isPickable - true if this node is pickable

getChildrenPickable

public boolean getChildrenPickable()
Return true if the children of this node should be picked. If this flag is false then this node will not try to pick its children. Children are pickable by default.

Returns:
true if this node tries to pick its children

setChildrenPickable

public void setChildrenPickable(boolean areChildrenPickable)
Set the children pickable flag. If this flag is false then this node will not try to pick its children. Children are pickable by default.

Parameters:
areChildrenPickable - true if this node tries to pick its children

pick

protected boolean pick(PPickPath pickPath)
Try to pick this node before its children have had a chance to be picked. Nodes that paint on top of their children may want to override this method to if the pick path intersects that paint.

Parameters:
pickPath - the pick path used for the pick operation
Returns:
true if this node was picked

fullPick

public boolean fullPick(PPickPath pickPath)
Try to pick this node and all of its descendents. Most subclasses should not need to override this method. Instead they should override pick or pickAfterChildren.

Parameters:
pickPath - the pick path to add the node to if its picked
Returns:
true if this node or one of its descendents was picked.

findIntersectingNodes

public void findIntersectingNodes(java.awt.geom.Rectangle2D fullBounds,
                                  java.util.ArrayList results)

pickAfterChildren

protected boolean pickAfterChildren(PPickPath pickPath)
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.

Parameters:
pickPath - the pick path used for the pick operation
Returns:
true if this node was picked

addChild

public void addChild(PNode child)
Add a node to be a new child of this node. The new node is added to the end of the list of this node's children. If child was previously a child of another node, it is removed from that first.

Parameters:
child - the new child to add to this node

addChild

public void addChild(int index,
                     PNode child)
Add a node to be a new child of this node at the specified index. If child was previously a child of another node, it is removed from that node first.

Parameters:
child - the new child to add to this node

addChildren

public void addChildren(java.util.Collection nodes)
Add a collection of nodes to be children of this node. If these nodes already have parents they will first be removed from those parents.

Parameters:
nodes - a collection of nodes to be added to this node

isAncestorOf

public boolean isAncestorOf(PNode node)
Return true if this node is an ancestor of the parameter node.

Parameters:
node - a possible descendent node
Returns:
true if this node is an ancestor of the given node

isDescendentOf

public boolean isDescendentOf(PNode node)
Return true if this node is a descendent of the parameter node.

Parameters:
node - a possible ancestor node
Returns:
true if this nodes descends from the given node

isDescendentOfRoot

public boolean isDescendentOfRoot()
Return true if this node descends from the root.


moveToBack

public void moveToBack()
Change the order of this node in its parent's children list so that it will draw in back of all of its other sibling nodes.


moveInBackOf

public void moveInBackOf(PNode sibling)
Change the order of this node in its parent's children list so that it will draw after the given sibling node.


moveToFront

public void moveToFront()
Change the order of this node in its parent's children list so that it will draw in front of all of its other sibling nodes.


moveInFrontOf

public void moveInFrontOf(PNode sibling)
Change the order of this node in its parent's children list so that it will draw before the given sibling node.


getParent

public PNode getParent()
Return the parent of this node. This will be null if this node has not been added to a parent yet.

Returns:
this nodes parent or null

setParent

public void setParent(PNode newParent)
Set the parent of this node. Note this is set automatically when adding and removing children.


indexOfChild

public int indexOfChild(PNode child)
Return the index where the given child is stored.


removeChild

public PNode removeChild(PNode child)
Remove the given child from this node's children list. Any subsequent children are shifted to the left (one is subtracted from their indices). The removed childís parent is set to null.

Parameters:
child - the child to remove
Returns:
the removed child

removeChild

public PNode removeChild(int index)
Remove the child at the specified position of this group node's children. Any subsequent children are shifted to the left (one is subtracted from their indices). The removed childís parent is set to null.

Parameters:
index - the index of the child to remove
Returns:
the removed child

removeChildren

public void removeChildren(java.util.Collection childrenNodes)
Remove all the children in the given collection from this nodeís list of children. All removed nodes will have their parent set to null.

Parameters:
childrenNodes - the collection of children to remove

removeAllChildren

public void removeAllChildren()
Remove all the children from this node. Node this method is more efficient then removing each child individually.


removeFromParent

public void removeFromParent()
Delete this node by removing it from its parentís list of children.


reparent

public void reparent(PNode newParent)
Set the parent of this node, and transform the node in such a way that it doesn't move in global coordinates.

Parameters:
newParent - The new parent of this node.

replaceWith

public void replaceWith(PNode replacementNode)
Swaps this node out of the scene graph tree, and replaces it with the specified replacement node. This node is left dangling, and it is up to the caller to manage it. The replacement node will be added to this node's parent in the same position as this was. That is, if this was the 3rd child of its parent, then after calling replaceWith(), the replacement node will also be the 3rd child of its parent. If this node has no parent when replace is called, then nothing will be done at all.

Parameters:
replacementNode - the new node that replaces the current node in the scene graph tree.

getChildrenCount

public int getChildrenCount()
Return the number of children that this node has.

Returns:
the number of children

getChild

public PNode getChild(int index)
Return the child node at the specified index.

Parameters:
index - a child index
Returns:
the child node at the specified index

getChildrenReference

public java.util.List getChildrenReference()
Return a reference to the list used to manage this nodeís children. This list should not be modified.

Returns:
reference to the children list

getChildrenIterator

public java.util.ListIterator getChildrenIterator()
Return an iterator over this nodeís direct descendent children.

Returns:
iterator over this nodes children

getRoot

public PRoot getRoot()
Return the root node (instance of PRoot). If this node does not descend from a PRoot then null will be returned.


getAllNodes

public java.util.Collection getAllNodes()
Return a collection containing this node and all of its descendent nodes.

Returns:
a new collection containing this node and all descendents

getAllNodes

public java.util.Collection getAllNodes(PNodeFilter filter,
                                        java.util.Collection results)
Return a collection containing the subset of this node and all of its descendent nodes that are accepted by the given node filter. If the filter is null then all nodes will be accepted. If the results parameter is not null then it will be used to collect this subset instead of creating a new collection.

Parameters:
filter - the filter used to determine the subset
Returns:
a collection containing this node and all descendents

toString

public java.lang.String toString()
Returns a string representation of this object for debugging purposes.


paramString

protected java.lang.String paramString()
Returns a string representing the state of this node. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns:
a string representation of this node's state


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