edu.umd.cs.jazz.component
Class ZPolyline

java.lang.Object
  |
  +--edu.umd.cs.jazz.scenegraph.ZVisualComponent
        |
        +--edu.umd.cs.jazz.component.ZCoordList
              |
              +--edu.umd.cs.jazz.component.ZPolyline

public class ZPolyline
extends ZCoordList

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


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
           
protected  int arrowHead
           
protected  int arrowHeadType
           
protected  int cap
           
static java.awt.Color DEFAULT_PEN_COLOR
           
static float DEFAULT_PEN_WIDTH
           
protected  java.awt.geom.GeneralPath firstArrowHead
           
protected  java.awt.geom.Point2D firstArrowHeadPoint
           
protected  int join
           
protected  java.awt.geom.GeneralPath lastArrowHead
           
protected  java.awt.geom.Point2D lastArrowHeadPoint
           
protected  java.awt.Color penColor
           
protected  float penWidth
           
protected  java.awt.BasicStroke stroke
           
 
Fields inherited from class edu.umd.cs.jazz.component.ZCoordList
ARRAY_INC, closed, DEFAULT_CLOSED, empty, np, path, xp, yp
 
Fields inherited from class edu.umd.cs.jazz.scenegraph.ZVisualComponent
cacheVolatile, findable, findable_DEFAULT, isVolatile, localBounds, localBoundsDirty, parent, pickable, pickable_DEFAULT, selected
 
Constructor Summary
ZPolyline()
          Constructs a new ZPolyline with no points.
ZPolyline(float[] xp, float[] yp)
          Constructs a new ZPolyline.
ZPolyline(float x, float y)
          Constructs a new ZPolyline with a single point.
ZPolyline(float x1, float y1, float x2, float y2)
          Constructs a new ZPolyline with a two points
ZPolyline(java.awt.geom.Point2D pt)
          Constructs a new ZPolyline with a single point.
ZPolyline(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)
          Constructs a new ZPolyline with two points.
ZPolyline(ZPolyline poly)
          Constructs a new ZPolyline that is a duplicate of the reference polyline, i.e., a "copy constructor"
 
Method Summary
 void add(float x, float y)
          Add a point to the end of this polyline.
 void add(float x, float y, int index)
          Add a point to the specified part of this coordinate list.
 java.lang.Object clone()
          Duplicates the current ZPolyline by using the copy constructor.
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 computeLocalBounds()
          Notifies this object that it has changed and that it should update its notion of its bounding box.
 int getArrowHead()
           
 java.awt.Color getPenColor()
          Get the pen color of this polyline.
 float getPenWidth()
          Get the width of the pen used to draw the line around the edge of this polyline.
 void paint(ZRenderContext renderContext)
          Paints this object.
 boolean pick(java.awt.geom.Rectangle2D rect)
          Returns true if the specified rectangle is on the polyline.
protected  void removeArrowHead(int ah)
          Remove one or both arrowheads from the polyline.
 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
protected  void setCoords(boolean updateArrowHeads, float[] xp, float[] yp)
          Set the coordinates of this polyline.
 void setCoords(float[] xp, float[] yp)
          Set the coordinates of this polyline.
 void setPenColor(java.awt.Color color)
          Set the pen color of this polyline.
 void setPenWidth(float width)
          Set the width of the pen used to draw the line around the edge of this polyline.
 void setState(java.lang.String fieldType, java.lang.String fieldName, java.lang.Object fieldValue)
          Set some state of this object as it gets read back in.
protected  void updateArrowHeads()
          Updates the internal representation of the arrowheads to reflect the current state of the polyline.
 void writeObject(ZObjectOutputStream out)
          Write out all of this object's state.
 
Methods inherited from class edu.umd.cs.jazz.component.ZCoordList
add, add, ensureSpace, getNumberPoints, getPath, getXCoords, getYCoords, isClosed, setClosed, trimToSize, updatePath
 
Methods inherited from class edu.umd.cs.jazz.scenegraph.ZVisualComponent
damage, damage, findNode, findVisualComponent, getLocalBounds, getParent, isFindable, isPickable, isSelected, isVolatile, pickBounds, select, select, setFindable, setParent, setPickable, setSelected, setVisualComponent, setVolatile, toString, transformChanged, unselect, updateBounds, updateChildBounds, updateLocalBounds, updateVolatility, writeObjectRecurse
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ARROW_NONE

public static final int ARROW_NONE

ARROW_FIRST

public static final int ARROW_FIRST

ARROW_LAST

public static final int ARROW_LAST

ARROW_BOTH

public static final int ARROW_BOTH

ARROW_CLOSED

public static final int ARROW_CLOSED

ARROW_OPEN

public static final int ARROW_OPEN

DEFAULT_PEN_COLOR

public static final java.awt.Color DEFAULT_PEN_COLOR

DEFAULT_PEN_WIDTH

public static final float DEFAULT_PEN_WIDTH

penColor

protected java.awt.Color penColor

penWidth

protected float penWidth

cap

protected int cap

join

protected int join

stroke

protected java.awt.BasicStroke stroke

arrowHead

protected int arrowHead

firstArrowHead

protected java.awt.geom.GeneralPath firstArrowHead

lastArrowHead

protected java.awt.geom.GeneralPath lastArrowHead

firstArrowHeadPoint

protected java.awt.geom.Point2D firstArrowHeadPoint

lastArrowHeadPoint

protected java.awt.geom.Point2D lastArrowHeadPoint

arrowHeadType

