首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向Zest图添加MouseListener

向Zest图添加MouseListener
EN

Stack Overflow用户
提问于 2012-07-08 08:27:43
回答 1查看 1.2K关注 0票数 1

我目前正在为eclipse开发一个使用Zest显示树的插件。

我尝试向显示节点的图形添加自定义MouseListener,因为我想添加双击功能,但这会覆盖允许拖动节点的自然呈现功能。

我尝试添加基于Draw2D的拖拽功能,但不起作用。下面是我尝试过的代码:

代码语言:javascript
复制
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();
}

有人能为我的代码提供修复或变通方法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-09 01:46:54

在Debug Visualization项目中,我们添加了一个双击侦听器,同时仍然支持拖动。

我们的代码在http://code.google.com/a/eclipselabs.org/p/debugvisualisation/source/browse/hu.cubussapiens.debugvisualisation/src/hu/cubussapiens/debugvisualisation/views/DebugVisualisationView.java中的第159行

代码语言:javascript
复制
  // double click on nodes
  graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {

          @Override
          public void mouseDoubleClick(MouseEvent e) {
                 toggleOpen.run();
          }
  });

您可以从MouseEvent中读取选定的节点(如果我没有记错的话),也可以检查当前的选择(这是我们在项目中采用的方法)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11379765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档