Package diva.canvas.connector
Class ArcConnector
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.connector.AbstractConnector
-
- diva.canvas.connector.ArcConnector
-
- All Implemented Interfaces:
CanvasComponent
,Connector
,Figure
,VisibleComponent
,UserObjectContainer
- Direct Known Subclasses:
KielerLayoutArcConnector
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:- 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.
- 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$
- Author:
- Edward Lee, John Reekie
- Pt.AcceptedRating:
- Red
-
-
Field Summary
Fields Modifier and Type Field Description protected static double
_CLOSE_THRESHOLD
The threshold for when a source and a destination of an arc are considered close to one another.
-
Constructor Summary
Constructors Constructor Description ArcConnector(Site tail, Site head)
Create a new arc connector between the given sites.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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." 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.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.CanvasComponent
getTransformContext, repaint, repaint
-
Methods inherited from interface diva.canvas.Figure
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, setInteractor, setParent, setToolTipText
-
Methods inherited from interface diva.util.UserObjectContainer
getUserObject, setUserObject
-
Methods inherited from interface diva.canvas.VisibleComponent
isVisible, paint, setVisible
-
-
-
-
Field Detail
-
_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
-
-
Method Detail
-
getAngle
public double getAngle()
Get the angle at which the arc leaves the tail figure.- Returns:
- the angle
- See Also:
setAngle(double)
-
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.- Returns:
- the gamma
- See Also:
setGamma(double)
-
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.- Returns:
- True if this arc is to be drawn as a self-loop.
- See Also:
setSelfLoop(boolean)
-
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 classAbstractConnector
-
route
public void route()
Tell the connector to route itself between the current positions of the head and tail sites.- Specified by:
route
in interfaceConnector
- Specified by:
route
in classAbstractConnector
-
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.- Parameters:
angle
- The angle- See Also:
getAngle()
-
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.- Parameters:
gamma
- The gamma- See Also:
getGamma()
-
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.- Parameters:
selfloop
- true if this is a self-loop.- See Also:
getSelfLoop()
-
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 interfaceFigure
- Specified by:
translate
in classAbstractConnector
- Parameters:
x
- The x value to be moved.y
- The y value to be moved.
-
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.- Parameters:
dx
- The x value to transformdy
- The y value to transform
-
-