连接点PathFigure
连接点从PolylineConnection继承下来,在构造函数中设置目标对象连接点的装饰类,也就是示例中的三角形(PolylineDecoration),以及设定连接线路由样式,这里设置为ManhattanConnectionRouter
1 |
public class PathFigure extends PolylineConnection { |
2 |
public PathFigure() { |
3 |
//setSourceDecoration(new PolygonDecoration()); |
4 |
setTargetDecoration( new PolylineDecoration()); |
5 |
//setConnectionRouter(new BendpointConnectionRouter()); |
6 |
setConnectionRouter( new ManhattanConnectionRouter()); |
7 |
|
8 |
} |
9 |
} |
监听移动事件
01 |
public class Dnd extends MouseMotionListener.Stub implements MouseListener { |
02 |
public Dnd(IFigure figure) { |
03 |
figure.addMouseMotionListener( this ); |
04 |
figure.addMouseListener( this ); |
05 |
} |
06 |
|
07 |
Point start; |
08 |
|
09 |
public void mouseReleased(MouseEvent e) { |
10 |
} |
11 |
|
12 |
public void mouseClicked(MouseEvent e) { |
13 |
} |
14 |
|
15 |
public void mouseDoubleClicked(MouseEvent e) { |
16 |
} |
17 |
|
18 |
public void mousePressed(MouseEvent e) { |
19 |
start = e.getLocation(); |
20 |
} |
21 |
|
22 |
public void mouseDragged(MouseEvent e) { |
23 |
Point p = e.getLocation(); |
24 |
Dimension d = p.getDifference(start); |
25 |
start = p; |
26 |
Figure f = ((Figure) e.getSource()); |
27 |
f.setBounds(f.getBounds().getTranslated(d.width, d.height)); |
28 |
} |
29 |
} |
Flowchart
Flowchart是主程序代码,生成最上图所示的所有图例、连接,并把连接于连接点关联起来,并加入监听移动事件对象
参考:Draw2D教程
本文转自 陈本峰 51CTO博客,原文链接:http://blog.51cto.com/zhoujg/516882,如需转载请自行联系原作者