Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/ChartExportHelper.java @ 648:d4c4fefb095b
The matrix that is used to transform chart image coordinates into chart coordinates supports inverted x-axis now.
flys-artifacts/trunk@2037 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 01 Jun 2011 09:18:00 +0000 |
parents | 084995dd1c9c |
children | 2f25ca828efd |
rev | line source |
---|---|
152
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 /* |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 * Copyright (c) 2011 by Intevation GmbH |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 package de.intevation.flys.exports; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import com.lowagie.text.Document; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import com.lowagie.text.DocumentException; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import com.lowagie.text.PageSize; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import com.lowagie.text.Rectangle; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import com.lowagie.text.pdf.PdfContentByte; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import com.lowagie.text.pdf.PdfTemplate; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import com.lowagie.text.pdf.PdfWriter; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import java.awt.Graphics2D; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import java.awt.Transparency; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import java.awt.geom.Rectangle2D.Double; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import java.awt.geom.Rectangle2D; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 import java.io.IOException; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 import java.io.OutputStream; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 import java.io.OutputStreamWriter; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 import java.io.UnsupportedEncodingException; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 import javax.imageio.ImageIO; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 import org.apache.batik.svggen.SVGGraphics2D; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 import org.apache.batik.svggen.SVGGraphics2DIOException; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 import org.apache.log4j.Logger; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 import org.jfree.chart.JFreeChart; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 import de.intevation.artifacts.CallContext; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 import de.intevation.artifacts.common.utils.XMLUtils; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 * This class is a helper class which supports some methods to export charts |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 * into specific formats. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 public class ChartExportHelper { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 * Constant field to define A4 as default page size. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 private static final String DEFAULT_PAGE_SIZE = "A4"; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 * Constant field to define UTF-8 as default encoding. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 private static final String DEFAULT_ENCODING = "UTF-8"; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 * Logger used for logging with log4j. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 private static Logger log = Logger.getLogger(ChartExportHelper.class); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 * A method to export a <code>JFreeChart</code> as image to an |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 * <code>OutputStream</code> with a given format, width and height. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 * @param out OutputStream |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 * @param chart JFreeChart object to be exported. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 * @param format Format (e.g. png, gif, jpg) |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 * @param width Width, the image used to be |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 * @param height Height, the image used to be |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 * @throws IOException if writing image to OutputStream failed. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 public static void exportImage( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 OutputStream out, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 JFreeChart chart, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 String format, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 int width, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 int height |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 ) |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 throws IOException |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 log.info("export chart as png"); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 ImageIO.write( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 chart.createBufferedImage( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 width, height, Transparency.BITMASK, null |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 ), |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 format, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 out |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 ); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 * A method to export a <code>JFreeChart</code> as SVG to an |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 * <code>OutputStream</code>. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 * @param out OutputStream |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 * @param chart JFreeChart to be exported |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 * @param encoding Encoding, defaults to {@link #DEFAULT_ENCODING} if null |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 * @param width Width the svg used to be |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 * @param height Height the svg used to be |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 public static void exportSVG( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 OutputStream out, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 JFreeChart chart, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 String encoding, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 int width, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 int height |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 ) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 log.info("export chart as svg"); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 if (encoding == null) |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 encoding = DEFAULT_ENCODING; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 org.w3c.dom.Document document = XMLUtils.newDocument(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 SVGGraphics2D graphics = new SVGGraphics2D(document); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 chart.draw(graphics, new Rectangle2D.Double(0.0D, 0.0D,width,height)); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 try { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 graphics.stream(new OutputStreamWriter(out, encoding)); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 catch (SVGGraphics2DIOException svge) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 log.error("Error while writing svg export to output stream.", svge); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 catch (UnsupportedEncodingException uee) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 log.error("Unsupported encoding: " + encoding, uee); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 * A method to export a <code>JFreeChart</code> as PDF to an |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 * <code>OutputStream</code>. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
144 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
145 * @param out OutputStream |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 * @param chart JFreeChart |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 * @param pageFormat String to specify a page format, {@link |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 * #DEFAULT_PAGE_SIZE} is used if no pageFormat is given |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 * @param landscape If this is true, the pdf is delivered in landscape |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 * format |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 * @param marginLeft Space to left border |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 * @param marginRight Space to right border |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 * @param marginTop Space to upper border |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
154 * @param marginBottom Space to lower border |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
155 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 public static void exportPDF( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
157 OutputStream out, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 JFreeChart chart, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
159 String pageFormat, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
160 float marginLeft, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 float marginRight, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
162 float marginTop, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
163 float marginBottom, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
164 CallContext context |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
165 ) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 log.info("export chart as pdf."); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
167 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
168 if (pageFormat == null) |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
169 pageFormat = DEFAULT_PAGE_SIZE; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 // max size of the chart |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
172 Rectangle page = PageSize.getRectangle(pageFormat); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
173 float pageWidth = page.getWidth(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
174 float pageHeight = page.getHeight(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
175 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
176 // the chart width |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
177 int chartWidth = (Integer) context.getContextValue("chart.width"); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
178 int chartHeight = (Integer) context.getContextValue("chart.height"); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
179 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
180 boolean landscape = chartWidth > chartHeight ? true : false; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
181 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
182 float width = 0; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
183 float height = 0; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 if (landscape) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 width = pageHeight; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 height = pageWidth; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
188 else { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 width = pageWidth; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 height = pageHeight; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
192 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 float spaceX = width - marginLeft - marginRight; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 if (chartWidth > spaceX) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
195 log.warn("Width of the chart is too big for pdf -> resize it now."); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
196 double ratio = ((double)spaceX) / chartWidth; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
197 chartWidth *= ratio; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
198 chartHeight *= ratio; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
199 log.debug("Resized chart to " + chartWidth + "x" + chartHeight); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
200 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
201 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
202 float spaceY = height - marginTop - marginBottom; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
203 if (chartHeight > spaceY) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
204 log.warn("Height of the chart is too big for pdf -> resize it now."); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
205 double ratio = ((double)spaceY) / chartHeight; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
206 chartWidth *= ratio; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
207 chartHeight *= ratio; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
208 log.debug("Resized chart to " + chartWidth + "x" + chartHeight); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
209 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
210 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 Document document = null; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 if (landscape) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 document = new Document(page.rotate()); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
214 log.debug("Create landscape pdf."); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
215 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 else |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 document = new Document(page); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
218 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
219 try { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
220 PdfWriter writer = PdfWriter.getInstance(document, out); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
221 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
222 document.addSubject(chart.getTitle().getText()); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
223 document.addCreationDate(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
224 document.open(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
225 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
226 PdfContentByte content = writer.getDirectContent(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
227 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
228 PdfTemplate template = content.createTemplate(width, height); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
229 Graphics2D graphics = template.createGraphics(width, height); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
230 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
231 double[] origin = getCenteredAnchor( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
232 marginLeft, marginRight, marginBottom, marginTop, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
233 width, height, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
234 chartWidth, chartHeight); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
235 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
236 Rectangle2D area = new Rectangle2D.Double( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
237 origin[0], origin[1], chartWidth, chartHeight); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
238 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
239 chart.draw(graphics, area); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
240 graphics.dispose(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
241 content.addTemplate(template, 0f, 0f); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
242 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
243 catch (DocumentException de) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
244 log.error("Error while exporting chart to pdf.", de); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
245 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
246 finally { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
247 document.close(); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
248 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
249 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
250 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
251 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
252 /** |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
253 * This method returns the anchor of the chart so that the chart is centered |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
254 * according to the given parameters. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
255 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
256 * @param mLeft Left margin |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
257 * @param mRight Right margin |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
258 * @param mBottom Bottom margin |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
259 * @param mTop Top margin |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
260 * @param width The complete width of the drawing area. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
261 * @param height The complete height of the drawing area. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
262 * @param chartWidth The width of the chart. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
263 * @param chartHeight The height of the chart. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
264 * |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
265 * @return an array that contains the anchor for a chart with the given |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
266 * parameters. The first value is the x point, the second value is the y |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
267 * point. |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
268 */ |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
269 public static double[] getCenteredAnchor( |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
270 double mLeft, double mRight, double mBottom, double mTop, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
271 double width, double height, |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
272 double chartWidth, double chartHeight |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
273 ) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
274 if (log.isDebugEnabled()) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
275 log.debug("Calculate centered origin..."); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
276 log.debug("-> PDF width : " + width); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
277 log.debug("-> PDF height : " + height); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
278 log.debug("-> Chart width : " + chartWidth); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
279 log.debug("-> Chart height : " + chartHeight); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
280 log.debug("-> margin left : " + mLeft); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
281 log.debug("-> margin right : " + mRight); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
282 log.debug("-> margin bottom: " + mBottom); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
283 log.debug("-> margin top : " + mTop); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
284 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
285 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
286 double[] origin = new double[2]; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
287 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
288 double centerX = width / 2; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
289 double centerY = height / 2; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
290 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
291 origin[0] = centerX - chartWidth / 2; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
292 origin[1] = centerY - chartHeight / 2; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
293 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
294 origin[0] = origin[0] >= mLeft ? origin[0] : mLeft; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
295 origin[1] = origin[1] >= mTop ? origin[1] : mTop; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
296 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
297 if (log.isDebugEnabled()) { |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
298 log.debug("==> centered left origin: " + origin[0]); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
299 log.debug("==> centered top origin: " + origin[1]); |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
300 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
301 |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
302 return origin; |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
303 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
304 } |
956445dd601d
Added a helper class to export charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
305 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |