From 9ee87e6319f660213a2395fe7a93c4446ebea681 Mon Sep 17 00:00:00 2001 From: Tiago Ferreira Date: Mon, 16 Sep 2024 10:26:34 -0400 Subject: [PATCH] GUI: Add (minor) convenience access to Spot Spine --- .../java/sc/fiji/snt/BookmarkManager.java | 5 ++- src/main/java/sc/fiji/snt/PathManagerUI.java | 6 +++ src/main/java/sc/fiji/snt/gui/DemoRunner.java | 6 ++- .../gui/cmds/EnableSciViewUpdateSiteCmd.java | 8 +++- .../fiji/snt/gui/cmds/SpotSpineLoaderCmd.java | 37 +++++++++++++++++++ 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/main/java/sc/fiji/snt/gui/cmds/SpotSpineLoaderCmd.java diff --git a/src/main/java/sc/fiji/snt/BookmarkManager.java b/src/main/java/sc/fiji/snt/BookmarkManager.java index 05d04457..0859bd6c 100644 --- a/src/main/java/sc/fiji/snt/BookmarkManager.java +++ b/src/main/java/sc/fiji/snt/BookmarkManager.java @@ -221,7 +221,6 @@ private JPopupMenu exportMenu() { JMenuItem jmi = new JMenuItem("To CSV File..."); menu.add(jmi); jmi.addActionListener(e -> { - if (noBookmarksError()) return; final File saveFile = sntui.saveFile("Export Bookmarks to CSV...", "SNT_Bookmarks.csv", "csv"); if (saveFile != null) { @@ -251,7 +250,9 @@ private JPanel assembleButtonPanel() { impButton.addActionListener(e -> impMenu.show(impButton, impButton.getWidth() / 2, impButton.getHeight() / 2)); final JButton expButton = new JButton("Export..."); final JPopupMenu expMenu = exportMenu(); - expButton.addActionListener(e -> expMenu.show(expButton, expButton.getWidth() / 2, expButton.getHeight() / 2)); + expButton.addActionListener(e -> { + if (!noBookmarksError()) expMenu.show(expButton, expButton.getWidth() / 2, expButton.getHeight() / 2); + }); final JPanel buttonPanel = new JPanel(new GridLayout(0, 2)); buttonPanel.setBorder(new EmptyBorder(SNTUI.InternalUtils.MARGIN, 0, SNTUI.InternalUtils.MARGIN, 0)); buttonPanel.add(impButton); diff --git a/src/main/java/sc/fiji/snt/PathManagerUI.java b/src/main/java/sc/fiji/snt/PathManagerUI.java index b6eabfef..a4e039aa 100644 --- a/src/main/java/sc/fiji/snt/PathManagerUI.java +++ b/src/main/java/sc/fiji/snt/PathManagerUI.java @@ -477,6 +477,12 @@ private JMenu getSpineUtilsMenu(final MultiPathActionListener multiPathListener) jmi.addActionListener(multiPathListener); menu.add(jmi); menu.addSeparator(); + jmi = new JMenuItem("Start Spot Spine..."); + jmi.addActionListener(e -> { + plugin.getContext().getService(CommandService.class).run(SpotSpineLoaderCmd.class, true, new HashMap<>()); + }); + menu.add(jmi); + menu.addSeparator(); jmi = GuiUtils.menuItemTriggeringHelpURL("Spine/Varicosity Utilities Help", "https://imagej.net/plugins/snt/step-by-step-instructions#spinevaricosity-analysis"); menu.add(jmi); diff --git a/src/main/java/sc/fiji/snt/gui/DemoRunner.java b/src/main/java/sc/fiji/snt/gui/DemoRunner.java index 935909af..9616579f 100644 --- a/src/main/java/sc/fiji/snt/gui/DemoRunner.java +++ b/src/main/java/sc/fiji/snt/gui/DemoRunner.java @@ -23,9 +23,11 @@ package sc.fiji.snt.gui; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import org.scijava.Context; +import org.scijava.command.CommandService; import org.scijava.plugin.Parameter; import ij.ImagePlus; @@ -34,6 +36,7 @@ import sc.fiji.snt.SNTService; import sc.fiji.snt.SNTUI; import sc.fiji.snt.Tree; +import sc.fiji.snt.gui.cmds.SpotSpineLoaderCmd; public class DemoRunner { @@ -340,13 +343,14 @@ public void load() { snt.getUI().runCommand("Display/Rebuild ZY/XZ Views"); if (!snt.getDrawDiameters()) snt.getUI().runCommand("Draw diameters"); + snt.getContext().getService(CommandService.class).run(SpotSpineLoaderCmd.class, true, new HashMap<>()); } } }; entry.summary = "Downloads the test dataset of the Spot Spine software (image stack and traced dendrite)."; entry.data = "Image (3D; 0.7MB) and tracings (160KB)"; - entry.source = "Spot Spine (https://imagej.net/plugins/spot-spine) manuscript, doi:10.12688/f1000research" + + entry.source = "Spot Spine (https://imagej.net/plugins/spot-spine) manuscript, doi:10.12688/f1000research.146327.2" + ".146327.1"; entry.online = true; entry.tracingsURL = "https://raw.githubusercontent.com/morphonets/misc/master/dataset-demos/SpotSpine/SpotSpine_ImageStack_Test.swc"; diff --git a/src/main/java/sc/fiji/snt/gui/cmds/EnableSciViewUpdateSiteCmd.java b/src/main/java/sc/fiji/snt/gui/cmds/EnableSciViewUpdateSiteCmd.java index a7c03d02..d01208b3 100644 --- a/src/main/java/sc/fiji/snt/gui/cmds/EnableSciViewUpdateSiteCmd.java +++ b/src/main/java/sc/fiji/snt/gui/cmds/EnableSciViewUpdateSiteCmd.java @@ -23,6 +23,7 @@ * . * #L% */ +import net.imagej.legacy.LegacyService; import org.scijava.command.Command; import org.scijava.command.CommandInfo; import org.scijava.command.CommandService; @@ -51,9 +52,12 @@ public class EnableSciViewUpdateSiteCmd implements Command { @Parameter private CommandService cmdService; + @Parameter + LegacyService legacyService; + @Override public void run() { - final UpdateSite updateSite = updateService.getUpdateSite("SciView"); // this may be outdated + final UpdateSite updateSite = updateService.getUpdateSite("sciview"); if (updateSite != null && updateSite.isActive()) { SNTUtils.log("sciview subscription detected"); return; @@ -64,7 +68,7 @@ public void run() { if (prompts[0]) runUpdater(); if (prompts[1]) - ij.IJ.runPlugIn("ij.plugin.BrowserLauncher", "https://docs.scenery.graphics/sciview"); + legacyService.runLegacyCommand("ij.plugin.BrowserLauncher","https://docs.scenery.graphics/sciview"); } private void runUpdater() { diff --git a/src/main/java/sc/fiji/snt/gui/cmds/SpotSpineLoaderCmd.java b/src/main/java/sc/fiji/snt/gui/cmds/SpotSpineLoaderCmd.java new file mode 100644 index 00000000..7e9201ae --- /dev/null +++ b/src/main/java/sc/fiji/snt/gui/cmds/SpotSpineLoaderCmd.java @@ -0,0 +1,37 @@ +package sc.fiji.snt.gui.cmds; + +import net.imagej.legacy.LegacyService; +import org.scijava.command.Command; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; +import org.scijava.util.Types; +import sc.fiji.snt.gui.GuiUtils; + +/** + * Implements the 'Open Spot Spine...' command. + * + * @author Tiago Ferreira + */ +@Plugin(type = Command.class, visible = false) +public class SpotSpineLoaderCmd implements Command { + + private static final String DOC_PAGE = "https://imagej.net/plugins/spot-spine#installation"; + private static final String CLASS = "spine_sources.Spine3D_All"; + + @Parameter + LegacyService legacyService; + + @Override + public void run() { + if (Types.load(CLASS) != null) { + legacyService.runLegacyCommand(CLASS, ""); + return; + } + final boolean openDoc = new GuiUtils().getConfirmation("Spot Spine does not seem to be available. Please " + + "install it by following the installation details on imagej.net. Open documentation page now?", + "Spot Spine Not Installed", "Yes. Open In Browser", "No. Dismiss"); + if (openDoc) + legacyService.runLegacyCommand("ij.plugin.BrowserLauncher", DOC_PAGE); + } + +}