problem using ImageComponent (from Incubator)

Hello guys!

I have been trying to use the image component from
Incubator
with no success, the problem is I am getting the following error.

The type com.itmill.toolkit.ui.Embedded cannot be resolved. It is indirectly referenced from required .class files

I have the jar added to the build path.


The component jar from here

Bellow is the code from the class I am trying to use the Image component.

import java.util.Map;

import javax.servlet.http.HttpSession;

import com.example.wabongosuomi.WabongosuomiApplication;
import com.example.wabongosuomi.utils.Utils;
import com.itmill.incubator.image.Image;
import com.vaadin.service.ApplicationContext;
import com.vaadin.terminal.FileResource;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
import com.vaadin.ui.Button;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;

@SuppressWarnings("serial")
public class MemberToolsPanel extends Panel implements Button.ClickListener{
	private String username = "";
	private java.io.File file;
	private FileResource fileResource;
	private Embedded embLogo;
	public ApplicationContext ctx;
	public WebApplicationContext webCtx;	
	public HttpSession session;
	private Window main;
	private Image image;
	@SuppressWarnings("unchecked")
	public MemberToolsPanel(WabongosuomiApplication app, Map params)
	{
		main = app.getMainWindow();
		ctx = main.getApplication().getContext();
		webCtx = (WebApplicationContext) ctx;
		session = webCtx.getHttpSession();
		username = (String)session.getAttribute("UserName");
		setCaption("Home");
		Label lb = new Label("This is the panel");
		addComponent(lb);
		setSizeFull();
		setStyleName(Panel.STYLE_LIGHT);
	
		int imageExists = Utils.checkFileExistance(Utils.imagePath()+"/images/Home_Thumb_"+username+".jpg");
		if(imageExists == 1)
		{	
			image = new Image(Utils.imagePath()+"/images/Home_Thumb_"+username+".jpg", true);
//			file = new java.io.File(Utils.imagePath()+"/images/Home_Thumb_"+username+".jpg");	
//			fileResource = new FileResource(file, app.getMainWindow().getApplication());
//			embLogo = new Embedded("",fileResource);
//			embLogo.setWidth("300px");
//			embLogo.setHeight("240px");
		}
		if(imageExists == 0)
		{	
			image = new Image(Utils.imagePath()+"/images/Home_Thumb_default.jpg", true);
//			file = new java.io.File(Utils.imagePath()+"/images/Home_Thumb_default.jpg");	
//			fileResource = new FileResource(file, app.getMainWindow().getApplication());
//			embLogo = new Embedded("",fileResource);			
		}
		image.fit(150,150,true);
		image.roundCorners(5);		
		image.shadow(135, 5);
		addComponent(image);
	}

	public void buttonClick(ClickEvent event) {
		// TODO Auto-generated method stub
		
	}


}

Thanks.

Quite so. The Jar is compiled against the IT Mill Toolkit 5.3.0 and it is not compatible with the Vaadin. There should not be nothing else to change than the import package naming. If you wish to use it with Vaadin, you need the source code from incubator and find and replace
com.itmill.toolkit
to
com.vaadin
.

Sorry about this. I haven’t got time to upgrade all the incubator projects yet.

I updated the ImageComponent source for Vaadin and created a new Jar. Take an update to try it, and let us know if there are any problems.

Great! Thanks it works fine, thanks for quick reply.

Any idea on how to add a click listener to the image component ?

Suggestion.

It would be nice to have a constructor for file too, now it accepts a URL as image source, how about a file, or just a normal file path. i.e

image = new Image(new java.io.File("/images/imageFile.jpg"), true)

or image = new Image("/images/imageFile.jpg", true)

Thanks

Thanks Risto for the quick upgrade!

I think it would be a good idea to add a file constructor. The suggested string constructor might also be meaningful with resources via classloader. I’ll add them them, but let me know if you are (again) faster than me :slight_smile:

Any update on this ?

N.

Hi,

Unfortunately no update yet - at least for my part. I haven’t forgot this, but just been busy with other projects so far. I’ll post here if/when I come up with an enhancements.

I actually did some of this on the weekend. I followed

Jonatan’s
instructions given on this very same question. After snooping around a bit I noticed that the Image -component is a extension of the Embedded -component, and it doesn’t say anything on how it should act on the client side. This is why it doesn’t need any gwt code to work and that you can just drop the jar into your project. Doing the clicklistener -extension would require to compile the new widget and build a new widgetset. Distribution is not anymore as easy as dropping a jar.

I suggest just copying the clickable layout instead of extending Image to give it the addlistener functionality. You can just drop the Image component into one of these layouts, and use the same layout to other components too!

We’re trying uservoice on pitching new ideas to Vaadin, so I made a
suggestion
about this as well. Go vote this up if you want this functionality natively into Vaadin!