From c9a8eaa18b55fa4ad91b484d4030bb61033d1276 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 28 Mar 2024 13:42:26 -0500 Subject: [PATCH] Purge the imagej-legacy dependency We can check whether the application frame is a UIComponent, then check whether its associated component is a Frame, without having a hard dependency on the LegacyApplicationFrame. This reduces labkit-ui's dependency footprint, and avoids downstream issues with the too-late patching of net.imagej:ij that can occur in some scenarios when imagej-legacy is on the classpath. --- pom.xml | 4 ---- src/main/java/sc/fiji/labkit/ui/LabkitFrame.java | 12 +++++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 816a249c..dcbb031c 100644 --- a/pom.xml +++ b/pom.xml @@ -170,10 +170,6 @@ net.imglib2 imglib2-algorithm - - net.imagej - imagej-legacy - net.imglib2 imglib2 diff --git a/src/main/java/sc/fiji/labkit/ui/LabkitFrame.java b/src/main/java/sc/fiji/labkit/ui/LabkitFrame.java index dcc7a1b1..ac4667ce 100644 --- a/src/main/java/sc/fiji/labkit/ui/LabkitFrame.java +++ b/src/main/java/sc/fiji/labkit/ui/LabkitFrame.java @@ -31,7 +31,6 @@ import io.scif.services.DatasetIOService; import net.imagej.Dataset; -import net.imagej.legacy.ui.LegacyApplicationFrame; import org.scijava.ui.ApplicationFrame; import org.scijava.ui.UIService; import org.scijava.widget.UIComponent; @@ -113,11 +112,14 @@ private Image getImageJIcon(Context context) { // NB: get ImageJ icon form the main UI window UIService uiService = context.service(UIService.class); ApplicationFrame applicationFrame = uiService.getDefaultUI().getApplicationFrame(); - if (applicationFrame instanceof LegacyApplicationFrame) - return ((LegacyApplicationFrame) applicationFrame).getComponent().getIconImage(); + Frame frame = null; if (applicationFrame instanceof Frame) - return ((Frame) applicationFrame).getIconImage(); - return null; + frame = (Frame) applicationFrame; + else if (applicationFrame instanceof UIComponent) { + Object uic = ((UIComponent) applicationFrame).getComponent(); + if (uic instanceof Frame) frame = (Frame) uic; + } + return frame == null ? null : frame.getIconImage(); } catch (Exception e) { return null;