org.jhotdraw.draw
Class AbstractConnector

java.lang.Object
  extended by org.jhotdraw.draw.AbstractConnector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Connector, DOMStorable
Direct Known Subclasses:
ChopRectangleConnector, LocatorConnector

public class AbstractConnector
extends java.lang.Object
implements Connector

AbstractConnector provides default implementation for the Connector interface.

Version:
3.0 2007-05-18 Rewritten due to changes in Connector interface.
2.1 2006-06-05 Support connection to decorator.
2.0 2006-01-14 Changed to support doubl precision coordinates.
1.0 2003-12-01 Derived from JHotDraw 5.4b1.
Author:
Werner Randelshofer
See Also:
Connector, Serialized Form

Field Summary
private  boolean isConnectToDecorator
          Whether we should connect to the figure or to its decorator.
private  boolean isStatePersistent
          Whether the state of this connector is persistent.
private  Figure owner
          The owner of the connector
 
Constructor Summary
AbstractConnector()
          Constructs a connector that has no owner.
AbstractConnector(Figure owner)
          Constructs a connector with the given owner figure.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of the Connection.
 boolean contains(java.awt.geom.Point2D.Double p)
          Tests if a point is contained in the connector.
 void draw(java.awt.Graphics2D g)
          Draws the connector.
 java.awt.geom.Point2D.Double findEnd(ConnectionFigure connection)
          Finds the end point for the connection.
protected  java.awt.geom.Point2D.Double findPoint(ConnectionFigure connection)
          Gets the connection point.
 java.awt.geom.Point2D.Double findStart(ConnectionFigure connection)
          Finds the start point for the connection.
 java.awt.geom.Point2D.Double getAnchor()
          Gets the anchor of the connector.
 java.awt.geom.Rectangle2D.Double getBounds()
          Gets the bounds of the connector.
protected  Figure getConnectorTarget(Figure f)
           
 java.awt.geom.Rectangle2D.Double getDrawingArea()
          Gets the drawing area of the connector.
 Figure getOwner()
          Gets the connector's owner.
 boolean isConnectToDecorator()
           
 void read(DOMInput in)
           
 void setConnectToDecorator(boolean newValue)
           
protected  void setOwner(Figure newValue)
          Sets the connector's owner.
 void updateAnchor(java.awt.geom.Point2D.Double p)
          Updates the anchor of the connector.
 void updateEndLocation(java.awt.geom.Point2D.Double p)
          This is called, when the end location of the connection has been moved by the user.
 void updateStartLocation(java.awt.geom.Point2D.Double p)
          This is called, when the start location of the connection has been moved by the user.
 void write(DOMOutput out)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

owner

private Figure owner
The owner of the connector


isConnectToDecorator

private boolean isConnectToDecorator
Whether we should connect to the figure or to its decorator.


isStatePersistent

private boolean isStatePersistent
Whether the state of this connector is persistent. Set this to true only, when the user interface allows to change the state of the connector.

Constructor Detail

AbstractConnector

public AbstractConnector()
Constructs a connector that has no owner. It is only used internally to resurrect a connectors from a StorableOutput. It should never be called directly.


AbstractConnector

public AbstractConnector(Figure owner)
Constructs a connector with the given owner figure.

Method Detail

setConnectToDecorator

public void setConnectToDecorator(boolean newValue)

isConnectToDecorator

public boolean isConnectToDecorator()

getConnectorTarget

protected final Figure getConnectorTarget(Figure f)

contains

public boolean contains(java.awt.geom.Point2D.Double p)
Tests if a point is contained in the connector.

Specified by:
contains in interface Connector

findStart

public java.awt.geom.Point2D.Double findStart(ConnectionFigure connection)
Description copied from interface: Connector
Finds the start point for the connection.

Specified by:
findStart in interface Connector

findEnd

public java.awt.geom.Point2D.Double findEnd(ConnectionFigure connection)
Description copied from interface: Connector
Finds the end point for the connection.

Specified by:
findEnd in interface Connector

findPoint

protected java.awt.geom.Point2D.Double findPoint(ConnectionFigure connection)
Gets the connection point. Override when the connector does not need to distinguish between the start and end point of a connection.


getOwner

public Figure getOwner()
Gets the connector's owner.

Specified by:
getOwner in interface Connector

setOwner

protected void setOwner(Figure newValue)
Sets the connector's owner.


clone

public java.lang.Object clone()
Description copied from interface: Connector
Returns a clone of the Connection.

Specified by:
clone in interface Connector
Overrides:
clone in class java.lang.Object

updateStartLocation

public void updateStartLocation(java.awt.geom.Point2D.Double p)
This is called, when the start location of the connection has been moved by the user. The user has this probably done, to adjust the layout. The connector may use this as a hint to improve the results for the next call to findEnd.


updateEndLocation

public void updateEndLocation(java.awt.geom.Point2D.Double p)
This is called, when the end location of the connection has been moved by the user. The user has this probably done, to adjust the layout. The connector may use this as a hint to improve the results for the next call to findStart.


getAnchor

public java.awt.geom.Point2D.Double getAnchor()
Description copied from interface: Connector
Gets the anchor of the connector. This is a point at the center or at the bounds of the figure, where the start or the end point will most likely be attached. The purpose of this method is to give the user a hint, where the connector will most likely be attached to the owner of the connector.

Specified by:
getAnchor in interface Connector

updateAnchor

public void updateAnchor(java.awt.geom.Point2D.Double p)
Description copied from interface: Connector
Updates the anchor of the connector. This method is called when the user manually changes the end point of the ConnectionFigure. The Connector uses this as a hint for choosing a new anchor position.

Specified by:
updateAnchor in interface Connector

getBounds

public java.awt.geom.Rectangle2D.Double getBounds()
Description copied from interface: Connector
Gets the bounds of the connector. This usually are the bounds of the Figure which owns the Connector. The bounds can differ from the Figure bounds, if the Connector connects to a specific region of the Figure.

Specified by:
getBounds in interface Connector

read

public void read(DOMInput in)
          throws java.io.IOException
Specified by:
read in interface DOMStorable
Throws:
java.io.IOException

write

public void write(DOMOutput out)
           throws java.io.IOException
Specified by:
write in interface DOMStorable
Throws:
java.io.IOException

getDrawingArea

public java.awt.geom.Rectangle2D.Double getDrawingArea()
Description copied from interface: Connector
Gets the drawing area of the connector.

Specified by:
getDrawingArea in interface Connector

draw

public void draw(java.awt.Graphics2D g)
Description copied from interface: Connector
Draws the connector.

Specified by:
draw in interface Connector