Bonjour,

J'aimerais dessiner un graphe à partir d'un fichier XML, donc j'ai utilisé l'API JGraph

Voici le contenu de fichier XML
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
<Annotation>
<annotateur>
<name>Torjmen</name>
<surname>Mouna</surname>
<date>27-03-2014</date>
</annotateur>
<concepts>
<concept>Person</concept>
<concept>Actor</concept>
</concepts>
<triplets>
<triplet>
<subject>
<value>Willard Christopher</value>
<instanceOf>Person</instanceOf>
</subject>
<predicate>equivalent</predicate>
<object>
<value>Will" Smith Jr</value>
<instanceOf>Actor</instanceOf>
</object>
</triplet>
</triplets>
</Annotation>
Et mon code Java
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
92
93
94
95
96
97
98
99
import java.awt.BorderLayout;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
 
public class Final2 {
 
        public static Object valSubject =null;
        public static Object valInstance =null;
 
        public Final2 () {}
 
        public JFrame frame;
 
        /** Pour éviter un warning venant du JFrame */
        private static final long serialVersionUID = -8123406571694511514L;
 
        public void dessin(String filename) throws SAXException, IOException, ParserConfigurationException {
 
            frame = new JFrame();
 
            JPanel contentPane;
 
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 320);
            frame.setVisible(true);
            frame.setBounds(100, 100, 550, 400);
            contentPane = new JPanel();
            contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            contentPane.setLayout(new BorderLayout(0, 0));
            mxGraph graph = new mxGraph();
            Object parent = graph.getDefaultParent();
 
            graph.getModel().beginUpdate();
 
            File nomf = new File(filename);
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(nomf);
            doc.getDocumentElement().normalize();
 
            //System.out.println( doc.getDocumentElement().getNodeName());
            //NodeList nodes = doc.getElementsByTagName("triplet");
            try {
                double h =  80;
                double l =  80;
 
                NodeList concepts = doc.getElementsByTagName("concepts");
                for (int i = 0; i < concepts.getLength(); i++){
 
                    Node nodeC=concepts.item(i);
 
                    if (nodeC.getNodeType() == Node.ELEMENT_NODE) {
                        Element elementC =(Element) nodeC ;
                        Object composantconcept=graph.insertVertex(parent,null, getValue("concept",elementC),h,l, 80,30, mxConstants.STYLE_SHAPE + "="+ mxConstants.SHAPE_ELLIPSE);
                        graph.insertEdge(parent, null,"hello" , composantconcept, composantconcept);
 
                        l=l+60;
                        h=h+60;     
                    }
               }
          }  catch (Exception ex) {
              ex.printStackTrace();
          }
 
          finally {
            graph.getModel().endUpdate();
 
            mxGraphComponent graphComponent = new mxGraphComponent(graph);
            frame.add(graphComponent);
         }
     }
 
     private static String getValue(String tag, Element element) { 
         NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
         Node node = (Node) nodes.item(0);
         return node.getNodeValue();
     }
 
     public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException {
         System.out.print("bonjour");
         Final2 frame = new Final2();
         frame.dessin("C:/Desktop/copie.xml");
     }
}
Ainsi que le format de graphe que je désire obtenir
Nom : 10358025_654572211298512_1552520570_n.jpg
Affichages : 477
Taille : 30,0 Ko
Après exécution, j'obtiens une frame vide.

Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?

Merci d'avance pour votre aide.