edu.umd.cs.piccolo.nodes
Class PPath

java.lang.Object
  extended by edu.umd.cs.piccolo.PNode
      extended by edu.umd.cs.piccolo.nodes.PPath
All Implemented Interfaces:
java.awt.print.Printable, java.io.Serializable, java.lang.Cloneable

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

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate
 
Field Summary
static int PROPERTY_CODE_PATH
          The property code that identifies a change of this node's path (see getPathReference).
static int PROPERTY_CODE_STROKE
          The property code that identifies a change of this node's stroke (see getStroke).
static int PROPERTY_CODE_STROKE_PAINT
          The property code that identifies a change of this node's stroke paint (see getStrokePaint).
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
FILL_STRATEGY_ASPECT_COVER, FILL_STRATEGY_ASPECT_FIT, FILL_STRATEGY_EXACT_FIT, PROPERTY_BOUNDS, PROPERTY_CHILDREN, PROPERTY_CHILDREN_PICKABLE, PROPERTY_CLIENT_PROPERTIES, PROPERTY_CODE_BOUNDS, PROPERTY_CODE_CHILDREN, PROPERTY_CODE_CHILDREN_PICKABLE, PROPERTY_CODE_CLIENT_PROPERTIES, PROPERTY_CODE_FULL_BOUNDS, PROPERTY_CODE_PAINT, PROPERTY_CODE_PARENT, PROPERTY_CODE_PICKABLE, PROPERTY_CODE_TRANSFORM, PROPERTY_CODE_TRANSPARENCY, PROPERTY_CODE_VISIBLE, PROPERTY_FULL_BOUNDS, PROPERTY_PAINT, PROPERTY_PARENT, PROPERTY_PICKABLE, PROPERTY_TRANSFORM, PROPERTY_TRANSPARENCY, PROPERTY_VISIBLE, SCENE_GRAPH_DELEGATE
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PPath()
          Creates an empty PPath with the default paint and stroke.
PPath(java.awt.Shape aShape)
          Creates an PPath in the given shape with the default paint and stroke.
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)
          Creates a PPath object in the shape of an ellipse.
static PPath createLine(float x1, float y1, float x2, float y2)
          Creates a PPath in the shape of a line.
static PPath createPolyline(float[] xp, float[] yp)
          Creates a PPath for the poly-line for the given points.
static PPath createPolyline(java.awt.geom.Point2D[] points)
          Creates a PPath for the poly-line for the given points.
static PPath createRectangle(float x, float y, float width, float height)
          Creates a PPath object in the shape of a rectangle.
static PPath createRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight)
          Creates a PPath object in the shape of a rounded rectangle.
 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()
          Returns the stroke paint of the PPath.
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.
 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 begin to repeatedly call setBounds .
 void updateBoundsFromPath()
           
 
Methods inherited from class edu.umd.cs.piccolo.PNode
addActivity, addAttribute, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, animateToRelativePosition, animateToTransform, animateToTransparency, animateTransformToBounds, centerBoundsOnPoint, centerFullBoundsOnPoint, clone, computeFullBounds, findIntersectingNodes, fireChildPropertyChange, firePropertyChange, fullIntersects, fullPaint, fullPick, getAllNodes, getAllNodes, getAttribute, getAttribute, getBooleanAttribute, getBounds, getBoundsChanged, getBoundsReference, getBoundsVolatile, getChild, getChildBoundsInvalid, getChildBoundsVolatile, getChildPaintInvalid, getChildrenCount, getChildrenIterator, getChildrenPickable, getChildrenReference, getClientProperties, getClientProperty, getClientPropertyKeysEnumeration, getClientPropertyKeysIterator, getDoubleAttribute, getFullBounds, getFullBoundsInvalid, getFullBoundsReference, getGlobalBounds, getGlobalFullBounds, getGlobalRotation, getGlobalScale, getGlobalToLocalTransform, getGlobalTranslation, getHeight, getInputEventListeners, getIntegerAttribute, getInverseTransform, getListenerList, getLocalToGlobalTransform, getName, getOccluded, getOffset, getPaint, getPaintInvalid, getParent, getPickable, getPropertyChangeParentMask, getRoot, getRotation, getScale, getTransform, getTransformReference, getTransparency, getUnionOfChildrenBounds, getVisible, getWidth, getX, getXOffset, getY, getYOffset, globalToLocal, globalToLocal, globalToLocal, indexOfChild, invalidateFullBounds, invalidateLayout, invalidatePaint, isAncestorOf, isDescendentOf, isDescendentOfRoot, isOpaque, layoutChildren, lerp, localToGlobal, localToGlobal, localToGlobal, localToParent, localToParent, localToParent, moveInBackOf, moveInFrontOf, moveToBack, moveToFront, offset, paintAfterChildren, paramString, parentBoundsChanged, parentToLocal, parentToLocal, parentToLocal, pick, 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, setName, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setPropertyChangeParentMask, setRotation, setScale, setTransform, setTransparency, setVisible, setWidth, setX, setY, signalBoundsChanged, toImage, toImage, toImage, toImage, transformBy, translate, validateFullBounds, validateFullPaint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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_CODE_STROKE_PAINT

