/** * Returns the scaled Image of the source Figure. If the Image needs to be updated, the * ThumbnailUpdater will notified. * * @return The thumbnail image */ protected Image getThumbnailImage() { Dimension oldSize = targetSize; targetSize = getPreferredSize(); targetSize.expand(new Dimension(getInsets().getWidth(), getInsets().getHeight()).negate()); setScales( targetSize.width / (float) getSourceRectangle().width, targetSize.height / (float) getSourceRectangle().height); if ((isDirty()) && !updater.isRunning()) updater.start(); else if (oldSize != null && !targetSize.equals(oldSize)) { revalidate(); updater.restart(); } return thumbnailImage; }
private Dimension adjustToAspectRatio(Dimension size, boolean adjustToMaxDimension) { Dimension sourceSize = getSourceRectangle().getSize(); Dimension borderSize = new Dimension(getInsets().getWidth(), getInsets().getHeight()); size.expand(borderSize.getNegated()); int width, height; if (adjustToMaxDimension) { width = Math.max( size.width, (int) (size.height * sourceSize.width / (float) sourceSize.height + 0.5)); height = Math.max( size.height, (int) (size.width * sourceSize.height / (float) sourceSize.width + 0.5)); } else { width = Math.min( size.width, (int) (size.height * sourceSize.width / (float) sourceSize.height + 0.5)); height = Math.min( size.height, (int) (size.width * sourceSize.height / (float) sourceSize.width + 0.5)); } size.width = width; size.height = height; return size.expand(borderSize); }