kaapo.project
Class ConnectionWrapper

java.lang.Object
  extended by kaapo.Observable
      extended by kaapo.project.DiagramComponentWrapper
          extended by kaapo.project.ConnectionWrapper
All Implemented Interfaces:
Serializable, Cloneable

public class ConnectionWrapper
extends DiagramComponentWrapper

An ConnectionWrapper is used to wrap a Connection. Wrappers contain all the metainformation for a Connection such as its path and connection ends. This way it is possible to include a Connection into several different Diagrams easily just by creating multiple wrappers for it.

All connection wrappers are directed: they have a start point and an end point. This is true even for connections that aren't logically directed, e.g. non-directed network arcs. Connections are between two components; n-ary connections are not supported by this class.

The connection may be between two elements, two connections or any combination of them. Also, either or both end points of the connection may be empty.

Author:
hprajani, aholsti
See Also:
Serialized Form

Field Summary
 
Fields inherited from class kaapo.project.DiagramComponentWrapper
dcgraphics, dComponent, inConnections, outConnections
 
Constructor Summary
ConnectionWrapper(Connection connection, DiagramComponentWrapper startComponent, DiagramComponentWrapper endComponent, Point2D[] path)
          Constructs a new ConnectionWrapper.
 
Method Summary
 void addPathSegment(boolean toStart)
          Adds a segment either to the start or end of the path.
static double[][] calcUnitVectors(double startX, double startY, double endX, double endY)
          Calculate orthogonal unit vectors v and w based on the line given as parameter.
static double[][] calcUnitVectors(Point2D startPoint, Point2D endPoint)
          Calculate orthogonal unit vectors v and w based on the line given as parameter.
 void generatePathBetween(Point2D startPoint, Point2D endPoint)
          Generates a path between the two points given and calls setPath() with the new path as parameter.
 DiagramComponentWrapper getEndComponent()
          Returns the end component wrapper.
 Point2D getEndPoint()
          Returns the ending point of the connection.
 Point2D[] getPath()
          Returns the connection path.
 DiagramComponentWrapper getStartComponent()
          Returns the start component wrapper.
 Point2D getStartPoint()
          Returns the starting point of the connection.
 boolean isDirect()
          Tells whether the connection is direct.
 void movePathSegment(int pathIndex, Point2D change)
          Moves the specified segment in the path by the given amount.
 void moveXY(double changeX, double changeY, Selection selection)
          Moves the conection path.
 void setEndComponent(DiagramComponentWrapper endComponent, boolean updateComponents)
          Sets the end component wrapper.
 void setPath(Point2D[] path)
          Sets the path to a completely new path.
 void setStartComponent(DiagramComponentWrapper startComponent, boolean updateComponents)
          Sets the start component.
 
Methods inherited from class kaapo.project.DiagramComponentWrapper
addConnection, canMove, canResize, getDCGraphics, getDiagramComponent, getInConnections, getOutConnections, reinstateConnections, removeAllConnections, removeConnection
 
Methods inherited from class kaapo.Observable
addObserver, notifyObservers, notifyObservers, removeAllObservers, removeObserver, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionWrapper

public ConnectionWrapper(Connection connection,
                         DiagramComponentWrapper startComponent,
                         DiagramComponentWrapper endComponent,
                         Point2D[] path)
Constructs a new ConnectionWrapper.

Parameters:
connection - the Connection
startComponent - the start element
endComponent - the end element
path - the path to follow
Method Detail

getStartComponent

public DiagramComponentWrapper getStartComponent()
Returns the start component wrapper.


setStartComponent

public void setStartComponent(DiagramComponentWrapper startComponent,
                              boolean updateComponents)
Sets the start component. Notifies observers.

Parameters:
startComponent - The startComponent to set.
updateComponents -

getEndComponent

public DiagramComponentWrapper getEndComponent()
Returns the end component wrapper.


setEndComponent

public void setEndComponent(DiagramComponentWrapper endComponent,
                            boolean updateComponents)
Sets the end component wrapper.

Parameters:
endComponent - The endComponent to set.

getPath

public Point2D[] getPath()
Returns the connection path.


setPath

public void setPath(Point2D[] path)
Sets the path to a completely new path. Notifies observers.

Parameters:
path - The new path to set.

generatePathBetween

public void generatePathBetween(Point2D startPoint,
                                Point2D endPoint)
Generates a path between the two points given and calls setPath() with the new path as parameter. Notifies observers.

Parameters:
startPoint - The starting point for the new path.
endPoint - The ending point for the new path.

movePathSegment

public void movePathSegment(int pathIndex,
                            Point2D change)
Moves the specified segment in the path by the given amount. Notifies observers. Segments are numbered so that segment 1 is between the start point and the first waypoint.

Parameters:
pathIndex - The number of the segment to be moved.
change - The amount by which the segment is to be moved.

addPathSegment

public void addPathSegment(boolean toStart)
Adds a segment either to the start or end of the path. Notifies observers.

Parameters:
toStart - A value of true adds a segment to the start of the path. False adds it to the end.

moveXY

public void moveXY(double changeX,
                   double changeY,
                   Selection selection)
Moves the conection path.

Specified by:
moveXY in class DiagramComponentWrapper
Parameters:
changeX - change in x
changeY - change in y
selection - all the moved DiagramComponents
See Also:
DiagramComponentWrapper.moveXY(double, double, Selection)

isDirect

public boolean isDirect()
Tells whether the connection is direct.

Returns:
True if direct, false if has multiple segments.

getStartPoint

public Point2D getStartPoint()
Returns the starting point of the connection.

Returns:
Starting point, or null if path is empty.

calcUnitVectors

public static double[][] calcUnitVectors(double startX,
                                         double startY,
                                         double endX,
                                         double endY)
Calculate orthogonal unit vectors v and w based on the line given as parameter. The line is defined by its start and end points. Unit vector v is parallel to the line given and w is orthogonal to v and the line given. The length of both v and w is 1.

This is an assistant method for connection-related classes.

Parameters:
startX - the x coordinate of the start point
startY - the y coordinate of the start point
endX - the x coordinate of the end point
endY - the y coordinate of the end point
Returns:
Array [[v_x, v_y], [w_x, w_y]]

calcUnitVectors

public static double[][] calcUnitVectors(Point2D startPoint,
                                         Point2D endPoint)
Calculate orthogonal unit vectors v and w based on the line given as parameter. The line is defined by its start and end points. Unit vector v is parallel to the line given and w is orthogonal to v and the line given. The length of both v and w is 1.

This is an assistant method for connection-related classes.

Parameters:
startPoint - the x coordinates of the start point
endPoint - the y coordinates of the start point
Returns:
Array [[v_x, v_y], [w_x, w_y]]

getEndPoint

public Point2D getEndPoint()
Returns the ending point of the connection.

Returns:
Ending point, or null if path is empty.