Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java @ 771:a0e63136954e
Added and repaired javadoc in de.intevation.gnv.exports package.
gnv-artifacts/trunk@827 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 25 Mar 2010 09:01:14 +0000 |
parents | e5f1e868ee3e |
children | 9a828e5a2390 |
comparison
equal
deleted
inserted
replaced
770:d70cac2bafc0 | 771:a0e63136954e |
---|---|
35 import org.apache.log4j.Logger; | 35 import org.apache.log4j.Logger; |
36 | 36 |
37 import org.jfree.chart.JFreeChart; | 37 import org.jfree.chart.JFreeChart; |
38 | 38 |
39 /** | 39 /** |
40 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> | 40 * This class is a helper class which supports some methods to export charts |
41 * into specific formats. | |
42 * | |
43 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
41 */ | 44 */ |
42 public class ChartExportHelper { | 45 public class ChartExportHelper { |
43 | 46 |
47 /** | |
48 * Constant field to define A4 as default page size. | |
49 */ | |
44 private static final String DEFAULT_PAGE_SIZE = "A4"; | 50 private static final String DEFAULT_PAGE_SIZE = "A4"; |
51 | |
52 /** | |
53 * Constant field to define UTF-8 as default encoding. | |
54 */ | |
45 private static final String DEFAULT_ENCODING = "UTF-8"; | 55 private static final String DEFAULT_ENCODING = "UTF-8"; |
46 | 56 |
57 /** | |
58 * Logger used for logging with log4j. | |
59 */ | |
47 private static Logger log = Logger.getLogger(ChartExportHelper.class); | 60 private static Logger log = Logger.getLogger(ChartExportHelper.class); |
48 | 61 |
62 | |
63 /** | |
64 * A method to export a <code>JFreeChart</code> as image to an | |
65 * <code>OutputStream</code> with a given format, width and height. | |
66 * | |
67 * @param out OutputStream | |
68 * @param JFreeChart Chart to be exported | |
69 * @param format Format (e.g. png, gif, jpg) | |
70 * @param width Width, the image used to be | |
71 * @param height Height, the image used to be | |
72 * | |
73 * @throws IOException if writing image to OutputStream failed. | |
74 */ | |
49 public static void exportImage( | 75 public static void exportImage( |
50 OutputStream out, | 76 OutputStream out, |
51 JFreeChart chart, | 77 JFreeChart chart, |
52 String format, | 78 String format, |
53 int width, | 79 int width, |
65 out | 91 out |
66 ); | 92 ); |
67 } | 93 } |
68 | 94 |
69 | 95 |
96 /** | |
97 * A method to export a <code>JFreeChart</code> histogram as image to an | |
98 * <code>OutputStream</code> with a given format, width and height. | |
99 * | |
100 * @param out OutputStream | |
101 * @param histograms Array of {@link de.intevation.gnv.chart.Chart} objects | |
102 * @param format A format (e.g. png, gif, jpg) | |
103 * @param width Width the image used to be | |
104 * @param height Height the image used to be | |
105 * | |
106 * @throws IOException if writing image to OutputStream failed. | |
107 */ | |
70 public static void exportHistograms( | 108 public static void exportHistograms( |
71 OutputStream out, | 109 OutputStream out, |
72 Chart[] histograms, | 110 Chart[] histograms, |
73 String format, | 111 String format, |
74 int width, | 112 int width, |
90 | 128 |
91 ImageIO.write(image, format, out); | 129 ImageIO.write(image, format, out); |
92 } | 130 } |
93 | 131 |
94 | 132 |
133 /** | |
134 * A method to export a <code>JFreeChart</code> histogram as SVG to an | |
135 * <code>OutputStream</code>. | |
136 * | |
137 * @param out OutputStream | |
138 * @param histograms Array of {@link de.intevation.gnv.chart.Chart} | |
139 * @param encoding Encoding, defaults to {@link DEFAULT_ENCODING} if null | |
140 * @param width Width the svg used to be | |
141 * @param height Height the svg used to be | |
142 */ | |
95 public static void exportHistogramsAsSVG( | 143 public static void exportHistogramsAsSVG( |
96 OutputStream out, | 144 OutputStream out, |
97 Chart[] histograms, | 145 Chart[] histograms, |
98 String encoding, | 146 String encoding, |
99 int width, | 147 int width, |
125 log.error("Unsupported encoding: " + encoding, uee); | 173 log.error("Unsupported encoding: " + encoding, uee); |
126 } | 174 } |
127 } | 175 } |
128 | 176 |
129 | 177 |
178 /** | |
179 * A method to export a <code>JFreeChart</code> as SVG to an | |
180 * <code>OutputStream</code>. | |
181 * | |
182 * @param out OutputStream | |
183 * @param chart JFreeChart to be exported | |
184 * @param encoding Encoding, defaults to {@link DEFAULT_ENCODING} if null | |
185 * @param width Width the svg used to be | |
186 * @param height Height the svg used to be | |
187 */ | |
130 public static void exportSVG( | 188 public static void exportSVG( |
131 OutputStream out, | 189 OutputStream out, |
132 JFreeChart chart, | 190 JFreeChart chart, |
133 String encoding, | 191 String encoding, |
134 int width, | 192 int width, |
154 log.error("Unsupported encoding: " + encoding, uee); | 212 log.error("Unsupported encoding: " + encoding, uee); |
155 } | 213 } |
156 } | 214 } |
157 | 215 |
158 | 216 |
217 /** | |
218 * A method to export a <code>JFreeChart</code> as PDF to an | |
219 * <code>OutputStream</code>. | |
220 * | |
221 * @param out OutputStream | |
222 * @param chart JFreeChart | |
223 * @param pageFormat String to specify a page format, {@link | |
224 * DEFAULT_PAGE_SIZE} is used if no pageFormat is given | |
225 * @param landscape If this is true, the pdf is delivered in landscape | |
226 * format | |
227 * @param marginLeft Space to left border | |
228 * @param marginRight Space to right border | |
229 * @param marginTop Space to upper border | |
230 * @param marginBottom Space to lower border | |
231 */ | |
159 public static void exportPDF( | 232 public static void exportPDF( |
160 OutputStream out, | 233 OutputStream out, |
161 JFreeChart chart, | 234 JFreeChart chart, |
162 String pageFormat, | 235 String pageFormat, |
163 boolean landscape, | 236 boolean landscape, |
218 document.close(); | 291 document.close(); |
219 } | 292 } |
220 } | 293 } |
221 | 294 |
222 | 295 |
296 /** | |
297 * A method to export <code>JFreeChart</code> histograms as PDF to an | |
298 * <code>OutputStream</code>. Each histogram contained in histograms is | |
299 * drawn to an own page in the resulting pdf. | |
300 * | |
301 * @param out OutputStream | |
302 * @param histograms JFreeChart histograms | |
303 * @param pageFormat String to specify a page format, {@link | |
304 * DEFAULT_PAGE_SIZE} is used if no pageFormat is given | |
305 * @param landscape If this is true, the pdf is delivered in landscape | |
306 * format | |
307 * @param marginLeft Space to left border | |
308 * @param marginRight Space to right border | |
309 * @param marginTop Space to upper border | |
310 * @param marginBottom Space to lower border | |
311 */ | |
223 public static void exportHistogramsAsPDF( | 312 public static void exportHistogramsAsPDF( |
224 OutputStream out, | 313 OutputStream out, |
225 Chart[] histograms, | 314 Chart[] histograms, |
226 String pageFormat, | 315 String pageFormat, |
227 boolean landscape, | 316 boolean landscape, |