From eb4013c413a9ad51ea8780eb452cf84bf1c7cfb9 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 18 Dec 2019 18:42:55 +0800 Subject: [PATCH] fix: Group some problem! todo: Group next problem! --- src/main/java/com/yame/Graph.java | 37 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/yame/Graph.java b/src/main/java/com/yame/Graph.java index 8b2ae0b..284171d 100644 --- a/src/main/java/com/yame/Graph.java +++ b/src/main/java/com/yame/Graph.java @@ -10,6 +10,7 @@ import java.util.List; import com.mxgraph.io.mxCodec; import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGeometry; import com.mxgraph.model.mxGraphModel; import com.mxgraph.model.mxICell; import com.mxgraph.model.mxIGraphModel; @@ -59,6 +60,11 @@ public class Graph { groupCell.cell.setConnectable(false); groupCell.cell.setVertex(true); groupCell.isGroup = true; + + mxGeometry geometry = new mxGeometry(); + geometry.add(graph.graph.getGraphBounds()); + groupCell.cell.setGeometry(geometry); + } for (final Object _cell : _cells) { @@ -125,14 +131,13 @@ public class Graph { if(isInGroup) { cloned.cell.setParent(groupCell.cell); mxICell parent = cloned.cell.getParent(); - System.out.println(parent); } } } if (isInGroup) { - cells.add(groupCell); + cells.add(0, groupCell); } return cells; @@ -156,32 +161,44 @@ public class Graph { final List cellCloneds2 = mxCellCloned.clone(g2, isInGroup); - HashMap groupmap = new HashMap(); + HashMap groupmap1 = new HashMap(); cellCloneds1.forEach(cloned -> { mxICell parent = cloned.cell.getParent(); if (parent != null) { - - Object np = groupmap.get(parent.getId()); + + Object np = groupmap1.get(parent.getId()); if(np != null) { - graph.getMXGraph().addCell(cloned.cell, np); + Object add = graph.getMXGraph().addCell(cloned.cell); + ((mxCell)add).setParent((mxCell)np); } else { System.out.println("x"); } } else { Object groupcell = graph.getMXGraph().addCell(cloned.cell); - groupmap.put(cloned.cell.getId(), groupcell); + groupmap1.put(cloned.cell.getId(), groupcell); } }); + HashMap groupmap2 = new HashMap(); cellCloneds2.forEach(cloned -> { - if (cloned.cell.getParent() != null) { - graph.getMXGraph().addCell(cloned.cell, cloned.cell.getParent()); + mxICell parent = cloned.cell.getParent(); + if (parent != null) { + + Object np = groupmap2.get(parent.getId()); + if(np != null) { + Object add = graph.getMXGraph().addCell(cloned.cell); + ((mxCell)add).setParent((mxCell)np); + } else { + System.out.println("x"); + } + } else { - graph.getMXGraph().addCell(cloned.cell); + Object groupcell = graph.getMXGraph().addCell(cloned.cell); + groupmap2.put(cloned.cell.getId(), groupcell); } });