public ImagePlusInteractiveDisplay2D(
      final int width,
      final int height,
      final ScreenImageRenderer renderer,
      final TransformListener2D renderTransformListener) {
    sourceToScreen = new AffineTransform2D();

    final ColorProcessor cp = new ColorProcessor(width, height);
    screenImage = new ARGBScreenImage(cp.getWidth(), cp.getHeight(), (int[]) cp.getPixels());

    this.renderer = renderer;
    renderer.screenImageChanged(screenImage);
    this.renderTransformListener = renderTransformListener;

    imp = new ImagePlus("argbScreenProjection", cp);
    imp.show();
    imp.getCanvas().setMagnification(1.0);
    imp.draw();

    gui = new GUI(imp);

    handler = new TransformEventHandler2Dij(imp, this);
    handler.setWindowCenter(width / 2, height / 2);
    addHandler(handler);

    // additional keyboard mappings
    addHandler(
        new KeyListener() {
          @Override
          public void keyPressed(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_E) {
              IJ.log(sourceToScreen.toString());
            } else if (e.getKeyCode() == KeyEvent.VK_F1) {
              IJ.showMessage(handler.getHelpString());
            } else if (e.getKeyCode() == KeyEvent.VK_PLUS || e.getKeyCode() == KeyEvent.VK_EQUALS) {
              IJ.run("In [+]");
            } else if (e.getKeyCode() == KeyEvent.VK_MINUS) {
              IJ.run("Out [-]");
            }
          }

          @Override
          public void keyTyped(final KeyEvent e) {}

          @Override
          public void keyReleased(final KeyEvent e) {}
        });
  }
Пример #2
0
 public void drawVerticalString(String string, int x, int y) {
   // x and y here are the center of the string
   FontMetrics fm = cp.getFontMetrics();
   int ascent = fm.getAscent();
   int descent = fm.getDescent();
   int height = ascent + descent;
   int width = cp.getStringWidth(string);
   int[] mask = new int[width * height];
   for (int i = 0; i < width * height; i++) {
     mask[i] = 0xffffffff;
   }
   ColorProcessor cp2 = new ColorProcessor(width, height, mask);
   cp2.setAntialiasedText(antialias);
   cp2.setFont(cp.getFont());
   cp2.drawString(string, 0, ascent);
   ColorProcessor cp3 = (ColorProcessor) cp2.rotateLeft();
   mask = (int[]) cp3.getPixels();
   int newx = x - height / 2;
   int newy = y - width / 2;
   int[] pixels = (int[]) cp.getPixels();
   int owidth = cp.getWidth();
   int oheight = cp.getHeight();
   for (int i = 0; i < width; i++) {
     int b = newy + i;
     if (b >= 0 && b < oheight) {
       for (int j = 0; j < height; j++) {
         int a = newx + j;
         if (a >= 0 && a < owidth) {
           if (mask[j + i * height] != 0xffffffff) {
             pixels[a + owidth * b] = mask[j + i * height];
           }
         }
       }
     }
   }
 }