Skip to content

Commit

Permalink
Simplify code, now ImagePlus.getListeners() exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
acardona committed Mar 22, 2024
1 parent 2feddbc commit bf55b3d
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/main/java/ini/trakem2/persistence/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ij.ImageListener> 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<ij.ImageListener>)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<ij.ImageListener>)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;
}
Expand Down

0 comments on commit bf55b3d

Please sign in to comment.