geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/gallery/ImagesGallery.java

165 lines
5.1 KiB
Java
Raw Normal View History

2021-07-19 18:04:14 +02:00
package org.gcube.portlets.user.geoportaldataviewer.client.ui.gallery;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
2021-07-19 18:04:14 +02:00
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
2021-07-21 12:13:24 +02:00
import com.google.gwt.user.client.Random;
2021-07-19 18:04:14 +02:00
import com.google.gwt.user.client.ui.HTMLPanel;
2021-07-21 12:13:24 +02:00
/**
* The Class ImagesGallery.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jul 21, 2021
*/
2021-07-19 18:04:14 +02:00
public class ImagesGallery {
2021-07-21 12:13:24 +02:00
private HTMLPanel galleryPanel;
2021-07-19 18:04:14 +02:00
private List<UploadedImageDV> listImages;
2021-07-21 12:13:24 +02:00
private String galleryDivId;
2021-07-19 18:04:14 +02:00
2021-07-21 12:13:24 +02:00
/**
* Show gallery.
*
* @param json_array_images the json array images
*/
private native void showGallery(JavaScriptObject json_array_images, String galleryDivId) /*-{
2021-07-19 18:04:14 +02:00
console.log("showing: " + json_array_images)
var waitForJQuery = setInterval(
function() {
if (typeof $wnd.$ != 'undefined') {
$wnd
2021-07-21 12:13:24 +02:00
.$("#"+galleryDivId)
2021-07-19 18:04:14 +02:00
.nanogallery2(
{
2021-07-21 12:13:24 +02:00
thumbnailHeight : '200 XS150 SM150', // RESPONSIVE THUMBNAIL HEIGHT: default=200px, XS resolution=150px, SM resolution=150px
2021-07-23 19:02:24 +02:00
thumbnailWidth : '218 XS150 SM150', // RESPONSIVE THUMBNAIL WIDTH: auto
2021-07-20 15:18:33 +02:00
thumbnailAlignment : 'left',
thumbnailBorderHorizontal : 0,
thumbnailBorderVertical : 0,
thumbnailGutterWidth : '10 XS10 SM10',
thumbnailGutterHeight : '10 XS10 SM10',
// THUMBNAIL TOOLS & LABEL
thumbnailLabel : {
display : true,
position : 'onBottom',
align : 'left'
},
thumbnailToolbarImage : {
bottomLeft : 'display'
},
// replace the default DISPLAY tool icon
icons : {
thumbnailDisplay : '<i class="fa fa-long-arrow-right" aria-hidden="true"></i> display'
},
2021-07-19 18:04:14 +02:00
2021-07-20 15:18:33 +02:00
// DISPLAY ANIMATION
galleryDisplayTransition : 'slideUp',
galleryDisplayTransitionDuration : 1000,
thumbnailDisplayTransition : 'scaleDown',
thumbnailDisplayTransitionDuration : 300,
thumbnailDisplayInterval : 50,
2021-07-19 18:04:14 +02:00
// THUMBNAIL'S HOVER ANIMATION
2021-07-20 15:18:33 +02:00
//thumbnailBuildInit2 : 'tools_font-size_1.5em|title_font-size_1.5em',
2021-07-21 12:13:24 +02:00
thumbnailHoverEffect2 : 'imageScaleIn80|tools_opacity_0_1|tools_translateX_-30px_0px|title_opacity_1_0|title_translateX_0px_-30px',
2021-07-19 18:04:14 +02:00
touchAnimation : true,
touchAutoOpenDelay : 800,
2021-07-20 15:18:33 +02:00
// GALLERY THEME
galleryTheme : {
thumbnail : {
2021-07-30 15:08:03 +02:00
borderRadius : '2px !important',
background : '#ffffff !important',
titleShadow : 'none !important',
titleColor : '#696969 !important',
labelBackground : '#f3f3f3 !important'
2021-07-20 15:18:33 +02:00
},
thumbnailIcon : {
color : '#000',
shadow : 'none'
},
},
2021-07-19 18:04:14 +02:00
viewerToolbar : {
display : true,
standard : 'minimizeButton, label',
minimized : 'minimizeButton, label, fullscreenButton, downloadButton'
},
viewerTools : {
topLeft : 'pageCounter',
topRight : 'playPauseButton, zoomButton, fullscreenButton, downloadButton, closeButton'
},
// DEEP LINKING
locationHash : false,
items : json_array_images
})
clearInterval(waitForJQuery);
}
}, 200);
}-*/;
2021-07-21 12:13:24 +02:00
/**
* Instantiates a new images gallery.
*
* @param immagini the immagini
*/
2021-07-19 18:04:14 +02:00
public ImagesGallery(List<UploadedImageDV> immagini) {
2021-07-21 12:13:24 +02:00
this.galleryDivId = "nanogallery"+Random.nextInt()+Random.nextInt();
this.galleryPanel = new HTMLPanel("<div id='"+galleryDivId+"'></div>");
2021-07-19 18:04:14 +02:00
this.listImages = immagini;
}
2021-07-21 12:13:24 +02:00
/**
* Gets the gallery panel.
*
* @return the gallery panel
*/
2021-07-19 18:04:14 +02:00
public HTMLPanel getGalleryPanel() {
return galleryPanel;
}
2021-07-21 12:13:24 +02:00
/**
* Fill gallery.
*/
2021-07-19 18:04:14 +02:00
public void fillGallery() {
JSONArray jsonArray = new JSONArray();
int index = 0;
for (UploadedImageDV image : listImages) {
for (WorkspaceContentDV imageContent : image.getListWsContent()) {
JSONObject json = new JSONObject();
json.put("src", new JSONString(imageContent.getLink()));
json.put("srct", new JSONString(imageContent.getLink()));
2021-07-20 15:18:33 +02:00
List<String> listAuthors = image.getResponsabili();
2021-07-21 12:13:24 +02:00
String txtAuthors = listAuthors.size()>1 ? "Authors: ": "Author: ";
2021-07-20 15:18:33 +02:00
for (String author : listAuthors) {
txtAuthors+= " "+author +",";
}
2021-07-21 12:13:24 +02:00
txtAuthors = txtAuthors.substring(0,txtAuthors.length()-2);
2021-07-23 19:02:24 +02:00
String description = txtAuthors + ". ID Licenza: "+image.getLicenseID();
2021-07-19 18:04:14 +02:00
json.put("title", new JSONString(image.getDidascalia()));
2021-07-20 15:18:33 +02:00
json.put("description", new JSONString(description));
2021-07-19 18:04:14 +02:00
json.put("downloadURL", new JSONString(imageContent.getLink()));
jsonArray.set(index, json);
index++;
}
}
2021-07-21 12:13:24 +02:00
showGallery(jsonArray.getJavaScriptObject(), galleryDivId);
2021-07-19 18:04:14 +02:00
}
}