@Override public void destroy() { if (parent() != null) { parent().remove(this); } setFlag(Flag.DESTROYED, true); }
/** * @return the index into the children array at which the layer was inserted (based on depth). */ public int add(GroupLayer self, L child) { // optimization if we're requested to add a child that's already added GroupLayer parent = child.parent(); if (parent == self) { return findChild(child, child.depth()); } // if this child has equal or greater depth to the last child, we can append directly and avoid // a log(N) search; this is helpful when all children have the same depth int count = children.size(), index; if (count == 0 || children.get(count-1).depth() <= child.depth()) { index = count; } else { // otherwise find the appropriate insertion point via binary search index = findInsertion(child.depth()); } // remove the child from any existing parent, preventing multiple parents if (parent != null) { child.parent().remove(child); } children.add(index, child); child.setParent(self); child.onAdd(); // if this child is active, we need to become active if (child.interactive()) self.setInteractive(true); return index; }