/** * Get the TMA core object that contains a specified PathObject, or null if the object is not contained within a TMA core. * * If the passed object already is a TMACore, it is returned directly. Otherwise, all ancestors are checked. * * @param pathObject * @return */ public static TMACoreObject getAncestorTMACore(final PathObject pathObject) { PathObject parent = pathObject; while (parent != null && !(parent instanceof TMACoreObject)) parent = parent.getParent(); return (TMACoreObject)parent; }
/** * Return a list of object ancestors, starting from the root object and ending with PathObject * (assuming that the object is part of a hierarchy with a root). * * @param pathObject * @return */ public static List<PathObject> getAncenstorList(final PathObject pathObject) { List<PathObject> ancestors = new ArrayList<>(); PathObject parent = pathObject; while (parent != null) { ancestors.add(0, parent); parent = parent.getParent(); } return ancestors; }
/** * Determine if a PathObject is within this hierarchy. * The actual test is to check the highest parent object of the PathObject is equal to the root object for this hierarchy. * * @param pathObject * @return */ private synchronized boolean inHierarchy(PathObject pathObject) { // made private as only called here if (pathObject == null) return false; while (pathObject.getParent() != null) pathObject = pathObject.getParent(); return pathObject.equals(getRootObject()); }
public String getDisplayedName() { String nameDisplayed = name; if (nameDisplayed == null) { PathClass pathClass = getPathClass(); if (pathClass != null) nameDisplayed = pathClass.getName(); else nameDisplayed = getClass().getSimpleName(); } if (getParent() != null && getParent().isTMACore()) nameDisplayed = getParent().getDisplayedName() + " - " + nameDisplayed; return nameDisplayed; }
/** * Check if a hierarchy contains a specified PathObject. * The actual check if carried out by seeing in the PathObject is descended from the root object of the hierarchy. * * @param hierarchy * @param pathObject * @return */ public static boolean hierarchyContainsObject(final PathObjectHierarchy hierarchy, final PathObject pathObject) { if (pathObject == null) return false; PathObject testObject = pathObject; while (testObject != null && (!(testObject instanceof PathRootObject))) testObject = testObject.getParent(); return testObject == hierarchy.getRootObject(); }
protected synchronized void fireObjectAddedEvent(Object source, PathObject pathObject) { PathObjectHierarchyEvent event = PathObjectHierarchyEvent.createObjectAddedEvent(source, this, pathObject.getParent(), pathObject); fireEvent(event); }
PathObject parent = pathObject.getParent(); if (parent == null) continue;
public synchronized boolean removeObject(PathObject pathObject, boolean keepChildren, boolean fireEvent) { // Check the object is within the hierarchy & has a valid parent (from which it can be removed) PathObject pathObjectParent = pathObject.getParent(); if (!inHierarchy(pathObject) || pathObjectParent == null) { logger.warn(pathObject + " could not be removed from the hierarchy"); return false; } // Can't keep children if there aren't any keepChildren = keepChildren && pathObject.hasChildren(); pathObjectParent.removePathObject(pathObject); // Assign the children to the parent object, if necessary if (keepChildren) { // We create a new array list because getPathObjectList returns an unmodifiable collection // List<PathObject> list = new ArrayList<>(pathObject.getPathObjectList()); pathObjectParent.addPathObjects(pathObject.getChildObjects()); // pathObject.clearPathObjects(); // Clear child objects, just in case } if (fireEvent) { if (keepChildren) fireObjectRemovedEvent(this, pathObject, pathObjectParent); else fireHierarchyChangedEvent(this, pathObjectParent); } return true; }
PathObject parent = isErosion ? pathObject : pathObject.getParent(); if (constrainToParent && !isErosion) { Area parentShape;
if (iterChild.next().getParent() != possibleParent) iterChild.remove();