void resetMaxBounds() { ImageWindow win = imp.getWindow(); if (win != null && (System.currentTimeMillis() - win.setMaxBoundsTime) > 500L) { win.setMaximizedBounds(win.maxWindowBounds); maxBoundsReset = true; } }
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(""); } }
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(); } } }
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(); }
private boolean ignoreArrowKeys(ImagePlus imp) { Frame frame = WindowManager.getFrontWindow(); String title = frame.getTitle(); if (title != null && title.equals("ROI Manager")) return true; // Control Panel? if (frame != null && frame instanceof javax.swing.JFrame) return true; ImageWindow win = imp.getWindow(); // LOCI Data Browser window? if (imp.getStackSize() > 1 && win != null && win.getClass().getName().startsWith("loci")) return true; return false; }
/** Implements the Image/Zoom/Original Scale command. */ public void unzoom() { double imag = imp.getWindow().getInitialMagnification(); if (magnification == imag) return; srcRect = new Rectangle(0, 0, imageWidth, imageHeight); ImageWindow win = imp.getWindow(); setDrawingSize((int) (imageWidth * imag), (int) (imageHeight * imag)); setMagnification(imag); setMaxBounds(); win.pack(); setMaxBounds(); repaint(); }
/** Overrides ImagePlus.show(). * */ public void show() { if (img == null && ip != null) img = ip.createImage(); ImageWindow.centerNextImage(); win = new ImageWindow(this, new ColorCanvas(this)); draw(); IJ.showStatus(""); }
public void fitToWindow() { ImageWindow win = imp.getWindow(); if (win == null) return; Rectangle bounds = win.getBounds(); Insets insets = win.getInsets(); int sliderHeight = (win instanceof StackWindow) ? 20 : 0; double xmag = (double) (bounds.width - 10) / srcRect.width; double ymag = (double) (bounds.height - (10 + insets.top + sliderHeight)) / srcRect.height; setMagnification(Math.min(xmag, ymag)); int width = (int) (imageWidth * magnification); int height = (int) (imageHeight * magnification); if (width == dstWidth && height == dstHeight) return; srcRect = new Rectangle(0, 0, imageWidth, imageHeight); setDrawingSize(width, height); getParent().doLayout(); }
protected Dimension canEnlarge(int newWidth, int newHeight) { // if ((flags&Event.CTRL_MASK)!=0 || IJ.controlKeyDown()) return null; ImageWindow win = imp.getWindow(); if (win == null) return null; Rectangle r1 = win.getBounds(); Insets insets = win.getInsets(); Point loc = getLocation(); if (loc.x > insets.left + 5 || loc.y > insets.top + 5) { r1.width = newWidth + insets.left + insets.right + 10; r1.height = newHeight + insets.top + insets.bottom + 10; if (win instanceof StackWindow) r1.height += 20; } else { r1.width = r1.width - dstWidth + newWidth + 10; r1.height = r1.height - dstHeight + newHeight + 10; } Rectangle max = win.getMaxWindow(r1.x, r1.y); boolean fitsHorizontally = r1.x + r1.width < max.x + max.width; boolean fitsVertically = r1.y + r1.height < max.y + max.height; if (fitsHorizontally && fitsVertically) return new Dimension(newWidth, newHeight); else if (fitsVertically && newHeight < dstWidth) return new Dimension(dstWidth, newHeight); else if (fitsHorizontally && newWidth < dstHeight) return new Dimension(newWidth, dstHeight); else return null; }
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); } }
/*------------------------------------------------------------------*/ public void run(String arg) { ImagePlus imp = WindowManager.getCurrentImage(); this.imp = imp; if (imp == null) { IJ.noImage(); return; } if ((1 < imp.getStackSize()) && (imp.getType() == imp.COLOR_256)) { IJ.error("Stack of color images not supported (use grayscale)"); return; } if (1 < imp.getStackSize()) { if (imp.getStack().isRGB()) { IJ.error("RGB color images not supported (use grayscale)"); return; } } if (1 < imp.getStackSize()) { if (imp.getStack().isHSB()) { IJ.error("HSB color images not supported (use grayscale)"); return; } } if (imp.getType() == imp.COLOR_256) { IJ.error("Indexed color images not supported (use grayscale)"); return; } if (imp.getType() == imp.COLOR_RGB) { IJ.error("Color images not supported (use grayscale)"); return; } differentialsDialog dialog = new differentialsDialog(IJ.getInstance(), "Differentials", true, operation); GUI.center(dialog); dialog.setVisible(true); cancel = dialog.getCancel(); operation = dialog.getOperation(); dialog.dispose(); if (cancel) { return; } imp.startTiming(); if (1 < imp.getStackSize()) { if (!(imp.getProcessor().getPixels() instanceof float[])) { new StackConverter(imp).convertToGray32(); } } else { if (!(imp.getProcessor().getPixels() instanceof float[])) { new ImageConverter(imp).convertToGray32(); } } ImageStack stack = imp.getStack(); stackSize = stack.getSize(); Undo.reset(); setupProgressBar(); resetProgressBar(); for (int i = 1; (i <= stackSize); i++) { ImageProcessor ip = stack.getProcessor(i); doIt(ip); imp.getProcessor().resetMinAndMax(); imp.setSlice(i); imp.updateAndRepaintWindow(); } imp.getProcessor().resetMinAndMax(); imp.setSlice(1); imp.updateAndRepaintWindow(); cleanUpProgressBar(); IJ.showTime(imp, imp.getStartTime(), "Differentials: "); ImageWindow win = imp.getWindow(); if (win != null) { win.running = false; } } /* end run */