diva.canvas.connector
Class Arrowhead

java.lang.Object
  extended by diva.canvas.connector.Arrowhead
All Implemented Interfaces:
ConnectorEnd

public class Arrowhead
extends java.lang.Object
implements ConnectorEnd

An arrowhead that is drawn on the end of a connector. This is a low-level utility class, not a self-contained Figure.

Version:
$Id: Arrowhead.java 47495 2007-12-06 21:57:21Z cxh $
Author:
John Reekie

Field Summary
private  boolean _filled
          Flag that says whether the arrowhead is filled or not.
private  boolean _flipped
          A flag that says to slip the direction in which the arrowhead is drawn.
private  double _length
          The arrowhead length, and its x and y components
private  double _normal
          The normal to the line
private  double _originX
          x and y-origins
private  double _originY
           
private  Polygon2D _polygon
          The shape to draw
private  boolean _polygonValid
          A flag that says whether the shape is valid
private  java.awt.Stroke _stroke
          The stroke.
 
Constructor Summary
Arrowhead()
          Create a new arrowhead at (0,0).
Arrowhead(double x, double y, double normal)
          Create a new arrowhead at the given point and with the given normal.
 
Method Summary
 java.awt.geom.Rectangle2D getBounds()
          Get the bounding box of the shape used to draw this connector end.
 void getConnection(java.awt.geom.Point2D p)
          Get the connection point into the given point
 boolean getFlipped()
          Get the flag saying to flip the arrowhead.
 double getLength()
          Get the length.
 void getOrigin(java.awt.geom.Point2D p)
          Get the origin into the given point.
 boolean isFilled()
          Test if the blob is filled or not.
 void paint(java.awt.Graphics2D g)
          Paint the arrow-head.
 void reshape()
          Recalculate the shape of the decoration.
 void setFilled(boolean flag)
          Set the flag that determines whether to fill the arrowhead.
 void setFlipped(boolean flag)
          Set the flag that says the arrowhead is "flipped."
 void setLength(double l)
          Set the length of the arrowhead.
 void setNormal(double angle)
          Set the normal of the decoration.
 void setOrigin(double x, double y)
          Set the origin of the decoration.
 void translate(double x, double y)
          Translate the origin by the given amount.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_filled

private boolean _filled
Flag that says whether the arrowhead is filled or not.


_length

private double _length
The arrowhead length, and its x and y components


_originX

private double _originX
x and y-origins


_originY

private double _originY

_normal

private double _normal
The normal to the line


_polygon

private Polygon2D _polygon
The shape to draw


_polygonValid

private boolean _polygonValid
A flag that says whether the shape is valid


_flipped

private boolean _flipped
A flag that says to slip the direction in which the arrowhead is drawn.


_stroke

private java.awt.Stroke _stroke
The stroke. This is needed to get the bounding box. As the default, we use a stroke width of 3.0 pixels, in order that redraw is clean even in the presence of anti-aliasing. Connectors that have non-unit stroke widths should set this variable to a stroke with appropriate width.

Constructor Detail

Arrowhead

public Arrowhead()
Create a new arrowhead at (0,0).


Arrowhead

public Arrowhead(double x,
                 double y,
                 double normal)
Create a new arrowhead at the given point and with the given normal.

Method Detail

getBounds

public java.awt.geom.Rectangle2D getBounds()
Get the bounding box of the shape used to draw this connector end.

Specified by:
getBounds in interface ConnectorEnd

getConnection

public void getConnection(java.awt.geom.Point2D p)
Get the connection point into the given point

Specified by:
getConnection in interface ConnectorEnd

getFlipped

public boolean getFlipped()
Get the flag saying to flip the arrowhead.


getOrigin

public void getOrigin(java.awt.geom.Point2D p)
Get the origin into the given point.

Specified by:
getOrigin in interface ConnectorEnd

getLength

public double getLength()
Get the length.


isFilled

public boolean isFilled()
Test if the blob is filled or not.


paint

public void paint(java.awt.Graphics2D g)
Paint the arrow-head. This method assumes that the graphics context is already set up with the correct paint and stroke.

Specified by:
paint in interface ConnectorEnd

reshape

public void reshape()
Recalculate the shape of the decoration.


setNormal

public void setNormal(double angle)
Set the normal of the decoration. The argument is the angle in radians away from the origin. The arrowhead is drawn so that the body of the arrowhead is in the same direction as the normal -- that is, the arrowhead appears to be pointed in the opposite direction to its "normal."

Specified by:
setNormal in interface ConnectorEnd

setFilled

public void setFilled(boolean flag)
Set the flag that determines whether to fill the arrowhead.


setFlipped

public void setFlipped(boolean flag)
Set the flag that says the arrowhead is "flipped." This means that the arrowhead is drawn so that the apparent direction of the arrowhead is the same as its normal.


setOrigin

public void setOrigin(double x,
                      double y)
Set the origin of the decoration.

Specified by:
setOrigin in interface ConnectorEnd

setLength

public void setLength(double l)
Set the length of the arrowhead.


translate

public void translate(double x,
                      double y)
Translate the origin by the given amount.

Specified by:
translate in interface ConnectorEnd