IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

2D Java Discussion :

[JUNG]Problème affichage circle layout


Sujet :

2D Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Doctorante
    Inscrit en
    Mai 2007
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Doctorante

    Informations forums :
    Inscription : Mai 2007
    Messages : 25
    Par défaut [JUNG]Problème affichage circle layout
    Bonjour à tous,

    Je suis en train de créer un graphe avec Jung, que j'aimerais afficher grâce à un CircleLayout. Tout se passe bien jusqu'à l'affichage, puisque tous mes sommets et mes liens se trouvent superposés en haut à gauche de ma fenêtre. Ayant essayé avec les autres layout de Jung, il se trouve que seul le DAGLayout me donne un affichage "normal". Tous les autres me produise la même superposition en haut à gauche. Voici le code de création de mon graphe. Est-ce que quelqu'un aurait une idée ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
     
    public class	ContactView extends JFrame {
     
    	private Graph effectiveGraph;
    	private Graph authGraph;
    	private Collection<String> allVertices;
    	private Collection<String> allEdges;
    	private JFrame jf; 
    	DAGLayout<String,String> layoutEffectiveGraphe;
    	CircleLayout<String,String> layoutAuthGraph;
    	BasicVisualizationServer<String,String> effectiveVv;
    	BasicVisualizationServer<String,String> authVv;
     
    	JPanel authPanel;
    	JPanel effectivePanel;
    	JTabbedPane mainPanel;
     
     
    	public ContactView(String title, String agentPath, String resPath){
     
    		addWindowListener(new WindowAdapter() {
    			public void	windowClosing(WindowEvent e) { end(); }
    		});
     
    		effectiveGraph = new DirectedSparseGraph<String,String>();
    		authGraph = new DirectedSparseGraph<String,String>();
     
    		layoutEffectiveGraphe = new DAGLayout(effectiveGraph);
    		layoutEffectiveGraphe.setSize(new Dimension(500,500));
     
    		layoutAuthGraph = new CircleLayout(authGraph);
    		layoutAuthGraph.setSize(new Dimension(500,500));
     
    		authGraph.addVertex("contact1");
    		authGraph.addVertex("contact2");
    		authGraph.addVertex("contact3");
    		authGraph.addVertex("contact4");
     
    		authGraph.addEdge("lien1", "contact1", "contact2");
    		authGraph.addEdge("lien2", "contact2", "contact4");
    		authGraph.addEdge("lien3", "contact1", "contact4");
    		authGraph.addEdge("lien4", "contact1", "contact3");
    		authGraph.addEdge("lien5", "contact3", "contact1");
     
    		effectiveVv = new BasicVisualizationServer(layoutEffectiveGraphe);
     
    		effectiveVv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());	
    		effectiveVv.setBackground(Color.WHITE);
     
    		authVv = new BasicVisualizationServer(layoutAuthGraph);
     
    		authVv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());	
    		authVv.setBackground(Color.WHITE);
     
     
    		/*Initialisation GUI*/
    		jf = new JFrame(title);
    		jf.setSize(800, 600);	
    		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    		mainPanel = new JTabbedPane();
     
    		authPanel = new JPanel();
    		effectivePanel = new JPanel();
     
    		effectivePanel.setBackground(Color.WHITE);
    		effectivePanel.add(effectiveVv);
     
    		authPanel.setBackground(Color.WHITE);
    		authPanel.add(authVv);
     
    		mainPanel.addTab("Authorized contacts", authPanel);
    		mainPanel.addTab("Effective contacts", effectivePanel);
     
    		jf.getContentPane().add(mainPanel);
    		jf.setVisible(true);
     
    	}
    }

    Pour l'instant, seul le authGraph est "rempli", mais le soucis est le même avec effectiveGraph.

    Merci d'avance.

  2. #2
    Membre averti
    Femme Profil pro
    Doctorante
    Inscrit en
    Mai 2007
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Doctorante

    Informations forums :
    Inscription : Mai 2007
    Messages : 25
    Par défaut
    Bon après quelques recherches, j'ai réussi à obtenir un graphe digne de ce nom avec ce code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
     
    public class	ContactView extends JFrame implements INaomiProcess {
     
    	private ISender	sender = null;
    	private Graph<String, String> effectiveGraph;
    	private Graph<String, String> authGraph;
    	private Collection<String> allVertices;
    	private Collection<String> allEdges;
    	private JFrame jf; 
    	Layout<String,String> layoutEffectiveGraphe;
    	Layout<String,String> layoutAuthGraph;
    	BasicVisualizationServer<String,String> effectiveVv;
    	BasicVisualizationServer<String,String> authVv;
     
    	JPanel authPanel;
    	JPanel effectivePanel;
    	JTabbedPane mainPanel;
     
     
    	public ContactView(String title, String agentPath, String resPath){
     
    	authGraph = new DirectedSparseGraph<String, String>();
    	effectiveGraph = new DirectedSparseGraph<String, String>();
    	// Create some MyNode objects to use as vertices
    	String n1 = new String("1"); String n2 = new String("2"); String n3 = new String("3");
    	String n4 = new String("4"); String n5 = new String("5"); // note n1-n5 declared elsewhere.
    	// Add some directed edges along with the vertices to the graph
    	authGraph.addEdge(new String("bouh"),n1, n2, EdgeType.DIRECTED); // This method
    	authGraph.addEdge(new String("bouh1"),n2, n3, EdgeType.DIRECTED);
    	authGraph.addEdge(new String("bouh2"), n3, n5, EdgeType.DIRECTED);
    	authGraph.addEdge(new String("bouh3"), n5, n4, EdgeType.DIRECTED); // or we can use
    	authGraph.addEdge(new String("bouh4"), n4, n2); // In a directed graph the
    	authGraph.addEdge(new String("bouh5"), n3, n1); // first node is the source
    	authGraph.addEdge(new String("bouh6"), n2, n5);// and the second the destination
     
    	effectiveGraph.addEdge(new String("bouh"),n1, n2, EdgeType.DIRECTED); // This method
    	effectiveGraph.addEdge(new String("bouh1"),n2, n3, EdgeType.DIRECTED);
    	effectiveGraph.addEdge(new String("bouh2"), n3, n5, EdgeType.DIRECTED);
    	effectiveGraph.addEdge(new String("bouh3"), n5, n4, EdgeType.DIRECTED); // or we can use
    	effectiveGraph.addEdge(new String("bouh4"), n4, n2); // In a directed graph the
    	effectiveGraph.addEdge(new String("bouh5"), n3, n1); // first node is the source
    	effectiveGraph.addEdge(new String("bouh6"), n2, n5);// and the second the destination
     
     
    	layoutAuthGraph = new CircleLayout(authGraph);
    	layoutAuthGraph.setSize(new Dimension(300,300));
    	authVv = new BasicVisualizationServer<String, String>(layoutAuthGraph);
    	authVv.setPreferredSize(new Dimension(350,350));
     
    	authPanel = new JPanel();
    	authPanel.add(authVv);
     
    	layoutEffectiveGraphe = new CircleLayout(authGraph);
    	layoutEffectiveGraphe.setSize(new Dimension(300,300));
    	effectiveVv = new BasicVisualizationServer<String, String>(layoutAuthGraph);
    	effectiveVv.setPreferredSize(new Dimension(350,350));
     
    	effectivePanel = new JPanel();
    	effectivePanel.add(effectiveVv);
     
    	mainPanel = new JTabbedPane();
    	mainPanel.addTab("Authorized links", authPanel);
    	mainPanel.addTab("Effective links", effectivePanel);
     
     
    	// Set up a new stroke Transformer for the edges
    	float dash[] = {10.0f};
    	final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
    	BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
    	Transformer<String, Stroke> edgeStrokeTransformer =
    	new Transformer<String, Stroke>() {
    	public Stroke transform(String s) {
    	return edgeStroke;
    	}
    	};
     
    	authVv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    	authVv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    	authVv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    	effectiveVv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    	effectiveVv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    	effectiveVv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    	JFrame frame = new JFrame("Simple Graph View 2");
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frame.getContentPane().add(mainPanel);
    	frame.pack();
    	frame.setVisible(true);
     
     
     
    	}

    Je ne sais pas pourquoi ça marche, mais ça marche (si quelqu'un me m'expliquer...)
    A présent, j'ai créé une fonction pour ajouter des points à authGraph :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    public void addAuthContact(String name, String contact) {
     
    		String n1 = new String(name);
    		String n2 = new String(contact);
    		authGraph.addEdge(new String(name + " : " + contact),n1, n2);
    	}
    Et les points ajoutés ainsi continuent à s'afficher en haut à gauche, alors que les autres sont correctement affichés...
    Personne n'a d'idée alors ?

  3. #3
    Membre averti
    Femme Profil pro
    Doctorante
    Inscrit en
    Mai 2007
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Doctorante

    Informations forums :
    Inscription : Mai 2007
    Messages : 25
    Par défaut
    J'ai fini par trouver ! Il semble qu'il y ait une petite "erreur" ou oubli dans la source du CircleLayout de Jung. A croire qu'ils n'ont pas pensé à l'ajout dynamique de nœuds. Lors du setSize(), il effectue automatiquement un initialise, dont voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    public void initialize() 
    	{
    		Dimension d = getSize();
     
    		if (d != null) 
    		{
    		    if (vertex_ordered_list == null) 
    		        setVertexOrder(new ArrayList<V>(getGraph().getVertices()));
     
    			double height = d.getHeight();
    			double width = d.getWidth();
     
    			if (radius <= 0) {
    				radius = 0.45 * (height < width ? height : width);
    			}
     
    			int i = 0;
    			for (V v : vertex_ordered_list)
    			{
    				Point2D coord = transform(v);
     
    				double angle = (2 * Math.PI * i) / vertex_ordered_list.size();
     
    				coord.setLocation(Math.cos(angle) * radius + width / 2,
    						Math.sin(angle) * radius + height / 2);
     
    				CircleVertexData data = getCircleData(v);
    				data.setAngle(angle);
    				i++;
    			}
    		}
    	}

    Le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    if (vertex_ordered_list == null) 
    		        setVertexOrder(new ArrayList<V>(getGraph().getVertices()));
    n'est jamais rafraichi, puisqu'après le premier initialize, vertex_ordered_list n'est plus à null.
    Pour contourner le problème, il faut rajouter, avec mes variables,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    layoutEffectiveGraphe.setVertexOrder(new ArrayList<String>(effectiveGraph.getVertices()));
    	layoutEffectiveGraphe.initialize();
    après chaque ajout de noeuds.

    J'espère que ça pourra en aider certains.

  4. #4
    Membre éclairé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2007
    Messages
    236
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Février 2007
    Messages : 236
    Par défaut
    Bonjour,

    J'ai eu du mal à installer Jung sous Netbeans. J'ai ajouté toutes les dépendances mais il ne trouve quelques classes comme :

    import edu.uci.ics.jung.graph.SparseMultigraph;
    import edu.uci.ics.jung.visualization.BasicVisualizationServer;

    Avez-vous une idée ? sinon comment avez-vous fait pour bien l'installer ?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'affichage de layout
    Par moumous24 dans le forum Débuter
    Réponses: 3
    Dernier message: 12/04/2011, 13h47
  2. Problème affichage avec les Layouts
    Par TWEESTY dans le forum Composants graphiques
    Réponses: 4
    Dernier message: 18/02/2011, 01h01
  3. [Struts-Layout] problème affichage CSS d'onglets
    Par valkeke dans le forum Struts 1
    Réponses: 3
    Dernier message: 19/11/2009, 17h49
  4. Réponses: 3
    Dernier message: 15/06/2007, 11h27
  5. [DOS] Problème affichage de DOS dans un Memo
    Par Pedro dans le forum API, COM et SDKs
    Réponses: 9
    Dernier message: 25/06/2004, 13h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo