comparison 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
comparison
equal deleted inserted replaced
646:d299e220d89c 647:bb484489d3df
1 package de.intevation.flys.exports;
2
3 import java.awt.Transparency;
4 import java.io.IOException;
5 import java.io.OutputStream;
6
7 import org.w3c.dom.Document;
8
9 import org.apache.log4j.Logger;
10
11 import org.jfree.chart.ChartRenderingInfo;
12 import org.jfree.chart.JFreeChart;
13
14 import de.intevation.artifacts.Artifact;
15 import de.intevation.artifacts.CallContext;
16
17 import de.intevation.artifacts.common.utils.XMLUtils;
18
19
20 /**
21 * An OutGenerator that generates meta information for charts. A concrete
22 * ChartInfoGenerator need to instantiate a concrete ChartGenerator and dispatch
23 * the methods to that instance. The only thing this ChartInfoGenerator needs
24 * to, is to overrite the generate() method which doesn't write the chart image
25 * to the OutputStream but a Document that contains some meta information of the
26 * created chart.
27 *
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
29 */
30 public abstract class ChartInfoGenerator implements OutGenerator {
31
32 /** The logger used in this generator.*/
33 private static Logger logger =
34 Logger.getLogger(ChartInfoGenerator.class);
35
36
37 /** The OutGenerator that creates the charts.*/
38 protected OutGenerator generator;
39
40 protected OutputStream out;
41
42
43
44 public ChartInfoGenerator(OutGenerator generator) {
45 this.generator = generator;
46 }
47
48
49 /**
50 * Dispatches the operation to the instantiated generator.
51 *
52 * @param request
53 * @param out
54 * @param context
55 */
56 public void init(Document request, OutputStream out, CallContext context) {
57 this.out = out;
58
59 generator.init(request, out, context);
60 }
61
62
63 /**
64 * Dispatches the operation to the instantiated generator.
65 *
66 * @param master
67 */
68 public void setMasterArtifact(Artifact master) {
69 generator.setMasterArtifact(master);
70 }
71
72
73 /**
74 * Dispatches the operation to the instantiated generator.
75 *
76 * @param artifacts
77 * @param facet
78 * @param attr
79 */
80 public void doOut(Artifact artifact, String facet, Document attr) {
81 generator.doOut(artifact, facet, attr);
82 }
83
84
85 /**
86 * This method generates the chart using a concrete ChartGenerator but
87 * doesn't write the chart itself to the OutputStream but a Document that
88 * contains meta information of the created chart.
89 */
90 @Override
91 public void generate()
92 throws IOException
93 {
94 logger.debug("ChartInfoGenerator.generate");
95
96 JFreeChart chart = generateChart();
97
98 int[] size = getSize();
99
100 ChartRenderingInfo info = new ChartRenderingInfo();
101
102 chart.createBufferedImage(size[0], size[1], Transparency.BITMASK, info);
103
104 Document doc = InfoGeneratorHelper.createInfoDocument(chart, info);
105
106 XMLUtils.toStream(doc, out);
107 }
108
109
110 /**
111 * Creates a chart object.
112 *
113 * @return a chart object.
114 */
115 protected abstract JFreeChart generateChart();
116
117 /**
118 * Returns the size of the generated chart.
119 *
120 * @return the size of the generated chart.
121 */
122 protected abstract int[] getSize();
123 }
124 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org