Package diva.canvas.connector
Class AbstractConnector
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.connector.AbstractConnector
-
- All Implemented Interfaces:
CanvasComponent
,Connector
,Figure
,VisibleComponent
,UserObjectContainer
- Direct Known Subclasses:
ArcConnector
,ManhattanConnector
,StraightConnector
public abstract class AbstractConnector extends AbstractFigure implements Connector
An abstract implementation of Connector. The implementation provides default implementations of all routing methods except for route(). It also provides a set of methods for setting the appearance of the connector, such as line width, dashes, and color. To do so, it uses an instance of PaintedPath, so see that class for a more detailed description of the paint- and stroke-related methods.- Version:
- $Id$
- Author:
- John Reekie, Michael Shilman
-
-
Constructor Summary
Constructors Constructor Description AbstractConnector(Site tail, Site head)
Create a new connector between the given sites.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.awt.geom.Rectangle2D
getBounds()
Get the bounding box of this connector.float[]
getDashArray()
Get the dash array.ConnectorEnd
getHeadEnd()
Get the object drawn at the head end of the connector, if there is one.Site
getHeadSite()
Get the site that marks the "head" of the connector.LabelFigure
getLabelFigure()
Get the figure that displays this connector's label.float
getLineWidth()
Get the line width of this figure.java.awt.Shape
getShape()
Get the outline shape of this connector.java.awt.Stroke
getStroke()
Get the stroke of this connector.java.awt.Paint
getStrokePaint()
Get the stroke paint pattern of this connector.ConnectorEnd
getTailEnd()
Get the object drawn at the tail end of the connector, if there is one.Site
getTailSite()
Get the site that marks the "tail" of the connector.void
headMoved()
Inform the connector that the head site has moved.boolean
hit(java.awt.geom.Rectangle2D r)
Test if this connector is hit by the given rectangle.boolean
intersects(java.awt.geom.Rectangle2D r)
Test if this connector intersects the given rectangle.void
paint(java.awt.Graphics2D g)
Paint the connector.abstract void
repositionLabel()
Tell the connector to reposition its label if it has one.void
reroute()
Tell the connector to re-route itself.abstract void
route()
Tell the connector to route itself completely, using all available information.void
setDashArray(float[] dashArray)
Set the dash array of the stroke.void
setHeadEnd(ConnectorEnd e)
Set the object drawn at the head end of the connector.void
setHeadSite(Site s)
Set the site that marks the "head" of the connector, and call headMoved();void
setLabelFigure(LabelFigure label)
Set the LabelFigure of this connector.void
setLineWidth(float lineWidth)
Set the line width.protected void
setShape(java.awt.Shape s)
Set the shape, for subclasses only.void
setStroke(java.awt.Stroke s)
Set the stroke of this connector.void
setStrokePaint(java.awt.Paint p)
Set the stroke paint pattern of this connector.void
setTailEnd(ConnectorEnd e)
Set the object drawn at the tail end of the connector.void
setTailSite(Site s)
Set the site that marks the "tail" of the connector.void
tailMoved()
Inform the connector that the tail site has moved.void
transform(java.awt.geom.AffineTransform at)
Transform the connector.abstract void
translate(double x, double y)
Translate the connector.-
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
-
-
-
-
Method Detail
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Get the bounding box of this connector.- Specified by:
getBounds
in interfaceFigure
- Overrides:
getBounds
in classAbstractFigure
- Returns:
- the bounding box
-
getDashArray
public float[] getDashArray()
Get the dash array. If the stroke is not a BasicStroke then null will always be returned.- Returns:
- The dash array.
- See Also:
setDashArray(float[])
-
getHeadEnd
public ConnectorEnd getHeadEnd()
Get the object drawn at the head end of the connector, if there is one.- Returns:
- the head end
- See Also:
setHeadEnd(ConnectorEnd)
-
getHeadSite
public Site getHeadSite()
Get the site that marks the "head" of the connector.- Specified by:
getHeadSite
in interfaceConnector
- Returns:
- the head site.
- See Also:
setHeadSite(Site)
-
getLabelFigure
public LabelFigure getLabelFigure()
Get the figure that displays this connector's label. This may be null.- Returns:
- the label figure.
- See Also:
setLabelFigure(LabelFigure)
-
getLineWidth
public float getLineWidth()
Get the line width of this figure. If the stroke is not a BasicStroke then 1.0 will always be returned.- Returns:
- the line width.
- See Also:
setLineWidth(float)
-
getShape
public java.awt.Shape getShape()
Get the outline shape of this connector.- Specified by:
getShape
in interfaceFigure
- Specified by:
getShape
in classAbstractFigure
- Returns:
- the shape
- See Also:
setShape(Shape)
-
getStroke
public java.awt.Stroke getStroke()
Get the stroke of this connector.- Returns:
- the stroke.
- See Also:
setStroke(Stroke)
-
getStrokePaint
public java.awt.Paint getStrokePaint()
Get the stroke paint pattern of this connector.- Returns:
- the stroke paint
- See Also:
setStrokePaint(Paint)
-
getTailEnd
public ConnectorEnd getTailEnd()
Get the object drawn at the tail end of the connector, if there is one.- Returns:
- the tail end.
- See Also:
setTailEnd(ConnectorEnd)
-
getTailSite
public Site getTailSite()
Get the site that marks the "tail" of the connector.- Specified by:
getTailSite
in interfaceConnector
- Returns:
- the tail site
- See Also:
setTailSite(Site)
-
headMoved
public void headMoved()
Inform the connector that the head site has moved. This default implementation simply calls reroute().
-
hit
public boolean hit(java.awt.geom.Rectangle2D r)
Test if this connector is hit by the given rectangle. If the connector is not visible, always return false, otherwise check to see if the rectangle intersects the path of the connector, either of its ends, or the label.- Specified by:
hit
in interfaceFigure
- Overrides:
hit
in classAbstractFigure
- Parameters:
r
- The rectangle- Returns:
- True if this connector is hit by the given rectangle.
-
intersects
public boolean intersects(java.awt.geom.Rectangle2D r)
Test if this connector intersects the given rectangle. This default implementation checks to see if the rectangle intersects with the path of the connector, the label, or either of the connector ends.- Specified by:
intersects
in interfaceFigure
- Overrides:
intersects
in classAbstractFigure
- Parameters:
r
- The rectangle- Returns:
- true if this connector intersects the given rectangle
-
paint
public void paint(java.awt.Graphics2D g)
Paint the connector.- Specified by:
paint
in interfaceVisibleComponent
- Specified by:
paint
in classAbstractFigure
- Parameters:
g
- The Graphics contexts
-
repositionLabel
public abstract void repositionLabel()
Tell the connector to reposition its label if it has one. This is an abstract method that must be implemented by subclasses. In general, implementations of the routing methods will also call this method.
-
reroute
public void reroute()
Tell the connector to re-route itself. This default implementation simply calls route(). In general, this method should be overridden to perform this more efficiently.
-
route
public abstract void route()
Tell the connector to route itself completely, using all available information.
-
setDashArray
public void setDashArray(float[] dashArray)
Set the dash array of the stroke. The existing stroke will be removed, but the line width will be preserved if possible.- Parameters:
dashArray
- The dashArray- See Also:
getDashArray()
-
setHeadEnd
public void setHeadEnd(ConnectorEnd e)
Set the object drawn at the head end of the connector.- Parameters:
e
- The connector end.- See Also:
getHeadEnd()
-
setHeadSite
public void setHeadSite(Site s)
Set the site that marks the "head" of the connector, and call headMoved();- Specified by:
setHeadSite
in interfaceConnector
- Parameters:
s
- The site- See Also:
getHeadSite()
-
setLabelFigure
public void setLabelFigure(LabelFigure label)
Set the LabelFigure of this connector. If there is no label figure currently, one is created and placed on the connector.- Parameters:
label
- The label of the figure- See Also:
getLabelFigure()
-
setLineWidth
public void setLineWidth(float lineWidth)
Set the line width. The existing stroke will be removed, but the dash array will be preserved if possible.- Parameters:
lineWidth
- The line width.- See Also:
getLineWidth()
-
setShape
protected void setShape(java.awt.Shape s)
Set the shape, for subclasses only.- Parameters:
s
- The shape- See Also:
getShape()
-
setStroke
public void setStroke(java.awt.Stroke s)
Set the stroke of this connector.- Parameters:
s
- The stroke- See Also:
getStroke()
-
setStrokePaint
public void setStrokePaint(java.awt.Paint p)
Set the stroke paint pattern of this connector.- Parameters:
p
- The stroke paint- See Also:
getStrokePaint()
-
setTailEnd
public void setTailEnd(ConnectorEnd e)
Set the object drawn at the tail end of the connector.- Parameters:
e
- The connector end- See Also:
getTailEnd()
-
setTailSite
public void setTailSite(Site s)
Set the site that marks the "tail" of the connector.- Specified by:
setTailSite
in interfaceConnector
- Parameters:
s
- The "tail" site
-
tailMoved
public void tailMoved()
Inform the connector that the tail site has moved. This default implementation simply calls reroute().
-
transform
public void transform(java.awt.geom.AffineTransform at)
Transform the connector. This method is ignored, since connectors are defined by the head and tail sites.- Specified by:
transform
in interfaceFigure
- Specified by:
transform
in classAbstractFigure
- Parameters:
at
- The transform to be used.
-
translate
public abstract void translate(double x, double y)
Translate the connector. This method must be implemented, since controllers may wish to translate connectors when the sites at both ends are moved the same distance.- Specified by:
translate
in interfaceFigure
- Overrides:
translate
in classAbstractFigure
- Parameters:
x
- The x value to be moved.y
- The y value to be moved.
-
-