Search in sources :

Example 6 with PathObjectHierarchyEvent

use of qupath.lib.objects.hierarchy.events.PathObjectHierarchyEvent in project qupath by qupath.

the class PathObjectHierarchy method fireObjectClassificationsChangedEvent.

/**
 * Fire a hierarchy update indicating object classifications have changed.
 * @param source
 * @param pathObjects
 */
public void fireObjectClassificationsChangedEvent(Object source, Collection<? extends PathObject> pathObjects) {
    PathObjectHierarchyEvent event = PathObjectHierarchyEvent.createObjectsChangedEvent(source, this, HierarchyEventType.CHANGE_CLASSIFICATION, pathObjects, false);
    fireEvent(event);
}
Also used : PathObjectHierarchyEvent(qupath.lib.objects.hierarchy.events.PathObjectHierarchyEvent)

Example 7 with PathObjectHierarchyEvent

use of qupath.lib.objects.hierarchy.events.PathObjectHierarchyEvent in project qupath by qupath.

the class PathObjectHierarchy method fireObjectRemovedEvent.

void fireObjectRemovedEvent(Object source, PathObject pathObject, PathObject previousParent) {
    PathObjectHierarchyEvent event = PathObjectHierarchyEvent.createObjectRemovedEvent(source, this, previousParent, pathObject);
    fireEvent(event);
}
Also used : PathObjectHierarchyEvent(qupath.lib.objects.hierarchy.events.PathObjectHierarchyEvent)

Example 8 with PathObjectHierarchyEvent

use of qupath.lib.objects.hierarchy.events.PathObjectHierarchyEvent in project qupath by qupath.

the class UndoRedoManager method hierarchyChanged.

@Override
public void hierarchyChanged(PathObjectHierarchyEvent event) {
    // Try to avoid calling too often
    if (undoingOrRedoing || event.isChanging() || maxUndoHierarchySize.get() <= 0 || event.getChangedObjects().stream().allMatch(p -> p instanceof ParallelTileObject))
        return;
    // *Potentially* we might have the same hierarchy in multiple viewers
    // Since we don't have the viewer stored in the event, check to see what viewers are impacted
    QuPathViewer[] viewers = map.keySet().toArray(new QuPathViewer[map.size()]);
    PathObjectHierarchy hierarchy = event.getHierarchy();
    int maxSize = maxUndoHierarchySize.get();
    boolean sizeOK = hierarchy.nObjects() <= maxSize;
    for (QuPathViewer viewer : viewers) {
        if (viewer.getHierarchy() == hierarchy) {
            SerializableUndoRedoStack<PathObjectHierarchy> undoRedo = map.get(viewer);
            // If the size is ok, register the change for potential undo-ing
            if (sizeOK) {
                if (undoRedo == null)
                    map.put(viewer, new SerializableUndoRedoStack<>(hierarchy));
                else
                    undoRedo.addLatest(hierarchy, maxUndoLevels.get());
            } else {
                // If the hierarchy is too big turn off undo/redo
                map.put(viewer, (SerializableUndoRedoStack<PathObjectHierarchy>) null);
            }
        }
    }
    refreshProperties();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) ReadOnlyBooleanProperty(javafx.beans.property.ReadOnlyBooleanProperty) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) Deque(java.util.Deque) IntegerProperty(javafx.beans.property.IntegerProperty) ByteArrayInputStream(java.io.ByteArrayInputStream) QuPathViewerPlus(qupath.lib.gui.viewer.QuPathViewerPlus) PathObjectHierarchyEvent(qupath.lib.objects.hierarchy.events.PathObjectHierarchyEvent) Map(java.util.Map) ObjectOutputStream(java.io.ObjectOutputStream) WeakHashMap(java.util.WeakHashMap) Shape(java.awt.Shape) ImageData(qupath.lib.images.ImageData) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) GeneralTools(qupath.lib.common.GeneralTools) ParallelTileObject(qupath.lib.plugins.ParallelTileObject) IOException(java.io.IOException) QuPathViewerListener(qupath.lib.gui.viewer.QuPathViewerListener) PathObject(qupath.lib.objects.PathObject) Platform(javafx.application.Platform) QuPathViewer(qupath.lib.gui.viewer.QuPathViewer) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ObservableValue(javafx.beans.value.ObservableValue) PathObjectHierarchyListener(qupath.lib.objects.hierarchy.events.PathObjectHierarchyListener) ArrayDeque(java.util.ArrayDeque) ChangeListener(javafx.beans.value.ChangeListener) PathPrefs(qupath.lib.gui.prefs.PathPrefs) PathObjectHierarchy(qupath.lib.objects.hierarchy.PathObjectHierarchy) ParallelTileObject(qupath.lib.plugins.ParallelTileObject) QuPathViewer(qupath.lib.gui.viewer.QuPathViewer)

Aggregations

PathObjectHierarchyEvent (qupath.lib.objects.hierarchy.events.PathObjectHierarchyEvent)8 Shape (java.awt.Shape)2 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Platform (javafx.application.Platform)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 PrintWriter (java.io.PrintWriter)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 HashSet (java.util.HashSet)1