Ejemplo n.º 1
0
 void addToRoiManager(ImagePlus imp) {
   if (IJ.macroRunning() && Interpreter.isBatchModeRoiManager())
     IJ.error("run(\"Add to Manager\") may not work in batch mode macros");
   Frame frame = WindowManager.getFrame("ROI Manager");
   if (frame == null) IJ.run("ROI Manager...");
   if (imp == null) return;
   Roi roi = imp.getRoi();
   if (roi == null) return;
   frame = WindowManager.getFrame("ROI Manager");
   if (frame == null || !(frame instanceof RoiManager)) IJ.error("ROI Manager not found");
   RoiManager rm = (RoiManager) frame;
   boolean altDown = IJ.altKeyDown();
   IJ.setKeyUp(IJ.ALL_KEYS);
   if (altDown && !IJ.macroRunning()) IJ.setKeyDown(KeyEvent.VK_SHIFT);
   if (roi.getState() == Roi.CONSTRUCTING) { // wait (up to 2 sec.) until ROI finished
     long start = System.currentTimeMillis();
     while (true) {
       IJ.wait(10);
       if (roi.getState() != Roi.CONSTRUCTING) break;
       if ((System.currentTimeMillis() - start) > 2000) {
         IJ.beep();
         IJ.error("Add to Manager", "Selection is not complete");
         return;
       }
     }
   }
   rm.runCommand("add");
   IJ.setKeyUp(IJ.ALL_KEYS);
 }
Ejemplo n.º 2
0
 void addToRoiManager(ImagePlus imp) {
   if (IJ.macroRunning() && Interpreter.isBatchModeRoiManager())
     IJ.error("run(\"Add to Manager\") may not work in batch mode macros");
   Frame frame = WindowManager.getFrame("ROI Manager");
   if (frame == null) IJ.run("ROI Manager...");
   if (imp == null) return;
   Roi roi = imp.getRoi();
   if (roi == null) return;
   frame = WindowManager.getFrame("ROI Manager");
   if (frame == null || !(frame instanceof RoiManager)) IJ.error("ROI Manager not found");
   RoiManager rm = (RoiManager) frame;
   boolean altDown = IJ.altKeyDown();
   IJ.setKeyUp(IJ.ALL_KEYS);
   if (altDown && !IJ.macroRunning()) IJ.setKeyDown(KeyEvent.VK_SHIFT);
   rm.runCommand("add");
   IJ.setKeyUp(IJ.ALL_KEYS);
 }
Ejemplo n.º 3
0
 public void keyReleased(KeyEvent e) {
   int keyCode = e.getKeyCode();
   IJ.setKeyUp(keyCode);
   int flags = e.getModifiers();
   boolean control = (flags & KeyEvent.CTRL_MASK) != 0;
   boolean meta = (flags & KeyEvent.META_MASK) != 0;
   boolean shift = (flags & e.SHIFT_MASK) != 0;
   if (keyCode == KeyEvent.VK_G && shift && (control || meta)) new ScreenGrabber().run("");
 }
Ejemplo n.º 4
0
 void zoomToSelection(int x, int y) {
   IJ.setKeyUp(IJ.ALL_KEYS);
   String macro =
       "args = split(getArgument);\n"
           + "x1=parseInt(args[0]); y1=parseInt(args[1]); flags=20;\n"
           + "while (flags&20!=0) {\n"
           + "getCursorLoc(x2, y2, z, flags);\n"
           + "if (x2>=x1) x=x1; else x=x2;\n"
           + "if (y2>=y1) y=y1; else y=y2;\n"
           + "makeRectangle(x, y, abs(x2-x1), abs(y2-y1));\n"
           + "wait(10);\n"
           + "}\n"
           + "run('To Selection');\n";
   new MacroRunner(macro, x + " " + y);
 }
Ejemplo n.º 5
0
 public void keyReleased(KeyEvent e) {
   IJ.setKeyUp(e.getKeyCode());
 }