added chached image, to avoid multiple download of the same image

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/image-previewer-widget@134913 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-26 15:10:04 +00:00
parent 8497c44374
commit d0dfa453a4
2 changed files with 57 additions and 28 deletions

View File

@ -2,6 +2,8 @@ package org.gcube.portlets.widgets.imagepreviewerwidget.client;
import org.gcube.portlets.widgets.imagepreviewerwidget.shared.Orientation;
import com.github.gwtbootstrap.client.ui.Image;
/**
* This class allows to build the image to show within the carousel. It contains:
* <ul>
@ -34,6 +36,11 @@ public class EnhancedImage {
*/
private Orientation orientation = Orientation.UNDEFINED;
/**
* The cached image (once downloaded)
*/
private Image cachedImage;
/**
* Build an enhanced image from a url.
* @param imageUrl the url of the image.
@ -129,6 +136,14 @@ public class EnhancedImage {
this.orientation = orientation;
}
public Image getCachedImage() {
return cachedImage;
}
public void setCachedImage(Image cachedImage) {
this.cachedImage = cachedImage;
}
@Override
public String toString() {
return "EnhancedImage [titleToShow=" + titleToShow + ", toolTipToShow="

View File

@ -332,6 +332,15 @@ public class Carousel extends Composite{
showLoader();
final EnhancedImage imageToShow = listOfAttachmentsToShow.get(index);
// check if it was already shown before and cached...
if(imageToShow.getCachedImage() != null){
shownImage = imageToShow.getCachedImage();
setOrientation(imageToShow, imageToShow.getOrientation());
}else{
final String url = imageToShow.getImageUrl();
// when image is downloaded ...
@ -361,12 +370,17 @@ public class Carousel extends Composite{
}else{
setOrientation(imageToShow, imageToShow.getOrientation());
}
// cache it
imageToShow.setCachedImage(shownImage);
}
});
// fetch the image from the url
shownImage.setUrl(url);
}
// change image tooltip
shownImage.setTitle(imageToShow.getToolTipToShow());