@@ -0,0 +1,2029 @@
+%0Apackage net.restlesscoder.sandbox.scijava;%0A%0Aimport javax.swing.JOptionPane;%0A%0Aimport org.scijava.MenuPath;%0Aimport org.scijava.SciJava;%0Aimport org.scijava.command.Command;%0Aimport org.scijava.command.CommandInfo;%0Aimport org.scijava.menu.ShadowMenu;%0A%0A/**%0A * Adds some commands to the SciJava menu which are backed by %7B@link Runnable%7D%0A * objects.%0A */%0Apublic class RunnableCommands %7B%0A%0A%09public static void main(final String... args) throws Exception %7B%0A%09%09// Create a SciJava application context.%0A%09%09final SciJava sj = new SciJava();%0A%0A%09%09// Create some simple Runnable objects, as a demo.%0A%09%09final Runnable hello = new Runnable() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09JOptionPane.showMessageDialog(null, %22Hello world%22);%0A%09%09%09%7D%0A%09%09%7D;%0A%09%09final Runnable aloha = new Runnable() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09JOptionPane.showMessageDialog(null, %22Aloha%22);%0A%09%09%09%7D%0A%09%09%7D;%0A%0A%09%09// Create Command wrappers for the Runnable objects, and register them.%0A%09%09final CommandInfo helloCommand = new RunnableCommandInfo(hello);%0A%09%09helloCommand.setMenuPath(new MenuPath(%22Greetings%3EHello World%22));%0A%09%09sj.module().addModule(helloCommand);%0A%0A%09%09final CommandInfo alohaCommand = new RunnableCommandInfo(aloha);%0A%09%09alohaCommand.setMenuPath(new MenuPath(%22Greetings%3EAloha%22));%0A%09%09sj.module().addModule(alohaCommand);%0A%0A%09%09// Verify that the SciJava menu has been updated accordingly.%0A%09%09final ShadowMenu greetingsMenu = sj.menu().getMenu().getMenu(%22Greetings%22);%0A%09%09sj.log().info(%22greetings menu:%5Cn%22 + greetingsMenu);%0A%0A%09%09// Display the UI, to test out the commands!%0A%09%09sj.ui().showUI();%0A%09%7D%0A%0A%09public static class RunnableCommandInfo extends CommandInfo %7B%0A%09%09private Runnable r;%0A%0A%09%09public RunnableCommandInfo(final Runnable r) %7B%0A%09%09%09super(RunnableCommand.class);%0A%09%09%09this.r = r;%0A%09%09%7D%0A%09%09@Override%0A%09%09public RunnableCommand createInstance() %7B%0A%09%09%09return new RunnableCommand(r);%0A%09%09%7D%0A%09%7D%0A%0A%09public static class RunnableCommand implements Command %7B%0A%09%09private final Runnable r;%0A%09%09public RunnableCommand(Runnable r) %7B%0A%09%09%09this.r = r;%0A%09%09%7D%0A%09%09@Override%0A%09%09public void run() %7B%0A%09%09%09r.run();%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add runnable SciJava command experiment