-
GEF中节点移动时,坐标错误?5
大家好:
我根据教程写了一个简单的GEF程序,在移动节点的时候,节点总是不能正确的移动到新的位置,请大家帮忙看一下:
这个就是节点的EditPart。
public class EllipsePart extends AbstractGraphicalEditPart implements
PropertyChangeListener {
@Override
protected IFigure createFigure() {
EllipseFigure figure = new EllipseFigure();
figure.setLayoutManager(new XYLayout());
return figure;
}
protected void refreshVisuals() {
Ellipse node = (Ellipse) this.getModel();
Point location = node.getLocation();
System.out.println(node+"->location:" + location);
Rectangle rectangle = new Rectangle(location, node.getSize());
((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), rectangle);
}
protected void createEditPolicies() {
}
@Override
public void activate() {
if (isActive()) {
return;
}
super.activate();
((Ellipse) getModel()).addPropertyChangeListener(this);
}
@Override
public void deactivate() {
if (!isActive()) {
return;
}
super.deactivate();
((Ellipse) getModel()).removePropertyChangeListener(this);
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("location"))
refreshVisuals();
}
}
这个是代表整个图的EditPart:
public class DiagramPart extends AbstractGraphicalEditPart implements
PropertyChangeListener {
@Override
protected IFigure createFigure() {
return new DiagramFigure();
}
protected List getModelChildren() {
List children = ((Diagram) getModel()).getChildren();
return children;
}
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.COMPONENT_ROLE, new DiagramLayoutEditPolicy());
}
@Override
public void activate() {
if (isActive()) {
return;
}
super.activate();
((Diagram) getModel()).addPropertyChangeListener(this);
}
@Override
public void deactivate() {
if (!isActive()) {
return;
}
super.deactivate();
((Diagram) getModel()).removePropertyChangeListener(this);
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("children".equals(propertyName)) {
refreshChildren();
}
}
}
DiagramLayoutEditPolicy.java
public class DiagramLayoutEditPolicy extends XYLayoutEditPolicy {
// Abstract methods from ConstrainedLayoutEditPolicy
protected Command createAddCommand(EditPart child, Object constraint) {
return null; // no support for adding
}
protected Command createChangeConstraintCommand(EditPart child,
Object constraint) {
// return a command to move the part to the location given by the
// constraint
System.out.println("old xy:" + ((Ellipse) child.getModel()).getLocation());
System.out.println("new xy:" + ((Rectangle) constraint).getLocation());
MoveCommand locationCommand = new MoveCommand();
locationCommand.setNode((Ellipse) child.getModel());
locationCommand.setLocation(((Rectangle) constraint).getLocation());
return locationCommand;
}
protected Command getCreateCommand(CreateRequest request) {
return null; // no support for creating
}
protected Command getDeleteDependantCommand(Request request) {
return null; // no support for deleting a dependant
}
}
MoveCommand.java
public class MoveCommand extends Command {
private Ellipse node;
private Point newPos;
private Point oldPos;
public void setLocation(Point p) {
this.newPos = p;
}
public void setNode(Ellipse node) {
this.node = node;
}
public String getLabel() {
return "Move Node";
}
public void execute() {
oldPos = this.node.getLocation();
this.node.setLocation(newPos);
System.out.println(node+"->after execute:" + this.node.getLocation());
}
public void undo() {
this.node.setLocation(oldPos);
}
public void redo() {
this.node.setLocation(newPos);
}
}
根据上面的程序,在控制台system out出来的结果是这样的:
old xy:Point(192, 253)
new xy:Point(252, 231)
com.ziscloud.zcdiagram.diagram.Ellipse@9c6201->location:Point(192, 253)
com.ziscloud.zcdiagram.diagram.Ellipse@9c6201->after execute:Point(252, 231)
好像节点EllipsePart中的refreshVisuals方法在MoveCommand中的execute方法先执行,使得在refreshVisuals时,节点的坐标不是最新的,请问这是什么回事啊?2009年6月05日 12:58
目前还没有答案
相关推荐
这是我参考了一些其他资料,自己写的一个GEF示例...1. 在你的Eclipse中要有GEF, Draw2d的包 2. 将此压缩包中的eclipse project引入到你的Eclipse环境中 3. 运行这个插件 4. 看到界面后,点击 Tools -- Open GEF Editor
dudu翻译的GEF中文教程,入门最佳资料。附每章代码。
GEF入门系列,八进制 的GEF入门系列教程, 由社区经作者授权后整理而成GEF(Graphical Editor Framework)是一个图形化编辑框架,它允许开发人员以图形化的方式展示和编辑模型,从而提升用户体验。这样的应用程序有很...
在GEF中property view 页面的实现!介绍了其实现的步骤方法!还结合了实例进行讲解!
这是我自己在学习GEF的时候做的一些总结。 1、GEF中的概念比如Command,Tool,Request等等。 2、GEF中使用到的几种设计模式。 3、GEF中对鼠标键盘事件处理的机制、流程。
GEF入门必读 GEF入门系列 GEF-whole-upload 感谢八进制
GEF(Graphical Editor Framework)是一个图形化编辑框架,它允许开发人员以图形化的方式展示和编辑模型,从而提升用户体验。这样的应用程序有很多,例如:UML类图编辑器、图形化XML编辑器、界面设计工具以及图形化...
GEF入门实例代码2《Eclipse插件开发》中实例
Agenda Start things off What is GEF? GEF Demo Draw2d Overview Example GEF Overview Break Hands-on Activity: Shapes Example
我下的资源的打包,希望有帮助,包括:GEF_Tutorial,GEF实例,入门教程,GEF-whole-upload
RCP GEF 入门教程,从法语班翻译过来的,自认为是比较全面细致的GEF入门教程,配套源码,很有学习价值!!!
GEF简易教程-学习GEF的入门教程,不错的gef入门教程
GEF eclipse 插件
gef 绘图折线的实现方法。 gef API chm 格式
RCP与GEF的课件,简单的介绍了RCP和GEF中的各组件的功能,已经工作流程
GEF: Graphical Editing Framework <br>GEF是一套MVC Framework,它能帮你比较容易的建立图形化的编辑器,V(View)的部分常常是基于SWT的Draw2D,因此Draw2D也看作是GEF的一部分。依赖:org.eclipse.gef***, org...
学习GEF的入门资料,简单地介绍了GEF使用过程中用到的基本类和函数的用法。
GEF.rar GEF.rar GEF.rar
GEF理解之第三部分,学习gef必备文档资料啊,值得下载
GEF理解之第一部分,学习gef必备文档资料啊,值得下载