Skip to content

Commit 5f3ea37

Browse files
committed
SNTUtils: Add convenience helper to start SNT in stream mode
1 parent e8a0107 commit 5f3ea37

4 files changed

Lines changed: 49 additions & 19 deletions

File tree

‎src/main/java/sc/fiji/snt/SNTUtils.java‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.scijava.Context;
3232
import org.scijava.app.StatusService;
3333
import org.scijava.batch.BatchService;
34+
import org.scijava.command.CommandModule;
3435
import org.scijava.command.CommandService;
3536
import org.scijava.convert.ConvertService;
3637
import org.scijava.display.DisplayService;
@@ -52,6 +53,7 @@
5253
import org.scijava.util.VersionUtils;
5354
import sc.fiji.snt.analysis.sholl.ShollUtils;
5455
import sc.fiji.snt.gui.GuiUtils;
56+
import sc.fiji.snt.gui.cmds.BigDataLoaderCmd;
5557
import sc.fiji.snt.util.BoundingBox;
5658
import sc.fiji.snt.viewer.Viewer3D;
5759

@@ -68,7 +70,10 @@
6870
import java.text.SimpleDateFormat;
6971
import java.util.List;
7072
import java.util.*;
73+
import java.util.concurrent.ExecutionException;
74+
import java.util.concurrent.Future;
7175
import java.util.concurrent.TimeUnit;
76+
import java.util.concurrent.TimeoutException;
7277
import java.util.jar.Attributes;
7378
import java.util.jar.Manifest;
7479
import java.util.regex.Matcher;
@@ -715,25 +720,47 @@ private static List<Class<? extends Service>> requiredServices() {
715720
}
716721

717722
/**
718-
* Convenience method to start up SNT's GUI.
719-
*
723+
* Convenience method to start up SNT's GUI in 'standard' mode.
724+
*
720725
* @return a reference to the {@link SNT} instance just started.s
721726
*/
722727
public static SNT startApp() {
728+
return startApp(false);
729+
}
730+
731+
/**
732+
* Convenience method to start up SNT's GUI.
733+
* @param streamMode If {@code true} SNT is initialized in stream (big data) mode, otherwise in 'standard' mode.
734+
* @return a reference to the {@link SNT} instance just started.s
735+
*/
736+
public static SNT startApp(final boolean streamMode) {
723737
GuiUtils.setLookAndFeel(); // needs to be called here to set L&F of image's contextual menu!?
724738
if (context == null && ij.IJ.getInstance() == null) {
725-
new ImageJ().ui().showUI();
739+
new ImageJ().ui().showUI(); // ImageJ ui needs to be displayed for proper display of scijava prompts
726740
}
727-
setIsLoading(true);
728-
final PathAndFillManager pathAndFillManager = new PathAndFillManager();
729-
final SNT snt = new SNT(getContext(), pathAndFillManager);
730-
snt.initialize(null);
731-
try {
732-
javax.swing.SwingUtilities.invokeAndWait(snt::startUI);
733-
} catch (final InvocationTargetException | InterruptedException e) {
734-
e.printStackTrace();
741+
742+
if (streamMode) {
743+
final Future<CommandModule> future = getContext().getService(CommandService.class).run(BigDataLoaderCmd.class,
744+
true, (Map<String, Object>) null);
745+
try {
746+
future.get(30, TimeUnit.SECONDS);
747+
} catch (final InterruptedException | ExecutionException | TimeoutException e) {
748+
error("SNTUTils.startApp(true) failed", e);
749+
}
750+
return getInstance();
751+
752+
} else {
753+
setIsLoading(true);
754+
final PathAndFillManager pathAndFillManager = new PathAndFillManager();
755+
final SNT snt = new SNT(getContext(), pathAndFillManager);
756+
snt.initialize(null);
757+
try {
758+
javax.swing.SwingUtilities.invokeAndWait(snt::startUI);
759+
} catch (final InvocationTargetException | InterruptedException e) {
760+
e.printStackTrace();
761+
}
762+
return snt;
735763
}
736-
return snt;
737764
}
738765
}
739766

‎src/main/java/sc/fiji/snt/gui/cmds/BigDataLoaderCmd.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ and big data formats with lazy loading (N5, Zarr, HDF5, OME-TIFF,
9797
File img2File;
9898

9999
@Parameter(required = false, label = "Reconstruction(s)",
100-
description = "Optional.\nEither a single file (TRACES, SWC, JSON), or a folder containing reconstruction files.")
100+
description = "Optional.\nEither a single file (TRACES, SWC, JSON), or a\n" +
101+
"folder/.zip archive of several such files.")
101102
File recFiles;
102103

103104
@Parameter(required = false, label = "Markers",

‎src/main/java/sc/fiji/snt/gui/cmds/SNTLoaderCmd.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class SNTLoaderCmd extends DynamicCommand {
108108
@Override
109109
public void initialize() {
110110
if (sntService != null && sntService.isActive() && sntService.getUI() != null) {
111-
exit("SNT seems to be already running.");
111+
exit("SNT seems to be already running. Please close the current instance and re-run.");
112112
return;
113113
}
114114
// TODO: load defaults from prefService?
@@ -382,8 +382,10 @@ private boolean validateImageDimensions() {
382382

383383
private void exit(final String msg) {
384384
SNTUtils.setIsLoading(false);
385-
if (msg != null && !msg.isEmpty())
386-
cancel(msg);
385+
if (msg != null && !msg.isEmpty()) {
386+
GuiUtils.errorPrompt(msg, true);
387+
}
388+
cancel("");
387389
}
388390

389391
/*

‎src/test/java/sc/fiji/snt/demo/StartImageJAndSNTDemo.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public class StartImageJAndSNTDemo {
4343
public static void main(final String[] args) throws InterruptedException, InvocationTargetException {
4444

4545
// 1. Start ImageJ and SNT
46-
final SNT snt = SNTUtils.startApp();
47-
// 2. Load a demo dataset (File> Load Demo Dataset...> Demo 03)
48-
snt.getUI().runCommand("Load Demo Dataset...", "3");
46+
final SNT snt = SNTUtils.startApp(false); // false: 'Regular' mode for traditional images; true: 'Stream' (big data) mode
47+
// 2. Load a demo dataset (File> Load Demo Dataset...> Demo 04)
48+
snt.getUI().runCommand("Load Demo Dataset...", "4");
4949

5050
}
5151
}

0 commit comments

Comments
 (0)