BaNg@taobao

Just Do It!

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  20 Posts :: -1 Stories :: 202 Comments :: 0 Trackbacks
GEF由于偏向的是以图形表达模型,所以图形表达能力一直都没有java2d强,rotation新闻组从2004年就有人陆续不断的提,但是3.5好像 也没有列入,不过社区的力量就是强大,有人了contribute一段支持旋转的代码。我拿到代码之后做了一个例子,由于它的transform不是 draw2d提供的平台相关性transform(如java2d所做的调用windows system api 驱动硬件),所以rotation的效果不是很好,线条有些模糊。



安装:

打开 https://bugs.eclipse.org/bugs/show_bug.cgi?id=117012,将附件下载下来,解压缩放到插件目录 (plugins或者dropins)。由于这是两个fragements,不能直接加到plugin的dependencies,参见 http://bongyee.blogspot.com/2009/02/plug-in-dependencies-depend-on.html提 供的解决办法。

更新代码支持旋转

在GEF中任何特征基本都会在MVC即model, editpart, figure三个层面做改动,rotation也不例外。

1 在model object上加一个属性int rotation_angle记录当前旋转角度,添加get/set方法,且在set方法中触发一个event给对应的editpart。

2 在editpart的createFigure方法中返回一个RotatableRectangleFigure。

3 稍微有点麻烦的就是修改Editpart了。在diagram editpart中安装继承了xylayouteditpolicy的editpolicy都会给child editpart默认安装一个resizableeditpolicy,这样选中一个editpart是就会在figure上出现八个handle,用来 move和resize。如果要支持rotation,覆盖默认的resiableeditpolicy为 RotatableResizableEditPolicy(捐献提供),覆盖方式为:

public class XXDiagramEditPart
{

protected void createEditPolicies() {
.
installEditPolicy(EditPolicy.LAYOUT_ROLE, 
new QQQXYLayoutEditPolicy());

 }

}

public class QQQXYLayoutEditPolicy
{

protected EditPolicy createChildEditPolicy(EditPart child) {
if (child is RotatableChildEditPart)
{
return new RotatableResizableEditPolicy(true){
 旋转命令
protected Command getRotateCommand(
RotatableChangeBoundsRequest request) {
return new RotateCommand(getHost().getModel(), request.getAngleDelta());
}

}
}
}

}

RotateCommand非常简单,execute的时候设置模型的角度 += angleDelta,undo的时候 -= angleDelta。

4 响应模型触发的rotation事件,更新figure。

public class MyRotatableEditPart //register as listener for model changing.
{

public void propertyChange(PropertyChangeEvent evt) {
if (evt is Rotation Event)
{
//更新figure
((RotatableRectangleFigure)getFigure()).setAngle(getModel().getRotationAngle());
}
}


欢迎大家来信msn多多交流
posted on 2009-02-20 11:04 Always BaNg. 阅读(2516) 评论(4)  编辑  收藏 所属分类: JavaEclipse

Feedback

# re: GEF社区捐献的一个图形旋转(Rotation)的例子 2009-02-20 13:33 jeasonzhao
貌似不错的样子,关注一下了  回复  更多评论
  

# re: GEF社区捐献的一个图形旋转(Rotation)的例子 2009-07-15 22:23 madapple
你好。我最近也在做gef方方面的东西,碰到了和你一样旋转的需求,很兴奋看到了你帖子。能不能发一份示例代码给我呢?谢谢  回复  更多评论
  

# re: GEF社区捐献的一个图形旋转(Rotation)的例子 2013-11-28 16:59 hustgaobo
楼主 https://bugs.eclipse.org/bugs/show_bug.cgi?id=117012链接为何错误?能否赐教旋转问题  回复  更多评论
  

# re: GEF社区捐献的一个图形旋转(Rotation)的例子 2013-11-29 20:56 hustgaobo
@madapple你好,你的gef旋转问题有了解决方法吗?我正在做这个,能否赐教
  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: