/** Moves and resizes this window. Changes the magnification so the image fills the window. */ public void setLocationAndSize(int x, int y, int width, int height) { setBounds(x, y, width, height); getCanvas().fitToWindow(); pack(); }
/** Moves and resizes this window. Changes the magnification so the image fills the window. */ public void setLocationAndSize(int x, int y, int width, int height) { setBounds(x, y, width, height); getCanvas().fitToWindow(); pack(); }
private void scaleToFit(ImagePlus imp) { ImageCanvas ic = imp.getCanvas(); if (ic==null) return; if (ic.getScaleToFit()) { ic.setScaleToFit(false); ic.unzoom(); IJ.showStatus("Exiting scale to fit mode (resize with 'alt' key to scale to fit)"); } else { ic.setScaleToFit(true); ic.fitToWindow(); IJ.showStatus("Resize window to scale (use 'alt' key as shortcut)"); } }
private void scaleToFit(ImagePlus imp) { ImageCanvas ic = imp.getCanvas(); if (ic==null) return; if (ic.getScaleToFit()) { ic.setScaleToFit(false); ic.unzoom(); IJ.showStatus("Exiting scale to fit mode (resize with 'alt' key to scale to fit)"); } else { ic.setScaleToFit(true); ic.fitToWindow(); IJ.showStatus("Resize window to scale (use 'alt' key as shortcut)"); } }
/** Resizes the plot (unless frozen) to fit the window */ public void fitToWindow() { if (plot == null || plot.isFrozen()) { super.fitToWindow(); return; } ImageWindow win = imp.getWindow(); if (win==null) return; Rectangle bounds = win.getBounds(); Dimension extraSize = win.getExtraSize(); int width = bounds.width-extraSize.width;//(insets.left+insets.right+ImageWindow.HGAP*2); int height = bounds.height-extraSize.height;//(insets.top+insets.bottom+ImageWindow.VGAP*2); //IJ.log("fitToWindow "+bounds+"-> w*h="+width+"*"+height); resizeCanvas(width, height); getParent().doLayout(); }
/** Resizes the plot (unless frozen) to fit the window */ public void fitToWindow() { if (plot == null || plot.isFrozen()) { super.fitToWindow(); return; } ImageWindow win = imp.getWindow(); if (win==null) return; Rectangle bounds = win.getBounds(); Dimension extraSize = win.getExtraSize(); int width = bounds.width-extraSize.width;//(insets.left+insets.right+ImageWindow.HGAP*2); int height = bounds.height-extraSize.height;//(insets.top+insets.bottom+ImageWindow.VGAP*2); //IJ.log("fitToWindow "+bounds+"-> w*h="+width+"*"+height); resizeCanvas(width, height); getParent().doLayout(); }
/** Resizes the canvas when the user resizes 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 (scaleToFit || IJ.altKeyDown()) {fitToWindow(); return;} if (width>imageWidth*magnification) width = (int)(imageWidth*magnification); if (height>imageHeight*magnification) height = (int)(imageHeight*magnification); Dimension size = getSize(); if (srcRect.width<imageWidth || srcRect.height<imageHeight || (painted&&(width!=size.width||height!=size.height))) { setSize(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); }
/** Resizes the canvas when the user resizes 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 (scaleToFit || IJ.altKeyDown()) {fitToWindow(); return;} if (width>imageWidth*magnification) width = (int)(imageWidth*magnification); if (height>imageHeight*magnification) height = (int)(imageHeight*magnification); Dimension size = getSize(); if (srcRect.width<imageWidth || srcRect.height<imageHeight || (painted&&(width!=size.width||height!=size.height))) { setSize(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); }