public static final int PROPERTY_CODE_STROKE_PAINT
The property code 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_CODE_STROKE

public static final int PROPERTY_CODE_STROKE
The property code 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

PROPERTY_CODE_PATH

public static final int PROPERTY_CODE_PATH
The property code 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()
Creates an empty PPath with the default paint and stroke.


PPath

public PPath(java.awt.Shape aShape)
Creates an PPath in the given shape with the default paint and stroke.

Parameters:
aShape - the desired shape

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.

Parameters:
aShape - desired shape or null if you desire an empty path
aStroke - desired stroke
Method Detail

createRectangle

public static PPath createRectangle(float x,
                                    float y,
                                    float width,
                                    float height)
Creates a PPath object in the shape of a rectangle.

Parameters:
x - left of the rectangle
y - top of the rectangle
width - width of the rectangle
height - height of the rectangle
Returns:
created rectangle

createRoundRectangle

public static PPath createRoundRectangle(float x,
                                         float y,
                                         float width,
                                         float height,
                                         float arcWidth,
                                         float arcHeight)
Creates a PPath object in the shape of a rounded rectangle.

Parameters:
x - left of the rectangle
y - top of the rectangle
width - width of the rectangle
height - height of the rectangle
arcWidth - the arc width at the corners of the rectangle
arcHeight - the arc height at the corners of the rectangle
Returns:
created rounded rectangle

createEllipse

public static PPath createEllipse(float x,
                                  float y,
                                  float width,
                                  float height)
Creates a PPath object in the shape of an ellipse.

Parameters:
x - left of the ellipse
y - top of the ellipse
width - width of the ellipse
height - height of the ellipse
Returns:
created ellipse

createLine

public static PPath createLine(float x1,
                               float y1,
                               float x2,
                               float y2)
Creates a PPath in the shape of a line.

Parameters:
x1 - x component of the first point
y1 - y component of the first point
x2 - x component of the second point
y2 - y component of the second point
Returns:
created line

createPolyline

public static PPath createPolyline(java.awt.geom.Point2D[] points)
Creates a PPath for the poly-line for the given points.

Parameters:
points - array of points for the point lines
Returns:
created poly-line for the given points

createPolyline

public static PPath createPolyline(float[] xp,
                                   float[] yp)
Creates a PPath for the poly-line for the given points.

Parameters:
xp - array of x components of the points of the poly-lines
yp - array of y components of the points of the poly-lines
Returns:
created poly-line for the given points

getStrokePaint

public java.awt.Paint getStrokePaint()
Returns the stroke paint of the PPath.

Returns:
stroke paint of the PPath

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 begin to repeatedly 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
Parameters:
x - x position of bounds
y - y position of bounds
width - width to apply to the bounds
height - height to apply to the bounds

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()


Copyright © 1995-2009 Piccolo2D. All Rights Reserved.