/** Predicts, whether Canvas can enlarge on this desktop, even in tiled mode */ // TODO: ChannelCanvas or z/t sliders are not handled fully correctly. @Override protected Dimension canEnlarge(final int newWidth, final int newHeight) { if ((flags & Event.SHIFT_MASK) != 0 || IJ.shiftKeyDown()) return null; final ImageWindow win = imp.getWindow(); if (win == null) return null; final Rectangle r1 = win.getBounds(); final Dimension prefSize = ((Image5DLayout) win.getLayout()).preferredLayoutSize(win, newWidth, newHeight); r1.width = prefSize.width; r1.height = prefSize.height; final Rectangle max = ((Image5DWindow) win).getMaxWindowI5d(); final boolean fitsHorizontally = r1.x + r1.width < max.x + max.width; final 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; }
/** Returns the size to which the window can be enlarged, or null if it can't be enlarged. * <code>newWidth, newHeight</code> is the size needed for showing the full image * at the magnification needed */ protected Dimension canEnlarge(int newWidth, int newHeight) { if (IJ.altKeyDown()) 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+ImageWindow.HGAP*2; r1.height = newHeight+insets.top+insets.bottom+ImageWindow.VGAP*2+win.getSliderHeight(); } else { r1.width = r1.width - dstWidth + newWidth; r1.height = r1.height - dstHeight + newHeight; } 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 fitToWindow() { ImageWindow win = imp.getWindow(); if (win==null) return; Rectangle bounds = win.getBounds(); Insets insets = win.getInsets(); int sliderHeight = win.getSliderHeight(); double xmag = (double)(bounds.width-(insets.left+insets.right+ImageWindow.HGAP*2))/srcRect.width; double ymag = (double)(bounds.height-(ImageWindow.VGAP*2+insets.top+insets.bottom+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); setSize(width, height); getParent().doLayout(); }
/** Returns the size to which the window can be enlarged, or null if it can't be enlarged. * <code>newWidth, newHeight</code> is the size needed for showing the full image * at the magnification needed */ protected Dimension canEnlarge(int newWidth, int newHeight) { if (IJ.altKeyDown()) 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+ImageWindow.HGAP*2; r1.height = newHeight+insets.top+insets.bottom+ImageWindow.VGAP*2+win.getSliderHeight(); } else { r1.width = r1.width - dstWidth + newWidth; r1.height = r1.height - dstHeight + newHeight; } 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 fitToWindow() { ImageWindow win = imp.getWindow(); if (win==null) return; Rectangle bounds = win.getBounds(); Insets insets = win.getInsets(); int sliderHeight = win.getSliderHeight(); double xmag = (double)(bounds.width-(insets.left+insets.right+ImageWindow.HGAP*2))/srcRect.width; double ymag = (double)(bounds.height-(ImageWindow.VGAP*2+insets.top+insets.bottom+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); setSize(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 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(); }
void zoomToSelection(ImagePlus imp, ImageCanvas ic) { Roi roi = imp.getRoi(); ic.unzoom(); if (roi==null) return; Rectangle w = imp.getWindow().getBounds(); Rectangle r = roi.getBounds(); double mag = ic.getMagnification(); int marginw = (int)((w.width - mag * imp.getWidth())); int marginh = (int)((w.height - mag * imp.getHeight())); int x = r.x+r.width/2; int y = r.y+r.height/2; mag = ic.getHigherZoomLevel(mag); while(r.width*mag<w.width - marginw && r.height*mag<w.height - marginh) { ic.zoomIn(ic.screenX(x), ic.screenY(y)); double cmag = ic.getMagnification(); if (cmag==32.0) break; mag = ic.getHigherZoomLevel(cmag); w = imp.getWindow().getBounds(); } }
void zoomToSelection(ImagePlus imp, ImageCanvas ic) { Roi roi = imp.getRoi(); ic.unzoom(); if (roi==null) return; Rectangle w = imp.getWindow().getBounds(); Rectangle r = roi.getBounds(); double mag = ic.getMagnification(); int marginw = (int)((w.width - mag * imp.getWidth())); int marginh = (int)((w.height - mag * imp.getHeight())); int x = r.x+r.width/2; int y = r.y+r.height/2; mag = ic.getHigherZoomLevel(mag); while(r.width*mag<w.width - marginw && r.height*mag<w.height - marginh) { ic.zoomIn(ic.screenX(x), ic.screenY(y)); double cmag = ic.getMagnification(); if (cmag==32.0) break; mag = ic.getHigherZoomLevel(cmag); w = imp.getWindow().getBounds(); } }