예제 #1
0
 /** Displays this dialog box. */
 public void showDialog() {
   if (macro) {
     dispose();
     recorderOn = Recorder.record && Recorder.recordInMacros;
   } else {
     if (pfr != null) // prepare preview (not in macro mode): tell the PlugInFilterRunner to listen
     pfr.setDialog(this);
     Panel buttons = new Panel();
     buttons.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 0));
     cancel = new Button(cancelLabel);
     cancel.addActionListener(this);
     cancel.addKeyListener(this);
     if (yesNoCancel) {
       okLabel = yesLabel;
       no = new Button(noLabel);
       no.addActionListener(this);
       no.addKeyListener(this);
     }
     okay = new Button(okLabel);
     okay.addActionListener(this);
     okay.addKeyListener(this);
     boolean addHelp = helpURL != null;
     if (addHelp) {
       help = new Button(helpLabel);
       help.addActionListener(this);
       help.addKeyListener(this);
     }
     if (IJ.isMacintosh()) {
       if (addHelp) buttons.add(help);
       if (yesNoCancel) buttons.add(no);
       if (!hideCancelButton) buttons.add(cancel);
       buttons.add(okay);
     } else {
       buttons.add(okay);
       if (yesNoCancel) buttons.add(no);
       ;
       if (!hideCancelButton) buttons.add(cancel);
       if (addHelp) buttons.add(help);
     }
     c.gridx = 0;
     c.gridy = y;
     c.anchor = GridBagConstraints.EAST;
     c.gridwidth = 2;
     c.insets = new Insets(15, 0, 0, 0);
     grid.setConstraints(buttons, c);
     add(buttons);
     if (IJ.isMacintosh()) setResizable(false);
     pack();
     setup();
     if (centerDialog) GUI.center(this);
     setVisible(true);
     recorderOn = Recorder.record;
     IJ.wait(50); // work around for Sun/WinNT bug
   }
   /* For plugins that read their input only via dialogItemChanged, call it at least once */
   if (!wasCanceled && dialogListeners != null && dialogListeners.size() > 0) {
     resetCounters();
     ((DialogListener) dialogListeners.elementAt(0)).dialogItemChanged(this, null);
     recorderOn = false;
   }
   resetCounters();
 }
예제 #2
0
 private Label makeLabel(String label) {
   if (IJ.isMacintosh()) label += " ";
   return new Label(label);
 }
예제 #3
0
  public void mousePressed(MouseEvent e) {
    // if (ij==null) return;
    showCursorStatus = true;
    int toolID = Toolbar.getToolId();
    ImageWindow win = imp.getWindow();
    if (win != null && win.running2 && toolID != Toolbar.MAGNIFIER) {
      if (win instanceof StackWindow) ((StackWindow) win).setAnimate(false);
      else win.running2 = false;
      return;
    }

    int x = e.getX();
    int y = e.getY();
    flags = e.getModifiers();
    // IJ.log("Mouse pressed: " + e.isPopupTrigger() + "  " + ij.modifiers(flags));
    // if (toolID!=Toolbar.MAGNIFIER && e.isPopupTrigger()) {
    if (toolID != Toolbar.MAGNIFIER
        && (e.isPopupTrigger() || (!IJ.isMacintosh() && (flags & Event.META_MASK) != 0))) {
      handlePopupMenu(e);
      return;
    }

    int ox = offScreenX(x);
    int oy = offScreenY(y);
    xMouse = ox;
    yMouse = oy;
    if (IJ.spaceBarDown()) {
      // temporarily switch to "hand" tool of space bar down
      setupScroll(ox, oy);
      return;
    }
    if (showAllROIs) {
      Roi roi = imp.getRoi();
      if (!(roi != null && (roi.contains(ox, oy) || roi.isHandle(x, y) >= 0))
          && roiManagerSelect(x, y)) return;
    }
    if (customRoi && overlay != null) return;

    switch (toolID) {
      case Toolbar.MAGNIFIER:
        if (IJ.shiftKeyDown()) zoomToSelection(ox, oy);
        else if ((flags & (Event.ALT_MASK | Event.META_MASK | Event.CTRL_MASK)) != 0) {
          // IJ.run("Out");
          zoomOut(x, y);
          if (getMagnification() < 1.0) imp.repaintWindow();
        } else {
          // IJ.run("In");
          zoomIn(x, y);
          if (getMagnification() <= 1.0) imp.repaintWindow();
        }
        break;
      case Toolbar.HAND:
        setupScroll(ox, oy);
        break;
      case Toolbar.DROPPER:
        setDrawingColor(ox, oy, IJ.altKeyDown());
        break;
      case Toolbar.WAND:
        Roi roi = imp.getRoi();
        if (roi != null && roi.contains(ox, oy)) {
          Rectangle r = roi.getBounds();
          if (r.width == imageWidth && r.height == imageHeight) imp.killRoi();
          else if (!e.isAltDown()) {
            handleRoiMouseDown(e);
            return;
          }
        }
        if (roi != null) {
          int handle = roi.isHandle(x, y);
          if (handle >= 0) {
            roi.mouseDownInHandle(handle, x, y);
            return;
          }
        }
        setRoiModState(e, roi, -1);
        String mode = WandToolOptions.getMode();
        double tolerance = WandToolOptions.getTolerance();
        int npoints = IJ.doWand(ox, oy, tolerance, mode);
        if (Recorder.record && npoints > 0) {
          if (tolerance == 0.0 && mode.equals("Legacy")) Recorder.record("doWand", ox, oy);
          else
            Recorder.recordString(
                "doWand(" + ox + ", " + oy + ", " + tolerance + ", \"" + mode + "\");\n");
        }
        break;
      case Toolbar.OVAL:
        if (Toolbar.getBrushSize() > 0) new RoiBrush();
        else handleRoiMouseDown(e);
        break;
      case Toolbar.SPARE1:
      case Toolbar.SPARE2:
      case Toolbar.SPARE3:
      case Toolbar.SPARE4:
      case Toolbar.SPARE5:
      case Toolbar.SPARE6:
      case Toolbar.SPARE7:
      case Toolbar.SPARE8:
      case Toolbar.SPARE9:
        Toolbar.getInstance().runMacroTool(toolID);
        break;
      default: // selection tool
        handleRoiMouseDown(e);
    }
  }