java - 将 MouseListener 添加到 Zest Graph

标签 java eclipse eclipse-plugin zest

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

我尝试向显示节点的图形添加自定义 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();
}

任何人都可以为我的代码提供修复或解决方法吗?

最佳答案

在调试可视化项目中,我们添加了一个双击监听器,同时保留了拖动支持。

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

  // double click on nodes
  graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {

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

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

关于java - 将 MouseListener 添加到 Zest Graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379765/

相关文章:

java - 配置pentaho的hdfs-vfs来获取hdfs-site.xml

java - 在状态 abb 之间添加逗号。和地址列表中的邮政编码

java - 从命令行传递数组参数而不是java中的扫描仪

eclipse - m2e Subclipse 连接器错误 - 'bundle org.tigris.subversion.subclipse.core [1.6.0,1.9.0)

java - 如何在 Eclipse 中获取工作区路径?

linux - 多个用户共享时 Linux 上的 Eclipse 行为

java - 如何在运行时从 bean 到 json 排除属性

java - 处理所有未处理的异常

java - Java的四级继承

eclipse - 如何让 Eclipse 解析使用 Maven 2 生成的类?