]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/gui/PhotoThumbnail.java
Version 11.1, August 2010
[GpsPrune.git] / tim / prune / gui / PhotoThumbnail.java
index 101f1a39c64aefcada6069c146765d4938ce3f34..cc7e776e224aa4bb93a3bb3831faac5c42c457c3 100644 (file)
@@ -7,6 +7,7 @@ import java.awt.Image;
 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;
@@ -19,6 +20,7 @@ public class PhotoThumbnail extends JPanel implements Runnable
        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") + " ...";
 
@@ -42,6 +44,7 @@ public class PhotoThumbnail extends JPanel implements Runnable
                if (_photo != inPhoto) {
                        _photo = inPhoto;
                        _thumbnail = null;
+                       _loadFailed = false;
                }
                repaint();
        }
@@ -51,6 +54,7 @@ public class PhotoThumbnail extends JPanel implements Runnable
         */
        public void refresh() {
                _thumbnail = null;
+               _loadFailed = false;
        }
 
        /**
@@ -63,7 +67,7 @@ public class PhotoThumbnail extends JPanel implements Runnable
                if (_photo != null)
                {
                        // read thumbnail in separate thread
-                       if (_thumbnail == null && !_loadingImage)
+                       if (_thumbnail == null && !_loadingImage && !_loadFailed)
                        {
                                _loadingImage = true;
                                new Thread(this).start();
@@ -74,7 +78,7 @@ public class PhotoThumbnail extends JPanel implements Runnable
                                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;
@@ -85,10 +89,19 @@ public class PhotoThumbnail extends JPanel implements Runnable
                                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();
+                                               }
+                                       });
                                }
                        }
                }
@@ -124,6 +137,7 @@ public class PhotoThumbnail extends JPanel implements Runnable
                                _thumbnail = ImageUtils.createScaledImage(image, thumbSize.width, thumbSize.height);
                                image = null;
                        }
+                       else _loadFailed = true;
                }
                _loadingImage = false;
                repaint();