edu.umd.cs.jazz.component
Class ZPolyline

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZSceneGraphObject
        |
        +--edu.umd.cs.jazz.ZVisualComponent
              |
              +--edu.umd.cs.jazz.component.ZBasicVisualComponent
                    |
                    +--edu.umd.cs.jazz.component.ZShape
                          |
                          +--edu.umd.cs.jazz.component.ZCoordList
                                |
                                +--edu.umd.cs.jazz.component.ZPolyline
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, ZAppearance, ZFillColor, ZFillPaint, ZPenColor, ZPenPaint, ZSerializable, ZStroke

public class ZPolyline
extends ZCoordList

ZPolyline is a visual component that represents a line with one or more segments.

Warning: Serialized and ZSerialized objects of this class will not be compatible with future Jazz releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Jazz. A future release of Jazz will provide support for long term persistence.

Author:
Benjamin B. Bederson
, Jesse Grosjean
See Also:
Serialized Form

Field Summary
static int ARROW_BOTH
           
static int ARROW_CLOSED
           
static int ARROW_FIRST
           
static int ARROW_LAST
           
static int ARROW_NONE
           
static int ARROW_OPEN
           
 
Fields inherited from class edu.umd.cs.jazz.component.ZCoordList
coordListShape
 
Fields inherited from class edu.umd.cs.jazz.component.ZBasicVisualComponent
absPenWidth, DEFAULT_ABS_PEN_WIDTH, DEFAULT_FILL_PAINT, DEFAULT_PEN_PAINT, DEFAULT_PEN_WIDTH, DEFAULT_STROKE, fillPaint, penPaint, penWidth, stroke
 
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject
bounds, inTransaction, invalidBounds, invalidVolatileBounds, listenerList, volatileBounds, volatileBounds_DEFAULT
 
Constructor Summary
ZPolyline()
          Constructs a new ZPolyline with no points.
ZPolyline(double[] xp, double[] yp)
          Constructs a new ZPolyline from an array of points.
ZPolyline(double x, double y)
          Constructs a new ZPolyline with a single point.
ZPolyline(double x1, double y1, double x2, double y2)
          Constructs a new ZPolyline with a two points
ZPolyline(java.awt.geom.Point2D aPoint)
          Constructs a new ZPolyline with no points.
ZPolyline(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)
          Constructs a new ZPolyline with two points.
 
Method Summary
 void add(double x, double y, int index)
          Add a point to the specified part of this coordinate list.
