Esempio n. 1
0
 public void mouseMoved(MouseEvent e) {
   // if (ij==null) return;
   int sx = e.getX();
   int sy = e.getY();
   int ox = offScreenX(sx);
   int oy = offScreenY(sy);
   flags = e.getModifiers();
   setCursor(sx, sy, ox, oy);
   IJ.setInputEvent(e);
   Roi roi = imp.getRoi();
   if (roi != null
       && (roi.getType() == Roi.POLYGON
           || roi.getType() == Roi.POLYLINE
           || roi.getType() == Roi.ANGLE)
       && roi.getState() == roi.CONSTRUCTING) {
     PolygonRoi pRoi = (PolygonRoi) roi;
     pRoi.handleMouseMove(ox, oy);
   } else {
     if (ox < imageWidth && oy < imageHeight) {
       ImageWindow win = imp.getWindow();
       // Cursor must move at least 12 pixels before text
       // displayed using IJ.showStatus() is overwritten.
       if ((sx - sx2) * (sx - sx2) + (sy - sy2) * (sy - sy2) > 144) showCursorStatus = true;
       if (win != null && showCursorStatus) win.mouseMoved(ox, oy);
     } else IJ.showStatus("");
   }
 }
Esempio n. 2
0
    public synchronized void adjustmentValueChanged(AdjustmentEvent e) {

      if (!checkImage()) {
        IJ.beep();
        IJ.showStatus("No Image");
        return;
      }

      if (e.getSource() == minSlider) {
        adjustMinHue((int) minSlider.getValue());
      } else if (e.getSource() == maxSlider) {
        adjustMaxHue((int) maxSlider.getValue());
      } else if (e.getSource() == minSlider2) {
        adjustMinSat((int) minSlider2.getValue());
      } else if (e.getSource() == maxSlider2) {
        adjustMaxSat((int) maxSlider2.getValue());
      } else if (e.getSource() == minSlider3) {
        adjustMinBri((int) minSlider3.getValue());
      } else if (e.getSource() == maxSlider3) {
        adjustMaxBri((int) maxSlider3.getValue());
      }
      originalB.setEnabled(true);
      updateLabels();
      updatePlot();
      notify();
    }
Esempio n. 3
0
 /** Handle menu events. */
 public void actionPerformed(ActionEvent e) {
   if ((e.getSource() instanceof MenuItem)) {
     MenuItem item = (MenuItem) e.getSource();
     String cmd = e.getActionCommand();
     commandName = cmd;
     ImagePlus imp = null;
     if (item.getParent() == Menus.getOpenRecentMenu()) {
       new RecentOpener(cmd); // open image in separate thread
       return;
     } else if (item.getParent() == Menus.getPopupMenu()) {
       Object parent = Menus.getPopupMenu().getParent();
       if (parent instanceof ImageCanvas) imp = ((ImageCanvas) parent).getImage();
     }
     int flags = e.getModifiers();
     hotkey = false;
     actionPerformedTime = System.currentTimeMillis();
     long ellapsedTime = actionPerformedTime - keyPressedTime;
     if (cmd != null && (ellapsedTime >= 200L || !cmd.equals(lastKeyCommand))) {
       if ((flags & Event.ALT_MASK) != 0) IJ.setKeyDown(KeyEvent.VK_ALT);
       if ((flags & Event.SHIFT_MASK) != 0) IJ.setKeyDown(KeyEvent.VK_SHIFT);
       new Executer(cmd, imp);
     }
     lastKeyCommand = null;
     if (IJ.debugMode) IJ.log("actionPerformed: time=" + ellapsedTime + ", " + e);
   }
 }
Esempio n. 4
0
 /** Called by ImageJ when the user selects Quit. */
 public void quit() {
   quitMacro = IJ.macroRunning();
   Thread thread = new Thread(this, "Quit");
   thread.setPriority(Thread.NORM_PRIORITY);
   thread.start();
   IJ.wait(10);
 }
