Posted on 2008-04-22 11:19
zDevil(Dengues Studio) 阅读(1328)
评论(0) 编辑 收藏
GEF的默认Connection只是一根直线但是在实际运用中,用到了不同的线型.
你只要在相应的Connection Edit Part里面的Figure里面添加一个Router.
keyFigure.setConnectionRouter(new FKRouter());
我这里产生的效果是:
代码如下:
在GEF里面自带一些线型:
public class FKRouter extends AbstractRouter {
/**
* Qiang.Zhang.Adolf@gmail.com FKRouter constructor comment.
*/
public FKRouter() {
}
private void processPositions(Ray start, Ray end, Connection conn) {
int i = 1;
PointList points = new PointList();
points.addPoint(new Point(start.x, start.y));
Point p = new Point(0, 0);
if (start.x == end.x || start.x > end.x && Math.abs(start.x - end.x) > 40) {
i = -1;
}
p.x = start.x + i * 20;
p.y = start.y;
points.addPoint(p);
if (Math.abs(start.x - end.x) < 40) {
i = i * -1;
}
p = new Point(0, 0);
p.x = end.x - i * 20;
p.y = end.y;
points.addPoint(p);
points.addPoint(new Point(end.x, end.y));
conn.setPoints(points);
}
/**
* @see ConnectionRouter#route(Connection)
*/
public void route(Connection conn) {
if ((conn.getSourceAnchor() == null) || (conn.getTargetAnchor() == null))
return;
Point startPoint = getStartPoint(conn);
conn.translateToRelative(startPoint);
Point endPoint = getEndPoint(conn);
conn.translateToRelative(endPoint);
Ray start = new Ray(startPoint);
Ray end = new Ray(endPoint);
processPositions(start, end, conn);
}
}
BendpointConnectionRouter这个是折线。
ManhattanConnectionRouter垂直水平线。
Dengues论坛(http://groups.google.com/group/dengues/),一个很好的Eclipse开发者乐园.