diff --git a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java
index f44366c..39c8b00 100644
--- a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java
+++ b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java
@@ -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:
*
@@ -33,6 +35,11 @@ public class EnhancedImage {
* The orientation
*/
private Orientation orientation = Orientation.UNDEFINED;
+
+ /**
+ * The cached image (once downloaded)
+ */
+ private Image cachedImage;
/**
* Build an enhanced image from a url.
@@ -128,6 +135,14 @@ public class EnhancedImage {
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
}
+
+ public Image getCachedImage() {
+ return cachedImage;
+ }
+
+ public void setCachedImage(Image cachedImage) {
+ this.cachedImage = cachedImage;
+ }
@Override
public String toString() {
diff --git a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java
index 927004d..31f5730 100644
--- a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java
+++ b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java
@@ -245,7 +245,7 @@ public class Carousel extends Composite{
currentPreviewPosition =
currentPreviewPosition == listOfAttachmentsToShow.size() -1 ?
0 : currentPreviewPosition + 1;
-
+
// show the image
showImage(currentPreviewPosition);
@@ -332,40 +332,54 @@ public class Carousel extends Composite{
showLoader();
final EnhancedImage imageToShow = listOfAttachmentsToShow.get(index);
- final String url = imageToShow.getImageUrl();
- // when image is downloaded ...
- shownImage.addLoadHandler(new LoadHandler() {
+ // check if it was already shown before and cached...
+ if(imageToShow.getCachedImage() != null){
- @Override
- public void onLoad(LoadEvent event) {
+ shownImage = imageToShow.getCachedImage();
+ setOrientation(imageToShow, imageToShow.getOrientation());
- // call only if undefined
- if(imageToShow.getOrientation().equals(Orientation.UNDEFINED)){
+ }else{
- imageServices.getImageOrientation(url, new AsyncCallback() {
+ final String url = imageToShow.getImageUrl();
- @Override
- public void onSuccess(Orientation result) {
- imageToShow.setOrientation(result);
- setOrientation(imageToShow, result);
- }
+ // when image is downloaded ...
+ shownImage.addLoadHandler(new LoadHandler() {
- @Override
- public void onFailure(Throwable caught) {
- imageToShow.setOrientation(Orientation.DO_NOT_ROTATE);
- setOrientation(imageToShow, Orientation.DO_NOT_ROTATE);
- }
- });
+ @Override
+ public void onLoad(LoadEvent event) {
- }else{
- setOrientation(imageToShow, imageToShow.getOrientation());
+ // call only if undefined
+ if(imageToShow.getOrientation().equals(Orientation.UNDEFINED)){
+
+ imageServices.getImageOrientation(url, new AsyncCallback() {
+
+ @Override
+ public void onSuccess(Orientation result) {
+ imageToShow.setOrientation(result);
+ setOrientation(imageToShow, result);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ imageToShow.setOrientation(Orientation.DO_NOT_ROTATE);
+ setOrientation(imageToShow, Orientation.DO_NOT_ROTATE);
+ }
+ });
+
+ }else{
+ setOrientation(imageToShow, imageToShow.getOrientation());
+ }
+
+ // cache it
+ imageToShow.setCachedImage(shownImage);
}
- }
- });
+ });
- // fetch the image from the url
- shownImage.setUrl(url);
+ // fetch the image from the url
+ shownImage.setUrl(url);
+
+ }
// change image tooltip
shownImage.setTitle(imageToShow.getToolTipToShow());
@@ -427,10 +441,10 @@ public class Carousel extends Composite{
default: shownImage.addStyleName("rotate-0");
}
-
+
// few ms are needed to remove/add the style, after that we remove the loading image
Timer t = new Timer() {
-
+
@Override
public void run() {
removeLoader();