diva.canvas.connector
Class ArcConnector

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by diva.canvas.connector.AbstractConnector
          extended by diva.canvas.connector.ArcConnector
All Implemented Interfaces:
CanvasComponent, Connector, Figure, VisibleComponent, UserObjectContainer

public class ArcConnector
extends AbstractConnector

A Connector that draws itself in an arc. The connector draws itself approximately through the center of the figures that own the sites to which it is connected. The curvature of the arc can be specified in one of two ways, depending on which variable of the arc's shape remain constant as the distance between the two figures at the ends of the arc is varied:

  1. Constant incident angle: The angle at which the arc connects to the figure remains constant. This is the default behaviour, and the default angle is 45 degrees.
  2. Constant displacement at the maximum arc point, from the straight line drawn between the two end points of the connector. The default displacement is 20 (not for any good reason, but is has to be something...).

    Currently, only the first is supported.

    The connector uses an instance of PaintedPath to draw itself, so see that class for a more detailed description of the paint- and stroke-related methods.

    Version:
    $Id: ArcConnector.java 57046 2010-01-27 23:35:53Z cxh $
    Author:
    Edward Lee, John Reekie
    Accepted Rating:
    Red

    Field Summary
    private  java.awt.geom.Arc2D _arc
              The arc shape that defines the connector shape
    private  double _centerX
              The calculated parameters of the arc
    private  double _centerY
               
    protected static double _CLOSE_THRESHOLD
              The threshold for when a source and a destination of an arc are considered close to one another.
    private  double _exitAngle
              The exit angle of the arc.
    private  double _extentAngle
               
    private  double _gamma
              The angle between the two ends of the arc.
    private  ArcMidpointSite _midpointSite
              The midpoint site.
    private  double _previousAngle
              The previous exit angle of the arc.
    private  double _radius
               
    private  boolean _selfloop
              The flag that says whether this connector is a "self-loop"
    private  double _startAngle
               
    private static double MINSELFLOOPANGLE
               
     
    Constructor Summary
    ArcConnector(Site tail, Site head)
              Create a new arc connector between the given sites.
     
    Method Summary
     double getAngle()
              Get the angle at which the arc leaves the tail figure.
     java.awt.geom.Point2D getArcMidpoint()
              Return the midpoint of the arc.
     double getGamma()
              Get the angle that determines the orientation of a self-loop.
     Site getMidpointSite()
              Get the site that marks the midpoint of the connector.
     boolean getSelfLoop()
              Get the flag saying whether this arc is to be drawn as a self-loop
     void repositionLabel()
              Tell the connector to reposition its label if it has one.
     void route()
              Tell the connector to route itself between the current positions of the head and tail sites.
     void setAngle(double angle)
              Set the angle at which the arc leaves the tail figure, in radians.
     void setGamma(double gamma)
              Set the angle that determines the orientation of a self-loop.
     void setSelfLoop(boolean selfloop)
              Set the flag that says that this arc is drawn as a "self-loop."
     void translate(double x, double y)
              Translate the connector.
     void translateMidpoint(double dx, double dy)
              Translate the midpoint of the arc.
     
    Methods inherited from class diva.canvas.connector.AbstractConnector
    getBounds, getDashArray, getHeadEnd, getHeadSite, getLabelFigure, getLineWidth, getShape, getStroke, getStrokePaint, getTailEnd, getTailSite, headMoved, hit, intersects, paint, reroute, setDashArray, setHeadEnd, setHeadSite, setLabelFigure, setLineWidth, setShape, setStroke, setStrokePaint, setTailEnd, setTailSite, tailMoved, transform
     
    Methods inherited from class diva.canvas.AbstractFigure
    contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, isVisible, paint, repaint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface diva.canvas.Figure
    contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, setInteractor, setParent, setToolTipText
     
    Methods inherited from interface diva.canvas.VisibleComponent
    isVisible, paint, setVisible
     
    Methods inherited from interface diva.canvas.CanvasComponent
    getTransformContext, repaint, repaint
     
    Methods inherited from interface diva.util.UserObjectContainer
    getUserObject, setUserObject
     

    Field Detail

    MINSELFLOOPANGLE

    private static double MINSELFLOOPANGLE

    _arc

    private java.awt.geom.Arc2D _arc
    The arc shape that defines the connector shape


    _selfloop

    private boolean _selfloop
    The flag that says whether this connector is a "self-loop"


    _exitAngle

    private double _exitAngle
    The exit angle of the arc. This is the *difference* of the angle of the line between the center of the head and tail objects, and the angle at which the arc "exits" the figure on the tail end. This parameter is used as the primary means of controlling the shape or the arc.


    _previousAngle

    private double _previousAngle
    The previous exit angle of the arc. This is used when the arc switches between a self-loop and a non-self-loop.


    _centerX

    private double _centerX
    The calculated parameters of the arc


    _centerY

    private double _centerY

    _radius

    private double _radius

    _startAngle

    private double _startAngle

    _extentAngle

    private double _extentAngle

    _gamma

    private double _gamma
    The angle between the two ends of the arc.


    _CLOSE_THRESHOLD

    protected static final double _CLOSE_THRESHOLD
    The threshold for when a source and a destination of an arc are considered close to one another. This determines how self-loops get drawn.

    See Also:
    Constant Field Values

    _midpointSite

    private ArcMidpointSite _midpointSite
    The midpoint site.

    Constructor Detail

    ArcConnector

    public ArcConnector(Site tail,
                        Site head)
    Create a new arc connector between the given sites. The connector is drawn with a width of one and in black, and at the default incident angle of 45 degrees (PI/4 radians).

    Method Detail

    getAngle

    public double getAngle()
    Get the angle at which the arc leaves the tail figure.


    getGamma

    public double getGamma()
    Get the angle that determines the orientation of a self-loop. This method should be used when saving an arc to an external representation, if the arc is a self-loop.


    getArcMidpoint

    public java.awt.geom.Point2D getArcMidpoint()
    Return the midpoint of the arc.

    Returns:
    The midpoint of the arc.

    getMidpointSite

    public Site getMidpointSite()
    Get the site that marks the midpoint of the connector.

    Returns:
    A site representing the midpoint of the arc.

    getSelfLoop

    public boolean getSelfLoop()
    Get the flag saying whether this arc is to be drawn as a self-loop


    repositionLabel

    public void repositionLabel()
    Tell the connector to reposition its label if it has one. The label is currently only positioned at the center of the arc.

    Specified by:
    repositionLabel in class AbstractConnector

    route

    public void route()
    Tell the connector to route itself between the current positions of the head and tail sites.

    Specified by:
    route in interface Connector
    Specified by:
    route in class AbstractConnector

    setAngle

    public void setAngle(double angle)
    Set the angle at which the arc leaves the tail figure, in radians. Because of the sign of the geometry, an arc with positive angle and with an arrowhead on its head will appear to be drawn counter-clockwise, and an arc with a negative angle will appear to be drawn clockwise. As a general rule, angles should be somewhat less than PI/2, and PI/4 a good general maximum figure. If the angle is outside the range -PI to PI, then it is corrected to lie within that range.


    setGamma

    public void setGamma(double gamma)
    Set the angle that determines the orientation of a self-loop. This value is roughly equal to the angle of the tangent to the loop at it's mid-point. This method is only intended for use when creating self-loop arcs from a saved representation.


    setSelfLoop

    public void setSelfLoop(boolean selfloop)
    Set the flag that says that this arc is drawn as a "self-loop." Apart from changing (slightly) the way the arc geometry is determined, this method resets some internal variables so that the arc doesn't get into a "funny state" when switching between self-loops and non-self-loops. Not, however, that this method should only be called when the arc changes, otherwise manipulation won't work properly. Use getSelfLoop() to test the current state of this flag.


    translate

    public void translate(double x,
                          double y)
    Translate the connector. This method is implemented, since controllers may wish to translate connectors when the sites at both ends are moved the same distance.

    Specified by:
    translate in interface Figure
    Specified by:
    translate in class AbstractConnector

    translateMidpoint

    public void translateMidpoint(double dx,
                                  double dy)
    Translate the midpoint of the arc. This method is not exact, but attempts to alter the shape of the arc so that the midpoint moves by something close to the given amount.