FanConnectionRouter.js
Summary
No overview generated for 'FanConnectionRouter.js'
draw2d.FanConnectionRouter=function()
{
}
draw2d.FanConnectionRouter.prototype = new draw2d.NullConnectionRouter;
draw2d.FanConnectionRouter.prototype.type="FanConnectionRouter";
draw2d.FanConnectionRouter.prototype.route=function( conn)
{
var fromPt = conn.getStartPoint();
var toPt = conn.getEndPoint();
var lines = conn.getSource().getConnections();
var connections = new draw2d.ArrayList();
var index=0;
for(var i=0;i<lines.getSize();i++)
{
var figure = lines.get(i);
if(figure.getTarget()==conn.getTarget() || figure.getSource()==conn.getTarget() )
{
connections.add(figure);
if(conn==figure)
index=connections.getSize();
}
}
if(connections.getSize()>1)
this.routeCollision(conn,index);
else
draw2d.NullConnectionRouter.prototype.route.call(this,conn);
}
draw2d.FanConnectionRouter.prototype.routeNormal=function( conn)
{
conn.addPoint(conn.getStartPoint());
conn.addPoint(conn.getEndPoint());
}
draw2d.FanConnectionRouter.prototype.routeCollision=function( conn, index)
{
var start = conn.getStartPoint();
var end = conn.getEndPoint();
conn.addPoint(start);
var separation = 10;
var midPoint = new draw2d.Point((end.x + start.x) / 2, (end.y + start.y) / 2);
var position = end.getPosition(start);
var ray;
if (position ==draw2d.PositionConstants.SOUTH || position == draw2d.PositionConstants.EAST)
ray = new draw2d.Point( end.x - start.x, end.y - start.y);
else
ray = new draw2d.Point( start.x - end.x, start.y - end.y);
var length = Math.sqrt(ray.x*ray.x+ray.y*ray.y);
var xSeparation = separation * ray.x / length;
var ySeparation = separation * ray.y / length;
var bendPoint;
if (index % 2 == 0)
bendPoint = new draw2d.Point( midPoint.x + (index / 2) * (-1 * ySeparation), midPoint.y + (index / 2) * xSeparation);
else
bendPoint = new draw2d.Point(midPoint.x + (index / 2) * ySeparation, midPoint.y + (index / 2) * (-1 * xSeparation));
conn.addPoint(bendPoint);
conn.addPoint(end);
}
Documentation generated by
JSDoc on Thu Feb 7 23:45:47 2008