graph - 在 Graphstream 中检索鼠标点击

标签 graph mouseevent java graphstream

由于我找不到任何具体的地方来讨论这个问题,所以我想我应该在这里发帖...... 我正在使用 graphstream 1.1 ( http://graphstream-project.org/ )(一个用于 java 的图形可视化库)来开发数据可视化工具。我需要检索节点上的鼠标点击来显示相关数据,但是在遵循库教程之后,我仍然不清楚如何执行此操作。使用过这个的人可以帮助我提供更直接的答案吗?我正在关注的教程位于:

http://graphstream-project.org/doc/Tutorials/Graph-Visualisation_1.0/#retrieving-mouse-clicks-on-the-viewer

public class Clicks implements ViewerListener {
    protected boolean loop;

    public static void main(String args[]) {
        new Clicks();
    }
    public Clicks() {
    // We do as usual to display a graph. This
    // connect the graph outputs to the viewer.
    // The viewer is a sink of the graph.
        Graph graph = new SingleGraph("Clicks");
        Viewer viewer = graph.display();

    // The default action when closing the view is to quit
    // the program.
        viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.HIDE_ONLY);

    // We connect back the viewer to the graph,
    // the graph becomes a sink for the viewer.
    // We also install us as a viewer listener to
    // intercept the graphic events.
        ViewerPipe fromViewer = viewer.newViewerPipe();
        fromViewer.addViewerListener(this);
        fromViewer.addSink(graph);

    // Then we need a loop to wait for events.
    // In this loop we will need to call the
    // pump() method to copy back events that have
    // already occured in the viewer thread inside
    // our thread.

        while(loop) {
            fromViewer.pump();
        }
    }

    viewClosed(String id) {
        loop = false;
    }

    buttonPushed(String id) {
        System.out.println("Button pushed on node "+id);
    }

    buttonReleased(String id) {
        System.out.println("Button released on node "+id);
    }
}

最佳答案

刚刚解决了!我向他们的邮件组发送了一封电子邮件。网站上的教程代码缺少一些信息。这三个函数需要是 public void,并且必须添加其他“导入”:

import org.graphstream.ui.swingViewer.Viewer;
import org.graphstream.ui.swingViewer.ViewerListener;
import org.graphstream.ui.swingViewer.ViewerPipe;

关于graph - 在 Graphstream 中检索鼠标点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16671143/

相关文章:

java - 如何将纬度和经度从数据库传递到 Google Maps Activity

java - 如何获取存储在枚举中的引用?

algorithm - 在非退化梯形中寻找全局最短路径

r - ggplot - 在折线图的 x 轴上有组

qt - 如果鼠标在鼠标释放前没有移动,则在 Qt 5 中获取鼠标放置事件

Java Swing : Extended jpanel class will not brighten upon repainting.

wpf - 如何在不使用代码的情况下处理 WPF Datagrid 双击

java - 如何在java中扩展以下API函数而不导致二义性

javascript - 原型(prototype): Why does modifying "child" object instance also modifies "parent" object instance?

javascript - 如何在 D3.js 强制布局中链接来自 json 数据的额外属性?