1
我目前正在開發一個eclipse插件,它使用Zest顯示一棵樹。添加MouseListener到Zest圖
我試着給顯示節點的圖添加一個自定義的MouseListener
,因爲我想添加一個雙擊功能,但是這覆蓋了允許拖動節點的自然存在的功能。
我已經嘗試添加基於Draw2D的拖拽功能,但它沒有奏效。這裏是我嘗試的代碼:
private Point location;
public void mousePressed(MouseEvent me) {
location = me.getLocation();
me.consume();
}
public void mouseReleased(MouseEvent me) {
location = null;
me.consume();
}
public void mouseDragged(MouseEvent me) {
if (location == null) {
return;
}
Point moved= me.getLocation();
if (moved == null) {
return;
}
Dimension offset= moved.getDifference(location);
if (offset.width == 0 && offset.height == 0) {
return;
}
location= moved;
UpdateManager uMgr= figure.getUpdateManager();
LayoutManager lMgr= figure.getLayoutManager();
Rectangle bounds= figure.getBounds();
uMgr.addDirtyRegion(figure.getParent(), bounds);
bounds= bounds.getCopy().translate(offset.width, offset.height);
lMgr.setConstraint(figure, bounds);
figure.translate(offset.width, offset.height);
uMgr.addDirtyRegion(figure.getParent(), bounds);
me.consume();
}
任何人都可以提供我的代碼或解決方法的修復?