Created
August 30, 2012 19:15
-
-
Save bdezonia/3538167 to your computer and use it in GitHub Desktop.
Example code using ContextPlugin code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package imagej.core.plugins.display; | |
import java.util.List; | |
import imagej.ImageJ; | |
import imagej.data.Dataset; | |
import imagej.data.display.ImageDisplay; | |
import imagej.display.Display; | |
import imagej.display.DisplayService; | |
import imagej.ext.plugin.Menu; | |
import imagej.ext.plugin.Parameter; | |
import imagej.ext.plugin.Plugin; | |
import imagej.ext.plugin.RunnablePlugin; | |
import imagej.menu.MenuConstants; | |
import imagej.module.ItemIO; | |
@Plugin(menu = { | |
@Menu(label = MenuConstants.PLUGINS_LABEL, | |
weight = MenuConstants.PLUGINS_WEIGHT, | |
mnemonic = MenuConstants.PLUGINS_MNEMONIC), | |
@Menu(label = "Utilities"), | |
@Menu(label = "Capture some other Image", weight = 22)}) | |
public class CaptureSomeOtherImage implements RunnablePlugin { | |
@Parameter | |
private ImageJ context; | |
@Parameter | |
private DisplayService displayService; | |
@Parameter | |
private ImageDisplay display; | |
@Parameter(type=ItemIO.OUTPUT) | |
private Dataset output; | |
@Override | |
public void run() { | |
CaptureImage capturer = new CaptureImage(); | |
capturer.setContext(context); | |
ImageDisplay someOtherDisplay = findOtherDisplay(); | |
if (someOtherDisplay == null) { | |
output = null; | |
} | |
else { | |
capturer.setImageDisplay(someOtherDisplay); | |
capturer.run(); | |
output = capturer.getOutput(); | |
} | |
} | |
private ImageDisplay findOtherDisplay() { | |
List<Display<?>> displays = displayService.getDisplays(); | |
for (Display<?> d : displays) { | |
if (d instanceof ImageDisplay) { | |
ImageDisplay id = (ImageDisplay) d; | |
if (id != display) return id; | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment