Package edu.umd.cs.piccolo
Class PNode
java.lang.Object
edu.umd.cs.piccolo.PNode
- All Implemented Interfaces:
Printable,Serializable,Cloneable
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacePSceneGraphDelegate is an interface to receive low level node events. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final inttoImage fill strategy that stretches the node be large enough to cover the image, and centers it.static final inttoImage fill strategy that stretches the node be as large as possible while still retaining its aspect ratio.static final inttoImage fill strategy that stretches the node to be exactly the dimensions of the image.static final StringThe property name that identifies a change of this node's bounds (seegetBounds,getBoundsReference).static final StringThe property name that identifies a change in the set of this node's direct children (seegetChildrenReference,getChildrenIterator).static final StringThe property name that identifies a change of this node's children pickable status (seegetChildrenPickable).static final StringThe property name that identifies a change in this node's client propertie (seegetClientProperty).static final intThe property code that identifies a change of this node's bounds (seegetBounds,getBoundsReference).static final intThe property code that identifies a change in the set of this node's direct children (seegetChildrenReference,getChildrenIterator).static final intThe property code that identifies a change of this node's children pickable status (seegetChildrenPickable).static final intThe property code that identifies a change in this node's client propertie (seegetClientProperty).static final intThe property code that identifies a change of this node's full bounds (seegetFullBounds,getFullBoundsReference).static final intThe property code that identifies a change of this node's paint (seegetPaint).static final intThe property code that identifies a change of this node's parent (seegetParent).static final intThe property code that identifies a change of this node's pickable status (seegetPickable).static final intThe property code that identifies a change of this node's transform (seegetTransform,getTransformReference).static final intThe property code that identifies a change of this node's transparency (seegetTransparency).static final intThe property code that identifies a change of this node's visibility (seegetVisible).static final StringThe property name that identifies a change of this node's full bounds (seegetFullBounds,getFullBoundsReference).static final StringThe property name that identifies a change of this node's paint (seegetPaint).static final StringThe property name that identifies a change of this node's parent (seegetParent).static final StringThe property name that identifies a change of this node's pickable status (seegetPickable).static final StringThe property name that identifies a change of this node's transform (seegetTransform,getTransformReference).static final StringThe property name that identifies a change of this node's transparency (seegetTransparency).static final StringThe property name that identifies a change of this node's visibility (seegetVisible).static PNode.PSceneGraphDelegateThe single scene graph delegate that receives low level node events.Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddActivity(PActivity activity) Schedule the given activity with the root, note that only scheduled activities will be stepped.voidaddAttribute(Object key, Object value) Add an arbitrary key/value to this node.voidAdd a node to be a new child of this node at the specified index.voidAdd a node to be a new child of this node.voidaddChildren(Collection nodes) Add a collection of nodes to be children of this node.voidaddClientProperty(Object key, Object value) Deprecated.use addAttribute(Object key, Object value)instead.voidaddInputEventListener(PInputEventListener listener) Adds the specified input event listener to receive input events from this node.voidAdd a PropertyChangeListener to the listener list.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) Add a PropertyChangeListener for a specific property.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.animateToColor(Color destColor, long duration) Animate this node's color from its current value to the new value specified.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.animateToRelativePosition(Point2D srcPt, Point2D destPt, 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.animateToTransform(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.animateToTransparency(float zeroToOne, long duration) Animate this node's transparency from its current value to the new value specified.animateTransformToBounds(double x, double y, double width, double height, long duration) Animate this node from it's current transform when the activity starts a new transform that will fit the node into the given bounds.booleancenterBoundsOnPoint(double localX, double localY) Center the bounds of this node so that they are centered on the given point specified on the local coordinates of this node.voidcenterFullBoundsOnPoint(double parentX, double parentY) Center the full bounds of this node so that they are centered on the given point specified on the local coordinates of this nodes parent.clone()The copy method copies this node and all of its descendants.computeFullBounds(PBounds dstBounds) Compute and return the full bounds of this node.voidNotify this node that you have finished a resize bounds sequence.voidfindIntersectingNodes(Rectangle2D fullBounds, ArrayList results) Finds all descendants of this node that intersect with the given bounds and adds them to the results array.protected voidfireChildPropertyChange(PropertyChangeEvent event, int propertyCode) Called by child node to forward property change events up the node tree so that property change listeners registered with this node will be notified of property changes of its children nodes.voidfirePropertyChange(int propertyCode, String propertyName, Object oldValue, Object newValue) Report a bound property update to any registered listeners.booleanfullIntersects(Rectangle2D parentBounds) Return true if the full bounds of this node intersects with the specified bounds.voidfullPaint(PPaintContext paintContext) Paint this node and all of its descendants.booleanTry to pick this node and all of its descendants.Return a collection containing this node and all of its descendant nodes.getAllNodes(PNodeFilter filter, Collection resultantNodes) Return a collection containing the subset of this node and all of its descendant nodes that are accepted by the given node filter.getAttribute(Object key) Returns the value of the client attribute with the specified key.getAttribute(Object key, Object defaultValue) Fetches the value of the requested attribute, returning defaultValue is not found.booleangetBooleanAttribute(Object key, boolean defaultValue) Fetches the boolean value of the requested attribute, returning defaultValue is not found.Return a copy of this node's bounds.protected booleanReturn true if this node's bounds have recently changed.Return a direct reference to this node's bounds.protected booleanReturn true if this nodes bounds may change at any time.getChild(int index) Return the child node at the specified index.protected booleanReturn true if one of this node's descendants has invalid bounds.protected booleanReturn true if this node has a child with volatile bounds.booleanReturn true if this node has a child with invalid paint.intReturn the number of children that this node has.Return an iterator over this node's direct descendant children.booleanReturn true if the children of this node should be picked.Return a reference to the list used to manage this node's children.Return mutable attributed set of client properties associated with this node.getClientProperty(Object key) Deprecated.use getAttribute(Object key)instead.Returns an enumeration of all keys maped to attribute values values.Deprecated.use getClientPropertyKeysEnumerator() instead.doublegetDoubleAttribute(Object key, double defaultValue) Fetches the double value of the requested attribute, returning defaultValue is not found.Return a copy of this node's full bounds.protected booleanReturn true if the full bounds of this node are invalid.Return a reference to this node's full bounds cache.Return a copy of the bounds of this node in the global coordinate system.Return a copy of the full bounds of this node in the global coordinate system.doubleReturn the total amount of rotation applied to this node by its own transform together with the transforms of all its ancestors.doubleReturn the global scale that is being applied to this node by its transform together with the transforms of all its ancestors.Return the transform that converts global coordinates to local coordinates of this node.Return the global translation that is being applied to this node by its transform together with the transforms of all its ancestors.doubleReturn the height (in local coords) of this node's bounds.Returns an array of input event listeners that are attached to this node.intgetIntegerAttribute(Object key, int defaultValue) Fetches the integer value of the requested attribute, returning defaultValue is not found.Return an inverted copy of the transform associated with this node.Return the list of event listeners associated with this node.Return the transform that converts local coordinates at this node to the global coordinate system.getName()Returns the name given to this node.booleanReturns whether this node has been flagged as occluded.Return the offset that is being applied to this node by its transform.getPaint()Return the paint used while painting this node.booleanReturn true if this nodes paint is invalid, in which case the node needs to be repainted.Return the parent of this node.booleanReturn true if this node is pickable.intReturn the propertyChangeParentMask that determines which property change events are forwared to this nodes parent so that its property change listeners will also be notified.getRoot()Return the root node (instance of PRoot).doubleReturns the rotation applied by this node's transform in radians.doublegetScale()Return the scale applied by this node's transform.Return a copy of the transform associated with this node.getTransformReference(boolean createNewTransformIfNull) Return a reference to the transform associated with this node.floatReturn the transparency used when painting this node.getUnionOfChildrenBounds(PBounds dstBounds) Compute and return the union of the full bounds of all the children of this node.booleanReturn true if this node is visible, that is if it will paint itself and descendants.doublegetWidth()Return the width (in local coords) of this node's bounds.doublegetX()Return the x position (in local coords) of this node's bounds.doubleReturns the x offset of this node as applied by its transform.doublegetY()Return the y position (in local coords) of this node's bounds.doubleReturns the y offset of this node as applied by its transform.globalToLocal(Dimension2D globalDimension) Transform the given dimension from global coordinates to this node's local coordinate system.globalToLocal(Point2D globalPoint) Transform the given point from global coordinates to this node's local coordinate system.globalToLocal(Rectangle2D globalRectangle) Transform the given rectangle from global coordinates to this node's local coordinate system.intindexOfChild(PNode child) Return the index where the given child is stored.protected voidinternalUpdateBounds(double x, double y, double width, double height) Gives nodes a chance to update their internal structure before bounds changed notifications are sent.booleanintersects(Rectangle2D localBounds) Return true if this node intersects the given rectangle specified in local bounds.voidInvalidates the full bounds of this node, and sets the child bounds invalid flag on each of this node's ancestors.voidInvalidate this node's layout, so that later layoutChildren will get called.voidInvalidate this node's paint, and mark all of its ancestors as having a node with invalid paint.booleanisAncestorOf(PNode node) Return true if this node is an ancestor of the parameter node.booleanisDescendentOf(PNode node) Return true if this node is a descendant of the parameter node.booleanReturn true if this node descends from the root.booleanisOpaque(Rectangle2D boundary) Returns whether this node is Opaque.protected voidNodes that apply layout constraints to their children should override this method and do the layout there.static doublelerp(double t, double a, double b) Linearly interpolates between a and b, based on t.localToGlobal(Dimension2D localDimension) Transform the given dimension from this node's local coordinate system to the global coordinate system.localToGlobal(Point2D localPoint) Transform the given point from this node's local coordinate system to the global coordinate system.localToGlobal(Rectangle2D localRectangle) Transform the given rectangle from this node's local coordinate system to the global coordinate system.localToParent(Dimension2D localDimension) Transform the given dimension from this node's local coordinate system to its parent's local coordinate system.localToParent(Point2D localPoint) Transform the given point from this node's local coordinate system to its parent's local coordinate system.localToParent(Rectangle2D localRectangle) Transform the given rectangle from this node's local coordinate system to its parent's local coordinate system.voidmoveInBackOf(PNode sibling) Change the order of this node in its parent's children list so that it will draw in back of the specified sibling node.voidmoveInFrontOf(PNode sibling) Change the order of this node in its parent's children list so that it will draw in front of the specified sibling node.voidChange 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.voidChange 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.voidoffset(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 voidpaint(PPaintContext paintContext) Paint this node behind any of its children nodes.protected voidpaintAfterChildren(PPaintContext paintContext) Subclasses that wish to do additional painting after their children are painted should override this method and do that painting here.protected StringDeprecated.see http://code.google.com/p/piccolo2d/issues/detail?id=99protected voidA notification that the bounds of this node's parent have changed.parentToLocal(Dimension2D parentDimension) Transform the given dimension from this node's parent's local coordinate system to the local coordinate system of this node.parentToLocal(Point2D parentPoint) Transform the given point from this node's parent's local coordinate system to the local coordinate system of this node.parentToLocal(Rectangle2D parentRectangle) Transform the given rectangle from this node's parent's local coordinate system to the local coordinate system of this node.protected booleanTry to pick this node before its children have had a chance to be picked.protected booleanpickAfterChildren(PPickPath pickPath) Try to pick this node after its children have had a chance to be picked.voidposition(Point2D srcPt, Point2D destPt, Rectangle2D destBounds, int millis) Deprecated.in favor of animateToRelativePosition It will calculate the necessary transform in order to make this node appear at a particular position relative to the specified bounding box.voidprint()Constructs a new PrinterJob, allows the user to select which printer to print to, And then prints the node.intprint(Graphics graphics, PageFormat pageFormat, int pageIndex) Prints the node into the given Graphics context using the specified format.voidRemove all the children from this node.removeChild(int index) Remove the child at the specified position of this group node's children.removeChild(PNode child) Remove the given child from this node's children list.voidremoveChildren(Collection childrenNodes) Remove all the children in the given collection from this node's list of children.voidDelete this node by removing it from its parent's list of children.voidremoveInputEventListener(PInputEventListener listener) Removes the specified input event listener so that it no longer receives input events from this node.voidRemove a PropertyChangeListener from the listener list.voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) Remove a PropertyChangeListener for a specific property.voidrepaint()Mark the area on the screen represented by this nodes full bounds as needing a repaint.voidrepaintFrom(PBounds localBounds, PNode childOrThis) Pass the given repaint request up the tree, so that any cameras can invalidate that region on their associated canvas.voidSet the parent of this node, and transform the node in such a way that it doesn't move in global coordinates.voidreplaceWith(PNode replacementNode) Swaps this node out of the scene graph tree, and replaces it with the specified replacement node.voidSet the empty bit of this bounds to true.voidrotate(double theta) Rotates this node by theta (in radians) about the 0,0 point.voidrotateAboutPoint(double theta, double x, double y) Rotates this node by theta (in radians) about the given point.voidrotateAboutPoint(double theta, Point2D point) Rotates this node by theta (in radians) about the given point.voidrotateInPlace(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.voidscale(double scale) Scale this nodes transform by the given amount.voidscaleAboutPoint(double scale, double x, double y) Scale this nodes transform by the given amount about the specified point.voidscaleAboutPoint(double scale, Point2D point) Scale this nodes transform by the given amount about the specified point.booleansetBounds(double x, double y, double width, double height) Set the bounds of this node to the given position and size.booleansetBounds(Rectangle2D newBounds) Set the bounds of this node to the given value.protected voidsetBoundsChanged(boolean boundsChanged) Set the bounds chnaged flag.protected voidsetChildBoundsInvalid(boolean childBoundsInvalid) Set the flag indicating that one of this node's descendants has invalid bounds.protected voidsetChildBoundsVolatile(boolean childBoundsVolatile) Set if this node has a child with volatile bounds.voidsetChildPaintInvalid(boolean childPaintInvalid) Mark this node as having a child with invalid paint.voidsetChildrenPickable(boolean areChildrenPickable) Set the children pickable flag.protected voidsetFullBoundsInvalid(boolean fullBoundsInvalid) Set the full bounds invalid flag.voidsetGlobalRotation(double theta) Set the global rotation (in radians) of this node.voidsetGlobalScale(double scale) Set the global scale of this node.voidsetGlobalTranslation(Point2D globalPoint) Set the global translation of this node.booleansetHeight(double height) Set's this node's bounds height, leaving x, y, and width unchanged.voidSets the name of this null, may be null.voidsetOccluded(boolean occluded) Flags this node as occluded.voidsetOffset(double x, double y) Set the offset that is being applied to this node by its transform.voidSet the offset that is being applied to this node by its transform.voidSet the paint used to paint this node, which may be null.voidsetPaintInvalid(boolean paintInvalid) Mark this node as having invalid paint.voidSet the parent of this node.voidsetPickable(boolean isPickable) Set the pickable flag for this node.voidsetPropertyChangeParentMask(int propertyChangeParentMask) Set the propertyChangeParentMask that determines which property change events are forwared to this nodes parent so that its property change listeners will also be notified.voidsetRotation(double theta) Sets the rotation of this nodes transform in radians.voidsetScale(double scale) Set the scale of this node's transform.voidsetTransform(AffineTransform transform) Set the transform applied to this node.voidsetTransparency(float newTransparency) Set the transparency used to paint this node.voidsetVisible(boolean isVisible) Set the visibility of this node and its descendants.booleansetWidth(double width) Set's this node's bounds width, leaving x, y, and height unchanged.booleansetX(double x) Set's this node's bounds left position, leaving y, width, and height unchanged.booleansetY(double y) Set's this node's bounds top position, leaving x, width, and height unchanged.voidThis method should be called when the bounds of this node are changed.voidNotify this node that you will begin to repeatedly callsetBounds.toImage()Return a new Image representing this node and all of its children.Return a new Image of the requested size representing this node and all of its children.toImage(BufferedImage image, Paint backGroundPaint) Paint a representation of this node into the specified buffered image.toImage(BufferedImage image, Paint backGroundPaint, int fillStrategy) Paint a representation of this node into the specified buffered image.voidtransformBy(AffineTransform aTransform) Transform this nodes transform by the given transform.voidtranslate(double dx, double dy) Translate this node's transform by the given amount, using the standard affine transform translate method.protected booleanThis method is called to validate the bounds of this node and all of its descendants.voidRepaint this node and any of its descendants if they have invalid paint.
-
Field Details
-
PROPERTY_CLIENT_PROPERTIES
The property name that identifies a change in this node's client propertie (seegetClientProperty). 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:
-
PROPERTY_CODE_CLIENT_PROPERTIES
public static final int PROPERTY_CODE_CLIENT_PROPERTIESThe property code that identifies a change in this node's client propertie (seegetClientProperty). 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:
-
PROPERTY_BOUNDS
The property name that identifies a change of this node's bounds (seegetBounds,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:
-
PROPERTY_CODE_BOUNDS
public static final int PROPERTY_CODE_BOUNDSThe property code that identifies a change of this node's bounds (seegetBounds,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:
-
PROPERTY_FULL_BOUNDS
The property name that identifies a change of this node's full bounds (seegetFullBounds,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:
-
PROPERTY_CODE_FULL_BOUNDS
public static final int PROPERTY_CODE_FULL_BOUNDSThe property code that identifies a change of this node's full bounds (seegetFullBounds,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:
-
PROPERTY_TRANSFORM
The property name that identifies a change of this node's transform (seegetTransform,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:
-
PROPERTY_CODE_TRANSFORM
public static final int PROPERTY_CODE_TRANSFORMThe property code that identifies a change of this node's transform (seegetTransform,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:
-
PROPERTY_VISIBLE
The property name that identifies a change of this node's visibility (seegetVisible). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_CODE_VISIBLE
public static final int PROPERTY_CODE_VISIBLEThe property code that identifies a change of this node's visibility (seegetVisible). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_PAINT
The property name that identifies a change of this node's paint (seegetPaint). Both old value and new value will be set correctly in any property change event.- See Also:
-
PROPERTY_CODE_PAINT
public static final int PROPERTY_CODE_PAINTThe property code that identifies a change of this node's paint (seegetPaint). Both old value and new value will be set correctly in any property change event.- See Also:
-
PROPERTY_TRANSPARENCY
The property name that identifies a change of this node's transparency (seegetTransparency). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_CODE_TRANSPARENCY
public static final int PROPERTY_CODE_TRANSPARENCYThe property code that identifies a change of this node's transparency (seegetTransparency). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_PICKABLE
The property name that identifies a change of this node's pickable status (seegetPickable). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_CODE_PICKABLE
public static final int PROPERTY_CODE_PICKABLEThe property code that identifies a change of this node's pickable status (seegetPickable). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_CHILDREN_PICKABLE
The property name that identifies a change of this node's children pickable status (seegetChildrenPickable). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_CODE_CHILDREN_PICKABLE
public static final int PROPERTY_CODE_CHILDREN_PICKABLEThe property code that identifies a change of this node's children pickable status (seegetChildrenPickable). Both old value and new value will be null in any property change event.- See Also:
-
PROPERTY_CHILDREN
The property name that identifies a change in the set of this node's direct children (seegetChildrenReference,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:
-
PROPERTY_CODE_CHILDREN
public static final int PROPERTY_CODE_CHILDRENThe property code that identifies a change in the set of this node's direct children (seegetChildrenReference,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:
-
PROPERTY_PARENT
The property name that identifies a change of this node's parent (seegetParent). Both old value and new value will be set correctly in any property change event.- See Also:
-
PROPERTY_CODE_PARENT
public static final int PROPERTY_CODE_PARENTThe property code that identifies a change of this node's parent (seegetParent). Both old value and new value will be set correctly in any property change event.- See Also:
-
SCENE_GRAPH_DELEGATE
The single scene graph delegate that receives low level node events. -
FILL_STRATEGY_ASPECT_FIT
public static final int FILL_STRATEGY_ASPECT_FITtoImage fill strategy that stretches the node be as large as possible while still retaining its aspect ratio.- Since:
- 1.3
- See Also:
-
FILL_STRATEGY_ASPECT_COVER
public static final int FILL_STRATEGY_ASPECT_COVERtoImage fill strategy that stretches the node be large enough to cover the image, and centers it.- Since:
- 1.3
- See Also:
-
FILL_STRATEGY_EXACT_FIT
public static final int FILL_STRATEGY_EXACT_FITtoImage fill strategy that stretches the node to be exactly the dimensions of the image. Will result in distortion if the aspect ratios are different.- Since:
- 1.3
- See Also:
-
-
Constructor Details
-
PNode
Creates a new PNode with the given name.- Parameters:
newName- name to assign to node- Since:
- 1.3
-
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 Details
-
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. Note this method animates the node's bounds, but does not change the node's transform. Use animateTransformToBounds() to animate the node's transform instead.- Parameters:
x- left of target boundsy- top of target boundswidth- width of target boundsheight- height of target boundsduration- amount of time that the animation should take- Returns:
- the newly scheduled activity
-
animateTransformToBounds
public PTransformActivity animateTransformToBounds(double x, double y, double width, double height, long duration) Animate this node from it's current transform when the activity starts a new transform that will fit the node into the given 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. Note this method animates the node's transform, but does not directly change the node's bounds rectangle. Use animateToBounds() to animate the node's bounds rectangle instead.- Parameters:
x- left of target boundsy- top of target boundswidth- width of target boundsheight- height of target boundsduration- 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:
x- the final target x position of nodey- the final target y position of nodeduration- amount of time that the animation should takescale- the final scale for the durationtheta- final theta value (in radians) for the animation- Returns:
- the newly scheduled activity
-
animateToTransform
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 valueduration- amount of time that the animation should take- Returns:
- the newly scheduled activity
-
animateToColor
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
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
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.
-
getClientProperties
Return mutable attributed set of client properties associated with this node.- Returns:
- the client properties associated to this node
-
getAttribute
Returns the value of the client attribute with the specified key. Only attributes added withaddAttributewill return a non-null value.- Parameters:
key- key to use while fetching client attribute- Returns:
- the value of this attribute or null
-
addAttribute
Add an arbitrary key/value to this node.The
get/add attributemethods provide access to a small per-instance attribute set. Callers can use get/add attribute to annotate nodes that were created by another module.If value is null this method will remove the attribute.
- Parameters:
key- to use when adding the attributevalue- value to associate to the new attribute
-
getClientPropertyKeysEnumeration
Returns an enumeration of all keys maped to attribute values values.- Returns:
- an Enumeration over attribute keys
-
getAttribute
Fetches the value of the requested attribute, returning defaultValue is not found.- Parameters:
key- attribute to search fordefaultValue- value to return if attribute is not found- Returns:
- value of attribute or defaultValue if not found
-
getBooleanAttribute
Fetches the boolean value of the requested attribute, returning defaultValue is not found.- Parameters:
key- attribute to search fordefaultValue- value to return if attribute is not found- Returns:
- value of attribute or defaultValue if not found
-
getIntegerAttribute
Fetches the integer value of the requested attribute, returning defaultValue is not found.- Parameters:
key- attribute to search fordefaultValue- value to return if attribute is not found- Returns:
- value of attribute or defaultValue if not found
-
getDoubleAttribute
Fetches the double value of the requested attribute, returning defaultValue is not found.- Parameters:
key- attribute to search fordefaultValue- value to return if attribute is not found- Returns:
- value of attribute or defaultValue if not found
-
getClientProperty
Deprecated.use getAttribute(Object key)instead.- Parameters:
key- name of property to search for- Returns:
- value of matching client property
-
addClientProperty
Deprecated.use addAttribute(Object key, Object value)instead.- Parameters:
key- name of property to addvalue- value or new attribute
-
getClientPropertyKeysIterator
Deprecated.use getClientPropertyKeysEnumerator() instead.- Returns:
- iterator for client property keys
-
clone
The copy method copies this node and all of its descendants. Note that copying is implemented in terms of java serialization. See the serialization notes for more information. -
localToParent
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
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
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
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
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
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
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
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
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
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
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
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
Return the transform that converts local coordinates at this node to the global coordinate system.- Parameters:
dest- PAffineTransform to transform to global coordinates- Returns:
- The concatenation of transforms from the top node down to this node.
-
getGlobalToLocalTransform
Return the transform that converts global coordinates to local coordinates of this node.- Parameters:
dest- PAffineTransform to transform from global to local- Returns:
- The inverse of the concatenation of transforms from the root down to this node.
-
getListenerList
Return the list of event listeners associated with this node.- Returns:
- event listener list or null
-
addInputEventListener
Adds the specified input event listener to receive input events from this node.- Parameters:
listener- the new input listener
-
removeInputEventListener
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
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
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
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
Remove a PropertyChangeListener for a specific property.- Parameters:
propertyName- The name of the property that was listened on.listener- The PropertyChangeListener to be removed
-
getPropertyChangeParentMask
public int getPropertyChangeParentMask()Return the propertyChangeParentMask that determines which property change events are forwared to this nodes parent so that its property change listeners will also be notified.- Returns:
- mask used for deciding whether to bubble property changes up to parent
-
setPropertyChangeParentMask
public void setPropertyChangeParentMask(int propertyChangeParentMask) Set the propertyChangeParentMask that determines which property change events are forwared to this nodes parent so that its property change listeners will also be notified.- Parameters:
propertyChangeParentMask- new mask for property change bubble up
-
firePropertyChange
public void firePropertyChange(int propertyCode, String propertyName, Object oldValue, Object newValue) Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null. If the propertyCode exists in this node's propertyChangeParentMask then a property change event will also be fired on this nodes parent.- Parameters:
propertyCode- The code of the property changed.propertyName- The name of the property that was changed.oldValue- The old value of the property.newValue- The new value of the property.
-
fireChildPropertyChange
Called by child node to forward property change events up the node tree so that property change listeners registered with this node will be notified of property changes of its children nodes. For performance reason only propertyCodes listed in the propertyChangeParentMask are forwarded.- Parameters:
event- The property change event containing source node and changed values.propertyCode- The code of the property changed.
-
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.- Returns:
- copy of this node's local bounds
-
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.- Returns:
- direct reference to local bounds
-
startResizeBounds
public void startResizeBounds()Notify this node that you will begin to repeatedly callsetBounds. When you are done callendResizeBoundsto 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) Set's this node's bounds left position, leaving y, width, and height unchanged.- Parameters:
x- new x position of bounds- Returns:
- whether the change was successful
-
setY
public boolean setY(double y) Set's this node's bounds top position, leaving x, width, and height unchanged.- Parameters:
y- new y position of bounds- Returns:
- whether the change was successful
-
setWidth
public boolean setWidth(double width) Set's this node's bounds width, leaving x, y, and height unchanged.- Parameters:
width- new width position of bounds- Returns:
- whether the change was successful
-
setHeight
public boolean setHeight(double height) Set's this node's bounds height, leaving x, y, and width unchanged.- Parameters:
height- new height position of bounds- Returns:
- whether the change was successful
-
setBounds
Set the bounds of this node to the given value. These bounds are stored in the local coordinate system of this node.- Parameters:
newBounds- bounds to apply to 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 position and size. 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 empty bit will be set to true. Subclasses must call the super.setBounds() method.- Parameters:
x- x position of boundsy- y position of boundswidth- width to apply to the boundsheight- height to apply to the bounds- 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.- Parameters:
x- x position of boundsy- y position of boundswidth- width to apply to the boundsheight- height to apply to the bounds
-
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.- Returns:
- local x position of bounds
-
getY
public double getY()Return the y position (in local coords) of this node's bounds.- Returns:
- local y position of bounds
-
getWidth
public double getWidth()Return the width (in local coords) of this node's bounds.- Returns:
- local width of bounds
-
getHeight
public double getHeight()Return the height (in local coords) of this node's bounds.- Returns:
- local width of bounds
-
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 coordinates of this node. Note that this method will modify the nodes bounds, while centerFullBoundsOnPoint will modify the nodes transform.- Parameters:
localX- x position of point around which to center boundslocalY- y position of point around which to center bounds- Returns:
- true if the bounds changed.
-
centerFullBoundsOnPoint
public void centerFullBoundsOnPoint(double parentX, double parentY) Center the full bounds of this node so that they are centered on the given point specified on the local coordinates of this nodes parent. Note that this method will modify the nodes transform, while centerBoundsOnPoint will modify the nodes bounds.- Parameters:
parentX- x position around which to center full boundsparentY- y position around which to center full bounds
-
intersects
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 thatfullIntersectsis 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
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 descendants.- Returns:
- a copy of this node's full bounds.
-
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 descendants. The bounds returned by this method should not be modified.- Returns:
- a reference to this node's full bounds cache.
-
computeFullBounds
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
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- Returns:
- union of children bounds
-
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
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 descendant 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.- Parameters:
fullBoundsInvalid- true=invalid, false=valid
-
getChildBoundsInvalid
protected boolean getChildBoundsInvalid()Return true if one of this node's descendants has invalid bounds.- Returns:
- whether child bounds are invalid
-
setChildBoundsInvalid
protected void setChildBoundsInvalid(boolean childBoundsInvalid) Set the flag indicating that one of this node's descendants has invalid bounds.- Parameters:
childBoundsInvalid- true=invalid, false=valid
-
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 descendants. It returns true if this nodes bounds or the bounds of any of its descendants are marked as volatile.- Returns:
- true if this node or any of its descendants 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 descendants. 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 descendants.- 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
Rotates this node by theta (in radians) about the given point. This will affect this node and all its descendants.- Parameters:
theta- the amount to rotate by in radianspoint- the point about which to rotate
-
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 descendants.- Parameters:
theta- the amount to rotate by in radiansx- the x coordinate of the point around which to rotatey- the y coordinate of the point around which to rotate
-
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 coordinate system.
-
getScale
public double getScale()Return the scale applied by this node's transform. The scale is effecting this node and all its descendants.- 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 descendants.- 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 descendants.- Parameters:
scale- the amount to scale by
-
scaleAboutPoint
Scale this nodes transform by the given amount about the specified point. This will affect this node and all of its descendants.- Parameters:
scale- the amount to scale bypoint- 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 descendants.- Parameters:
scale- the amount to scale byx- the x coordinate of the point around which to scaley- the y coordinate of the point around which to scale
-
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.- Returns:
- global scale of this node
-
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()Returns the x offset of this node as applied by its transform.- Returns:
- x offset of this node as applied by its transform
-
getYOffset
public double getYOffset()Returns the y offset of this node as applied by its transform.- Returns:
- y offset of this node as applied by its transform
-
getOffset
Return the offset that is being applied to this node by its transform. This offset effects this node and all of its descendants 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
Set the offset that is being applied to this node by its transform. This offset effects this node and all of its descendants 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- value of new 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 descendants 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 offsety- 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.- Parameters:
dx- amount to add to this nodes current x Offsetdy- amount to add to this nodes current y Offset
-
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 descendants.- Parameters:
dx- amount to add to this nodes current x translationdy- amount to add to this nodes current y translation
-
getGlobalTranslation
Return the global translation that is being applied to this node by its transform together with the transforms of all its ancestors.- Returns:
- the global translation applied to this node
-
setGlobalTranslation
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
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:
t- variable 'time' parametera- from pointb- to Point- Returns:
- linear interpolation between and b at time interval t (given as # between 0f and 1f)
-
animateToRelativePosition
public PActivity animateToRelativePosition(Point2D srcPt, Point2D destPt, 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 nodemillis- Number of milliseconds over which to perform the animation- Returns:
- newly scheduled activity or node if activity could not be scheduled
- Since:
- 1.3
-
position
Deprecated.in favor of animateToRelativePosition It 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 nodemillis- Number of milliseconds over which to perform the animation
-
getTransform
Return a copy of the transform associated with this node.- Returns:
- copy of this node's transform
-
getTransformReference
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.- Parameters:
createNewTransformIfNull- if the transform has not been initialised, should it be?- Returns:
- reference to this node's transform
-
getInverseTransform
Return an inverted copy of the transform associated with this node.- Returns:
- inverted copy of this node's transform
-
setTransform
Set the transform applied to this node.- Parameters:
transform- 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 descendants 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
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 repaintchildOrThis- if childOrThis does not equal this then this nodes transform will be applied to the localBounds param
-
isOpaque
Returns whether this node is Opaque.- Parameters:
boundary- boundary to check and see if this node covers completely.- Returns:
- true if opaque
-
getOccluded
public boolean getOccluded()Returns whether this node has been flagged as occluded.- Returns:
- true if occluded
-
setOccluded
public void setOccluded(boolean occluded) Flags this node as occluded.- Parameters:
occluded- new value for occluded
-
getVisible
public boolean getVisible()Return true if this node is visible, that is if it will paint itself and descendants.- Returns:
- true if this node and its descendants are visible.
-
setVisible
public void setVisible(boolean isVisible) Set the visibility of this node and its descendants.- Parameters:
isVisible- true if this node and its descendants are visible
-
getPaint
Return the paint used while painting this node. This value may be null.- Returns:
- the paint used while painting this node.
-
setPaint
Set the paint used to paint this node, which may be null.- Parameters:
newPaint- paint that this node should use when painting itself.
-
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 descendants.- Returns:
- how transparent this node is 0f = completely transparent, 1f = completely opaque
-
setTransparency
public void setTransparency(float newTransparency) Set the transparency used to paint this node. Note that this transparency applies to this node and all of its descendants.- Parameters:
newTransparency- transparency value for this node. 0f = fully transparent, 1f = fully opaque
-
paint
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
Paint this node and all of its descendants. Most subclasses do not need to override this method, they should overridepaintorpaintAfterChildreninstead.- Parameters:
paintContext- the paint context to use for painting this node and its children
-
paintAfterChildren
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
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 descendants
-
toImage
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, otherwise those regions will be filled with the backgroundPaint.- Parameters:
width- pixel width of the resulting imageheight- pixel height of the resulting imagebackgroundPaint- paint to fill the image with before drawing this node, may be null- Returns:
- a new image representing this node and its descendants
-
toImage
Paint a representation of this node into the specified buffered image. If background, paint is null, then the image will not be filled with a color prior to rendering- Parameters:
image- Image onto which this node will be paintedbackGroundPaint- will fill background of image with this. May be null.- Returns:
- a rendering of this image and its descendants onto the specified image
-
toImage
Paint a representation of this node into the specified buffered image. If background, paint is null, then the image will not be filled with a color prior to rendering- Parameters:
image- Image onto which this node will be paintedbackGroundPaint- will fill background of image with this. May be null.fillStrategy- strategy to use regarding how node will cover the image- Returns:
- a rendering of this image and its descendants onto the specified image
- Since:
- 1.3
-
print
public void print()Constructs a new PrinterJob, allows the user to select which printer to print to, And then prints the node. -
print
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. -
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
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
Try to pick this node and all of its descendants. Most subclasses should not need to override this method. Instead they should overridepickorpickAfterChildren.- Parameters:
pickPath- the pick path to add the node to if its picked- Returns:
- true if this node or one of its descendants was picked.
-
findIntersectingNodes
Finds all descendants of this node that intersect with the given bounds and adds them to the results array.- Parameters:
fullBounds- bounds to compare againstresults- array into which to add matches
-
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.- Parameters:
pickPath- the pick path used for the pick operation- Returns:
- true if this node was picked
-
addChild
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
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:
index- where in the children list to insert the childchild- the new child to add to this node
-
addChildren
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
Return true if this node is an ancestor of the parameter node.- Parameters:
node- a possible descendant node- Returns:
- true if this node is an ancestor of the given node
-
isDescendentOf
Return true if this node is a descendant 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.- Returns:
- whether this node descends from root node
-
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
Change the order of this node in its parent's children list so that it will draw in back of the specified sibling node.- Parameters:
sibling- sibling to move in back of
-
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
Change the order of this node in its parent's children list so that it will draw in front of the specified sibling node.- Parameters:
sibling- sibling to move in front of
-
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
Set the parent of this node. Note this is set automatically when adding and removing children.- Parameters:
newParent- the parent to which this node should be added
-
indexOfChild
Return the index where the given child is stored.- Parameters:
child- child so search for- Returns:
- index of child or -1 if not found
-
removeChild
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
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
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
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
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.
-
setName
Sets the name of this null, may be null.- Parameters:
name- new name for this node- Since:
- 1.3
-
getName
Returns the name given to this node.- Returns:
- name given to this node, may be null
- Since:
- 1.3
-
getChildrenCount
public int getChildrenCount()Return the number of children that this node has.- Returns:
- the number of children
-
getChild
Return the child node at the specified index.- Parameters:
index- a child index- Returns:
- the child node at the specified index
-
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
Return an iterator over this node's direct descendant children.- Returns:
- iterator over this nodes children
-
getRoot
Return the root node (instance of PRoot). If this node does not descend from a PRoot then null will be returned.- Returns:
- root element of this node, or null if this node does not descend from a PRoot
-
getAllNodes
Return a collection containing this node and all of its descendant nodes.- Returns:
- a new collection containing this node and all descendants
-
getAllNodes
Return a collection containing the subset of this node and all of its descendant 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 subsetresultantNodes- where matching nodes should be added- Returns:
- a collection containing this node and all descendants
-
paramString
Deprecated.see http://code.google.com/p/piccolo2d/issues/detail?id=99- Returns:
- a string representation of this node's state
-
getInputEventListeners
Returns an array of input event listeners that are attached to this node.- Returns:
- event listeners attached to this node
- Since:
- 1.3
-