读书人

gef直接编者的思路

发布时间: 2012-11-06 14:07:00 作者: rapoo

gef直接编辑的思路

拦截编辑的事件,在同样的位置,同样的大小,用Text来覆盖。

?

首先需要在原有的基础上多加两个类

EDirectEditManager ? 直接编辑管理类?

ECellEditorLocator ? 单元格的编辑的位置?

?

public class ECellEditorLocator ?implements CellEditorLocator{

?

private IFigure figure;

public ECellEditorLocator(IFigure figure)

{

this.figure=figure;

}

@Override

public void relocate(CellEditor celleditor) {

更具figure的位置大小,显示 widget Text。其实就是用Text 来覆盖 Figure。

? ? ? ? ? ? ? ? 这里你也可以显示table,tree都可以。更具你的需要

Text text= (Text) celleditor.getControl();

Rectangle rct= ?figure.getBounds().getCopy();

figure.translateToAbsolute(rct);

text.setBounds(rct.x, rct.y, rct.width, rct.height);

}

?

}

?

?

?

在你需要编辑的part中填写以下代码。

@Override

public void performRequest(Request req) {

if(req.getType().equals(RequestConstants.REQ_DIRECT_EDIT))

{

performDirectEdit();

return;

}

super.performRequest(req);

}

?

private void performDirectEdit()

{

// 关键是这里,。。。,用 ECellEditorLocator ? ?创建EDirectEditManager ? 。并显示 EDirectEditManager .show();

if(directManager==null)

{

directManager=new EDirectEditManager(this, TextCellEditor.class, new ECellEditorLocator(getFigure()));

}

directManager.show();

}

?

?

读书人网 >编程

热点推荐