Esempio n. 5
0
 void handleMouseMove(int sx, int sy) {
   // Do rubber banding
   int tool = Toolbar.getToolId();
   if (!(tool == Toolbar.POLYGON || tool == Toolbar.POLYLINE || tool == Toolbar.ANGLE)) {
     imp.deleteRoi();
     imp.draw();
     return;
   }
   drawRubberBand(sx, sy);
   degrees = Double.NaN;
   double len = -1;
   if (nPoints > 1) {
     double x1, y1, x2, y2;
     if (xpf != null) {
       x1 = xpf[nPoints - 2];
       y1 = ypf[nPoints - 2];
       x2 = xpf[nPoints - 1];
       y2 = ypf[nPoints - 1];
     } else {
       x1 = xp[nPoints - 2];
       y1 = yp[nPoints - 2];
       x2 = xp[nPoints - 1];
       y2 = yp[nPoints - 1];
     }
     degrees =
         getAngle(
             (int) Math.round(x1),
             (int) Math.round(y1),
             (int) Math.round(x2),
             (int) Math.round(y2));
     if (tool != Toolbar.ANGLE) {
       Calibration cal = imp.getCalibration();
       double pw = cal.pixelWidth, ph = cal.pixelHeight;
       if (IJ.altKeyDown()) {
         pw = 1.0;
         ph = 1.0;
       }
       len = Math.sqrt((x2 - x1) * pw * (x2 - x1) * pw + (y2 - y1) * ph * (y2 - y1) * ph);
     }
   }
   if (tool == Toolbar.ANGLE) {
     if (nPoints == 2) angle1 = degrees;
     else if (nPoints == 3) {
       double angle2 = getAngle(xp[1], yp[1], xp[2], yp[2]);
       degrees = Math.abs(180 - Math.abs(angle1 - angle2));
       if (degrees > 180.0) degrees = 360.0 - degrees;
     }
   }
   String length = len != -1 ? ", length=" + IJ.d2s(len) : "";
   double degrees2 =
       tool == Toolbar.ANGLE && nPoints == 3 && Prefs.reflexAngle ? 360.0 - degrees : degrees;
   String angle = !Double.isNaN(degrees) ? ", angle=" + IJ.d2s(degrees2) : "";
   int ox = ic != null ? ic.offScreenX(sx) : sx;
   int oy = ic != null ? ic.offScreenY(sy) : sy;
   IJ.showStatus(imp.getLocationAsString(ox, oy) + length + angle);
 }
