ImageFilter component: Filter and display images in Vaadin application

Hi all,

Continuing to publish my stock of more or less experimental Vaadin components. Here is the “ImageFilter”. It was originally an IT Mill Toolkit component, but I rewrote it to support stacking of filters. This version also uses (a lot of) filters from the excellent
JH Labs Java image filter package
.

Here is how you would use the (server-side) image filter component:

// Load an image from a public URL and cache it. Caching is useful if
// you revert and re-apply the filters.
Image image = new Image(
        "http://www.streamhead.com/wp-content/uploads/2010/01/vaadin.png",
        true);
mainWindow.addComponent(image);

// Create transparent rounded corners
op = FilterOperation
        .getByName(FilterOperation.ROUNDEDCORNERS);
((RoundedCornersFilter) op.getFilter()).setCornerRadius(cornerRadius);
image.addOperation(op);

// Add a drop shadow using default values
image.addOperation(FilterOperation.getByName(FilterOperation.DROPSHADOW));

// Remember to apply the filter stack
image.applyOperations();

Attached the Vaadin add-on jar. Remember to download the Filters.jar from
JH Labs
also.

Apache 2.0 source code is here:
http://dev.vaadin.com/svn/contrib/ImageFilter/

Oh, almost forgot the
online demo
.
11224.jar (374 KB)

The demo is hypnotic… So many filters to choose from.

I tried the demo and got this error

com.vaadin.event.ListenerMethod$MethodException
Cause: java.lang.ClassCastException: com.jhlabs.image.BrushedMetalFilter cannot be cast to com.jhlabs.image.AbstractBufferedImageOp
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:507)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1106)
	at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:864)
	at com.vaadin.ui.AbstractField.setValue(AbstractField.java:514)
	at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:640)
	at com.vaadin.ui.AbstractSelect.changeVariables(AbstractSelect.java:449)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1058)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:559)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:260)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:438)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
	at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
	at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
	at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
	at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: com.jhlabs.image.BrushedMetalFilter cannot be cast to com.jhlabs.image.AbstractBufferedImageOp
	at org.vaadin.imagefilter.FilterOperation.createBufferedImageOp(FilterOperation.java:217)
	at org.vaadin.imagefilter.FilterOperation.getByName(FilterOperation.java:235)
	at org.vaadin.imagefilter.ImageSampleApplication$2.valueChange(ImageSampleApplication.java:153)
	at sun.reflect.GeneratedMethodAccessor170.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487)
	... 27 more

Sorry about that. Unfortunately, not all filters in the JH Labs filter package are implemented the same way. Tried to filter out all “incompatible” filters, but you found one.

I deployed a new demo, but the add-on jar still lists the incompatible filter. So be careful out there. :slight_smile:

This is an excellent widget for image manipulation but If you just need a light-weight image scaling at the client-side you might consider using the ImageScaler add-on instead. See
http://vaadin.com/directory#addon/130