- // Make icon to load image into
- Image image = new ImageIcon(_photo.getFile().getAbsolutePath()).getImage();
- // save scaled, smoothed thumbnail for reuse
- _thumbnail = ImageUtils.createScaledImage(image, thumbSize.width, thumbSize.height);
- image = null;
- // TODO: Calculate and set size of thumbnail here
- // setPreferredSize(new Dimension(200, 200));
+ int displayWidth = Math.min(getWidth(), getParent().getWidth());
+ // System.out.println("width = " + getWidth() + ", " + getParent().getWidth() + " = " + displayWidth);
+ int displayHeight = Math.min(getHeight(), getParent().getHeight());
+ // System.out.println("height = " + getHeight() + ", " + getParent().getHeight() + " = " + displayHeight);
+
+ // calculate maximum thumbnail size
+ Dimension thumbSize = ImageUtils.getThumbnailSize(picWidth, picHeight, displayWidth, displayHeight);
+ // Work out if need to remake image
+ boolean needToRemake = (_thumbnail == null)
+ || _thumbnail.getWidth() != thumbSize.width || _thumbnail.getHeight() != thumbSize.height;
+ if (thumbSize.width > 0 && thumbSize.height > 0 && needToRemake)
+ {
+ // Make icon to load image into
+ Image image = new ImageIcon(_photo.getFile().getAbsolutePath()).getImage();
+ // save scaled, smoothed thumbnail for reuse
+ _thumbnail = ImageUtils.createScaledImage(image, thumbSize.width, thumbSize.height);
+ image = null;
+ // TODO: Calculate and set size of thumbnail here
+ // setPreferredSize(new Dimension(200, 200));
+ }