Esempio n. 6
0
 private boolean checkImage() {
   imp = WindowManager.getCurrentImage();
   if (imp == null) {
     IJ.beep();
     IJ.showStatus("No image");
     return false;
   }
   ip = setup(imp);
   if (ip == null) return false;
   return true;
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
 /** Quit using a separate thread, hopefully avoiding thread deadlocks. */
 public void run() {
   quitting = true;
   boolean changes = false;
   int[] wList = WindowManager.getIDList();
   if (wList != null) {
     for (int i = 0; i < wList.length; i++) {
       ImagePlus imp = WindowManager.getImage(wList[i]);
       if (imp != null && imp.changes == true) {
         changes = true;
         break;
       }
     }
   }
   Frame[] frames = WindowManager.getNonImageWindows();
   if (frames != null) {
     for (int i = 0; i < frames.length; i++) {
       if (frames[i] != null && (frames[i] instanceof Editor)) {
         if (((Editor) frames[i]).fileChanged()) {
           changes = true;
           break;
         }
       }
     }
   }
   if (windowClosed
       && !changes
       && Menus.window.getItemCount() > Menus.WINDOW_MENU_ITEMS
       && !(IJ.macroRunning() && WindowManager.getImageCount() == 0)) {
     GenericDialog gd = new GenericDialog("ImageJ", this);
     gd.addMessage("Are you sure you want to quit ImageJ?");
     gd.showDialog();
     quitting = !gd.wasCanceled();
     windowClosed = false;
   }
   if (!quitting) return;
   if (!WindowManager.closeAllWindows()) {
     quitting = false;
     return;
   }
   // IJ.log("savePreferences");
   if (applet == null) {
     saveWindowLocations();
     Prefs.savePreferences();
   }
   IJ.cleanup();
   // setVisible(false);
   // IJ.log("dispose");
   dispose();
   if (exitWhenQuitting) System.exit(0);
 }
Esempio n. 9
0
    public void actionPerformed(ActionEvent e) {
      Button b = (Button) e.getSource();
      if (b == null) return;

      boolean imageThere = checkImage();

      if (imageThere) {
        if (b == originalB) {
          reset(imp, ip);
          filteredB.setEnabled(true);
        } else if (b == filteredB) {
          apply(imp, ip);
        } else if (b == sampleB) {
          reset(imp, ip);
          sample();
          apply(imp, ip);
        } else if (b == stackB) {
          applyStack();
        } else if (b == helpB) {
          IJ.showMessage(
              "Help",
              "Threshold Colour  v1.0\n \n"
                  + "Modification of Bob Dougherty's BandPass2 plugin by G.Landini to\n"
                  + "threshold 24 bit RGB images based on Hue, Saturation and Brightness\n"
                  + "or Red, Green and Blue components.\n \n"
                  + "Pass: Band-pass filter (anything within range is displayed).\n \n"
                  + "Stop: Band-reject filter (anything within range is NOT displayed).\n \n"
                  + "Original: Shows the original image and updates the buffer when\n"
                  + " switching to another image.\n \n"
                  + "Filtered: Shows the filtered image.\n \n"
                  + "Stack: Processes the rest of the slices in the stack (if any)\n"
                  + " using the current settings.\n \n"
                  + "Threshold: Shows the object/background in the foreground and\n"
                  + " background colours selected in the ImageJ toolbar.\n \n"
                  + "Invert: Swaps the fore/background colours.\n \n"
                  + "Sample: (experimental) Sets the ranges of the filters based on the\n"
                  + " pixel value componentd in a rectangular, user-defined, ROI.\n \n"
                  + "HSB RGB: Selects HSB or RGB space and resets all the filters.\n \n"
                  + "Note that the \'thresholded\' image is RGB, not 8 bit grey.");
        }
        updatePlot();
        updateLabels();
        imp.updateAndDraw();
      } else {
        IJ.beep();
        IJ.showStatus("No Image");
      }
      notify();
    }
Esempio n. 10
0
 /** Enlarge the canvas if the user enlarges the window. */
 void resizeCanvas(int width, int height) {
   ImageWindow win = imp.getWindow();
   // IJ.log("resizeCanvas: "+srcRect+" "+imageWidth+"  "+imageHeight+" "+width+"  "+height+"
   // "+dstWidth+"  "+dstHeight+" "+win.maxBounds);
   if (!maxBoundsReset
       && (width > dstWidth || height > dstHeight)
       && win != null
       && win.maxBounds != null
       && width != win.maxBounds.width - 10) {
     if (resetMaxBoundsCount != 0)
       resetMaxBounds(); // Works around problem that prevented window from being larger than
                         // maximized size
     resetMaxBoundsCount++;
   }
   if (IJ.altKeyDown()) {
     fitToWindow();
     return;
   }
   if (srcRect.width < imageWidth || srcRect.height < imageHeight) {
     if (width > imageWidth * magnification) width = (int) (imageWidth * magnification);
     if (height > imageHeight * magnification) height = (int) (imageHeight * magnification);
     setDrawingSize(width, height);
     srcRect.width = (int) (dstWidth / magnification);
     srcRect.height = (int) (dstHeight / magnification);
     if ((srcRect.x + srcRect.width) > imageWidth) srcRect.x = imageWidth - srcRect.width;
     if ((srcRect.y + srcRect.height) > imageHeight) srcRect.y = imageHeight - srcRect.height;
     repaint();
   }
   // IJ.log("resizeCanvas2: "+srcRect+" "+dstWidth+"  "+dstHeight+" "+width+"  "+height);
 }
Esempio n. 11
0
 /** Sets the cursor based on the current tool and cursor location. */
 public void setCursor(int sx, int sy, int ox, int oy) {
   xMouse = ox;
   yMouse = oy;
   mouseExited = false;
   Roi roi = imp.getRoi();
   ImageWindow win = imp.getWindow();
   if (win == null) return;
   if (IJ.spaceBarDown()) {
     setCursor(handCursor);
     return;
   }
   int id = Toolbar.getToolId();
   switch (Toolbar.getToolId()) {
     case Toolbar.MAGNIFIER:
       setCursor(moveCursor);
       break;
     case Toolbar.HAND:
       setCursor(handCursor);
       break;
     default: // selection tool
       if (id == Toolbar.SPARE1 || id >= Toolbar.SPARE2) {
         if (Prefs.usePointerCursor) setCursor(defaultCursor);
         else setCursor(crosshairCursor);
       } else if (roi != null && roi.getState() != roi.CONSTRUCTING && roi.isHandle(sx, sy) >= 0)
         setCursor(handCursor);
       else if (Prefs.usePointerCursor
           || (roi != null && roi.getState() != roi.CONSTRUCTING && roi.contains(ox, oy)))
         setCursor(defaultCursor);
       else setCursor(crosshairCursor);
   }
 }
Esempio n. 12
0
 public void mouseDragged(MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   xMouse = offScreenX(x);
   yMouse = offScreenY(y);
   flags = e.getModifiers();
   // IJ.log("mouseDragged: "+flags);
   if (flags == 0) // workaround for Mac OS 9 bug
   flags = InputEvent.BUTTON1_MASK;
   if (Toolbar.getToolId() == Toolbar.HAND || IJ.spaceBarDown()) scroll(x, y);
   else {
     IJ.setInputEvent(e);
     Roi roi = imp.getRoi();
     if (roi != null) roi.handleMouseDrag(x, y, flags);
   }
 }
Esempio n. 13
0
 public void mouseExited(MouseEvent e) {
   // autoScroll(e);
   ImageWindow win = imp.getWindow();
   if (win != null) setCursor(defaultCursor);
   IJ.showStatus("");
   mouseExited = true;
 }
Esempio n. 14
0
 void enlargeArrays() {
   if (xp != null) {
     int[] xptemp = new int[maxPoints * 2];
     int[] yptemp = new int[maxPoints * 2];
     System.arraycopy(xp, 0, xptemp, 0, maxPoints);
     System.arraycopy(yp, 0, yptemp, 0, maxPoints);
     xp = xptemp;
     yp = yptemp;
   }
   if (xpf != null) {
     float[] xpftemp = new float[maxPoints * 2];
     float[] ypftemp = new float[maxPoints * 2];
     System.arraycopy(xpf, 0, xpftemp, 0, maxPoints);
     System.arraycopy(ypf, 0, ypftemp, 0, maxPoints);
     xpf = xpftemp;
     ypf = ypftemp;
   }
   int[] xp2temp = new int[maxPoints * 2];
   int[] yp2temp = new int[maxPoints * 2];
   System.arraycopy(xp2, 0, xp2temp, 0, maxPoints);
   System.arraycopy(yp2, 0, yp2temp, 0, maxPoints);
   xp2 = xp2temp;
   yp2 = yp2temp;
   if (IJ.debugMode) IJ.log("PolygonRoi: " + maxPoints + " points");
   maxPoints *= 2;
 }
Esempio n. 15
0
 protected void moveHandle(int sx, int sy) {
   if (clipboard != null) return;
   int ox = ic.offScreenX(sx);
   int oy = ic.offScreenY(sy);
   if (xpf != null) {
     double offset = getOffset(-0.5);
     xpf[activeHandle] = (float) (ic.offScreenXD(sx) - x + offset);
     ypf[activeHandle] = (float) (ic.offScreenYD(sy) - y + offset);
   } else {
     xp[activeHandle] = ox - x;
     yp[activeHandle] = oy - y;
   }
   if (xSpline != null) {
     fitSpline(splinePoints);
     updateClipRect();
     imp.draw(clipX, clipY, clipWidth, clipHeight);
     oldX = x;
     oldY = y;
     oldWidth = width;
     oldHeight = height;
   } else {
     resetBoundingRect();
     if (type == POINT && width == 0 && height == 0) {
       width = 1;
       height = 1;
     }
     updateClipRectAndDraw();
   }
   String angle = type == ANGLE ? getAngleAsString() : "";
   IJ.showStatus(imp.getLocationAsString(ox, oy) + angle);
 }
Esempio n. 16
0
 public void mouseWheelMoved(MouseWheelEvent event) {
   synchronized (this) {
     int rotation = event.getWheelRotation();
     if (hyperStack) {
       if (rotation > 0) IJ.run(imp, "Next Slice [>]", "");
       else if (rotation < 0) IJ.run(imp, "Previous Slice [<]", "");
     } else {
       int slice = imp.getCurrentSlice() + rotation;
       if (slice < 1) slice = 1;
       else if (slice > imp.getStack().getSize()) slice = imp.getStack().getSize();
       imp.setSlice(slice);
       imp.updateStatusbarValue();
       SyncWindows.setZ(this, slice);
     }
   }
 }
Esempio n. 17
0
 /** Opens a stack of images. */
 ImagePlus openStack(ColorModel cm, boolean show) {
   ImageStack stack = new ImageStack(fi.width, fi.height, cm);
   long skip = fi.getOffset();
   Object pixels;
   try {
     ImageReader reader = new ImageReader(fi);
     InputStream is = createInputStream(fi);
     if (is == null) return null;
     IJ.resetEscape();
     for (int i = 1; i <= fi.nImages; i++) {
       if (!silentMode) IJ.showStatus("Reading: " + i + "/" + fi.nImages);
       if (IJ.escapePressed()) {
         IJ.beep();
         IJ.showProgress(1.0);
         silentMode = false;
         return null;
       }
       pixels = reader.readPixels(is, skip);
       if (pixels == null) break;
       stack.addSlice(null, pixels);
       skip = fi.gapBetweenImages;
       if (!silentMode) IJ.showProgress(i, fi.nImages);
     }
     is.close();
   } catch (Exception e) {
     IJ.log("" + e);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory(fi.fileName);
     stack.trim();
   }
   if (!silentMode) IJ.showProgress(1.0);
   if (stack.getSize() == 0) return null;
   if (fi.sliceLabels != null && fi.sliceLabels.length <= stack.getSize()) {
     for (int i = 0; i < fi.sliceLabels.length; i++) stack.setSliceLabel(fi.sliceLabels[i], i + 1);
   }
   ImagePlus imp = new ImagePlus(fi.fileName, stack);
   if (fi.info != null) imp.setProperty("Info", fi.info);
   if (show) imp.show();
   imp.setFileInfo(fi);
   setCalibration(imp);
   ImageProcessor ip = imp.getProcessor();
   if (ip.getMin() == ip.getMax()) // find stack min and max if first slice is blank
   setStackDisplayRange(imp);
   if (!silentMode) IJ.showProgress(1.0);
   silentMode = false;
   return imp;
 }
Esempio n. 18
0
 public FileOpener(FileInfo fi) {
   this.fi = fi;
   if (fi != null) {
     width = fi.width;
     height = fi.height;
   }
   if (IJ.debugMode) IJ.log("FileInfo: " + fi);
 }
Esempio n. 19
0
 public String getInfo() {
   return version()
       + System.getProperty("os.name")
       + " "
       + System.getProperty("os.version")
       + "; "
       + IJ.freeMemory();
 }
Esempio n. 20
0
 private String version() {
   return "ImageJ "
       + VERSION
       + BUILD
       + "; "
       + "Java "
       + System.getProperty("java.version")
       + (IJ.is64Bit() ? " [64-bit]; " : " [32-bit]; ");
 }
Esempio n. 21
0
 void drawAllROIs(Graphics g) {
   RoiManager rm = RoiManager.getInstance();
   if (rm == null) {
     rm = Interpreter.getBatchModeRoiManager();
     if (rm != null && rm.getList().getItemCount() == 0) rm = null;
   }
   if (rm == null) {
     // if (showAllList!=null)
     //	overlay = showAllList;
     showAllROIs = false;
     repaint();
     return;
   }
   initGraphics(g, null, showAllColor);
   Hashtable rois = rm.getROIs();
   java.awt.List list = rm.getList();
   boolean drawLabels = rm.getDrawLabels();
   currentRoi = null;
   int n = list.getItemCount();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " \"Show All\" ROIs");
   if (labelRects == null || labelRects.length != n) labelRects = new Rectangle[n];
   if (!drawLabels) showAllList = new Overlay();
   else showAllList = null;
   if (imp == null) return;
   int currentImage = imp.getCurrentSlice();
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = Prefs.useNamesAsLabels;
   for (int i = 0; i < n; i++) {
     String label = list.getItem(i);
     Roi roi = (Roi) rois.get(label);
     if (roi == null) continue;
     if (showAllList != null) showAllList.add(roi);
     if (i < 200 && drawLabels && roi == imp.getRoi()) currentRoi = roi;
     if (Prefs.showAllSliceOnly && imp.getStackSize() > 1) {
       if (hyperstack && roi.getPosition() == 0) {
         int c = roi.getCPosition();
         int z = roi.getZPosition();
         int t = roi.getTPosition();
         if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame))
           drawRoi(g, roi, drawLabels ? i : -1);
       } else {
         int position = roi.getPosition();
         if (position == 0) position = getSliceNumber(roi.getName());
         if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i : -1);
       }
     } else drawRoi(g, roi, drawLabels ? i : -1);
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
Esempio n. 22
0
 void setMaxBounds() {
   if (maxBoundsReset) {
     maxBoundsReset = false;
     ImageWindow win = imp.getWindow();
     if (win != null && !IJ.isLinux() && win.maxBounds != null) {
       win.setMaximizedBounds(win.maxBounds);
       win.setMaxBoundsTime = System.currentTimeMillis();
     }
   }
 }
