GraphStream Users

Archives de la liste Aide


Re: Graph animation problem


Chronologique Discussions 
  • From: Yoann Pigné <yoann.pigne AT gmail.com>
  • To: "graphstream-users AT litislab.fr" <graphstream-users AT litislab.fr>, Stephen Andrasi <andristv94 AT gmail.com>
  • Subject: Re: Graph animation problem
  • Date: Sun, 12 Mar 2017 16:25:59 +0100

Hi Stephen,

I guess the « walking » class is somehow defined in your css file (that you
did not provide).

There are two errors in your code, in the actionPerformed of your button.

First, I guess you have a typo when you change the node attribute the second
time. You might want to set another class than « walking » or maybe you want
the remove that attribute (Node.removeAttribute()).

Second, and it’s a major conceptual flaw, you cannot block the GUI thread
with your « small pause ». When you do that, nothing gets updated in the UI.
So you can’t expect to have the graph change colour or anything.

I understand the « small pause » simulates the time taken by an algorithm,
but again you won’t be able to run the algorithm in the GUI thread **and**
observe GUI modifications at the same time.

The problem is not GraphStream here. You need to properly understand Swing’s
concurrency model before you can go on with your project.

I suggest you go read about this model and about SwingWorkers :
https://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html

Good luck,
Yoann

> Le 11 mars 2017 à 21:24, Stephen Andrasi
> <andristv94 AT gmail.com>
> a écrit :
>
> Hi, my name is Stephen.
>
> I'm working on a project where my task is to make a graph algorithm
> visualizer.
>
> I have a Jbutton at the bottom of the window and above it there is the
> graph.
> I have an "Animate" button to start the algorithm on the graph, but it does
> not
> work.
>
> I want to draw the edges step by step. (I added a little pause)
> What am I doing wrong? :(
>
>
>
> public class EZ{
> private static Graph graph = new SingleGraph("Graph");
>
> public static class MyFrame extends JFrame
> {
> private Viewer viewer = new
> Viewer(graph,Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
> private View view = viewer.addDefaultView(false);
> private JButton button = new JButton("ASD");
> public ViewerPipe pipe = viewer.newViewerPipe();
>
> public MyFrame()
> {
>
> graph.addAttribute("ui.stylesheet", "url('src/style/graph.css')");
> viewer.enableAutoLayout();
> setLayout(new BorderLayout());
> add((Component) view,BorderLayout.CENTER);
> add(button, BorderLayout.AFTER_LAST_LINE);
> setDefaultCloseOperation(EXIT_ON_CLOSE);
>
> button.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent e) {
>
> graph.getNode("A").setAttribute("ui.class",
> "walking");
> pipe.pump();
> long start = new Date().getTime(); // small pause
> while(new Date().getTime() - start < 1000L){}
>
> graph.getNode("A").setAttribute("ui.class",
> "walking");
> pipe.pump();
> }
> });
> }
> }
>
> public static void main(String args[])
> {
> SwingUtilities.invokeLater(new Runnable()
> {
>
> public void run() {
>
> graph.addNode("A").setAttribute("ui.label", "A");
> graph.addNode("B").setAttribute("ui.label", "B");
> graph.addNode("C").setAttribute("ui.label", "C");
> graph.addEdge("AB", "A", "B").setAttribute("ui.label", "1");
> graph.addEdge("BC", "B", "C").setAttribute("ui.label", "6");
> graph.addEdge("CA", "C", "A").setAttribute("ui.label", "2");
>
> MyFrame frame = new MyFrame();
> frame.setSize(500, 500);
> frame.setLocationRelativeTo(null);
> frame.setVisible(true);
> }
> });
> }
> }
>
>
> Greetings,
> Stephen




Archives gérées par MHonArc 2.6.16.

Top of page