159 lines
4.0 KiB
Java
159 lines
4.0 KiB
Java
package org.gcube.portlets.user.reportgenerator.client.targets;
|
|
|
|
|
|
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.Image;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
/**
|
|
* <code> ImageArea </code> class is the Widget that goes into the workspace
|
|
*
|
|
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
|
* @version October 2008 (0.2)
|
|
*/
|
|
public class ImageArea extends Composite {
|
|
|
|
private String templateName;
|
|
private String imageName;
|
|
|
|
private String currentUser;
|
|
private String currentScope;
|
|
|
|
VerticalPanel myPanel;
|
|
Image myImage = new Image();
|
|
|
|
/**
|
|
* Creates an image with a specified URL. The load event will be fired once
|
|
* the image at the given URL has been retrieved by the browser.
|
|
*
|
|
* @param presenter .
|
|
* @param param the imageName of the image to be displayed or the URL to be displayed depending on the isURL param
|
|
* @param myTemplate the template name that owns the image, useful when template it's saved with another name
|
|
* to eventually copy the images in the new template images folder
|
|
* @param isURL true if passing a URL, false is passing image name
|
|
* @param w width
|
|
* @param h height
|
|
*/
|
|
public ImageArea(Presenter presenter, String param, String myTemplate, boolean isURL, int w, int h) {
|
|
myPanel = new VerticalPanel();
|
|
currentUser = presenter.getCurrentUser().getUsername();
|
|
currentScope = presenter.getCurrentScope();
|
|
//Window.alert("Image Area");
|
|
|
|
if (isURL) {
|
|
//need to get the name from the URL
|
|
int lastSlash = param.lastIndexOf("/");
|
|
if (lastSlash > -1) {
|
|
imageName = param.substring(lastSlash+1, param.length());
|
|
}
|
|
else
|
|
imageName = param;
|
|
this.templateName = "CURRENT_OPEN";
|
|
//Window.alert(param);
|
|
myImage.setUrl(param);
|
|
|
|
} else {
|
|
imageName = param;
|
|
this.templateName = myTemplate;
|
|
|
|
String imgURL = getImageURL(imageName, "CURRENT_OPEN");
|
|
|
|
|
|
myImage.setUrl(imgURL);
|
|
}
|
|
myImage.setPixelSize(w, h);
|
|
myPanel.setStyleName("d4sFrame");
|
|
myPanel.add(myImage);
|
|
initWidget(myPanel);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return .
|
|
*/
|
|
public String getUrl() {
|
|
return myImage.getUrl();
|
|
}
|
|
|
|
/**
|
|
* return a URL which is lookable for on the web
|
|
* @param imageName .
|
|
* @param templateName .
|
|
* @return .
|
|
*/
|
|
public String getImageURL(String imageName, String templateName) {
|
|
|
|
|
|
/**
|
|
* Images will be stored under webapps/usersArea...
|
|
* GWT.getModuleBaseURL() returns * e.g. http://dlib28.isti.cnr.it/templatecreator/html/
|
|
* need to get just http://dlib28.isti.cnr.it/
|
|
*/
|
|
//remove "/html/" and get e.g. http://dlib28.isti.cnr.it/templatecreator
|
|
String host = GWT.getModuleBaseURL().substring(0, GWT.getModuleBaseURL().length()-6);
|
|
|
|
//loog for last slash
|
|
int lastSlash = host.lastIndexOf("/");
|
|
|
|
//get what i need : e.g. http://dlib28.isti.cnr.it/ or host = "http://localhost:8080/";
|
|
host = host.substring(0, lastSlash +1 );
|
|
//host = "http://localhost:8080/";
|
|
|
|
String imgURL = host + "usersArea/" + currentScope + "/templates/"
|
|
+ currentUser + "/" + "CURRENT_OPEN" + "/images/" + imageName;
|
|
GWT.log(imgURL);
|
|
return imgURL;
|
|
}
|
|
/**
|
|
*
|
|
* @return a string containing the owner template name
|
|
*/
|
|
public String getTemplateName() {
|
|
return templateName;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param myTemplate the template owner
|
|
*/
|
|
public void setTemplateName(String myTemplate) {
|
|
this.templateName = myTemplate;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return .
|
|
*/
|
|
public String getImageName() {
|
|
return imageName;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param imageName .
|
|
*/
|
|
public void setImageName(String imageName) {
|
|
this.imageName = imageName;
|
|
}
|
|
/**
|
|
*
|
|
* @return the scope in which the application is running on
|
|
*/
|
|
public String getCurrentScope() {
|
|
return currentScope;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return the user username who is using the application
|
|
*/
|
|
public String getCurrentUser() {
|
|
return currentUser;
|
|
}
|
|
|
|
|
|
}
|