Esempio n. 23
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;
 }
Esempio n. 24
0
 void addScrollbars(ImagePlus imp) {
   ImageStack s = imp.getStack();
   int stackSize = s.getSize();
   nSlices = stackSize;
   hyperStack = imp.getOpenAsHyperStack();
   // imp.setOpenAsHyperStack(false);
   int[] dim = imp.getDimensions();
   int nDimensions = 2 + (dim[2] > 1 ? 1 : 0) + (dim[3] > 1 ? 1 : 0) + (dim[4] > 1 ? 1 : 0);
   if (nDimensions <= 3 && dim[2] != nSlices) hyperStack = false;
   if (hyperStack) {
     nChannels = dim[2];
     nSlices = dim[3];
     nFrames = dim[4];
   }
   // IJ.log("StackWindow: "+hyperStack+" "+nChannels+" "+nSlices+" "+nFrames);
   if (nSlices == stackSize) hyperStack = false;
   if (nChannels * nSlices * nFrames != stackSize) hyperStack = false;
   if (cSelector != null || zSelector != null || tSelector != null) removeScrollbars();
   ImageJ ij = IJ.getInstance();
   if (nChannels > 1) {
     cSelector = new ScrollbarWithLabel(this, 1, 1, 1, nChannels + 1, 'c');
     add(cSelector);
     if (ij != null) cSelector.addKeyListener(ij);
     cSelector.addAdjustmentListener(this);
     cSelector.setFocusable(false); // prevents scroll bar from blinking on Windows
     cSelector.setUnitIncrement(1);
     cSelector.setBlockIncrement(1);
   }
   if (nSlices > 1) {
     char label = nChannels > 1 || nFrames > 1 ? 'z' : 't';
     if (stackSize == dim[2] && imp.isComposite()) label = 'c';
     zSelector = new ScrollbarWithLabel(this, 1, 1, 1, nSlices + 1, label);
     if (label == 't') animationSelector = zSelector;
     add(zSelector);
     if (ij != null) zSelector.addKeyListener(ij);
     zSelector.addAdjustmentListener(this);
     zSelector.setFocusable(false);
     int blockIncrement = nSlices / 10;
     if (blockIncrement < 1) blockIncrement = 1;
     zSelector.setUnitIncrement(1);
     zSelector.setBlockIncrement(blockIncrement);
     sliceSelector = zSelector.bar;
   }
   if (nFrames > 1) {
     animationSelector = tSelector = new ScrollbarWithLabel(this, 1, 1, 1, nFrames + 1, 't');
     add(tSelector);
     if (ij != null) tSelector.addKeyListener(ij);
     tSelector.addAdjustmentListener(this);
     tSelector.setFocusable(false);
     int blockIncrement = nFrames / 10;
     if (blockIncrement < 1) blockIncrement = 1;
     tSelector.setUnitIncrement(1);
     tSelector.setBlockIncrement(blockIncrement);
   }
 }
