首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

让连线下的Label动起来吧

2012-10-26 
让连线上的Label动起来吧大家都知道GEF中连线上的label默认是在线的中间,一旦要连很多线的时候显示label就

让连线上的Label动起来吧
大家都知道GEF中连线上的label默认是在线的中间,一旦要连很多线的时候显示label就是棘手的问题了,所以啊就要求可以移动label避免重叠啊
三个步骤
第一步:写个类继承MidpointLocator

conditionLabel.addMouseListener(new MouseListener(){public void mouseDoubleClicked(MouseEvent me){}public void mousePressed(MouseEvent me){anchorX = me.x;anchorY = me.y;me.consume();}public void mouseReleased(MouseEvent me){me.consume();}});conditionLabel.addMouseMotionListener(new MouseMotionListener(){public void mouseDragged(MouseEvent me){dx += me.x - anchorX;dy += me.y - anchorY;anchorX = me.x;anchorY = me.y;Object constraint = connection.getLayoutManager().getConstraint(conditionLabel);if(constraint instanceof MidpointOffsetLocator){((MidpointOffsetLocator) constraint).setOffset(new Point(dx,dy));conditionLabel.revalidate();}me.consume();}@Overridepublic void mouseEntered(MouseEvent me) {// TODO Auto-generated method stub}@Overridepublic void mouseExited(MouseEvent me) {// TODO Auto-generated method stub}@Overridepublic void mouseHover(MouseEvent me) {// TODO Auto-generated method stub}@Overridepublic void mouseMoved(MouseEvent me) {// TODO Auto-generated method stub}});

经过上面三个步骤就大功告成了

热点排行