protected  java.awt.geom.GeneralPath computeArrowHead(int ah, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Calculate the points used to represent the arrowhead.
protected  void computeBounds()
          Notifies this object that it has changed and that it should update its notion of its bounding box.
protected  java.lang.Object duplicateObject()
          Returns a clone of this object.
 int getArrowHead()
          Get the arrowhead type used by this ZPolyline.
 void lineTo(double x, double y)
          Return the append the given vertex onto the end of the list of points that define this polygon.
 boolean pick(java.awt.geom.Rectangle2D rect, ZSceneGraphPath path)
          Returns true if the specified rectangle is on the polygon.
protected  void removeArrowHead(int ah)
          Remove one or both arrowheads from the polyline.
 void render(ZRenderContext renderContext)
          Renders this object.
 void setArrowHead(int ah)
          Set arrowheads for this polyline.
 void setArrowHeadType(int aht)
          Set arrowHeads for this polyline to a certain style: open, closed, etc
 void setCoords(double[] xp, double[] yp)
          Set the coords of this polygon.
 void setCoords(java.awt.geom.Point2D[] points)
          Set the coords of this polygon.
 void setCoords(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)
          Set the coords of this polygon.
 void setPenWidth(double width)
          The arrow head shape depends on the ZPolyline's pen width, so when the pen width changes the arrow heads must be updated.
protected  boolean updateArrowHeads()
          Updates the internal representation of the arrowheads to reflect the current state of the polyline.
 
Methods inherited from class edu.umd.cs.jazz.component.ZCoordList
add, add, add, getCoordListShape, getNumberPoints, getShape, getX, getXCoords, getY, getYCoords, isClosed, moveTo, reset, setClosed, setState, writeObject
 
Methods inherited from class edu.umd.cs.jazz.component.ZShape
getFrame, getHeight, getStrokeTransformForAbsPenWidth, getWidth, getX, getY, pickStroke
 
Methods inherited from class edu.umd.cs.jazz.component.ZBasicVisualComponent
getAbsPenWidth, getFillColor, getFillPaint, getPenColor, getPenPaint, getPenWidth, getPenWidthForCurrentContext, getStroke, setAbsPenWidth, setFillColor, setFillPaint, setPenColor, setPenPaint, setStroke
 
Methods inherited from class edu.umd.cs.jazz.ZVisualComponent
addParent, getNumParents, getParents, getParentsReference, getRoot, paint, pickBounds, removeParent, repaint, repaint, trimToSize, updateBounds, updateObjectReferences, updateVolatility, writeObjectRecurse
 
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject
addClientProperty, addMouseListener, addMouseMotionListener, clone, computeVolatileBounds, dump, endTransaction, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getClientProperty, getHandles, getListenerList, getVolatileBounds, hasLisenerOfType, hasListenerOfType, hasMouseListener, markInTransaction, markNotInTransaction, processMouseEvent, putClientProperty, removeEventListener, removeMouseListener, removeMouseMotionListener, reshape, setBounds, setVolatileBounds, startTransaction
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARROW_NONE

public static final int ARROW_NONE
See Also:
Constant Field Values

ARROW_FIRST

public static final int ARROW_FIRST
See Also:
Constant Field Values

ARROW_LAST

public static final int ARROW_LAST
See Also:
Constant Field Values

ARROW_BOTH

public static final int ARROW_BOTH
See Also:
Constant Field Values

ARROW_CLOSED

public static final int ARROW_CLOSED
See Also:
Constant Field Values

ARROW_OPEN

public static final int ARROW_OPEN
See Also:
Constant Field Values
Constructor Detail

ZPolyline

public ZPolyline()
Constructs a new ZPolyline with no points.


ZPolyline

public ZPolyline(java.awt.geom.Point2D aPoint)
Constructs a new ZPolyline with no points.


ZPolyline

public ZPolyline(java.awt.geom.Point2D pt1,
                 java.awt.geom.Point2D pt2)
Constructs a new ZPolyline with two points.


ZPolyline

public ZPolyline(double x,
                 double y)
Constructs a new ZPolyline with a single point.


ZPolyline

public ZPolyline(double x1,
                 double y1,
                 double x2,
                 double y2)
Constructs a new ZPolyline with a two points


ZPolyline

public ZPolyline(double[] xp,
                 double[] yp)
Constructs a new ZPolyline from an array of points. The xp, yp parameters are stored within this polyline, so the caller must not modify them after passing them in.

Method Detail

duplicateObject

protected java.lang.Object duplicateObject()
Returns a clone of this object.

Overrides:
duplicateObject in class ZCoordList
See Also:
ZSceneGraphObject.duplicateObject()

removeArrowHead

protected void removeArrowHead(int ah)
Remove one or both arrowheads from the polyline.


getArrowHead

public int getArrowHead()
Get the arrowhead type used by this ZPolyline. ArrowHead is one of ARROW_NONE, ARROW_FIRST, ARROW_LAST, ARROW_BOTH.


setArrowHead

public void setArrowHead(int ah)
Set arrowheads for this polyline.


setArrowHeadType

public void setArrowHeadType(int aht)
Set arrowHeads for this polyline to a certain style: open, closed, etc


add

public void add(double x,
                double y,
                int index)
Add a point to the specified part of this coordinate list. Specifying an index of 0 puts the point at the beginning of the list. Specifying an index greater than the number of points in the coordinate list puts the point at the end of the list of points.

Overrides:
add in class ZCoordList
Parameters:
index - The index of the new point.

setCoords

public void setCoords(java.awt.geom.Point2D pt1,
                      java.awt.geom.Point2D pt2)
Set the coords of this polygon.

Overrides:
setCoords in class ZCoordList

setCoords

public void setCoords(double[] xp,
                      double[] yp)
Set the coords of this polygon.

Overrides:
setCoords in class ZCoordList

setCoords

public void setCoords(java.awt.geom.Point2D[] points)
Set the coords of this polygon.

Overrides:
setCoords in class ZCoordList

lineTo

public void lineTo(double x,
                   double y)
Return the append the given vertex onto the end of the list of points that define this polygon.

Overrides:
lineTo in class ZCoordList

setPenWidth

public void setPenWidth(double width)
The arrow head shape depends on the ZPolyline's pen width, so when the pen width changes the arrow heads must be updated.

Specified by:
setPenWidth in interface ZStroke
Overrides:
setPenWidth in class ZBasicVisualComponent
Parameters:
width - the pen width.
See Also:
ZBasicVisualComponent.setAbsPenWidth(double)

render

public void render(ZRenderContext renderContext)
Renders this object.

The transform, clip, and composite will be set appropriately when this object is rendered. It is up to this object to restore the transform, clip, and composite of the Graphics2D if this node changes any of them. However, the color, font, and stroke are unspecified by Jazz. This object should set those things if they are used, but they do not need to be restored.

Overrides:
render in class ZShape

computeBounds

protected void computeBounds()
Notifies this object that it has changed and that it should update its notion of its bounding box. Note that this should not be called directly. Instead, it is called by updateBounds when needed.

Overrides:
computeBounds in class ZShape

pick

public boolean pick(java.awt.geom.Rectangle2D rect,
                    ZSceneGraphPath path)
Description copied from class: ZShape
Returns true if the specified rectangle is on the polygon.

Overrides:
pick in class ZShape
Parameters:
rect - Pick rectangle of object coordinates.
path - The path through the scenegraph to the picked node. Modified by this call.
Returns:
True if rectangle overlaps object.
See Also:
ZDrawingSurface.pick(int, int)

updateArrowHeads

protected boolean updateArrowHeads()
Updates the internal representation of the arrowheads to reflect the current state of the polyline. This should be called whenever the polyline has changed.

Returns:
True if arrowheads were actually computed resulting in possible bounds changes

computeArrowHead

protected java.awt.geom.GeneralPath computeArrowHead(int ah,
                                                     java.awt.geom.Point2D p1,
                                                     java.awt.geom.Point2D p2)
Calculate the points used to represent the arrowhead. We use a simple algorithm that just starts at p2, backs up to p1 a bit (as represented with p3), and goes to either side by rotating (p3-p2) +/- 90 degrees.



Copyright � 2003 by University of Maryland, College Park, MD 20742, USA All rights reserved.