graphstream / gs-core

Graphstream core
http://graphstream-project.org/
Other
400 stars 108 forks source link

can not retrieving mouse-clicks in Graphstream #360

Open kiendao515 opened 3 years ago

kiendao515 commented 3 years ago

I try to do the same as the tutorial "Retrieving mouse clicks on the viewer" in graphstream ,I have added some nodes and edges but there is no thing to happen.

`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(); graph.addNode("a"); graph.addNode("b"); graph.addNode("c"); graph.addEdge("ab","a","b"); graph.addEdge("bc","c","b"); // 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 do our work and to wait for events.
    // In this loop we will need to call the
    // pump() method before each use of the graph to copy back events
    // that have already occurred in the viewer thread inside
    // our thread.

    while(loop) {
        fromViewer.pump(); // or fromViewer.blockingPump(); in the nightly builds

        // here your simulation code.

        // You do not necessarily need to use a loop, this is only an example.
        // as long as you call pump() before using the graph. pump() is non
        // blocking.  If you only use the loop to look at event, use blockingPump()
        // to avoid 100% CPU usage. The blockingPump() method is only available from
        // the nightly builds.
    }
}

public void viewClosed(String id) {
    loop = false;
}

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

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

public void mouseLeft(String arg0) {}

public void mouseOver(String arg0) {}`
geert3 commented 3 years ago

I'm also not getting the above basic node click example to work. Also view.findGraphicElementAt() is inaccurate and doesn't find the proper graph node given MouseEvent coordinates. Mostly it returns null. When clicking randomly, it sometimes finds a node but it is never anywhere near the cursor. Any help would be appreciated.

geert3 commented 3 years ago

Seems to be the same as issue 301, i.e. due to Java9+ HDPI settings. Adding -Dsun.java2d.uiScale=100% fixes the bad coordinates but makes the application scale to barely readable font size.

legolie commented 2 years ago

I have the same problem, any solution ?