Esempio n. 25
0
 void applyStack() {
   // int minKeepH = minHue, maxKeepH = maxHue; //GL not needed?
   // int minKeepS = minSat, maxKeepS = maxSat;
   // int minKeepB = minBri, maxKeepB = maxBri;
   for (int i = 1; i <= numSlices; i++) {
     imp.setSlice(i);
     if (!checkImage()) {
       IJ.beep();
       IJ.showStatus("No Image");
       return;
     }
     //	minHue = minKeepH;
     //	maxHue = maxKeepH;
     //	minSat = minKeepS;
     //	maxSat = maxKeepS;
     //	minBri = minKeepB;
     //	maxBri = maxKeepB;
     apply(imp, ip);
   }
 }
Esempio n. 26
0
 /**
  * With segmented selections, ignore first mouse up and finalize when user double-clicks,
  * control-clicks or clicks in start box.
  */
 protected void handleMouseUp(int sx, int sy) {
   if (state == MOVING) {
     state = NORMAL;
     return;
   }
   if (state == MOVING_HANDLE) {
     cachedMask = null; // mask is no longer valid
     state = NORMAL;
     updateClipRect();
     oldX = x;
     oldY = y;
     oldWidth = width;
     oldHeight = height;
     return;
   }
   if (state != CONSTRUCTING) return;
   if (IJ.spaceBarDown()) // is user scrolling image?
   return;
   boolean samePoint = false;
   if (xpf != null)
     samePoint = (xpf[nPoints - 2] == xpf[nPoints - 1] && ypf[nPoints - 2] == ypf[nPoints - 1]);
   else samePoint = (xp[nPoints - 2] == xp[nPoints - 1] && yp[nPoints - 2] == yp[nPoints - 1]);
   Rectangle biggerStartBox =
       new Rectangle(ic.screenXD(startXD) - 5, ic.screenYD(startYD) - 5, 10, 10);
   if (nPoints > 2
       && (biggerStartBox.contains(sx, sy)
           || (ic.offScreenXD(sx) == startXD && ic.offScreenYD(sy) == startYD)
           || (samePoint && (System.currentTimeMillis() - mouseUpTime) <= 500))) {
     nPoints--;
     addOffset();
     finishPolygon();
     return;
   } else if (!samePoint) {
     mouseUpTime = System.currentTimeMillis();
     if (type == ANGLE && nPoints == 3) {
       addOffset();
       finishPolygon();
       return;
     }
     // add point to polygon
     if (xpf != null) {
       xpf[nPoints] = xpf[nPoints - 1];
       ypf[nPoints] = ypf[nPoints - 1];
       nPoints++;
       if (nPoints == xpf.length) enlargeArrays();
     } else {
       xp[nPoints] = xp[nPoints - 1];
       yp[nPoints] = yp[nPoints - 1];
       nPoints++;
       if (nPoints == xp.length) enlargeArrays();
     }
     // if (lineWidth>1) fitSpline();
   }
 }
