com.mindfusion.diagramming
Class ConnectionPoint

java.lang.Object
  extended by com.mindfusion.diagramming.ConnectionPoint
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
TreeViewConnectionPoint

public class ConnectionPoint
extends java.lang.Object
implements java.io.Externalizable

This class represents a connection between an edge and a node in a graph. It decouples the DiagramLink class from the DiagramNode class, allowing edges to connect different types of nodes without knowing anything of their implementation details. Each DiagramLink object contains two ConnectionPoint instances describing the connections at both ends of the link.

See Also:
Serialized Form

Field Summary
protected  DiagramNode node
           
 
Constructor Summary
ConnectionPoint()
          Initializes a new instance of the ConnectionPoint class.
ConnectionPoint(DiagramNode node, DiagramLink link, boolean incoming)
          Initializes a new instance of the ConnectionPoint class between the specified node and link.
 
Method Summary
 void addLinkToNode()
          Adds the link associated with this connection point to the associated node.
 boolean calculateIntersections()
          Determines whether the end of a link should be aligned to the point where the node contour is intersected by the line connecting the centers of the connected nodes.
 boolean canMoveLink(java.awt.geom.Point2D.Float point)
          Checks whether the specified point, expressed in document coordinates, is a valid location for this connection point.
 java.awt.geom.Point2D getAnchorPos(int anchor)
          Returns the point from the node's associated anchor pattern (if any) with the specified index or the link's initial point.
 boolean getAnchorPos(int anchorIdx, java.awt.geom.Point2D.Float point)
          Returns the point from the node's associated anchor pattern (if any) with the specified index.
 java.awt.geom.Point2D getEndPoint()
          Calculates the coordinates of the this connection point expressed in document coordinates.
protected  boolean getIncoming()
          Gets a flag indicating whether this connection point is at the origin or the destination of the associated link.
 java.awt.geom.Point2D getInitialPoint()
          Returns a point (usually the center of the bounding rectangle) contained within the associated node.
 java.awt.geom.Point2D getIntersection(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)
          Calculates the intersection point between the specified line segment and the contour of the node associated with this connection point.
protected  DiagramLink getLink()
          Gets the link associated with this connection point.
protected  DiagramNode getNode()
          Gets the node associated with this connection point.
 java.awt.geom.Rectangle2D getNodeRect(boolean rotated)
          Returns the bounding rectangle of the node associated with this connection point.
 java.awt.geom.Point2D.Float getRelativePosition()
          Gets the position of this connection point, relative to the associated node's bounding rectangle, expressed in percents.
 int getRow()
          Gets the index of a constituent item within the associated node where the link represented by this connection point is connected, or -1, if the link is connected to the node itself.
 boolean linkChanges(DiagramNode node, java.awt.geom.Point2D point)
          Checks whether the relationship represented by the associated link would change if the link is attached to the specified node at the specified point.
 boolean nodesIntersect(ConnectionPoint connectionPoint)
          Checks whether the node associated with the current connection point and the node associated with the specified connection point intersect.
 void readExternal(java.io.ObjectInput in)
          Deserializes the connection point data.
 void removeLinkFromNode()
          Removes the link associated with this connection point from the associated node.
 boolean sameNode(ConnectionPoint otherConnectionPoint)
          Checks whether the current connection point and the specified connection point are associated with the same node.
 void saveEndRelative()
          Updates the coordinates of the connection point represented by this link, relative to the bounding rectangle of the associated node.
 void setRelativePosition(java.awt.geom.Point2D.Float value)
          Sets the position of this connection point, relative to the associated node's bounding rectangle, expressed in percents.
protected  void updateFromPoint(java.awt.geom.Point2D point)
          Updates the connection state according to the specified point, without changing the related node.
 void writeExternal(java.io.ObjectOutput out)
          Serializes the connection point data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

protected DiagramNode node
Constructor Detail

ConnectionPoint

public ConnectionPoint(DiagramNode node,
                       DiagramLink link,
                       boolean incoming)
Initializes a new instance of the ConnectionPoint class between the specified node and link.

Parameters:
node - The node whose connection to a link is managed by this ConnectionPoint.
link - The link whose connection to a node is managed by this ConnectionPoint.
incoming - Specifies which end of the link is represented by this ConnectionPoint.

ConnectionPoint

public ConnectionPoint()
Initializes a new instance of the ConnectionPoint class. This constructor is used only during deserialization.

Method Detail

sameNode

public boolean sameNode(ConnectionPoint otherConnectionPoint)
Checks whether the current connection point and the specified connection point are associated with the same node.


linkChanges

public boolean linkChanges(DiagramNode node,
                           java.awt.geom.Point2D point)
Checks whether the relationship represented by the associated link would change if the link is attached to the specified node at the specified point.


updateFromPoint

protected void updateFromPoint(java.awt.geom.Point2D point)
Updates the connection state according to the specified point, without changing the related node.


nodesIntersect

public boolean nodesIntersect(ConnectionPoint connectionPoint)
Checks whether the node associated with the current connection point and the node associated with the specified connection point intersect.


getIntersection

public java.awt.geom.Point2D getIntersection(java.awt.geom.Point2D pt1,
                                             java.awt.geom.Point2D pt2)
Calculates the intersection point between the specified line segment and the contour of the node associated with this connection point.


getNodeRect

public java.awt.geom.Rectangle2D getNodeRect(boolean rotated)
Returns the bounding rectangle of the node associated with this connection point.


addLinkToNode

public void addLinkToNode()
Adds the link associated with this connection point to the associated node.


removeLinkFromNode

public void removeLinkFromNode()
Removes the link associated with this connection point from the associated node.


saveEndRelative

public void saveEndRelative()
Updates the coordinates of the connection point represented by this link, relative to the bounding rectangle of the associated node.


getEndPoint

public java.awt.geom.Point2D getEndPoint()
Calculates the coordinates of the this connection point expressed in document coordinates.


getInitialPoint

public java.awt.geom.Point2D getInitialPoint()
Returns a point (usually the center of the bounding rectangle) contained within the associated node.


canMoveLink

public boolean canMoveLink(java.awt.geom.Point2D.Float point)
Checks whether the specified point, expressed in document coordinates, is a valid location for this connection point.


calculateIntersections

public boolean calculateIntersections()
Determines whether the end of a link should be aligned to the point where the node contour is intersected by the line connecting the centers of the connected nodes.


getAnchorPos

public java.awt.geom.Point2D getAnchorPos(int anchor)
Returns the point from the node's associated anchor pattern (if any) with the specified index or the link's initial point.


getAnchorPos

public boolean getAnchorPos(int anchorIdx,
                            java.awt.geom.Point2D.Float point)
Returns the point from the node's associated anchor pattern (if any) with the specified index.


writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Serializes the connection point data.

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Deserializes the connection point data.

Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getLink

protected DiagramLink getLink()
Gets the link associated with this connection point.


getNode

protected DiagramNode getNode()
Gets the node associated with this connection point.


getIncoming

protected boolean getIncoming()
Gets a flag indicating whether this connection point is at the origin or the destination of the associated link.


getRelativePosition

public java.awt.geom.Point2D.Float getRelativePosition()
Gets the position of this connection point, relative to the associated node's bounding rectangle, expressed in percents.


setRelativePosition

public void setRelativePosition(java.awt.geom.Point2D.Float value)
Sets the position of this connection point, relative to the associated node's bounding rectangle, expressed in percents.


getRow

public int getRow()
Gets the index of a constituent item within the associated node where the link represented by this connection point is connected, or -1, if the link is connected to the node itself.