diva.canvas.connector
Class AbstractConnectorTarget

java.lang.Object
  extended by diva.canvas.connector.AbstractConnectorTarget
All Implemented Interfaces:
ConnectorTarget
Direct Known Subclasses:
CenterTarget, ConnectorTutorial.SRTarget, PerimeterTarget

public abstract class AbstractConnectorTarget
extends java.lang.Object
implements ConnectorTarget

An abstract implementation of the ConnectorTarget interface. Most connector targets do only basic filtering on a connector, by disallowing the head and tail of a connector from attaching to the same figure. Most connector targets also have the same behavior for heads and for tails. This class allows connector targets to only implement a single method to use this functionality.

Version:
$Id: AbstractConnectorTarget.java 43579 2006-09-08 15:01:33Z cxh $
Author:
John Reekie

Constructor Summary
AbstractConnectorTarget()
           
 
Method Summary
 boolean acceptHead(Connector c, Figure f)
          Return true if the given connector can be connected to the given figure.
 boolean acceptTail(Connector c, Figure f)
          Return true if the given connector can be connected to the given figure.
 Site getHeadSite(Connector c, Figure f, double x, double y)
          Return a suitable site to connect the given connector's head to, based on this figure and location.
 Site getHeadSite(Connector c, Site s, double x, double y)
          Return a suitable site to connect a connector's head to.
abstract  Site getHeadSite(Figure f, double x, double y)
          Return a suitable site to connect a connector's head to, based on this figure and location.
 Site getHeadSite(Site s, double x, double y)
          Deprecated. Use getHeadSite that takes a connector.
 Site getTailSite(Connector c, Figure f, double x, double y)
          Return a suitable site to connect the given connector's tail to, based on this figure and location.
 Site getTailSite(Connector c, Site s, double x, double y)
          Return a suitable site to connect a connector's tail to.
 Site getTailSite(Figure f, double x, double y)
          Deprecated. Use getTailSite that takes a connector.
 Site getTailSite(Site s, double x, double y)
          Deprecated. Use getTailSite that takes a connector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractConnectorTarget

public AbstractConnectorTarget()
Method Detail

acceptHead

public boolean acceptHead(Connector c,
                          Figure f)
Return true if the given connector can be connected to the given figure. In this base class return true if the tail of the connector is not attached to the same figure.


acceptTail

public boolean acceptTail(Connector c,
                          Figure f)
Return true if the given connector can be connected to the given figure. In this base class return true if the head of the connector is not attached to the same figure.


getHeadSite

public abstract Site getHeadSite(Figure f,
                                 double x,
                                 double y)
Return a suitable site to connect a connector's head to, based on this figure and location. Return null if there is no suitable site. In general, it is better to use the method that takes a connector, as this gives the target a chance to disallow the connection. This method is primarily useful for manually creating new figures.

Specified by:
getHeadSite in interface ConnectorTarget

getTailSite

public Site getTailSite(Figure f,
                        double x,
                        double y)
Deprecated. Use getTailSite that takes a connector.

Return a suitable site to connect a connector's tail to, based on this figure and location. Return null if there is no suitable site. In general, it is better to use the method that takes a connector, as this gives the target a chance to disallow the connection. This method is primarily useful for manually creating new figures. In this base class, assume that tails are treated the same way as heads, so call the getHeadSite method with the same arguments.

Specified by:
getTailSite in interface ConnectorTarget

getHeadSite

public Site getHeadSite(Site s,
                        double x,
                        double y)
Deprecated. Use getHeadSite that takes a connector.

Return a suitable site to connect a connector's head to. The passed site is usually taken to be a site that the connector is already connected to, so the target should take this into account if it has restrictions such as only allowing one connection to each site. The returned site can be the same as the passed site, which signals that the passed site is the best one available. In this base class, just return the same site.

Specified by:
getHeadSite in interface ConnectorTarget

getTailSite

public Site getTailSite(Site s,
                        double x,
                        double y)
Deprecated. Use getTailSite that takes a connector.

Return a suitable site to connect a connector's tail to. See the description for getheadSite(). In this base class, just return the same site.

Specified by:
getTailSite in interface ConnectorTarget

getHeadSite

public Site getHeadSite(Connector c,
                        Figure f,
                        double x,
                        double y)
Return a suitable site to connect the given connector's head to, based on this figure and location. Return null if there is no suitable site. In this base class, return null if the acceptHead method called with the connector and the figure returns false. Otherwise call the method that just takes a figure.

Specified by:
getHeadSite in interface ConnectorTarget

getTailSite

public Site getTailSite(Connector c,
                        Figure f,
                        double x,
                        double y)
Return a suitable site to connect the given connector's tail to, based on this figure and location. Return null if there is no suitable site. In this base class, return null if the acceptHead method called with the connector and the figure returns false. Otherwise call the method that just takes a figure.

Specified by:
getTailSite in interface ConnectorTarget

getHeadSite

public Site getHeadSite(Connector c,
                        Site s,
                        double x,
                        double y)
Return a suitable site to connect a connector's head to. The passed site is usually taken to be a site that the connector is already connected to, so the target should take this into account if it has restrictions such as only allowing one connection to each site. The returned site can be the same as the passed site, which signals that the passed site is the best one available. In this base class, just return the site.

Specified by:
getHeadSite in interface ConnectorTarget

getTailSite

public Site getTailSite(Connector c,
                        Site s,
                        double x,
                        double y)
Return a suitable site to connect a connector's tail to. See the description for getheadSite(). In this base class, just return the site.

Specified by:
getTailSite in interface ConnectorTarget