Esempio n. 27
0
 void abortPluginOrMacro(ImagePlus imp) {
   if (imp != null) {
     ImageWindow win = imp.getWindow();
     if (win != null) {
       win.running = false;
       win.running2 = false;
     }
   }
   Macro.abort();
   Interpreter.abort();
   if (Interpreter.getInstance() != null) IJ.beep();
 }
  public void run(String arg) {
    if (IJ.versionLessThan("1.49d")) return;

    if (!showDialog()) return;

    SaveDialog sd = new SaveDialog("Save as Bricks...", "", "");
    basename = sd.getFileName();
    directory = sd.getDirectory();
    if (basename == null || directory == null) return;

    build_bricks();
  }
Esempio n. 29
0
 protected void handlePopupMenu(MouseEvent e) {
   if (disablePopupMenu) return;
   if (IJ.debugMode) IJ.log("show popup: " + (e.isPopupTrigger() ? "true" : "false"));
   int x = e.getX();
   int y = e.getY();
   Roi roi = imp.getRoi();
   if (roi != null
       && (roi.getType() == Roi.POLYGON
           || roi.getType() == Roi.POLYLINE
           || roi.getType() == Roi.ANGLE)
       && roi.getState() == roi.CONSTRUCTING) {
     roi.handleMouseUp(x, y); // simulate double-click to finalize
     roi.handleMouseUp(x, y); // polygon or polyline selection
     return;
   }
   PopupMenu popup = Menus.getPopupMenu();
   if (popup != null) {
     add(popup);
     if (IJ.isMacOSX()) IJ.wait(10);
     popup.show(this, x, y);
   }
 }
Esempio n. 30
0
 public void paint(Graphics g) {
   Roi roi = imp.getRoi();
   if (roi != null || showAllROIs || overlay != null) {
     if (roi != null) roi.updatePaste();
     if (!IJ.isMacOSX() && imageWidth != 0) {
       paintDoubleBuffered(g);
       return;
     }
   }
   try {
     if (imageUpdated) {
       imageUpdated = false;
       imp.updateImage();
     }
     Java2.setBilinearInterpolation(g, Prefs.interpolateScaledImages);
     Image img = imp.getImage();
     if (img != null)
       g.drawImage(
           img,
           0,
           0,
           (int) (srcRect.width * magnification),
           (int) (srcRect.height * magnification),
           srcRect.x,
           srcRect.y,
           srcRect.x + srcRect.width,
           srcRect.y + srcRect.height,
           null);
     if (overlay != null) drawOverlay(g);
     if (showAllROIs) drawAllROIs(g);
     if (roi != null) drawRoi(roi, g);
     if (srcRect.width < imageWidth || srcRect.height < imageHeight) drawZoomIndicator(g);
     if (IJ.debugMode) showFrameRate(g);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory("Paint");
   }
 }