From bf55b3ddc71d7e383e0ae1586e0bb91b1e40ed11 Mon Sep 17 00:00:00 2001 From: Albert Cardona Date: Fri, 22 Mar 2024 13:53:59 +0000 Subject: [PATCH] Simplify code, now ImagePlus.getListeners() exists. --- .../java/ini/trakem2/persistence/Loader.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/java/ini/trakem2/persistence/Loader.java b/src/main/java/ini/trakem2/persistence/Loader.java index d0aa601b..7efde9ea 100644 --- a/src/main/java/ini/trakem2/persistence/Loader.java +++ b/src/main/java/ini/trakem2/persistence/Loader.java @@ -4204,32 +4204,21 @@ public long estimateImageFileSize(final Patch p, final int level) { // Dummy class to provide access the notifyListeners from Image static private final class ImagePlusAccess extends ImagePlus { - final int CLOSE = CLOSED; // from super class ImagePlus, which is not visible - final int OPEN = OPENED; - final int UPDATE = UPDATED; - private Vector my_listeners; - @SuppressWarnings("unchecked") public ImagePlusAccess() { super(); - try { - final java.lang.reflect.Field f = ImagePlus.class.getDeclaredField("listeners"); - f.setAccessible(true); - this.my_listeners = (Vector)f.get(this); - } catch (final Exception e) { - IJError.print(e); - } } + @SuppressWarnings("unchecked") public final void notifyListeners(final ImagePlus imp, final int action) { try { - for (final ij.ImageListener listener : my_listeners) { + for (final ij.ImageListener listener : (Vector)ImagePlus.getListeners()) { switch (action) { - case CLOSE: + case ImagePlus.CLOSED: listener.imageClosed(imp); break; - case OPEN: + case ImagePlus.OPENED: listener.imageOpened(imp); break; - case UPDATE: + case ImagePlus.UPDATED: listener.imageUpdated(imp); break; }