edu.umd.cs.piccolox.swt
Class PSWTPath

java.lang.Object
  extended by edu.umd.cs.piccolo.PNode
      extended by edu.umd.cs.piccolox.swt.PSWTPath
All Implemented Interfaces:
java.awt.print.Printable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
PSWTHandle

public class PSWTPath
extends PNode

PSWTPath is a wrapper around a java.awt.geom.GeneralPath, with workarounds for drawing shapes in SWT where necessary.

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 java.lang.String PROPERTY_SHAPE
          The property name that identifies a change of this node's path.
 
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
PSWTPath()
          Creates an empty PSWTPath.
PSWTPath(java.awt.Shape aShape)
          Creates an SWTPath in the given shape with the default paint and stroke.
 
Method Summary
 java.awt.Shape cloneShape(java.awt.Shape aShape)
          Clone's the shape provided.
static PSWTPath createEllipse(float x, float y, float width, float height)
          Creates a path representing an ellipse that covers the rectangle provided.
static PSWTPath createPolyline(float[] xp, float[] yp)
          Creates a PPath for the poly-line for the given points.
static PSWTPath createPolyline(java.awt.geom.Point2D[] points)
          Creates a PPath for the poly-line for the given points.
static PSWTPath createRectangle(float x, float y, float width, float height)
          Creates a path representing the rectangle provided.
static PSWTPath createRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight)
          Creates a path representing the rounded rectangle provided.
 java.awt.geom.Point2D getCenter()
          Return the center of this SWT path node, based on its bounds.
 java.awt.Paint getStrokePaint()
          Returns the paint to use when drawing the stroke of the shape.
protected  void internalUpdateBounds(double x, double y, double width, double height)
          Set the bounds of this path.
 boolean intersects(java.awt.geom.Rectangle2D aBounds)
          Returns true if path crosses the provided bounds.
protected  void paint(PPaintContext paintContext)
          Paints the path on the context 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(java.awt.geom.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 setPathToRoundRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight)
          Resets the path to a rectangle with the dimensions and position provided.
 void setShape(java.awt.Shape newShape)
          Changes the underlying shape of this PSWTPath.
 void setStrokeColor(java.awt.Paint strokeColor)
          Sets the paint to use when drawing the stroke of the shape.
 void updateBoundsFromPath()
          Recalculates the path's bounds by examining it's associated shape.
 void updateShapePoints(java.awt.Shape aShape)
          Updates the internal points used to draw the shape.
 
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, endResizeBounds, 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, startResizeBounds, 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_SHAPE

public static final java.lang.String PROPERTY_SHAPE
The property name that identifies a change of this node's path. 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

PSWTPath

public PSWTPath()
Creates an empty PSWTPath.


PSWTPath

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

Parameters:
aShape - the desired shape
Method Detail

createRectangle

public static PSWTPath createRectangle(float x,
                                       float y,
                                       float width,
                                       float height)
Creates a path representing the rectangle provided.

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

createRoundRectangle

public static PSWTPath createRoundRectangle(float x,
                                            float y,
                                            float width,
                                            float height,
                                            float arcWidth,
                                            float arcHeight)
Creates a path representing the rounded rectangle provided.

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

createEllipse

public static PSWTPath createEllipse(float x,
                                     float y,
                                     float width,
                                     float height)
Creates a path representing an ellipse that covers the rectangle provided.

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

createPolyline

public static PSWTPath 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 PSWTPath 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 paint to use when drawing the stroke of the shape.

Returns:
path's stroke paint

setStrokeColor

public void setStrokeColor(java.awt.Paint strokeColor)
Sets the paint to use when drawing the stroke of the shape.

Parameters:
strokeColor - new stroke color

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(java.awt.geom.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

updateBoundsFromPath

public void updateBoundsFromPath()
Recalculates the path's bounds by examining it's associated shape.


paint

protected void paint(PPaintContext paintContext)
Paints the path on the context provided.

Overrides:
paint in class PNode
Parameters:
paintContext - the context onto which the path will be painted

setShape

public void setShape(java.awt.Shape newShape)
Changes the underlying shape of this PSWTPath.

Parameters:
newShape - new associated shape of this PSWTPath

updateShapePoints

public void updateShapePoints(java.awt.Shape aShape)
Updates the internal points used to draw the shape.

Parameters:
aShape - shape to read points from

cloneShape

public java.awt.Shape cloneShape(java.awt.Shape aShape)
Clone's the shape provided.

Parameters:
aShape - shape to be cloned
Returns:
a cloned version of the provided shape

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

setPathToRoundRectangle

public void setPathToRoundRectangle(float x,
                                    float y,
                                    float width,
                                    float height,
                                    float arcWidth,
                                    float arcHeight)
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
arcWidth - width of arc in the corners of the rectangle
arcHeight - height of arc in the corners 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(java.awt.geom.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

getCenter

public java.awt.geom.Point2D getCenter()
Return the center of this SWT path node, based on its bounds.

Returns:
the center of this SWT path node, based on its bounds


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.