public void loadEmbeddedMacros() {
    boolean altDown = IJ.altKeyDown(); // 3.8.2009
    boolean shiftDown = IJ.shiftKeyDown(); // 18.8.2009
    if (shiftDown) {
      shiftDown = shiftDown && true;
    }
    if (IJ.debugMode) {
      IJ.log("alt=" + altDown + "   shift=" + shiftDown);
    }
    String macros_text = null;
    String macroFileName = null;
    if (OJ.isProjectOpen) {
      DataOJ data = OJ.getData();
      String project_name = data.getName();

      String directory = data.getDirectory();
      macroFileName = project_name + ".txt";
      File macros_file = new File(directory, macroFileName);
      MacroInstaller mi = new MacroInstaller();
      // mechanism to remove manually loaded project files
      macros_text = OJ.getData().getLinkedMacroText(); // 18.3.2010
      boolean externalMacroExists = macros_file.exists() && macros_file.isFile();
      boolean internalMacroExists = (macros_text != null);
      if (!internalMacroExists && !externalMacroExists) {
        // mi.install(macros_text);16.9.2010
        return;
      }
      if (externalMacroExists && internalMacroExists) {
        IJ.showMessage("Project has internal macro, so external macro is ignored");
      }
      if (externalMacroExists && !internalMacroExists) {
        String thisVersion = IJ.getVersion();
        boolean is143d = thisVersion.compareToIgnoreCase("1.43d") >= 0;
        if (is143d) {
          String oldMacroName = ij.plugin.MacroInstaller.getFileName();
          if (oldMacroName != null && oldMacroName.equalsIgnoreCase(macroFileName)) {
            oldMacroName = oldMacroName + "";
            String macro = "macro 'Dummy Tool-Cf00O8822' {}\n"; // kill old tools
            mi.install(macro);

            String dir = IJ.getDirectory("macros") + "StartupMacros.txt";
            File startup_file = new File(IJ.getDirectory("macros"), "StartupMacros.txt");
            if (startup_file.exists()) {
              IJ.showMessage("Macros in \"" + macroFileName + "\" will appear under ObjectJ menu");
              mi.installFile(dir);
            }
            mi.setFileName(""); // 15.7.2009
          }
        }

        macros_text = UtilsOJ.readStringFromFile(macros_file);
      }
      OJ.getData().setLinkedMacroText(macros_text);
      doInstall(macros_text);
    }
  }
示例#2
0
 protected void handleRoiMouseDown(MouseEvent e) {
   int sx = e.getX();
   int sy = e.getY();
   int ox = offScreenX(sx);
   int oy = offScreenY(sy);
   Roi roi = imp.getRoi();
   int handle = roi != null ? roi.isHandle(sx, sy) : -1;
   boolean multiPointMode =
       roi != null
           && (roi instanceof PointRoi)
           && handle == -1
           && Toolbar.getToolId() == Toolbar.POINT
           && Toolbar.getMultiPointMode();
   if (multiPointMode) {
     imp.setRoi(((PointRoi) roi).addPoint(ox, oy));
     return;
   }
   setRoiModState(e, roi, handle);
   if (roi != null) {
     if (handle >= 0) {
       roi.mouseDownInHandle(handle, sx, sy);
       return;
     }
     Rectangle r = roi.getBounds();
     int type = roi.getType();
     if (type == Roi.RECTANGLE
         && r.width == imp.getWidth()
         && r.height == imp.getHeight()
         && roi.getPasteMode() == Roi.NOT_PASTING
         && !(roi instanceof ImageRoi)) {
       imp.killRoi();
       return;
     }
     if (roi.contains(ox, oy)) {
       if (roi.modState == Roi.NO_MODS) roi.handleMouseDown(sx, sy);
       else {
         imp.killRoi();
         imp.createNewRoi(sx, sy);
       }
       return;
     }
     if ((type == Roi.POLYGON || type == Roi.POLYLINE || type == Roi.ANGLE)
         && roi.getState() == roi.CONSTRUCTING) return;
     int tool = Toolbar.getToolId();
     if ((tool == Toolbar.POLYGON || tool == Toolbar.POLYLINE || tool == Toolbar.ANGLE)
         && !(IJ.shiftKeyDown() || IJ.altKeyDown())) {
       imp.killRoi();
       return;
     }
   }
   imp.createNewRoi(sx, sy);
 }
示例#3
0
 protected void mouseDownInHandle(int handle, int sx, int sy) {
   if (state == CONSTRUCTING) return;
   int ox = ic.offScreenX(sx), oy = ic.offScreenY(sy);
   double oxd = ic.offScreenXD(sx), oyd = ic.offScreenYD(sy);
   if (IJ.altKeyDown() && !(nPoints <= 3 && type != POINT)) {
     deleteHandle(oxd, oyd);
     return;
   } else if (IJ.shiftKeyDown() && type != POINT) {
     addHandle(oxd, oyd);
     return;
   }
   state = MOVING_HANDLE;
   activeHandle = handle;
   int m = (int) (10.0 / ic.getMagnification());
   xClipMin = ox - m;
   yClipMin = oy - m;
   xClipMax = ox + m;
   yClipMax = oy + m;
 }
示例#4
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);
    }
  }