...
Code Block |
---|
import java.io.ByteArrayOutputStream; import java.io.IOException; import org.apache.wicket.Resource; import org.apache.wicket.markup.html.image.Image; import org.apache.wicket.markuprequest.html.image.resource.DynamicImageResource; import org.apache.wicket.model.Model; import org.apache.wicket.protocolrequest.http.WebResponse; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; public class JFreeChartImage extends Image { private final int width; private final int height; public JFreeChartImage(String id, JFreeChart chart, int width, int height){ super(id, new Model(chart)); this.width = width; this.height = height; } @Override protected ResourceDynamicImageResource getImageResource() { return new DynamicImageResource(){ @Override protected byte[] getImageData() { JFreeChart chart = (JFreeChart)getDefaultModelObject(); return toImageData(chart.createBufferedImage(width, height)); } @Override protected void setHeaders(WebResponse response) { if (isCacheable()) { super.setHeaders(response); } else { response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); } } }; } } |
...
Code Block |
---|
@Override protected IResourceDynamicImageResource getImageResource() { DynamicImageResource resource = new DynamicImageResource() { @Override protected byte[] getImageData(final Attributes attributes) { JFreeChart chart = (JFreeChart) getDefaultModelObject(); return toImageData(chart.createBufferedImage(width, height)); } @Override protected void configureResponse(final ResourceResponse response, final Attributes attributes) { super.configureResponse(response, attributes); if (isCacheAble() == false) { response.setCacheDuration(Duration.NONE); response.setCacheScope(CacheScope.PRIVATE); } } }; return resource; } |
...