Package edu.umd.cs.piccolo.nodes
Class PPath
java.lang.Object
edu.umd.cs.piccolo.PNode
edu.umd.cs.piccolo.nodes.PPath
- All Implemented Interfaces:
Printable,Serializable,Cloneable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe property code that identifies a change of this node's path (seegetPathReference).static final intThe property code that identifies a change of this node's stroke (seegetStroke).static final intThe property code that identifies a change of this node's stroke paint (seegetStrokePaint).static final StringThe property name that identifies a change of this node's path (seegetPathReference).static final StringThe property name that identifies a change of this node's stroke (seegetStroke).static final StringThe property name that identifies a change of this node's stroke paint (seegetStrokePaint).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_DELEGATEFields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends the provided shape to the end of this path, it may conditionally connect them together if they are disjoint.voidMarks the path as closed.static PPathcreateEllipse(float x, float y, float width, float height) Creates a PPath object in the shape of an ellipse.static PPathcreateLine(float x1, float y1, float x2, float y2) Creates a PPath in the shape of a line.static PPathcreatePolyline(float[] xp, float[] yp) Creates a PPath for the poly-line for the given points.static PPathcreatePolyline(Point2D[] points) Creates a PPath for the poly-line for the given points.static PPathcreateRectangle(float x, float y, float width, float height) Creates a PPath object in the shape of a rectangle.static PPathcreateRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight) Creates a PPath object in the shape of a rounded rectangle.voidcurveTo(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.voidClears the size of the path before resizing.Calculates the path's bounds taking stroke into account.Provides direct access to the underlying GeneralPath object.Returns the stroke to use when drawing the path.Returns the stroke paint of the PPath.protected voidinternalUpdateBounds(double x, double y, double width, double height) Set the bounds of this path.booleanintersects(Rectangle2D aBounds) Returns true if path crosses the provided bounds.voidlineTo(float x, float y) Draws a line from the last point in the path to point provided.voidmoveTo(float x, float y) Appends a "move" operation to the end of the path.protected voidpaint(PPaintContext paintContext) Paints the path in the provided paintContext.voidquadTo(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.voidreset()Empties the path.voidReplaces this PPath's path with the one provided.voidsetPathToEllipse(float x, float y, float width, float height) Resets the path to an ellipse positioned at the coordinate provided with the dimensions provided.voidsetPathToPolyline(float[] xp, float[] yp) Sets the path to a sequence of segments described by the point components provided.voidsetPathToPolyline(Point2D[] points) Sets the path to a sequence of segments described by the points.voidsetPathToRectangle(float x, float y, float width, float height) Resets the path to a rectangle with the dimensions and position provided.voidSets the stroke to use when drawing the path.voidsetStrokePaint(Paint newStrokePaint) Sets the stroke paint of the path.voidStores the original size of the path before resizing started.voidRecomputes 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
-
Field Details
-
PROPERTY_STROKE_PAINT
The property name that identifies a change of this node's stroke paint (seegetStrokePaint). Both old and new value will be set correctly to Paint objects in any property change event.- See Also:
-
PROPERTY_CODE_STROKE_PAINT
public static final int PROPERTY_CODE_STROKE_PAINTThe property code that identifies a change of this node's stroke paint (seegetStrokePaint). Both old and new value will be set correctly to Paint objects in any property change event.- See Also:
-
PROPERTY_STROKE
The property name that identifies a change of this node's stroke (seegetStroke). Both old and new value will be set correctly to Stroke objects in any property change event.- See Also:
-
PROPERTY_CODE_STROKE
public static final int PROPERTY_CODE_STROKEThe property code that identifies a change of this node's stroke (seegetStroke). Both old and new value will be set correctly to Stroke objects in any property change event.- See Also:
-
PROPERTY_PATH
The property name that identifies a change of this node's path (seegetPathReference). 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:
-
PROPERTY_CODE_PATH
public static final int PROPERTY_CODE_PATHThe property code that identifies a change of this node's path (seegetPathReference). 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:
-
-
Constructor Details
-
PPath
public PPath()Creates an empty PPath with the default paint and stroke. -
PPath
Creates an PPath in the given shape with the default paint and stroke.- Parameters:
aShape- the desired shape
-
PPath
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 pathaStroke- desired stroke
-
-
Method Details
-
createRectangle
Creates a PPath object in the shape of a rectangle.- Parameters:
x- left of the rectangley- top of the rectanglewidth- width of the rectangleheight- 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 rectangley- top of the rectanglewidth- width of the rectangleheight- height of the rectanglearcWidth- the arc width at the corners of the rectanglearcHeight- the arc height at the corners of the rectangle- Returns:
- created rounded rectangle
-
createEllipse
Creates a PPath object in the shape of an ellipse.- Parameters:
x- left of the ellipsey- top of the ellipsewidth- width of the ellipseheight- height of the ellipse- Returns:
- created ellipse
-
createLine
Creates a PPath in the shape of a line.- Parameters:
x1- x component of the first pointy1- y component of the first pointx2- x component of the second pointy2- y component of the second point- Returns:
- created line
-
createPolyline
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
Creates a PPath for the poly-line for the given points.- Parameters:
xp- array of x components of the points of the poly-linesyp- array of y components of the points of the poly-lines- Returns:
- created poly-line for the given points
-
getStrokePaint
Returns the stroke paint of the PPath.- Returns:
- stroke paint of the PPath
-
setStrokePaint
Sets the stroke paint of the path.- Parameters:
newStrokePaint- the paint to use as this path's stroke paint
-
getStroke
Returns the stroke to use when drawing the path.- Returns:
- current stroke of path
-
setStroke
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:
startResizeBoundsin classPNode
-
endResizeBounds
public void endResizeBounds()Clears the size of the path before resizing.- Overrides:
endResizeBoundsin classPNode
-
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:
internalUpdateBoundsin classPNode- Parameters:
x- new left position of boundsy- new top position of boundswidth- the new width of the boundsheight- the new height of the bounds
-
intersects
Returns true if path crosses the provided bounds. Takes visibility of path into account.- Overrides:
intersectsin classPNode- Parameters:
aBounds- bounds being tested for intersection- Returns:
- true if path visibly crosses bounds
-
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
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. -
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 toy- 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 pointy- 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 pointy1- y component of quadratic parametric control pointx2- x component of point through which quad curve will passy2- 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 pointy1- y component of first Bézier control pointx2- x component of second Bézier control pointy2- y component of second Bézier control pointx3- x component of point through which curve must passy3- y component of point through which curve must pass
-
append
Appends the provided shape to the end of this path, it may conditionally connect them together if they are disjoint.- Parameters:
aShape- shape to appendconnect- whether to perform a lineTo operation to the beginning of the shape before appending
-
setPathTo
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 rectangley- top of te rectanglewidth- width of the rectangleheight- 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 ellipsey- top of the ellipsewidth- width of the ellipseheight- height of the ellipse
-
setPathToPolyline
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 pathyp- 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.
-