/** * Zooms in by making the window bigger. If it can't be made bigger, then make the source * rectangle (srcRect) smaller and center it at (sx,sy). Note that sx and sy are screen * coordinates. */ public void zoomIn(int sx, int sy) { if (magnification >= 32) return; double newMag = getHigherZoomLevel(magnification); int newWidth = (int) (imageWidth * newMag); int newHeight = (int) (imageHeight * newMag); Dimension newSize = canEnlarge(newWidth, newHeight); if (newSize != null) { setDrawingSize(newSize.width, newSize.height); if (newSize.width != newWidth || newSize.height != newHeight) adjustSourceRect(newMag, sx, sy); else setMagnification(newMag); imp.getWindow().pack(); } else adjustSourceRect(newMag, sx, sy); repaint(); if (srcRect.width < imageWidth || srcRect.height < imageHeight) resetMaxBounds(); }
/** Implements the Image/Zoom/View 100% command. */ public void zoom100Percent() { if (magnification == 1.0) return; double imag = imp.getWindow().getInitialMagnification(); if (magnification != imag) unzoom(); if (magnification == 1.0) return; if (magnification < 1.0) { while (magnification < 1.0) zoomIn(imageWidth / 2, imageHeight / 2); } else if (magnification > 1.0) { while (magnification > 1.0) zoomOut(imageWidth / 2, imageHeight / 2); } else return; int x = xMouse, y = yMouse; if (mouseExited) { x = imageWidth / 2; y = imageHeight / 2; } int sx = screenX(x); int sy = screenY(y); adjustSourceRect(1.0, sx, sy); repaint(); }