/** Copy the given graph and make the nodes/edges in the copied
* graph point to the nodes/edges in the original.
*/
protected Object copyComposite(Object origComposite) {
LayoutTarget target = getLayoutTarget();
GraphModel model = target.getGraphModel();
diva.graph.basic.BasicGraphModel local = getLocalGraphModel();
Object copyComposite = local.createComposite(null);
HashMap map = new HashMap();
// Copy all the nodes for the graph.
for (Iterator i = model.nodes(origComposite); i.hasNext();) {
Object origNode = i.next();
if (target.isNodeVisible(origNode)) {
Rectangle2D r = target.getBounds(origNode);
LevelInfo inf = new LevelInfo();
inf.origNode = origNode;
inf.x = r.getX();
inf.y = r.getY();
inf.width = r.getWidth();
inf.height = r.getHeight();
Object copyNode = local.createNode(inf);
local.addNode(this, copyNode, copyComposite);
map.put(origNode, copyNode);
}
}
// Add all the edges.
Iterator i = GraphUtilities.partiallyContainedEdges(origComposite,
model);
while (i.hasNext()) {
Object origEdge = i.next();
Object origTail = model.getTail(origEdge);
Object origHead = model.getHead(origEdge);
if ((origHead != null) && (origTail != null)) {
Figure tailFigure = (Figure) target
.getVisualObject(origTail);
Figure headFigure = (Figure) target
.getVisualObject(origHead);
// Swap the head and the tail if it will improve the
// layout, since LevelLayout only uses directed edges.
if (tailFigure instanceof Terminal) {