{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 1602 plugins available.\n", "[INFO] Ignoring negative sigma value.\n", "There are 319 menu items total.\n" ] }, { "data": { "text/plain": [ "No Outputs" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#!groovy\n", "// @ImageJ ij\n", "\n", "// The plugin service manages the available plugins (see \"Plugins\" below).\n", "pluginCount = ij.plugin().getIndex().size()\n", "println(\"There are \" + pluginCount + \" plugins available.\")\n", "\n", "// The log service is used for logging messages.\n", "ij.log().info(\"Ignoring negative sigma value.\")\n", "\n", "// The status service is used to report the current status of operations.\n", "// Within a notebook like this, the call does not do anything visible.\n", "ij.status().showStatus(\"Processing data file 34 of 97...\")\n", "\n", "// The menu service organizes a menu hierarchy for modules (see \"Modules\" below).\n", "menuItemCount = ij.menu().getMenu().size()\n", "println(\"There are \" + menuItemCount + \" menu items total.\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "java​.util​.concurrent​.FutureTask​@20a367ec" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import org.scijava.plugin.Plugin\n", "import org.scijava.plugin.Parameter\n", "import org.scijava.log.LogService\n", "import org.scijava.command.Command\n", "\n", "@Plugin(type = Command.class)\n", "public class MyPlugin implements Command {\n", " \n", " // This @Parameter notation is 'asking' the Context\n", " // for an instance of LogService.\n", " @Parameter\n", " private LogService logService\n", " \n", " @Parameter\n", " private String message\n", " \n", " @Override\n", " public void run() {\n", " // Just use the LogService!\n", " // There is no need to construct it, since the Context\n", " // has already provided an appropriate instance.\n", " logService.info(message)\n", " }\n", " \n", " public void log(String message) {\n", " // Just use the LogService!\n", " // There is no need to construct it, since the Context\n", " // has already provided an appropriate instance.\n", " logService.info(message);\n", " }\n", "}\n", "\n", "// executing our sample command\n", "ij.command().run(MyPlugin.class, true, \"message\", \"Success!\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "java​.util​.concurrent​.FutureTask​@c753f55" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import org.scijava.plugin.Plugin\n", "import org.scijava.Context;\n", "import org.scijava.plugin.Parameter\n", "import org.scijava.command.Command\n", "\n", "@Plugin(type = Command.class)\n", "public class MyService implements Command {\n", " \n", " // This service will manually create plugin instances.\n", " // So, we need a reference to our containing Context,\n", " // then we can use it to inject our plugins.\n", " @Parameter\n", " private Context context\n", " \n", " @Override\n", " public void run() {\n", " // Manually create a plugin instance.\n", " // It is not connected to a Context yet\n", " MyPlugin plugin = new MyPlugin();\n", " \n", " // Inject the plugin instance with our Context.\n", " context.inject(plugin);\n", " \n", " // Now that our plugin is injected, we can use\n", " // it with the knowledge that its parameters\n", " // have been populated.\n", " plugin.log(\"Success!\");\n", " }\n", "}\n", "\n", "// executing our sample command\n", "ij.command().run(MyService.class, true)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Plugin count: 1604\n", "Module count: 1105\n", "Service count: 97\n", "SciJava version: 2.64.0\n", "Where is SciJava? file:/home/hadim/local/Fiji.app/jars/scijava-common-2.64.0.jar\n" ] }, { "data": { "text/plain": [ "No Outputs" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Create a SciJava gateway.\n", "import org.scijava.SciJava\n", "sj = new SciJava()\n", "\n", "// Now bask in the convenience!\n", "\n", "println(\"Plugin count: \" + sj.plugin().getPlugins().size())\n", "println(\"Module count: \" + sj.module().getModules().size())\n", "\n", "import org.scijava.service.Service\n", "println(\"Service count: \" + sj.plugin().getPluginsOfType(Service.class).size())\n", "\n", "println(\"SciJava version: \" + sj.getVersion())\n", "println(\"Where is SciJava? \" + sj.getApp().getLocation())" ] } ], "metadata": { "kernelspec": { "display_name": "Scijava", "language": "groovy", "name": "scijava" }, "language_info": { "codemirror_mode": "groovy", "file_extension": "", "mimetype": "", "name": "scijava", "nbconverter_exporter": "", "pygments_lexer": "groovy", "version": "1.0" } }, "nbformat": 4, "nbformat_minor": 2 }