/**
* copy the given node. the new copy replaces the given one, so you should manipulate the original node, instead of the copy.
* This is useful when in interaction listener, especially.
*/
public void copyNode(RenderableNode node) {
BehaviorTreeData data = new BehaviorTreeData();
data.setRoot(node.getNode());
BehaviorTreeLoader loader = new BehaviorTreeLoader();
ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
try {
loader.save(os, data);
BehaviorTreeData copy = loader.load(null, new ByteArrayInputStream(os.toByteArray()), null, Collections.<URL>emptyList());
Port.OutputPort parent = node.getInputPort().getTargetPort();
copy.createRenderable();
RenderableNode copyRenderable = copy.getRenderableNode(copy.getRoot());
addNode(copyRenderable);
RenderableNode nodeToLayout;
if (parent != null && copyRenderable.getInputPort() != null) {
parent.setTarget(copyRenderable.getInputPort());
nodeToLayout = parent.node;