JHotDraw 6.0b1

org.jhotdraw.standard
Class OffsetConnector

java.lang.Object
  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
Prototype
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
fOwner
 
Constructor Summary
OffsetConnector()
          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

trackingConnector1

public static OffsetConnector trackingConnector1

trackingConnector2

public static OffsetConnector trackingConnector2
Constructor Detail

OffsetConnector

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

reset

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

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

trackConnector

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

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

finalizeConnector

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
Overrides:
finalizeConnector in class AbstractConnector
Parameters:
start - - a boolean indicating whether the receiver is a start or end Connector
Returns:
- the receiver unchanged if it is not a tracking connector; a new Offset connector if this is a tracking connector.
See Also:
LineConnection

connectorMovedTo

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
Overrides:
connectorMovedTo in class AbstractConnector
Parameters:
x - - x coordinate of point moved to
y - - y coordinate of point moved to
See Also:
ChangeConnectionHandle, Connector.connectorMovedTo(int, int)

findPoint

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.

Overrides:
findPoint in class AbstractConnector
See Also:
AbstractConnector.findPoint(org.jhotdraw.framework.ConnectionFigure)

locate

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

locateX

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

locateY

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

calculateFigureConstrainedOffsets

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

Parameters:
x - - x coordinate
y - - y coordinate

calculateFigureConstrainedTrackingPoint

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.

Parameters:
x - - x coordinate
y - - y coordinate
Returns:
internal tracking point containing the constrained coordinates

JHotDraw 6.0b1