本文整理汇总了Java中org.scijava.command.Command类的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Command类属于org.scijava.command包,在下文中一共展示了Command类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNullImageCancelsPlugin
import org.scijava.command.Command; //导入依赖的package包/类
public static <C extends Command> void testNullImageCancelsPlugin(
final ImageJ imageJ, final Class<C> commandClass) throws Exception
{
// SETUP
final UserInterface mockUI = mockUIService(imageJ);
// EXECUTE
final CommandModule module = imageJ.command().run(commandClass, true,
"inputImage", null).get();
// VERIFY
assertTrue("Null image should have canceled the plugin", module
.isCanceled());
assertEquals("Cancel reason is incorrect", CommonMessages.NO_IMAGE_OPEN,
module.getCancelReason());
verify(mockUI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(),
any());
}
示例2: test2DImageCancelsPlugin
import org.scijava.command.Command; //导入依赖的package包/类
public static <C extends Command> void test2DImageCancelsPlugin(
final ImageJ imageJ, final Class<C> commandClass) throws Exception
{
// SETUP
final UserInterface mockUI = mockUIService(imageJ);
// Create an image with only two spatial dimensions
final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X);
final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y);
final DefaultLinearAxis cAxis = new DefaultLinearAxis(Axes.CHANNEL);
final Img<DoubleType> img = ArrayImgs.doubles(10, 10, 3);
final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", xAxis,
yAxis, cAxis);
// EXECUTE
final CommandModule module = imageJ.command().run(commandClass, true,
"inputImage", imgPlus).get();
// VERIFY
assertTrue("2D image should have cancelled the plugin", module
.isCanceled());
assertEquals("Cancel reason is incorrect", CommonMessages.NOT_3D_IMAGE,
module.getCancelReason());
verify(mockUI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(),
any());
}
示例3: test2DImagePlusCancelsPlugin
import org.scijava.command.Command; //导入依赖的package包/类
public static <C extends Command> void test2DImagePlusCancelsPlugin(
final ImageJ imageJ, final Class<C> commandClass) throws Exception
{
// SETUP
final UserInterface mockUI = mockUIService(imageJ);
final ImagePlus image = mock(ImagePlus.class);
when(image.getNSlices()).thenReturn(1);
// EXECUTE
final CommandModule module = imageJ.command().run(commandClass, true,
"inputImage", image).get();
// VERIFY
assertTrue("2D image should have cancelled the plugin", module
.isCanceled());
assertEquals("Cancel reason is incorrect", CommonMessages.NOT_3D_IMAGE,
module.getCancelReason());
verify(mockUI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(),
any());
}
示例4: buildSlideSetPluginsMenu
import org.scijava.command.Command; //导入依赖的package包/类
/** Build the menu listing {@code SlideSetPlugin}s */
private JMenu buildSlideSetPluginsMenu() {
JMenu m = new JMenu("Slide Set Commands");
List<CommandInfo> plugins = sspl.getPluginInfo();
for(PluginInfo<Command> plugin : plugins) {
String[] path = plugin.getMenuPath().getMenuString().split(MenuPath.PATH_SEPARATOR);
if(path == null || path[0] == null || path[0].equals("")) {
path = new String[1];
path[0] = plugin.getTitle();
}
if(path.length > 3
&& path[0].trim().equalsIgnoreCase("Plugins")
&& path[1].trim().equalsIgnoreCase("Slide Set")
&& path[2].trim().equalsIgnoreCase("Commands")) {
String[] pathShrunk
= Arrays.copyOfRange(path, 3, path.length);
path = pathShrunk;
}
String command = "sspl/" + plugin.getClassName();
UIUtil.parseRecursiveMenuAdd(path, command, m, this);
}
return m;
}
示例5: testNonBinaryImageCancelsPlugin
import org.scijava.command.Command; //导入依赖的package包/类
public static <C extends Command> void testNonBinaryImageCancelsPlugin(
final ImageJ imageJ, final Class<C> commandClass) throws Exception
{
// SETUP
final UserInterface mockUI = mockUIService(imageJ);
// Create a test image with more than two colors
final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X);
final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y);
final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z);
final Img<DoubleType> img = ArrayImgs.doubles(5, 5, 5);
final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", xAxis,
yAxis, zAxis);
final Iterator<Integer> intIterator = IntStream.iterate(0, i -> i + 1)
.iterator();
imgPlus.cursor().forEachRemaining(e -> e.setReal(intIterator.next()));
// EXECUTE
final CommandModule module = imageJ.command().run(commandClass, true,
"inputImage", imgPlus).get();
// VERIFY
assertTrue(
"An image with more than two colours should have cancelled the plugin",
module.isCanceled());
assertEquals("Cancel reason is incorrect", CommonMessages.NOT_BINARY, module
.getCancelReason());
verify(mockUI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(),
any());
}
示例6: testNoCalibrationShowsWarning
import org.scijava.command.Command; //导入依赖的package包/类
public static <C extends Command> void testNoCalibrationShowsWarning(
final ImageJ imageJ, final Class<C> commandClass,
Object... additionalInputs) throws Exception
{
// SETUP
// Mock UI
final UserInterface mockUI = mock(UserInterface.class);
final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class);
when(mockUI.dialogPrompt(eq(BAD_CALIBRATION), anyString(), eq(
WARNING_MESSAGE), any())).thenReturn(mockPrompt);
imageJ.ui().setDefaultUI(mockUI);
// Create an hyperstack with no calibration
final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X);
final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y);
final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z);
final DefaultLinearAxis tAxis = new DefaultLinearAxis(Axes.TIME);
final Img<DoubleType> img = ArrayImgs.doubles(5, 5, 5, 2);
final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", xAxis,
yAxis, zAxis, tAxis);
final List<Object> inputs = new ArrayList<>();
inputs.add("inputImage");
inputs.add(imgPlus);
Collections.addAll(inputs, additionalInputs);
// EXECUTE
imageJ.command().run(commandClass, true, inputs.toArray()).get();
// VERIFY
verify(mockUI, timeout(1000).times(1)).dialogPrompt(eq(BAD_CALIBRATION),
anyString(), eq(WARNING_MESSAGE), any());
}
示例7: testNonBinaryImagePlusCancelsPlugin
import org.scijava.command.Command; //导入依赖的package包/类
public static <C extends Command> void testNonBinaryImagePlusCancelsPlugin(
final ImageJ imageJ, final Class<C> commandClass) throws Exception
{
// SETUP
final UserInterface mockUI = mockUIService(imageJ);
final ImagePlus nonBinaryImage = mock(ImagePlus.class);
final ImageStatistics stats = new ImageStatistics();
stats.pixelCount = 3;
stats.histogram = new int[256];
stats.histogram[0x00] = 1;
stats.histogram[0x01] = 1;
stats.histogram[0xFF] = 1;
when(nonBinaryImage.getStatistics()).thenReturn(stats);
when(nonBinaryImage.getNSlices()).thenReturn(2);
// EXECUTE
final CommandModule module = imageJ.command().run(commandClass, true,
"inputImage", nonBinaryImage).get();
// VERIFY
assertTrue(
"An image with more than two colours should have cancelled the plugin",
module.isCanceled());
assertEquals("Cancel reason is incorrect",
CommonMessages.NOT_8_BIT_BINARY_IMAGE, module.getCancelReason());
verify(mockUI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(),
any());
}
示例8: testAnisotropyWarning
import org.scijava.command.Command; //导入依赖的package包/类
/**
* Tests that running the given command with an anisotropic {@link ImagePlus}
* shows a warning dialog that can be used to cancel the plugin
*/
public static <C extends Command> void testAnisotropyWarning(
final ImageJ imageJ, final Class<C> commandClass) throws Exception
{
// SETUP
final UserInterface mockUI = mock(UserInterface.class);
final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class);
when(mockPrompt.prompt()).thenReturn(DialogPrompt.Result.CANCEL_OPTION);
when(mockUI.dialogPrompt(startsWith("The image is anisotropic"),
anyString(), eq(WARNING_MESSAGE), any())).thenReturn(mockPrompt);
imageJ.ui().setDefaultUI(mockUI);
final Calibration calibration = new Calibration();
calibration.pixelWidth = 300;
calibration.pixelHeight = 1;
calibration.pixelDepth = 1;
final ImagePlus imagePlus = NewImage.createByteImage("", 5, 5, 5, 1);
imagePlus.setCalibration(calibration);
// EXECUTE
final CommandModule module = imageJ.command().run(commandClass, true,
"inputImage", imagePlus).get();
// VERIFY
verify(mockUI, timeout(1000).times(1)).dialogPrompt(startsWith(
"The image is anisotropic"), anyString(), eq(WARNING_MESSAGE), any());
assertTrue("Pressing cancel on warning dialog should have cancelled plugin",
module.isCanceled());
}
示例9: buildOtherCommandsMenu
import org.scijava.command.Command; //导入依赖的package包/类
/** Build the menu listing other ImageJ commands */
private JMenu buildOtherCommandsMenu() {
JMenu m = new JMenu("Other ImageJ Commands");
m.add(new JMenu("Edit "));
m.add(new JMenu("Image "));
m.add(new JMenu("Process "));
m.add(new JMenu("Analyze "));
m.add(new JMenu("Plugins "));
/*MenuService ijms = ij.getService(MenuService.class); // Possible alternative way to do this?
SwingJMenuCreator ijmc = new SwingJMenuCreator();
ShadowMenu ijMenu = ijms.getMenu();
ijmc.createMenus(ijMenu, m);*/
PluginService ps = ij.get(PluginService.class);
List<PluginInfo<Command>> plugins = ps.getPluginsOfType(Command.class);
for(PluginInfo<Command> plugin : plugins) {
String[] path = plugin.getMenuPath().getMenuString().split(MenuPath.PATH_SEPARATOR);
String command = "ijps/" + plugin.getClassName();
if(path != null && !path[0].equals("") && path.length > 1
&& !path[0].equals("File ")
&& !path[0].equals("Window ")
&& !path[0].equals("Help ")
&& plugin.getAnnotation() != null
&& plugin.getAnnotation().visible())
UIUtil.parseRecursiveMenuAdd(path, command, m, this);
}
return m;
}
示例10: testGenerateAll
import org.scijava.command.Command; //导入依赖的package包/类
@Test
public void testGenerateAll() throws IOException {
// create a context with a minimal command set
final PluginIndex pluginIndex = new PluginIndex() {
@Override
public void discover() {
super.discover();
removeAll(getPlugins(Command.class));
add(pluginInfo(FileNew.class));
add(pluginInfo(FileOpen.class));
add(pluginInfo(FileSave.class));
add(pluginInfo(FileExit.class));
add(pluginInfo(Lion.class));
add(pluginInfo(Tiger.class));
add(pluginInfo(Bear.class));
}
};
final ArrayList<Class<? extends Service>> classes =
new ArrayList<Class<? extends Service>>();
classes.add(AppService.class);
classes.add(CommandService.class);
classes.add(MenuService.class);
final Context context = new Context(classes, pluginIndex);
final ScriptGenerator scriptGen = new ScriptGenerator(context);
final File tempDir =
TestUtils.createTemporaryDirectory("script-generator-");
final File libDir = new File(tempDir, "lib");
final File scriptsDir = new File(libDir, "scripts");
assertTrue(scriptsDir.mkdirs());
final int returnCode = scriptGen.generateAll(tempDir);
context.dispose();
assertEquals(0, returnCode);
final File imagejDir = new File(scriptsDir, "imagej");
assertTrue(imagejDir.isDirectory());
final File fileDir = new File(imagejDir, "File");
assertTrue(fileDir.isDirectory());
final File animalsDir = new File(imagejDir, "\ufeffAnimals");
assertTrue(animalsDir.isDirectory());
assertTrue(new File(fileDir, "New.py").exists());
assertTrue(new File(fileDir, "\ufeffOpen.py").exists());
assertTrue(new File(fileDir, "\ufeff\ufeffSave.py").exists());
assertTrue(new File(fileDir, "\ufeff\ufeff\ufeffExit.py").exists());
assertTrue(new File(animalsDir, "Lion.py").exists());
assertTrue(new File(animalsDir, "\ufeffTiger.py").exists());
assertTrue(new File(animalsDir, "\ufeff\ufeffBear.py").exists());
FileUtils.deleteRecursively(tempDir);
}
示例11: pluginInfo
import org.scijava.command.Command; //导入依赖的package包/类
private PluginInfo<Command> pluginInfo(
final Class<? extends Command> pluginClass)
{
final Plugin ann = pluginClass.getAnnotation(Plugin.class);
return new PluginInfo<Command>(pluginClass, Command.class, ann);
}