Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1017 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Graphe par Graphstream

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Graphe par Graphstream

n°2216174
ense29
Etudiant
Posté le 15-01-2014 à 14:45:24  profilanswer
 

Salut;
je travail par la lib Graphstream pour la création d'un graphe et l'afficher dans un JPanel,mais quand j'ai  modifier le graphe et je l'affiche à nouveau j'ai toujours le premier graphe sa change pas malgré que le graphe est modifié (en mémoire ).
voila le code pour la création du graphe initial :

Code :
  1. Graph g =new SingleGraph("graphe" );
  2. g.addNode("N1" );
  3. g.addNode("N2" );
  4. g.addEdge("N1N2","N1","N2" );
  5. JPanel pane1 = new JPanel();
  6. Viewer vue = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
  7. vue.enableAutoLayout();
  8. View view = vue.addDefaultView(false);
  9. pane1.setLayout(new BorderLayout());
  10. pane1.add(view,BorderLayout.CENTER);
  11. tab.addTab("graphe", pane1);


et pour changer le graphe par Click bouton je fait le même code seulement la partie de la création du graphe qui change,j'ai pas trouver exactement le problème. merci de votre aide.


---------------
Merci;
mood
Publicité
Posté le 15-01-2014 à 14:45:24  profilanswer
 

n°2216263
honrisse
Posté le 16-01-2014 à 08:05:36  profilanswer
 

ense29 a écrit :

Salut;
je travail par la lib Graphstream pour la création d'un graphe et l'afficher dans un JPanel,mais quand j'ai  modifier le graphe et je l'affiche à nouveau j'ai toujours le premier graphe sa change pas malgré que le graphe est modifié (en mémoire ).
voila le code pour la création du graphe initial :

Code :
  1. Graph g =new SingleGraph("graphe" );
  2. g.addNode("N1" );
  3. g.addNode("N2" );
  4. g.addEdge("N1N2","N1","N2" );
  5. JPanel pane1 = new JPanel();
  6. Viewer vue = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
  7. vue.enableAutoLayout();
  8. View view = vue.addDefaultView(false);
  9. pane1.setLayout(new BorderLayout());
  10. pane1.add(view,BorderLayout.CENTER);
  11. tab.addTab("graphe", pane1);


et pour changer le graphe par Click bouton je fait le même code seulement la partie de la création du graphe qui change,j'ai pas trouver exactement le problème. merci de votre aide.


 
Salut.
Je ne suis pas sûr d'avoir bien compris le problème. Si le problème est d'actualiser l'affichage après modification du graphe après appuie sur un bouton, voila un bout de code qui le fait :

Code :
  1. package gui;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.util.Random;
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10. import javax.swing.SwingUtilities;
  11. import org.graphstream.graph.Graph;
  12. import org.graphstream.graph.implementations.SingleGraph;
  13. import org.graphstream.ui.swingViewer.View;
  14. import org.graphstream.ui.swingViewer.Viewer;
  15. /**
  16. *  
  17. * @see http://graphstream-project.org/med [...] html#/home
  18. * @see http://graphstream-project.org/med [...] html#/home
  19. * @see http://graphstream-project.org/doc [...] ation_1.0/
  20. * @see http://forum.hardware.fr/hfr/Progr [...] 1174_1.htm
  21. *
  22. */
  23. public class Main {
  24. private static int cpt = 1;
  25. private static Random random = new Random();
  26. public static void createAndShowGui() {
  27.  JFrame f = new JFrame("GraphStream Window" );
  28.  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29.     final Graph g = new SingleGraph("graphe" );
  30.     g.addNode("N0" );
  31.     g.addNode("N1" );
  32.     g.addEdge("N0N1","N0","N1" );
  33.     g.addAttribute("ui.quality" );
  34.     g.addAttribute("ui.antialias" );
  35.     g.addAttribute("ui.stylesheet", "edge { fill-color: grey; }" );
  36.    
  37.     JPanel panel1 = new JPanel();
  38.     Viewer vue = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
  39.     vue.enableAutoLayout();
  40.    
  41.     View view = vue.addDefaultView(false);
  42.     panel1.setLayout(new BorderLayout());
  43.     panel1.add(view, BorderLayout.CENTER);
  44.    
  45.     JButton button = new JButton("Add random node" );
  46.     button.addActionListener(new ActionListener() {
  47.   @Override
  48.   public void actionPerformed(ActionEvent arg0) {
  49.    cpt++;
  50.    int randomNode = random.nextInt(cpt);
  51.    g.addNode("N" + String.valueOf(cpt));
  52.       g.addEdge("N" + String.valueOf(randomNode) + "N" + String.valueOf(cpt),
  53.         "N" + String.valueOf(randomNode), "N" + String.valueOf(cpt));
  54.       g.addAttribute("ui.screenshot", "screenshot.png" );
  55.   }
  56.  });
  57.    
  58.     JPanel panel2 = new JPanel();
  59.     panel2.add(button);
  60.     f.add("Center", panel1);
  61.     f.add("South", panel2);
  62.    
  63.     f.setMinimumSize(new Dimension(640, 480));
  64.     f.setSize(640, 480);
  65.     f.setLocationRelativeTo(null);
  66.     f.setVisible(true);
  67. }
  68. public static void main(String[] args) {
  69.  SwingUtilities.invokeLater(new Runnable() {
  70.   @Override
  71.   public void run() {
  72.    createAndShowGui();
  73.   }
  74.  });
  75. }
  76. }


 
http://hfr-rehost.dev.syn.fr/thumb/self/3b6142433359dbbba1d420c0b0a1e5786d9ccff2.png

n°2216269
ense29
Etudiant
Posté le 16-01-2014 à 09:43:19  profilanswer
 

Premièrement merci;
ce que je veut faire est à chaque clic du bouton je réinitialise mon graphe et je créer un nouveau,mais l'affichage n'est pas actualisé.


---------------
Merci;
n°2216305
honrisse
Posté le 16-01-2014 à 11:38:02  profilanswer
 

ense29 a écrit :

Premièrement merci;
ce que je veut faire est à chaque clic du bouton je réinitialise mon graphe et je créer un nouveau,mais l'affichage n'est pas actualisé.


 
Quelque chose comme ça peut être :

Code :
  1. package gui;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.SwingUtilities;
  10. import org.graphstream.graph.Graph;
  11. import org.graphstream.graph.implementations.SingleGraph;
  12. import org.graphstream.ui.swingViewer.View;
  13. import org.graphstream.ui.swingViewer.Viewer;
  14. public class Main2 extends JFrame {
  15. public Graph graph;
  16. public JPanel panel1;
  17. public boolean flipValue;
  18. public Main2() {
  19.  super("GraphStream Window" );
  20.  flipValue = false;
  21.  graph = new SingleGraph("graph" );
  22.  initComponents();
  23.  setMinimumSize(new Dimension(640, 480));
  24.  setSize(640, 480);
  25.  setLocationRelativeTo(null);
  26.  setVisible(true);
  27. }
  28. private void initComponents() {
  29.  setDefaultCloseOperation(EXIT_ON_CLOSE);
  30.  graph.addNode("N0" );
  31.  graph.addNode("N1" );
  32.  graph.addEdge("N0N1","N0","N1" );
  33.    
  34.     panel1 = new JPanel();
  35.     Viewer vue = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
  36.     vue.enableAutoLayout();
  37.    
  38.     View view = vue.addDefaultView(false);
  39.     panel1.setLayout(new BorderLayout());
  40.     panel1.add(view, BorderLayout.CENTER);
  41.    
  42.     JButton button = new JButton("Flip graph" );
  43.     button.addActionListener(new ActionListener() {
  44.   @Override
  45.   public void actionPerformed(ActionEvent arg0) {
  46.    flipValue = !flipValue;
  47.    if(flipValue) {
  48.     graph = new SingleGraph("tutorial 1" );
  49.        graph.setStrict(false);
  50.        graph.setAutoCreate(true);
  51.        graph.addEdge("AB", "A", "B" );
  52.        graph.addEdge("BC", "B", "C" );
  53.        graph.addEdge("CA", "C", "A" );
  54.        graph.addEdge("AD", "A", "D" );
  55.        graph.addEdge("DE", "D", "E" );
  56.        graph.addEdge("DF", "D", "F" );
  57.        graph.addEdge("EF", "E", "F" );
  58.    } else {
  59.     graph = new SingleGraph("graph" );
  60.     graph.addNode("N0" );
  61.     graph.addNode("N1" );
  62.     graph.addEdge("N0N1","N0","N1" );
  63.    }
  64.      
  65.       Viewer vue = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
  66.       vue.enableAutoLayout();
  67.      
  68.       View view = vue.addDefaultView(false);
  69.       panel1.removeAll();
  70.       panel1.add(view, BorderLayout.CENTER);
  71.       validate();
  72.   }
  73.  });
  74.    
  75.     JPanel panel2 = new JPanel();
  76.     panel2.add(button);
  77.     add("Center", panel1);
  78.     add("South", panel2);
  79. }
  80. public static void main(String[] args) {
  81.  SwingUtilities.invokeLater(new Runnable() {
  82.   @Override
  83.   public void run() {
  84.    new Main2();
  85.   }
  86.  });
  87. }
  88. }

n°2216321
ense29
Etudiant
Posté le 16-01-2014 à 14:30:18  profilanswer
 

merci;votre code marche trop bien sauf que il ne reconnait pas validate() que j'ai remplacer par revalidate(), mais j'ai un dernier soucis est que quand le boutton sur lequel je clic pour créer mon nouveau graphe est dans une autre classe sa marche pas.


---------------
Merci;
n°2216609
ense29
Etudiant
Posté le 19-01-2014 à 14:01:00  profilanswer
 

c'est résolu j'avait un probleme dans l'instanciation,merci beaucoup votre aide ma été très utile.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Graphe par Graphstream

 

Sujets relatifs
Rajouter des series en boucles Graphe excel.[Résolu]listes chainées et graphe
graphe a partir d'excel par VBAAffichage optimisé d'un graphe de dépendances
graphe d'objetmatrice à partir d'un fichier ( module graphe)
[Graphe] Affecter une même valeur au nœuds reliés par un chemin[Algo] Abstraction de graphe et algo.
Dessiner graphe via un programme C++Modélisation d'un gestionnaire de données en graphe.
Plus de sujets relatifs à : Graphe par Graphstream


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR