Last active
January 3, 2017 17:18
-
-
Save bogovicj/90a1d5f15833fe70181a02ede2a87ab1 to your computer and use it in GitHub Desktop.
ImageJ Keypress example
This file contains hidden or 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
import java.awt.event.KeyEvent; | |
import java.awt.event.KeyListener; | |
import ij.IJ; | |
import ij.ImageJ; | |
import ij.ImagePlus; | |
public class SpaceToContinueExample implements KeyListener { | |
final ImageJ ij; | |
ImagePlus ip; | |
public SpaceToContinueExample( ) | |
{ | |
ij = IJ.getInstance(); | |
System.out.println( "ij: " + ij ); | |
} | |
public SpaceToContinueExample( ImagePlus ip ) | |
{ | |
this(); | |
this.ip = ip; | |
ip.show(); | |
ip.getCanvas().addKeyListener(this); | |
} | |
public void processBefore() | |
{ | |
ip = IJ.getImage(); | |
IJ.run("Gaussian Blur...", "sigma=2"); | |
IJ.getImage().show(); | |
} | |
public void processAfter() | |
{ | |
System.out.println("process after"); | |
IJ.run("Measure"); | |
// remove this key listener to be safe | |
ip.getCanvas().removeKeyListener(this); | |
} | |
public void run() | |
{ | |
processBefore(); | |
// process After is called on keypress | |
} | |
@Override | |
public void keyTyped(KeyEvent e) {} | |
@Override | |
public void keyPressed(KeyEvent e) { } | |
@Override | |
public void keyReleased(KeyEvent e) { | |
if ( e.getKeyCode() == KeyEvent.VK_SPACE ) | |
{ | |
processAfter(); | |
} | |
} | |
public static void main(String[] args) { | |
ImageJ ij = new ImageJ(); | |
IJ.run("Boats (356K)"); | |
SpaceToContinueExample obj = new SpaceToContinueExample( IJ.getImage() ); | |
obj.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This java snippet: