GraphStream Users

Archives de la liste Aide


Re: Retrieving Mouse Clicks


Chronologique Discussions 
  • From: Stefan Balev <stefan.balev AT gmail.com>
  • To: graphstream-users AT litislab.fr
  • Subject: Re: Retrieving Mouse Clicks
  • Date: Tue, 28 May 2013 23:57:47 +0200

Hi,

You can put a Thread.sleep() call inside the loop. This will considerably reduce the CPU usage without a perceptible delay for the user.

Hope this helps,

--
Stefan

Le 28 mai 2013 23:44, "Sebastian Bock" <sebastian.bock AT bluewin.ch> a écrit :
Hi there

Just a question to the example from the graphstream site. In the following example a while(true)-loop is used and AFAIK the pump() method is non blocking. This results in a loop which causes a 100% CPU usage.

Is this a normal behavior? Are there any other ways to retrieve mouse clicks without 100% CPU usage?

Thank you in advance
Sebastian

Example:
public class Clicks implements ViewerListener {
    protected boolean loop = true;
 
    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 occurred in the viewer thread inside
        // our thread.
 
        while(loop) {
            fromViewer.pump();
        }
    }
 
    
...



Archives gérées par MHonArc 2.6.16.

Top of page