//Recursively find the last child and separate it public void Unpin() { ShapeGraphic tempChild = childShapeGraphic; ShapeGraphic tempParent = parentShapeGraphic; childShapeGraphic = new ShapeGraphic(); parentShapeGraphic = new ShapeGraphic(); childShapeGraphic = null; parentShapeGraphic = null; if (tempChild != null) { if (tempParent == null) { tempChild.removeParent(); } else { tempChild.giveParent(tempParent); } } if (tempParent != null) { if (tempChild == null) { tempParent.removeChild(); } else { tempParent.giveChild(tempChild); } } }
//Recursively find the child who doesn't have a child yet public void Pin(ShapeGraphic childToPin) { if (childShapeGraphic == null) { //Find the highest parent in the child graphic while (true) { if (childToPin.hasParent()) { childToPin = childToPin.getParent(); } else { break; } } childShapeGraphic = childToPin; childToPin.giveParent(this); } else { childShapeGraphic.Pin(childToPin); } }