protected int arrowHeadType
Constructor Detail

ZPolyline

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

ZPolyline

public ZPolyline(java.awt.geom.Point2D pt)
Constructs a new ZPolyline with a single point.
Parameters:
pt - Initial point

ZPolyline

public ZPolyline(java.awt.geom.Point2D pt1,
                 java.awt.geom.Point2D pt2)
Constructs a new ZPolyline with two points.
Parameters:
pt1 - First point
pt2 - Second point

ZPolyline

public ZPolyline(float x,
                 float y)
Constructs a new ZPolyline with a single point.
Parameters:
x,y - Initial point

ZPolyline

public ZPolyline(float x1,
                 float y1,
                 float x2,
                 float y2)
Constructs a new ZPolyline with a two points
Parameters:
x,y - First point
x,y - Second point

ZPolyline

public ZPolyline(float[] xp,
                 float[] yp)
Constructs a new ZPolyline. The xp, yp parameters are stored within this polyline, so the caller must not modify them after passing them in.
Parameters:
xp - Array of X points
yp - Array of Y points

ZPolyline

public ZPolyline(ZPolyline poly)
Constructs a new ZPolyline that is a duplicate of the reference polyline, i.e., a "copy constructor"
Parameters:
poly - Reference polyline
Method Detail

clone

public java.lang.Object clone()
Duplicates the current ZPolyline by using the copy constructor. See the copy constructor comments for complete information about what is duplicated.
Overrides:
clone in class ZCoordList
See Also:
ZPolyline(ZPolyline)

getPenWidth

public float getPenWidth()
Get the width of the pen used to draw the line around the edge of this polyline. The pen is drawn centered around the polyline vertices, so if the pen width is thick, the bounds of the polyline will grow.
Returns:
the pen width.

setPenWidth

public void setPenWidth(float width)
Set the width of the pen used to draw the line around the edge of this polyline. The pen is drawn centered around the polyline vertices, so if the pen width is thick, the bounds of the polyline will grow.
Parameters:
width - the pen width.

getPenColor

public java.awt.Color getPenColor()
Get the pen color of this polyline.
Returns:
the pen color.

setPenColor

public void setPenColor(java.awt.Color color)
Set the pen color of this polyline.
Parameters:
color - the pen color, or null if none.

removeArrowHead

protected void removeArrowHead(int ah)
Remove one or both arrowheads from the polyline.
Parameters:
ah - ARROW_FIRST, ARROW_LAST or ARROW_BOTH

getArrowHead

public int getArrowHead()

setArrowHead

public void setArrowHead(int ah)
Set arrowheads for this polyline.
Parameters:
ah - ArrowHead Specification, such as ARROW_FIRST, ARROW_LAST, ARROW_BOTH, ARROW_NONE.

setArrowHeadType

public void setArrowHeadType(int aht)
Set arrowHeads for this polyline to a certain style: open, closed, etc
Parameters:
ah - ArrowHead type, such as ARROW_OPEN OR ARROW_CLOSED.

add

public void add(float x,
                float y)
Add a point to the end of this polyline.
Parameters:
x,y - The new point
Overrides:
add in class ZCoordList

add

public void add(float x,
                float 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.
Parameters:
x,y - The new point
index - The index of the new point.
Overrides:
add in class ZCoordList

setCoords

public void setCoords(float[] xp,
                      float[] yp)
Set the coordinates of this polyline. The specified points completely replace the previous points in this polyline.
Parameters:
xp - An array of the X coordinates of the new points.
yp - An array of the Y coordinates of the new points.
Overrides:
setCoords in class ZCoordList

setCoords

protected void setCoords(boolean updateArrowHeads,
                         float[] xp,
                         float[] yp)
Set the coordinates of this polyline. The specified points completely replace the previous points in this polyline.
Parameters:
xp - An array of the X coordinates of the new points.
yp - An array of the Y coordinates of the new points.
updateArrowHeads - Updates the internal representation of the arrowheads.

paint

public void paint(ZRenderContext renderContext)
Paints this object.
Parameters:
g2 - The graphics context to paint into.
Overrides:
paint in class ZVisualComponent

computeLocalBounds

protected void computeLocalBounds()
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:
computeLocalBounds in class ZCoordList
See Also:
ZNode.getGlobalBounds()

pick

public boolean pick(java.awt.geom.Rectangle2D rect)
Returns true if the specified rectangle is on the polyline.
Parameters:
rect - Pick rectangle of object coordinates.
Returns:
True if rectangle overlaps object.
Overrides:
pick in class ZVisualComponent

updateArrowHeads

protected void 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.

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. BBB 12/98: There is a bug with Sun's JDK1.2 where if we create a Shape of zero area (due to the two points being equal, and then add them to another shape (as we do when we compute the local bounds), then the JDK will hang at run time. And so, we check to make sure the points aren't equal.

writeObject

public void writeObject(ZObjectOutputStream out)
                 throws java.io.IOException
Write out all of this object's state.
Parameters:
out - The stream that this object writes into
Overrides:
writeObject in class ZCoordList

setState

public void setState(java.lang.String fieldType,
                     java.lang.String fieldName,
                     java.lang.Object fieldValue)
Set some state of this object as it gets read back in. After the object is created with its default no-arg constructor, this method will be called on the object once for each bit of state that was written out through calls to ZObjectOutputStream.writeState() within the writeObject method.
Parameters:
fieldType - The fully qualified type of the field
fieldName - The name of the field
fieldValue - The value of the field
Overrides:
setState in class ZCoordList