JHotDraw 6.0b1

Class OffsetConnector

  extended by org.jhotdraw.standard.AbstractConnector
      extended by org.jhotdraw.standard.LocatorConnector
          extended by org.jhotdraw.standard.OffsetConnector
All Implemented Interfaces:
java.io.Serializable, Connector, Storable

public class OffsetConnector
extends LocatorConnector

An OffsetConnector locates connection points with the help of an OffsetLocator.

It allows the dynamic creation of connection points for new LineConnections.

It dynamically adjusts connection points when connection handles are dragged.

This class is not thread safe

Design Patterns

 o Proxy
Tracking connectors are Proxy Objects that are provided by the trackConnector method when new connectors need to be created. The tracking connectors permit deferral of OffsetConnector creation until the finalizeConnector() method is called. New connectors are then created by copying the tracking connectors (as in the Prototype pattern).

See Also:
OffsetLocator, Connector, Serialized Form

Field Summary
static OffsetConnector trackingConnector1
static OffsetConnector trackingConnector2
Fields inherited from class org.jhotdraw.standard.LocatorConnector
myLocator, SIZE
Fields inherited from class org.jhotdraw.standard.AbstractConnector
Constructor Summary
          Constructs a connector that has no owner.
Method Summary
 OffsetConnector calculateFigureConstrainedOffsets(int x, int y)
          Constrains the point (x,y) to the figure and calculates the offsets for the resulting constrained point.
protected  java.awt.Point calculateFigureConstrainedTrackingPoint(int x, int y)
          Constrains the point (x,y) to the figure and returns a constrained point.
 java.awt.Point connectorMovedTo(int x, int y)
          Resets offsets for an existing OffsetConnector.
 Connector finalizeConnector(boolean start)
          Returns a newly created OffsetConnector for tracking connectors.
protected  java.awt.Point findPoint(ConnectionFigure connection)
          Gets the connection point.
protected  java.awt.Point locate(ConnectionFigure connection)
 int locateX()
 int locateY()
 void reset(DrawingView drawingView)
          Called when a ConnectionTool starts a new connection.
static OffsetConnector trackConnector(Figure owner, int x, int y)
          Use this method to create new OffsetConnectors.
Methods inherited from class org.jhotdraw.standard.LocatorConnector
containsPoint, displayBox, draw, getLocator, read, setLocator, write
Methods inherited from class org.jhotdraw.standard.AbstractConnector
connectorVisibility, findEnd, findStart, owner
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static OffsetConnector trackingConnector1


public static OffsetConnector trackingConnector2
Constructor Detail


public OffsetConnector()
Constructs a connector that has no owner. It is used internally to resurrect a connector from a StorableOutput and to create the static tracking connectors.

Method Detail


public void reset(DrawingView drawingView)
Called when a ConnectionTool starts a new connection. (ConnectionTool MouseDown event).

drawingView - - the current DrawingView; needed for it's GridConstrainer


public static OffsetConnector trackConnector(Figure owner,
                                             int x,
                                             int y)
Use this method to create new OffsetConnectors.

Returns a tracking Connector initialized to the required owner and location. The trackingConnector will create a new connector when it's method finalizeConnector() is called.

This method depends on trackingConnector1.reset() resetting the trackingConnectors

owner - - the owning figure
x - - x co-ordinate
y - - y co-ordinate
- either trackingConnector1 or trackingConnector2 (if 1 is in use)
See Also:
finalizeConnector(boolean start)


public Connector finalizeConnector(boolean start)
Returns a newly created OffsetConnector for tracking connectors. The tracking connector's owner and offsets are copied to the new connector.

Existing non-tracking connectors are returned unchanged without side effects.

This method is called by the connectStart(Connector) and the connectEnd(Connector) methods of the LineConnection object

Specified by:
finalizeConnector in interface Connector
finalizeConnector in class AbstractConnector
start - - a boolean indicating whether the receiver is a start or end Connector
- the receiver unchanged if it is not a tracking connector; a new Offset connector if this is a tracking connector.
See Also:


public java.awt.Point connectorMovedTo(int x,
                                       int y)
Resets offsets for an existing OffsetConnector. Called when dragging a ChangeConnectionHandle.

Specified by:
connectorMovedTo in interface Connector
connectorMovedTo in class AbstractConnector
x - - x coordinate of point moved to
y - - y coordinate of point moved to
See Also:
ChangeConnectionHandle, Connector.connectorMovedTo(int, int)


protected java.awt.Point findPoint(ConnectionFigure connection)
Gets the connection point. If the owner is resized the connection points are (visually) preserved provided they lie on the box of the resized figure.

findPoint in class AbstractConnector
See Also:


protected java.awt.Point locate(ConnectionFigure connection)
the connector Point


public int locateX()
the x-coordinate of this connector


public int locateY()
the y-coordinate of this connector


public OffsetConnector calculateFigureConstrainedOffsets(int x,
                                                         int y)
Constrains the point (x,y) to the figure and calculates the offsets for the resulting constrained point.

x - - x coordinate
y - - y coordinate


protected java.awt.Point calculateFigureConstrainedTrackingPoint(int x,
                                                                 int y)
Constrains the point (x,y) to the figure and returns a constrained point. This method can be overridden for different figure types or different constraining policies.

For efficiency reasons the same point object is returned from every call. Be careful not to publicly expose this internal tracking point when overriding.

This method is NOT thread safe.

x - - x coordinate
y - - y coordinate
internal tracking point containing the constrained coordinates

JHotDraw 6.0b1