public void setImage(BufferedImage image, String format) { ImageDocument document = imageComponent.getDocument(); BufferedImage previousImage = document.getValue(); document.setValue(image); if (image == null) return; document.setFormat(format); ImageZoomModel zoomModel = getZoomModel(); if (previousImage == null || !zoomModel.isZoomLevelChanged()) { // Set smart zooming behaviour on open Options options = OptionsManager.getInstance().getOptions(); ZoomOptions zoomOptions = options.getEditorOptions().getZoomOptions(); // Open as actual size zoomModel.setZoomFactor(1.0d); if (zoomOptions.isSmartZooming()) { Dimension prefferedSize = zoomOptions.getPrefferedSize(); if (prefferedSize.width > image.getWidth() && prefferedSize.height > image.getHeight()) { // Resize to preffered size // Calculate zoom factor double factor = (prefferedSize.getWidth() / (double) image.getWidth() + prefferedSize.getHeight() / (double) image.getHeight()) / 2.0d; zoomModel.setZoomFactor(Math.ceil(factor)); } } } }
public boolean canZoomOut() { double factor = getZoomFactor(); double minFactor = getMinimumZoomFactor(); double stepSize = (1.0 - minFactor) / MICRO_ZOOM_LIMIT; double step = Math.ceil((1.0 - factor) / stepSize); return step < MICRO_ZOOM_LIMIT; }
public void zoomOut() { double factor = getZoomFactor(); if (factor > 1.0d) { // Macro setZoomFactor(factor / 2.0d); } else { // Micro double minFactor = getMinimumZoomFactor(); double stepSize = (1.0d - minFactor) / MICRO_ZOOM_LIMIT; int step = (int) Math.ceil((1.0d - factor) / stepSize); setZoomFactor(1.0d - stepSize * (step + 1)); } myZoomLevelChanged = true; }