0

我通过 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 类......这对我来说似乎很奇怪......

4

1 回答 1

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)
 }

阿特,

于 2014-05-06T18:53:34.887 回答