|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.umd.cs.piccolo.PNode
edu.umd.cs.piccolo.nodes.PPath
public class PPath
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.
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 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 java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PROPERTY_STROKE_PAINT
getStrokePaint
). Both old and new value will
be set correctly to Paint objects in any property change event.
public static final int PROPERTY_CODE_STROKE_PAINT
getStrokePaint
). Both old and new value will
be set correctly to Paint objects in any property change event.
public static final String PROPERTY_STROKE
getStroke
). Both old and new value will be set
correctly to Stroke objects in any property change event.
public static final int PROPERTY_CODE_STROKE
getStroke
). Both old and new value will be set
correctly to Stroke objects in any property change event.
public static final String PROPERTY_PATH
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.
public static final int PROPERTY_CODE_PATH
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.
Constructor Detail |
---|
public PPath()
public PPath(Shape aShape)
aShape
- the desired shapepublic PPath(Shape aShape, Stroke aStroke)
aShape
- desired shape or null if you desire an empty pathaStroke
- desired strokeMethod Detail |
---|
public static PPath createRectangle(float x, float y, float width, float height)
x
- left of the rectangley
- top of the rectanglewidth
- width of the rectangleheight
- height of the rectangle
public static PPath createRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight)
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
public static PPath createEllipse(float x, float y, float width, float height)
x
- left of the ellipsey
- top of the ellipsewidth
- width of the ellipseheight
- height of the ellipse
public static PPath createLine(float x1, float y1, float x2, float y2)
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
public static PPath createPolyline(Point2D[] points)
points
- array of points for the point lines
public static PPath createPolyline(float[] xp, float[] yp)
xp
- array of x components of the points of the poly-linesyp
- array of y components of the points of the poly-lines
public Paint getStrokePaint()
public void setStrokePaint(Paint newStrokePaint)
newStrokePaint
- the paint to use as this path's stroke paintpublic Stroke getStroke()
public void setStroke(Stroke aStroke)
aStroke
- stroke to use when drawing the pathpublic void startResizeBounds()
startResizeBounds
in class PNode
public void endResizeBounds()
endResizeBounds
in class PNode
protected void internalUpdateBounds(double x, double y, double width, double height)
internalUpdateBounds
in class PNode
x
- new left position of boundsy
- new top position of boundswidth
- the new width of the boundsheight
- the new height of the boundspublic boolean intersects(Rectangle2D aBounds)
intersects
in class PNode
aBounds
- bounds being tested for intersection
public Rectangle2D getPathBoundsWithStroke()
public void updateBoundsFromPath()
protected void paint(PPaintContext paintContext)
paint
in class PNode
paintContext
- context in which painting is occurringpublic GeneralPath getPathReference()
public void moveTo(float x, float y)
x
- the x component of the point to move toy
- the y component of the point to move topublic void lineTo(float x, float y)
x
- the x component of the pointy
- the y component of the pointpublic void quadTo(float x1, float y1, float x2, float y2)
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 passpublic void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
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 passpublic void append(Shape aShape, boolean connect)
aShape
- shape to appendconnect
- whether to perform a lineTo operation to the beginning of
the shape before appendingpublic void setPathTo(Shape aShape)
aShape
- shape to replace the current one withpublic void setPathToRectangle(float x, float y, float width, float height)
x
- left of the rectangley
- top of te rectanglewidth
- width of the rectangleheight
- height of the rectanglepublic void setPathToEllipse(float x, float y, float width, float height)
x
- left of the ellipsey
- top of the ellipsewidth
- width of the ellipseheight
- height of the ellipsepublic void setPathToPolyline(Point2D[] points)
points
- points to that lie along the generated pathpublic void setPathToPolyline(float[] xp, float[] yp)
xp
- the x components of the points along the pathyp
- the y components of the points along the pathpublic void closePath()
public void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |