diva.canvas.connector
Class AbstractConnector

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by 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: AbstractConnector.java 38798 2005-07-08 20:00:01Z cxh $
Author:
John Reekie, Michael Shilman

Field Summary
private  ConnectorEnd _headEnd
          The head end
private  Site _headSite
          The head site
private  LabelFigure _labelFigure
          The label figure
private  java.awt.Paint _paint
          The stroke paint.
private  java.awt.Shape _shape
          The shape that we use to draw the connector.
private  java.awt.Stroke _stroke
          The stroke.
private  ConnectorEnd _tailEnd
          The tail end
private  Site _tailSite
          The tail site
 
Constructor Summary
AbstractConnector(Site tail, Site head)
          Create a new connector between the given sites.
 
Method Summary
 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 display's 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.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

_headEnd

private ConnectorEnd _headEnd
The head end


_tailEnd

private ConnectorEnd _tailEnd
The tail end


_headSite

private Site _headSite
The head site


_tailSite

private Site _tailSite
The tail site


_labelFigure

private LabelFigure _labelFigure
The label figure


_shape

private java.awt.Shape _shape
The shape that we use to draw the connector.


_stroke

private java.awt.Stroke _stroke
The stroke.


_paint

private java.awt.Paint _paint
The stroke paint.

Constructor Detail

AbstractConnector

public AbstractConnector(Site tail,
                         Site head)
Create a new connector between the given sites. The connector, by default, is stroked with a unit-width continuous black stroke.

Method Detail

getBounds

public java.awt.geom.Rectangle2D getBounds()
Get the bounding box of this connector.

Specified by:
getBounds in interface Figure
Overrides:
getBounds in class AbstractFigure

getDashArray

public float[] getDashArray()
Get the dash array. If the stroke is not a BasicStroke then null will always be returned.


getHeadEnd

public ConnectorEnd getHeadEnd()
Get the object drawn at the head end of the connector, if there is one.


getHeadSite

public Site getHeadSite()
Get the site that marks the "head" of the connector.

Specified by:
getHeadSite in interface Connector

getLabelFigure

public LabelFigure getLabelFigure()
Get the figure that display's this connector's label. This may be null.


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.


getTailEnd

public ConnectorEnd getTailEnd()
Get the object drawn at the tail end of the connector, if there is one.


getShape

public java.awt.Shape getShape()
Get the outline shape of this connector.

Specified by:
getShape in interface Figure
Specified by:
getShape in class AbstractFigure

getStroke

public java.awt.Stroke getStroke()
Get the stroke of this connector.


getStrokePaint

public java.awt.Paint getStrokePaint()
Get the stroke paint pattern of this connector.


getTailSite

public Site getTailSite()
Get the site that marks the "tail" of the connector.

Specified by:
getTailSite in interface Connector

headMoved

public void headMoved()
Inform the connector that the head site has moved. This default implementation simply calls reroute().

Specified by:
headMoved in interface Connector

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 interface Figure
Overrides:
hit in class AbstractFigure

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 interface Figure
Overrides:
intersects in class AbstractFigure

paint

public void paint(java.awt.Graphics2D g)
Paint the connector.

Specified by:
paint in interface VisibleComponent
Specified by:
paint in class AbstractFigure

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.

Specified by:
reroute in interface Connector

route

public abstract void route()
Tell the connector to route itself completely, using all available information.

Specified by:
route in interface Connector

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.


setHeadEnd

public void setHeadEnd(ConnectorEnd e)
Set the object drawn at the head end of the connector.


setHeadSite

public void setHeadSite(Site s)
Set the site that marks the "head" of the connector, and call headMoved();

Specified by:
setHeadSite in interface Connector

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.


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.


setShape

protected void setShape(java.awt.Shape s)
Set the shape, for subclasses only.


setStroke

public void setStroke(java.awt.Stroke s)
Set the stroke of this connector.


setStrokePaint

public void setStrokePaint(java.awt.Paint p)
Set the stroke paint pattern of this connector.


setTailEnd

public void setTailEnd(ConnectorEnd e)
Set the object drawn at the tail end of the connector.


setTailSite

public void setTailSite(Site s)
Set the site that marks the "tail" of the connector.

Specified by:
setTailSite in interface Connector

tailMoved

public void tailMoved()
Inform the connector that the tail site has moved. This default implementation simply calls reroute().

Specified by:
tailMoved in interface Connector

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 interface Figure
Specified by:
transform in class AbstractFigure

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 interface Figure
Overrides:
translate in class AbstractFigure