Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java @ 647:bb484489d3df
Introduced a new output generators for creating chart info documents.
flys-artifacts/trunk@2032 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 01 Jun 2011 08:01:07 +0000 |
parents | |
children | 67c7020f4ed3 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java Wed Jun 01 08:01:07 2011 +0000 @@ -0,0 +1,124 @@ +package de.intevation.flys.exports; + +import java.awt.Transparency; +import java.io.IOException; +import java.io.OutputStream; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import org.jfree.chart.ChartRenderingInfo; +import org.jfree.chart.JFreeChart; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.artifacts.common.utils.XMLUtils; + + +/** + * An OutGenerator that generates meta information for charts. A concrete + * ChartInfoGenerator need to instantiate a concrete ChartGenerator and dispatch + * the methods to that instance. The only thing this ChartInfoGenerator needs + * to, is to overrite the generate() method which doesn't write the chart image + * to the OutputStream but a Document that contains some meta information of the + * created chart. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public abstract class ChartInfoGenerator implements OutGenerator { + + /** The logger used in this generator.*/ + private static Logger logger = + Logger.getLogger(ChartInfoGenerator.class); + + + /** The OutGenerator that creates the charts.*/ + protected OutGenerator generator; + + protected OutputStream out; + + + + public ChartInfoGenerator(OutGenerator generator) { + this.generator = generator; + } + + + /** + * Dispatches the operation to the instantiated generator. + * + * @param request + * @param out + * @param context + */ + public void init(Document request, OutputStream out, CallContext context) { + this.out = out; + + generator.init(request, out, context); + } + + + /** + * Dispatches the operation to the instantiated generator. + * + * @param master + */ + public void setMasterArtifact(Artifact master) { + generator.setMasterArtifact(master); + } + + + /** + * Dispatches the operation to the instantiated generator. + * + * @param artifacts + * @param facet + * @param attr + */ + public void doOut(Artifact artifact, String facet, Document attr) { + generator.doOut(artifact, facet, attr); + } + + + /** + * This method generates the chart using a concrete ChartGenerator but + * doesn't write the chart itself to the OutputStream but a Document that + * contains meta information of the created chart. + */ + @Override + public void generate() + throws IOException + { + logger.debug("ChartInfoGenerator.generate"); + + JFreeChart chart = generateChart(); + + int[] size = getSize(); + + ChartRenderingInfo info = new ChartRenderingInfo(); + + chart.createBufferedImage(size[0], size[1], Transparency.BITMASK, info); + + Document doc = InfoGeneratorHelper.createInfoDocument(chart, info); + + XMLUtils.toStream(doc, out); + } + + + /** + * Creates a chart object. + * + * @return a chart object. + */ + protected abstract JFreeChart generateChart(); + + /** + * Returns the size of the generated chart. + * + * @return the size of the generated chart. + */ + protected abstract int[] getSize(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :