edu.umd.cs.piccolo.nodes
Class PPath

java.lang.Object
  extended byedu.umd.cs.piccolo.PNode
      extended byedu.umd.cs.piccolo.nodes.PPath
All Implemented Interfaces:
java.lang.Cloneable, java.awt.print.Printable, java.io.Serializable
Direct Known Subclasses:
PClip, PHandle

public class PPath
extends PNode

PPath is a wrapper around a java.awt.geom.GeneralPath. The setBounds method works by scaling the path to fit into the specified bounds. This normally works well, but if the specified base bounds get too small then it is impossible to expand the path shape again since all its numbers have tended to zero, so application code may need to take this into consideration.

One option that applications have is to call startResizeBounds before starting an interaction that may make the bounds very small, and calling endResizeBounds when this interaction is finished. When this is done PPath will use a copy of the original path to do the resizing so the numbers in the path wont loose resolution.

This class also provides methods for constructing common shapes using a general path.

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

Field Summary
static java.lang.String PROPERTY_PATH
          The property name that identifies a change of this node's path (see getPathReference).
static java.lang.String PROPERTY_STROKE
          The property name that identifies a change of this node's stroke (see getStroke).
static java.lang.String PROPERTY_STROKE_PAINT
          The property name that identifies a change of this node's stroke paint (see getStrokePaint).
 
Fields inherited from class edu.umd.cs.piccolo.PNode
PROPERTY_BOUNDS, PROPERTY_CHILDREN, PROPERTY_CHILDREN_PICKABLE, PROPERTY_CLIENT_PROPERTIES, PROPERTY_FULL_BOUNDS, PROPERTY_PAINT, PROPERTY_PARENT, PROPERTY_PICKABLE, PROPERTY_TRANSFORM, PROPERTY_TRANSPARENCY, PROPERTY_VISIBLE
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PPath()
           
PPath(java.awt.Shape aShape)
           
PPath(java.awt.Shape aShape, java.awt.Stroke aStroke)
          Construct this path with the given shape and stroke.
 
Method Summary
 void append(java.awt.Shape aShape, boolean connect)
           
 void closePath()
           
static PPath createEllipse(float x, float y, float width, float height)
           
static PPath createLine(float x1, float y1, float x2, float y2)
           
static PPath createPolyline(float[] xp, float[] yp)
           
static PPath createPolyline(java.awt.geom.Point2D[] points)
           
static PPath createRectangle(float x, float y, float width, float height)
           
 void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
           
 void endResizeBounds()
          Notify this node that you have finished a resize bounds sequence.
 java.awt.geom.Rectangle2D getPathBoundsWithStroke()
           
 java.awt.geom.GeneralPath getPathReference()
           
 java.awt.Stroke getStroke()
           
 java.awt.Paint getStrokePaint()
           
protected  void internalUpdateBounds(double x, double y, double width, double height)
          Set the bounds of this path.
 boolean intersects(java.awt.geom.Rectangle2D aBounds)
          Return true if this node intersects the given rectangle specified in local bounds.
 void lineTo(float x, float y)
           
 void moveTo(float x, float y)
           
protected  void paint(PPaintContext paintContext)
          Paint this node behind any of its children nodes.
protected  java.lang.String paramString()
          Returns a string representing the state of this node.
 void quadTo(float x1, float y1, float x2, float y2)
           
 void reset()
           
 void setPathTo(java.awt.Shape aShape)
           
 void setPathToEllipse(float x, float y, float width, float height)
           
 void setPathToPolyline(float[] xp, float[] yp)
           
 void setPathToPolyline(java.awt.geom.Point2D[] points)
           
 void setPathToRectangle(float x, float y, float width, float height)
           
 void setStroke(java.awt.Stroke aStroke)
           
 void setStrokePaint(java.awt.Paint aPaint)
           
 void startResizeBounds()
          Notify this node that you will beging to repeadily call setBounds.
 void updateBoundsFromPath()
           
 
Methods inherited from class edu.umd.cs.piccolo.PNode
addActivity, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, animateToTransform, animateToTransparency, centerBoundsOnPoint, centerFullBoundsOnPoint, clone, computeFullBounds, findIntersectingNodes, firePropertyChange, fullIntersects, fullPaint, fullPick, getAllNodes, getAllNodes, getBounds, getBoundsChanged, getBoundsReference, getBoundsVolatile, getChild, getChildBoundsInvalid, getChildBoundsVolatile, getChildPaintInvalid, getChildrenCount, getChildrenIterator, getChildrenPickable, getChildrenReference, getClientProperty, getClientPropertyKeysIterator, getFullBounds, getFullBoundsInvalid, getFullBoundsReference, getGlobalBounds, getGlobalFullBounds, getGlobalRotation, getGlobalScale, getGlobalToLocalTransform, getGlobalTranslation, getHeight, getInverseTransform, getListenerList, getLocalToGlobalTransform, getOccluded, getOffset, getPaint, getPaintInvalid, getParent, getPickable, getRoot, getRotation, getScale, getTransform, getTransformReference, getTransparency, getUnionOfChildrenBounds, getVisible, getWidth, getX, getXOffset, getY, getYOffset, globalToLocal, globalToLocal, globalToLocal, indexOfChild, invalidateFullBounds, invalidateLayout, invalidatePaint, isAncestorOf, isDescendentOf, isDescendentOfRoot, isOpaque, layoutChildren, lerp, localToGlobal, localToGlobal, localToGlobal, localToParent, localToParent, localToParent, moveInBackOf, moveInFrontOf, moveToBack, moveToFront, offset, paintAfterChildren, parentBoundsChanged, parentToLocal, parentToLocal, parentToLocal, pick, pickAfterChildren, position, print, print, removeAllChildren, removeChild, removeChild, removeChildren, removeFromParent, removeInputEventListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaintFrom, reparent, replaceWith, resetBounds, rotate, rotateAboutPoint, rotateAboutPoint, rotateInPlace, scale, scaleAboutPoint, scaleAboutPoint, setBounds, setBounds, setBoundsChanged, setChildBoundsInvalid, setChildBoundsVolatile, setChildPaintInvalid, setChildrenPickable, setFullBoundsInvalid, setGlobalRotation, setGlobalScale, setGlobalTranslation, setHeight, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setRotation, setScale, setTransform, setTransparency, setVisible, setWidth, setX, setY, signalBoundsChanged, toImage, toImage, toString, transformBy, translate, validateFullBounds, validateFullPaint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_STROKE_PAINT

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

See Also:
Constant Field Values

PROPERTY_STROKE

public static final java.lang.String PROPERTY_STROKE
The property name that identifies a change of this node's stroke (see getStroke). Both old and new value will be set correctly to Stroke objects in any property change event.

See Also:
Constant Field Values

PROPERTY_PATH

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

See Also:
Constant Field Values
Constructor Detail

PPath

public PPath()

PPath

public PPath(java.awt.Shape aShape)

PPath

public PPath(java.awt.Shape aShape,
             java.awt.Stroke aStroke)
Construct this path with the given shape and stroke. This method may be used to optimize the creation of a large number of PPaths. Normally PPaths have a default stroke of width one, but when a path has a non null stroke it takes significantly longer to compute its bounds. This method allows you to override that default stroke before the bounds are ever calculated, so if you pass in a null stroke here you won't ever have to pay that bounds calculation price if you don't need to.

Method Detail

createRectangle

public static PPath createRectangle(float x,
                                    float y,
                                    float width,
                                    float height)

createEllipse

public static PPath createEllipse(float x,
                                  float y,
                                  float width,
                                  float height)

createLine

public static PPath createLine(float x1,
                               float y1,
                               float x2,
                               float y2)

createPolyline

public static PPath createPolyline(java.awt.geom.Point2D[] points)

createPolyline

public static PPath createPolyline(float[] xp,
                                   float[] yp)

getStrokePaint

public java.awt.Paint getStrokePaint()

setStrokePaint

public void setStrokePaint(java.awt.Paint aPaint)

getStroke

public java.awt.Stroke getStroke()

setStroke

public void setStroke(java.awt.Stroke aStroke)

startResizeBounds

public void startResizeBounds()
Description copied from class: PNode
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.

Overrides:
startResizeBounds in class PNode

endResizeBounds

public void endResizeBounds()
Description copied from class: PNode
Notify this node that you have finished a resize bounds sequence.

Overrides:
endResizeBounds in class PNode

internalUpdateBounds

protected void internalUpdateBounds(double x,
                                    double y,
                                    double width,
                                    double height)
Set the bounds of this path. This method works by scaling the path to fit into the specified bounds. This normally works well, but if the specified base bounds get too small then it is impossible to expand the path shape again since all its numbers have tended to zero, so application code may need to take this into consideration.

Overrides:
internalUpdateBounds in class PNode

intersects

public boolean intersects(java.awt.geom.Rectangle2D aBounds)
Description copied from class: PNode
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.

Overrides:
intersects in class PNode
Parameters:
aBounds - the bounds to test for intersection against
Returns:
true if the given rectangle intersects this nodes geometry.

getPathBoundsWithStroke

public java.awt.geom.Rectangle2D getPathBoundsWithStroke()

updateBoundsFromPath

public void updateBoundsFromPath()

paint

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

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

getPathReference

public java.awt.geom.GeneralPath getPathReference()

moveTo

public void moveTo(float x,
                   float y)

lineTo

public void lineTo(float x,
                   float y)

quadTo

public void quadTo(float x1,
                   float y1,
                   float x2,
                   float y2)

curveTo

public void curveTo(float x1,
                    float y1,
                    float x2,
                    float y2,
                    float x3,
                    float y3)

append

public void append(java.awt.Shape aShape,
                   boolean connect)

setPathTo

public void setPathTo(java.awt.Shape aShape)

setPathToRectangle

public void setPathToRectangle(float x,
                               float y,
                               float width,
                               float height)

setPathToEllipse

public void setPathToEllipse(float x,
                             float y,
                             float width,
                             float height)

setPathToPolyline

public void setPathToPolyline(java.awt.geom.Point2D[] points)

setPathToPolyline

public void setPathToPolyline(float[] xp,
                              float[] yp)

closePath

public void closePath()

reset

public void reset()

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.

Overrides:
paramString in class PNode
Returns:
a string representation of this node's state


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