/******************************************************************************* * * * ******************************************************************************/ private Point computeCenterPoint() { return new Point(-(int)Math.round(((getAvailableWidth() / scale) - image.getWidth()) / 2), -(int)Math.round(((getAvailableHeight() / scale) - image.getHeight()) / 2)); }
/******************************************************************************* * * Computes a new origin so that the given image point is shown at the given * relative coordinates. * * @param imagePoint the coordinates of the image pixel * @param componentPoint the relative coordinates where to show imagePoint * @return the new origin * ******************************************************************************/ protected Point computeOrigin (final Point imagePoint, final Point componentPoint, final double scale) { if (image == null) { return null; } int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); if ((imageWidth == 0) || (imageHeight == 0)) // can happen if metadata is not loaded yet { return null; } return new Point((int)Math.round(imagePoint.x - (componentPoint.x / scale)), (int)Math.round(imagePoint.y - (componentPoint.y / scale))); }
int imageWidth = image.getWidth(); int imageHeight = image.getHeight();
int imageWidth = image.getWidth(); int imageHeight = image.getHeight();
final int widthWithMargin = image.getWidth() + margin.left + margin.right; final int heightWithMargin = image.getHeight() + margin.top + margin.bottom; final int xMax = (image.getWidth() + margin.right) - maxWidth; final int yMax = (image.getHeight() + margin.bottom) - maxHeight; this.origin.x = (maxWidth <= widthWithMargin) ? Math.min(Math.max(xMin, origin.x), xMax) : (-(maxWidth - image.getWidth()) / 2); this.origin.y = (maxHeight <= heightWithMargin) ? Math.min(Math.max(yMin, origin.y), yMax) : (-(maxHeight - image.getHeight()) / 2);
/******************************************************************************* * * * ******************************************************************************/ public double getFitScale () { double hScale = (double)getAvailableWidth() / image.getWidth(); double vScale = (double)getAvailableHeight() / image.getHeight(); return Math.min(hScale, vScale); // if (this.scale < 0) // { // logger.info("SCALE < 0: w:" + w + " h:" + h + " iw:" + iw + " ih:" + ih); // } }
/*************************************************************************** * * Updates the scrollbar cursors positions. * **************************************************************************/ private void updateScrollBars () { if (scrollBarsVisible) { horizontalScrollBar.setValues(this.origin.x, (int)Math.round(getAvailableWidth() / scale), 0, image.getWidth()); verticalScrollBar.setValues(this.origin.y, (int)Math.round(getAvailableHeight() / scale), 0, image.getHeight()); } }
@Override public int print (final Graphics graphics, final PageFormat pageFormat, final int pageIndex) throws PrinterException { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } Graphics2D g2d = (Graphics2D)graphics; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); final double xScale = pageFormat.getImageableWidth() / image.getWidth(); final double yScale = pageFormat.getImageableHeight() / image.getHeight(); final double aspectScale = Math.min(xScale, yScale); final int width = (int)Math.round(image.getWidth() * aspectScale); final int height = (int)Math.round(image.getHeight() * aspectScale); image.execute(new PaintOp(g2d, 0, 0, width, height, null, null)); return Printable.PAGE_EXISTS; } };
/******************************************************************************************************************* * * Creates a resized image. - FIXME should be removed * @deprecated * ******************************************************************************************************************/ public final EditableImage createResizedImage (final int width, final int height, final Quality quality) { double hScale = (double)width / (double)getWidth(); double vScale = (double)height / (double)getHeight(); ScaleOp scaleOp = new ScaleOp(hScale, vScale, quality); execute(scaleOp); return this; }
/******************************************************************************* * * Sets the image point which is displayed in the top left corner (coordinates * are in actual image pixels). * * @param origin the origin * ******************************************************************************/ public void setOrigin (final Point origin) { logger.info("setOrigin(" + origin + ")"); if ((image != null) && (image.getWidth() > 0) && (image.getHeight() > 0)) { internalSetOrigin(origin); updateScrollBars(); repaint(); } }
double maxSize = scale * Math.max(image.getWidth(), image.getHeight()); boolean needScaling = true; int rotationDeltaX = 0; scaledImage = optimizedImage.execute2(new ScaleOp(scale, getScaleQuality())); final int prevWidth = scaledImage.getWidth(); final int prevHeight = scaledImage.getHeight(); scaledImage.execute(new RotateOp(angle, getRotateQuality())); rotationDeltaX = (prevWidth - scaledImage.getWidth()) / 2; rotationDeltaY = (prevHeight - scaledImage.getHeight()) / 2; shownImageWidth = scaledImage.getWidth(); shownImageHeight = scaledImage.getHeight(); needScaling = false; shownImageWidth = (int)Math.round(scale * optimizedImage.getWidth()); shownImageHeight = (int)Math.round(scale * optimizedImage.getHeight());