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:
Printable, Serializable, 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 String PROPERTY_PATH
          The property name that identifies a change of this node's path (see getPathReference).
static String PROPERTY_STROKE
          The property name that identifies a change of this node's stroke (see getStroke).
static 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(Shape aShape)
          Creates an PPath in the given shape with the default paint and stroke.
PPath(Shape aShape, Stroke aStroke)
          Construct this path with the given shape and stroke.
 
Method Summary
 void append(Shape aShape, boolean connect)
          Appends the provided shape to the end of this path, it may conditionally connect them together if they are disjoint.
 void closePath()
          Marks the path as closed.
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(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)
          Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the coordinates (x3, y3), using the specified points (x1, y1) and (x2, y2) as Bézier control points.
 void endResizeBounds()
          Clears the size of the path before resizing.
 Rectangle2D getPathBoundsWithStroke()
          Calculates the path's bounds taking stroke into account.
 GeneralPath getPathReference()
          Provides direct access to the underlying GeneralPath object.
 Stroke getStroke()
          Returns the stroke to use when drawing the path.
 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(Rectangle2D aBounds)
          Returns true if path crosses the provided bounds.
 void lineTo(float x, float y)
          Draws a line from the last point in the path to point provided.
 void moveTo(float x, float y)
          Appends a "move" operation to the end of the path.
protected  void paint(PPaintContext paintContext)
          Paints the path in the provided paintContext.
 void quadTo(float x1, float y1, float x2, float y2)
          Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the coordinates (x2, y2), using the specified point (x1, y1) as a quadratic parametric control point.
 void reset()
          Empties the path.
 void setPathTo(Shape aShape)
          Replaces this PPath's path with the one provided.
 void setPathToEllipse(float x, float y, float width, float height)
          Resets the path to an ellipse positioned at the coordinate provided with the dimensions provided.
 void setPathToPolyline(float[] xp, float[] yp)
          Sets the path to a sequence of segments described by the point components provided.
 void setPathToPolyline(Point2D[] points)
          Sets the path to a sequence of segments described by the points.
 void setPathToRectangle(float x, float y, float width, float height)
          Resets the path to a rectangle with the dimensions and position provided.
 void setStroke(Stroke aStroke)
          Sets the stroke to use when drawing the path.
 void setStrokePaint(Paint newStrokePaint)
          Sets the stroke paint of the path.
 void startResizeBounds()
          Stores the original size of the path before resizing started.
 void updateBoundsFromPath()
          Recomputes the bounds taking stroke into account.
 
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 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 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 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(Shape aShape)
Creates an PPath in the given shape with the default paint and stroke.

Parameters:
aShape - the desired shape

PPath

public PPath(Shape aShape,
             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(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 Paint getStrokePaint()
Returns the stroke paint of the PPath.

Returns:
stroke paint of the PPath

setStrokePaint

public void setStrokePaint(Paint newStrokePaint)
Sets the stroke paint of the path.

Parameters:
newStrokePaint - the paint to use as this path's stroke paint

getStroke

public Stroke getStroke()
Returns the stroke to use when drawing the path.

Returns:
current stroke of path

setStroke

public void setStroke(Stroke aStroke)
Sets the stroke to use when drawing the path.

Parameters:
aStroke - stroke to use when drawing the path

startResizeBounds

public void startResizeBounds()
Stores the original size of the path before resizing started.

Overrides:
startResizeBounds in class PNode

endResizeBounds

public void endResizeBounds()
Clears the size of the path before resizing.

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 - new left position of bounds
y - new top position of bounds
width - the new width of the bounds
height - the new height of the bounds

intersects

public boolean intersects(Rectangle2D aBounds)
Returns true if path crosses the provided bounds. Takes visibility of path into account.

Overrides:
intersects in class PNode
Parameters:
aBounds - bounds being tested for intersection
Returns:
true if path visibly crosses bounds

getPathBoundsWithStroke

public Rectangle2D getPathBoundsWithStroke()
Calculates the path's bounds taking stroke into account.

Returns:
bounds of the path taking stroke width into account

updateBoundsFromPath

public void updateBoundsFromPath()
Recomputes the bounds taking stroke into account.


paint

protected void paint(PPaintContext paintContext)
Paints the path in the provided paintContext. Can perform very differently depending on whether the path is being drawn using its stroke or its paint. It both are provided to the path, fun ensues.

Overrides:
paint in class PNode
Parameters:
paintContext - context in which painting is occurring

getPathReference

public GeneralPath getPathReference()
Provides direct access to the underlying GeneralPath object.

Returns:
underlying GeneralPath

moveTo

public void moveTo(float x,
                   float y)
Appends a "move" operation to the end of the path.

Parameters:
x - the x component of the point to move to
y - the y component of the point to move to

lineTo

public void lineTo(float x,
                   float y)
Draws a line from the last point in the path to point provided.

Parameters:
x - the x component of the point
y - the y component of the point

quadTo

public void quadTo(float x1,
                   float y1,
                   float x2,
                   float y2)
Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the coordinates (x2, y2), using the specified point (x1, y1) as a quadratic parametric control point.

Parameters:
x1 - x component of quadratic parametric control point
y1 - y component of quadratic parametric control point
x2 - x component of point through which quad curve will pass
y2 - y component of point through which quad curve will pass

curveTo

public void curveTo(float x1,
                    float y1,
                    float x2,
                    float y2,
                    float x3,
                    float y3)
Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the coordinates (x3, y3), using the specified points (x1, y1) and (x2, y2) as Bézier control points.

Parameters:
x1 - x component of first Bézier control point
y1 - y component of first Bézier control point
x2 - x component of second Bézier control point
y2 - y component of second Bézier control point
x3 - x component of point through which curve must pass
y3 - y component of point through which curve must pass

append

public void append(Shape aShape,
                   boolean connect)
Appends the provided shape to the end of this path, it may conditionally connect them together if they are disjoint.

Parameters:
aShape - shape to append
connect - whether to perform a lineTo operation to the beginning of the shape before appending

setPathTo

public void setPathTo(Shape aShape)
Replaces this PPath's path with the one provided.

Parameters:
aShape - shape to replace the current one with

setPathToRectangle

public void setPathToRectangle(float x,
                               float y,
                               float width,
                               float height)
Resets the path to a rectangle with the dimensions and position provided.

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

setPathToEllipse

public void setPathToEllipse(float x,
                             float y,
                             float width,
                             float height)
Resets the path to an ellipse positioned at the coordinate provided with the dimensions provided.

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

setPathToPolyline

public void setPathToPolyline(Point2D[] points)
Sets the path to a sequence of segments described by the points.

Parameters:
points - points to that lie along the generated path

setPathToPolyline

public void setPathToPolyline(float[] xp,
                              float[] yp)
Sets the path to a sequence of segments described by the point components provided.

Parameters:
xp - the x components of the points along the path
yp - the y components of the points along the path

closePath

public void closePath()
Marks the path as closed. Making changes to it impossible.


reset

public void reset()
Empties the path.



Copyright © 1995-2011 Piccolo2D. All Rights Reserved.