import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
import tim.prune.I18nManager;
import tim.prune.data.Photo;
private Photo _photo = null;
private BufferedImage _thumbnail = null;
private boolean _loadingImage = false;
+ private boolean _loadFailed = false;
/** String to show before photo is loaded */
private static final String LOADING_STRING = I18nManager.getText("details.photo.loading") + " ...";
if (_photo != inPhoto) {
_photo = inPhoto;
_thumbnail = null;
+ _loadFailed = false;
}
repaint();
}
*/
public void refresh() {
_thumbnail = null;
+ _loadFailed = false;
}
/**
if (_photo != null)
{
// read thumbnail in separate thread
- if (_thumbnail == null && !_loadingImage)
+ if (_thumbnail == null && !_loadingImage && !_loadFailed)
{
_loadingImage = true;
new Thread(this).start();
inG.setColor(Color.BLACK);
inG.drawString(LOADING_STRING, 10, 30);
}
- else
+ else if (_thumbnail != null && !_loadFailed)
{
// Copy scaled, smoothed (and rotated) image into scaled
int usableWidth = getParent().getWidth()-10;
int horizOffset = (getWidth() - scaleWidth) / 2;
int vertOffset = (getHeight() - scaleHeight) / 2;
inG.drawImage(scaled, horizOffset, vertOffset, scaleWidth, scaleHeight, null);
- if (getHeight() < getWidth())
+ if (getHeight() < getWidth() || getHeight() > usableWidth)
{
- setPreferredSize(new Dimension(usableWidth, usableWidth));
+ Dimension newsize = new Dimension(usableWidth, usableWidth);
+ setPreferredSize(newsize);
+ setSize(newsize);
invalidate();
+ // Schedule a relayout because the size has changed
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ try {Thread.sleep(200);} catch (InterruptedException e) {}
+ getParent().getParent().getParent().validate();
+ }
+ });
}
}
}
_thumbnail = ImageUtils.createScaledImage(image, thumbSize.width, thumbSize.height);
image = null;
}
+ else _loadFailed = true;
}
_loadingImage = false;
repaint();