Commit d7d3f33b authored by lombardo's avatar lombardo
Browse files

Replace IJ1 by IJ2 calls

parent 84650985
package de.mpicbg.scf.sandbox; package de.mpicbg.scf.sandbox;
import ij.IJ; //import ij.IJ;
import ij.ImagePlus; //import ij.ImagePlus;
import java.util.concurrent.Future;
import net.imagej.Dataset; import net.imagej.Dataset;
import net.imagej.ImageJ; import net.imagej.ImageJ;
import net.imagej.display.ImageDisplay;
import org.scijava.command.Command; import org.scijava.command.Command;
import org.scijava.command.CommandModule;
import org.scijava.command.DynamicCommand; import org.scijava.command.DynamicCommand;
import org.scijava.log.LogService; import org.scijava.log.LogService;
import org.scijava.module.Module;
import org.scijava.plugin.Parameter; import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin; import org.scijava.plugin.Plugin;
...@@ -18,21 +23,27 @@ import org.scijava.plugin.Plugin; ...@@ -18,21 +23,27 @@ import org.scijava.plugin.Plugin;
@Plugin(type = Command.class, menuPath = "SCF>test IJ2 command>testCancelReason") @Plugin(type = Command.class, menuPath = "SCF>test IJ2 command>testCancelReason")
public class testCancelReason extends DynamicCommand { public class testCancelReason extends DynamicCommand {
@Parameter LogService logService;
@Parameter(persist = false) @Parameter(persist = false)
Dataset dataset; Dataset dataset;
//ImagePlus imp; //ImagePlus imp;
@Override @Override
public void run() { public void run() {
IJ.log("hello, image name is:"+ dataset.getName() ); //IJ.log("hello, image name is:"+ dataset.getName() );
logService.info("hello, image name is:"+ dataset.getName() );
} }
@Override @Override
public void cancel(){ public void cancel(){
IJ.log( getCancelReason() ); //IJ.log( getCancelReason() );
logService.info(getCancelReason() );
if ( dataset!=null ) if ( dataset!=null )
IJ.log("script is canceled but image name is:"+ dataset.getName() ); {
//IJ.log("script is canceled but image name is:"+ dataset.getName() );
logService.info("script is canceled but image name is:"+ dataset.getName() );
}
} }
...@@ -40,15 +51,39 @@ public class testCancelReason extends DynamicCommand { ...@@ -40,15 +51,39 @@ public class testCancelReason extends DynamicCommand {
public static void main(final String... args) throws Exception { public static void main(final String... args) throws Exception {
// Launch ImageJ as usual. // Launch ImageJ as usual.
final ImageJ ij = net.imagej.Main.launch(args);
ij.log().setLevel(LogService.DEBUG); final ImageJ ij = net.imagej.Main.launch(args);
// Launch the command without and with image open. ij.ui().showUI();
ij.command().run(testCancelReason.class, true);
ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
imp.show();
ij.command().run(testCancelReason.class, true); ij.command().run(testCancelReason.class, true);
// run command with one image open
/* ij.log().info("1----------------------");
ij.ui().show(dataset);
final Future<CommandModule> future1 =
ij.command().run(testCancelReason.class, true);
// wait for the execution thread to complete
ij.module().waitFor(future1);
*/
// run command with no image open
/*
final Future<CommandModule> future2 =
ij.command().run(testCancelReason.class, true);
// wait for the execution thread to complete
ij.module().waitFor(future2);
// run command with one image open
ij.log().info("3----------------------");
ij.ui().show(dataset);
final Future<CommandModule> future3 =
ij.command().run(testCancelReason.class, true);
// wait for the execution thread to complete
ij.module().waitFor(future3);
*/
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment