如何探索JGraphX对象(即找到边和节点)?

时间:2014-04-04 08:59:25

标签: java jgraphx

我通过xml字符串获取图形,所以首先我在mxGraph对象中对其进行转换:

mxGraph newGraph = new mxGraph();
org.w3c.dom.Node node = mxXmlUtils.parseXml(xml);
mxCodec decoder = new mxCodec(node.getOwnerDocument());
decoder.decode(node.getFirstChild(),newGraph.getModel());

现在我想做点什么:

for Edge edge newGraph.getAllEdges()
     System.out.println(edge.src+" "+edge.dst);

然而getallEdges返回Objects而我找不到任何Edge类......我觉得这很奇怪......

1 个答案:

答案 0 :(得分:1)

newGraph.clearSelection(); 
newGraph.selectAll();
Object[] cells = newGraph.getSelectionCells(); //here you have all cells
for (Object c : cells) {
 mxCell cell = (mxCell) c; //cast
 if (cell.isVertex()) { //isVertex
   //todo
 }else{ //is not a vertex, so u can get source and target 
   //todo
   cell.getChildCount(); //Returns the number of child cells. (edges)
   cell.getChildAt(x); //Returns the child at the specified index. (target)
 }

ATT,