package org.gcube.portlets.user.reportgenerator.client.dialog;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
import org.gcube.portlets.user.reportgenerator.client.components.FancyFileUpload;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* ImageUploaderDialog
class is the Dialog for uploading images
*
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
* @version October 2008 (0.2)
*/
public class ImageUploaderDialog extends DialogBox {
private int width;
private int height;
private Presenter presenter;
private String currTemplateName = "";
private HorizontalPanel topLabel = new HorizontalPanel();
private EventListener listener = new EventListener();
private RadioButton local = new RadioButton("");
private RadioButton web = new RadioButton("");
/**
* the container panel
*/
private VerticalPanel mainLayout = new VerticalPanel();
private VerticalPanel dialogPanel = new VerticalPanel();
/**
* Creates the dialog
* @param presenter my controller
*/
public ImageUploaderDialog(Presenter presenter) {
// Create a dialog box and set the caption text
this.width = 400;
this.height = 200;
this.presenter = presenter;
setText("Insert Image");
local.setHTML(" From this computer");
topLabel.add(local);
local.setChecked(true);
web.setHTML(" From the web (URL)");
topLabel.add(web);
web.addClickListener(listener);
local.addClickListener(listener);
currTemplateName = presenter.getModel().getTemplateName();
dialogPanel.add(getFromLocalPanel());
dialogPanel.setPixelSize(this.width, this.height);
mainLayout.add(topLabel);
mainLayout.add(dialogPanel);
setWidget(mainLayout);
}
private VerticalPanel getFromLocalPanel() {
VerticalPanel toReturn = new VerticalPanel();
FancyFileUpload uploader = new FancyFileUpload(this, currTemplateName);
HTML theLabel = new HTML("Browse your computer for the image file to upload:");
toReturn.add(theLabel);
toReturn.add(uploader);
toReturn.setSpacing(4);
toReturn.setStyleName("uploadDialog");
toReturn.setPixelSize(this.width, this.height);
return toReturn;
}
private VerticalPanel getFromURLPanel() {
VerticalPanel toReturn = new VerticalPanel();
toReturn.setSpacing(5);
HTML theLabel = new HTML("Enter image web address:");
final TextBox urlTextbox = new TextBox();
urlTextbox.setWidth("90%");
final HTML previewBox = new HTML("