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.Rectangle2DgetBounds()Get the bounding box of this connector.float[]getDashArray()Get the dash array.ConnectorEndgetHeadEnd()Get the object drawn at the head end of the connector, if there is one.SitegetHeadSite()Get the site that marks the "head" of the connector.LabelFiguregetLabelFigure()Get the figure that displays this connector's label.floatgetLineWidth()Get the line width of this figure.java.awt.ShapegetShape()Get the outline shape of this connector.java.awt.StrokegetStroke()Get the stroke of this connector.java.awt.PaintgetStrokePaint()Get the stroke paint pattern of this connector.ConnectorEndgetTailEnd()Get the object drawn at the tail end of the connector, if there is one.SitegetTailSite()Get the site that marks the "tail" of the connector.voidheadMoved()Inform the connector that the head site has moved.booleanhit(java.awt.geom.Rectangle2D r)Test if this connector is hit by the given rectangle.booleanintersects(java.awt.geom.Rectangle2D r)Test if this connector intersects the given rectangle.voidpaint(java.awt.Graphics2D g)Paint the connector.abstract voidrepositionLabel()Tell the connector to reposition its label if it has one.voidreroute()Tell the connector to re-route itself.abstract voidroute()Tell the connector to route itself completely, using all available information.voidsetDashArray(float[] dashArray)Set the dash array of the stroke.voidsetHeadEnd(ConnectorEnd e)Set the object drawn at the head end of the connector.voidsetHeadSite(Site s)Set the site that marks the "head" of the connector, and call headMoved();voidsetLabelFigure(LabelFigure label)Set the LabelFigure of this connector.voidsetLineWidth(float lineWidth)Set the line width.protected voidsetShape(java.awt.Shape s)Set the shape, for subclasses only.voidsetStroke(java.awt.Stroke s)Set the stroke of this connector.voidsetStrokePaint(java.awt.Paint p)Set the stroke paint pattern of this connector.voidsetTailEnd(ConnectorEnd e)Set the object drawn at the tail end of the connector.voidsetTailSite(Site s)Set the site that marks the "tail" of the connector.voidtailMoved()Inform the connector that the tail site has moved.voidtransform(java.awt.geom.AffineTransform at)Transform the connector.abstract voidtranslate(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:
getBoundsin interfaceFigure- Overrides:
getBoundsin 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:
getHeadSitein 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:
getShapein interfaceFigure- Specified by:
getShapein 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:
getTailSitein 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:
hitin interfaceFigure- Overrides:
hitin 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:
intersectsin interfaceFigure- Overrides:
intersectsin 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:
paintin interfaceVisibleComponent- Specified by:
paintin 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:
setHeadSitein 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:
setTailSitein 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:
transformin interfaceFigure- Specified by:
transformin 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:
translatein interfaceFigure- Overrides:
translatein classAbstractFigure- Parameters:
x- The x value to be moved.y- The y value to be moved.
-
-