Rectangle viewRect = null;
if ( parent instanceof JViewport ) {
viewRect = ((JViewport)parent).getViewRect();
}
PhotoInfo nextPhoto = null;
// Walk through all photos until we find a photo that is visible
// and does not have a thumbnail. If all visible photos have a thumbnail
// but some non-visible ones do not, create a thumbnail for one of those.
log.debug( "Finding photo without thumbnail" );
for ( int n = 0; n < photoCollection.getPhotoCount(); n++ ) {
PhotoInfo photoCandidate = photoCollection.getPhoto( n );
log.debug( "Photo " + photoCandidate.getUid() );
if ( !photoCandidate.hasThumbnail() ) {
log.debug( "No thumbnail" );
Rectangle photoRect = getPhotoBounds( n );
if ( photoRect.intersects( viewRect ) ) {
// This photo is visible so it is a perfect candidate
// for thumbnail creation. Do not look further
nextPhoto = photoCandidate;
break;
} else if ( nextPhoto == null ) {
// Not visible but no photo without thumbnail has been
// found previously. Store as a candidate and keep looking.
nextPhoto = photoCandidate;
}
}
}
if ( nextPhoto != null && !thumbCreatorThread.isBusy() ) {
final PhotoInfo p = nextPhoto;
// SwingUtilities.invokeLater( new Runnable() {
// public void run() {
log.debug( "Making request for the next thumbail, " + p.getUid() );
thumbCreatorThread.createThumbnail( p );
log.debug( "request submitted" );
// }
// });
}