GraphStream Users

Archives de la liste Aide


RES: GraphStream usage issue


Chronologique Discussions 
  • From: Matheus Silva <matheus.g.unicamp AT gmail.com>
  • To: Bilal Najeeb <bilal.najeeb2011 AT gmail.com>, "graphstream-users AT litislab.fr" <graphstream-users AT litislab.fr>
  • Subject: RES: GraphStream usage issue
  • Date: Mon, 2 May 2016 15:01:37 -0300
  • Importance: normal

Well, after a looooong time searching on the internet and doing some experiments with the code, i could find a way to avoid this issue with this inifiny loop that Bilal is experiencing.

 

At first billal, i saw you were calling the Graphstream class from a Swing Jpanel (or Jframe, doesnt matter...its a swing element) and the graph wasn’t rendering.

 

So, the while loop is intended to be used when you have a sort of algorithm there, any type of manipulation, its what they say on the comments.

 

Well, i’m using JFRAME to resize the view because i could’nt find any reference if it was possible, so here we go.

      

       //call the viewer, using another thread

        viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);

        viewer.enableAutoLayout();

        // in my case, i’m removing the default view, its optional.

        view = viewer.addDefaultView(false);

       

       //add a viewpipe

        fromViewer = viewer.newViewerPipe();

        // and than the clicklistener.

        fromViewer.addViewerListener(new NodeClickListener(fromViewer, view, graph));

       

 

 

The NodeClickListener is just a NodeClickListener implements ViewerListener

Call ViewPiper.pump() on the mouseReleased function, and it will work.

You dont need the loop.

 

De: Matheus Silva
Enviado:segunda-feira, 2 de maio de 2016 14:17
Para: Bilal Najeeb; graphstream-users AT litislab.fr
Assunto: RES: GraphStream usage issue

 

You did the same thing as me, forgot the reply all 😝.

 

Anyways, what i did was this:

SwingWorker sw = new SwingWorker<Void, Void>{

   @Override

    protected Void doInBackground() throws Exception {

        MyGraphClass gf = new MyGraphClass();

        return null;

    }

 

But as i said, it worked, but the user interaction just went away. I’m seeking for someone to help me fix this issue.

Even though the while loop still there.

 

 

Enviado do Email para Windows 10

 

De: Bilal Najeeb
Enviado:segunda-feira, 2 de maio de 2016 13:57
Para: Matheus Silva
Assunto: Re: GraphStream usage issue

 

Removing while loop again wont help ... basically graph is not being displayed what so ever ... making independent project with the given code works ... but when i call the same class from a button event it stops working

 

public class Clicks implements ViewerListener {
         protected boolean loop = true;
         public static void main(String args[]) {
                 new Clicks();
         }
         public Clicks() {
                 Graph graph = new SingleGraph("Clicks");
                 Viewer viewer = graph.display();
                 viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.HIDE_ONLY);
                 ViewerPipe fromViewer = viewer.newViewerPipe();
                 fromViewer.addViewerListener(this);
                 fromViewer.addSink(graph);
                 while(loop) {
                          fromViewer.pump();
                 }
         }
         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);
         }
}

 

On Mon, May 2, 2016 at 8:57 PM, Matheus Silva <matheus.g.unicamp AT gmail.com> wrote:

Well, this behaviour will keep the mouse interaction? As you can see here https://gist.github.com/PlayMa256/689a517504f3f63f03449f38b168d46b i’m using the loop and it blocked the graph rendering. I created a thread and invoked this class within another thread. But the mouse interaction stopped working. Should i remove the while loop from inside of it and invoke as you saying?

 

MyGraphClass g = new MyGraphClass();

 

..?

 

 

 

 

Enviado do Email para Windows 10

 

De: Stefan Balev
Enviado:segunda-feira, 2 de maio de 2016 12:28
Para: graphstream-users AT litislab.fr; Bilal Najeeb
Assunto: Re: GraphStream usage issue

 

Hi,

 

This is not a GraphStream issue. This is the expected behavior when you block the swing thread. Try the following (without using GraphStream) :

 

private void btnGraphStreamActionPerformed(java.awt.event.ActionEvent evt) {

    while(true);

}

 

and you will obtain the same result.

 

Cheers,

 

--

Stefan

 

 

2016-05-02 17:04 GMT+02:00 Bilal Najeeb <bilal.najeeb2011 AT gmail.com>:

Greetings everyone,

 

I am Bilal, a software engineer from Pakistan. First of all i would like to tell you that the graphstream library is admirable, great work.

 

I am currently working on a project in which i have to generate some graphical output and I am using graphstream. From the tutorial given on the website, it is working fine when i make a separate test project in net beans for interactive graph which would respond to click events but when i try to do the same thing in the project I am working on, the graph wont appear just a Jframe and that too even wont close when i click on the cross button. I am pasting my code below kindly help me out. I shall be very great-full to you guys.

 

This is the code of the button click event from another Jframe

 

private void btnGraphStreamActionPerformed(java.awt.event.ActionEvent evt) {                                               

        new Clicks();

    }  

 

 

and this is the code where the graph will actually be made

 

package forms;

import org.graphstream.graph.Graph;

import org.graphstream.graph.implementations.SingleGraph;

import org.graphstream.ui.view.Viewer;

import org.graphstream.ui.view.ViewerListener;

import org.graphstream.ui.view.ViewerPipe;

 

public class Clicks implements ViewerListener{

    protected boolean loop = true;

    public Clicks() {

Graph graph = new SingleGraph("Clicks");

Viewer viewer = graph.display();

viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);

                graph.addNode("A");

                graph.addNode("ch");

graph.addNode("2");

ViewerPipe fromViewer = viewer.newViewerPipe();

fromViewer.addViewerListener(this);

fromViewer.addSink(graph);

while(loop) {

fromViewer.pump();

}

}

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);

}

}

 

kindly reply me as soon as possible.

 

Regards

 

 

 

 

 




Archives gérées par MHonArc 2.6.16.

Top of page