GraphStream Users

Archives de la liste Aide


Re: Graphe dynamique


Chronologique Discussions 
  • From: guilhelm savin <guilhelm.savin AT gmail.com>
  • To: Emile <emile.duf AT gmail.com>, "users AT graphstream-project.org" <users AT graphstream-project.org>
  • Subject: Re: Graphe dynamique
  • Date: Tue, 18 Dec 2012 16:10:07 +0100

PS: if you do not add coordinates to nodes, think to call viewer.enableAutoLayout() method when creating the viewer.


2012/12/18 guilhelm savin <guilhelm.savin AT gmail.com>
So, this is not a GraphStream problem ....
Just replace your actionPerformed(..) in startListener by this :

public void actionPerformed(ActionEvent arg0) {
Runnable r = new Runnable() {
public void run() {
for (int i = 0; i < parent.graph.getNodeCount() - 1; i++) {
Node node = parent.graph.getNode(i);
Node next = parent.graph.getNode(i + 1);
parent.graph.addEdge(i + "," + i + 1, node, next);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
Thread t = new Thread(r);
t.start();
}

Regards.


2012/12/18 Emile <emile.duf AT gmail.com>
Hi guilhelm,

Here, my little application, there are two objects:
    1: a JFrame that istanciates the graph and the panelConfig
    2: a config JPanel that has one buttons "start".

I want my graph dynamically adds edges. I know this is a problem of threading with swing but i don't find the solution.

Thank you for your help.

Emile

-------------------------

    public MainWindow(){
        graph = new DefaultGraph("mg");
        viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);

        add(viewer.addDefaultView( false ), BorderLayout.CENTER);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(800, 600);
        setVisible(true);


        PanelConfig panelcfg = new PanelConfig(this);
        add(panelcfg, BorderLayout.EAST);
    }

public class PanelConfig extends JPanel{
    private static final long serialVersionUID = 1L;
    JButton boutonStart = new JButton("Start");
    MainWindow parent;

    public PanelConfig (MainWindow parent) {
        this.parent = parent;

        boutonStart.addActionListener(new startListener());
        add(boutonStart);
        add(boutonStop);

    }

    class startListener  implements ActionListener{
        public ViewerPipe fromViewer;
        }


        public void actionPerformed(ActionEvent arg0) {
            for (int i = 0; i < parent.graph.getNodeCount() - 1; i++) {
                Node node = parent.graph.getNode(i);
                Node next = parent.graph.getNode(i+1);
                parent.graph.addEdge(i+","+i+1, node, next);

                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}




--
Guilhelm Savin
PhD Student of Computer Science




--
Guilhelm Savin
PhD Student of Computer Science




Archives gérées par MHonArc 2.6.16.

Top of page