Class 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 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.
        Parameters:
        tail - The tail of the connector.
        head - The head of the connector.
    • 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
        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[])
      • 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)
      • 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)
      • 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
        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 interface Figure
        Overrides:
        intersects in class AbstractFigure
        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 interface VisibleComponent
        Specified by:
        paint in class AbstractFigure
        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.
        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.
        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 interface Connector
        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 interface Connector
        Parameters:
        s - The "tail" site
      • 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
        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 interface Figure
        Overrides:
        translate in class AbstractFigure
        Parameters:
        x - The x value to be moved.
        y - The y value to be moved.