indices.put(part, new Integer(index));
}
protected void clonePart(LogicSubpart oldPart, LogicDiagram newParent, Rectangle newBounds,
List newConnections, Map connectionPartMap, int index) {
LogicSubpart newPart = null;
if (oldPart instanceof AndGate) {
newPart = new AndGate();
} else if (oldPart instanceof Circuit) {
newPart = new Circuit();
} else if (oldPart instanceof GroundOutput) {
newPart = new GroundOutput();
} else if (oldPart instanceof LED) {
newPart = new LED();
newPart.setPropertyValue(LED.P_VALUE, oldPart.getPropertyValue(LED.P_VALUE));
} else if (oldPart instanceof LiveOutput) {
newPart = new LiveOutput();
} else if (oldPart instanceof LogicLabel) {
newPart = new LogicLabel();
((LogicLabel)newPart).setLabelContents(((LogicLabel)oldPart).getLabelContents());
} else if (oldPart instanceof OrGate) {
newPart = new OrGate();
} else if (oldPart instanceof LogicFlowContainer) {
newPart = new LogicFlowContainer();
} else if (oldPart instanceof XORGate) {
newPart = new XORGate();
}
if (oldPart instanceof LogicDiagram) {
Iterator i = ((LogicDiagram)oldPart).getChildren().iterator();
while (i.hasNext()) {
// for children they will not need new bounds
clonePart((LogicSubpart)i.next(), (LogicDiagram)newPart, null,
newConnections, connectionPartMap, -1);
}
}
Iterator i = oldPart.getTargetConnections().iterator();
while (i.hasNext()) {
Wire connection = (Wire)i.next();
Wire newConnection = new Wire();
newConnection.setValue(connection.getValue());
newConnection.setTarget(newPart);
newConnection.setTargetTerminal(connection.getTargetTerminal());
newConnection.setSourceTerminal(connection.getSourceTerminal());
newConnection.setSource(connection.getSource());
Iterator b = connection.getBendpoints().iterator();
Vector newBendPoints = new Vector();
while (b.hasNext()) {
WireBendpoint bendPoint = (WireBendpoint)b.next();
WireBendpoint newBendPoint = new WireBendpoint();
newBendPoint.setRelativeDimensions(bendPoint.getFirstRelativeDimension(),
bendPoint.getSecondRelativeDimension());
newBendPoint.setWeight(bendPoint.getWeight());
newBendPoints.add(newBendPoint);
}
newConnection.setBendpoints(newBendPoints);
newConnections.add(newConnection);
}
if (index < 0) {
newParent.addChild(newPart);
} else {
newParent.addChild(newPart, index);
}
newPart.setSize(oldPart.getSize());
if (newBounds != null) {
newPart.setLocation(newBounds.getTopLeft());
} else {
newPart.setLocation(oldPart.getLocation());
}
// keep track of the new parts so we can delete them in undo
// keep track of the oldpart -> newpart map so that we can properly attach
// all connections.