Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java @ 476:ffb38c6c928e
Added new Step for querying the Years where measurements has been done into the TestCase.
gnv-artifacts/trunk@543 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 15 Jan 2010 09:54:51 +0000 |
parents | a88e15972c72 |
children | 3d13fa281a7e |
rev | line source |
---|---|
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.exports; |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
320
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
3 import com.lowagie.text.Document; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
4 import com.lowagie.text.DocumentException; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
5 import com.lowagie.text.PageSize; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
6 import com.lowagie.text.Rectangle; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
7 import com.lowagie.text.pdf.PdfContentByte; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
8 import com.lowagie.text.pdf.PdfTemplate; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
9 import com.lowagie.text.pdf.PdfWriter; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
10 |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import java.awt.Transparency; |
320
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
12 import java.awt.Graphics2D; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
13 import java.awt.geom.Rectangle2D; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
14 import java.awt.geom.Rectangle2D.Double; |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import java.io.OutputStream; |
321
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
16 import java.io.OutputStreamWriter; |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import java.io.IOException; |
321
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
18 import java.io.UnsupportedEncodingException; |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import javax.imageio.ImageIO; |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
321
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
21 import org.apache.batik.svggen.SVGGraphics2D; |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
22 import org.apache.batik.svggen.SVGGraphics2DIOException; |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import org.apache.log4j.Logger; |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 import org.jfree.chart.JFreeChart; |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
323
a88e15972c72
Updated Batik library to 1.7
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
321
diff
changeset
|
27 import de.intevation.artifactdatabase.XMLUtils; |
a88e15972c72
Updated Batik library to 1.7
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
321
diff
changeset
|
28 |
320
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
29 |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 /** |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 */ |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 public class ChartExportHelper { |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
320
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
35 private static final String DEFAULT_PAGE_SIZE = "A4"; |
321
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
36 private static final String DEFAULT_ENCODING = "UTF-8"; |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 private static Logger log = Logger.getLogger(ChartExportHelper.class); |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 public static void exportImage( |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 OutputStream out, |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 JFreeChart chart, |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 String format, |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 int width, |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 int height |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 ) |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 throws IOException |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 { |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 log.info("export chart as png"); |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 ImageIO.write( |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 chart.createBufferedImage( |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 width, height, Transparency.BITMASK, null |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 ), |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 format, |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 out |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 ); |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 } |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 |
320
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
60 |
321
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
61 public static void exportSVG( |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
62 OutputStream out, |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
63 JFreeChart chart, |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
64 String encoding, |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
65 int width, |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
66 int height |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
67 ) { |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
68 log.info("export chart as svg"); |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
69 |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
70 if (encoding == null) |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
71 encoding = DEFAULT_ENCODING; |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
72 |
323
a88e15972c72
Updated Batik library to 1.7
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
321
diff
changeset
|
73 org.w3c.dom.Document document = XMLUtils.newDocument(); |
321
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
74 SVGGraphics2D graphics = new SVGGraphics2D(document); |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
75 |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
76 chart.draw(graphics, new Rectangle2D.Double(0.0D, 0.0D,width,height)); |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
77 |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
78 try { |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
79 graphics.stream(new OutputStreamWriter(out, encoding)); |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
80 } |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
81 catch (SVGGraphics2DIOException svge) { |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
82 log.error("Error while writing svg export to output stream.", svge); |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
83 } |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
84 catch (UnsupportedEncodingException uee) { |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
85 log.error("Unsupported encoding: " + encoding, uee); |
a4376fd23f99
Implemented svg export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
320
diff
changeset
|
86 } |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 } |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 |
320
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
89 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
90 public static void exportPDF( |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
91 OutputStream out, |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
92 JFreeChart chart, |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
93 String pageFormat, |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
94 boolean landscape, |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
95 float marginLeft, |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
96 float marginRight, |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
97 float marginTop, |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
98 float marginBottom |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
99 ) { |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
100 log.info("export chart as pdf."); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
101 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
102 if (pageFormat == null) |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
103 pageFormat = DEFAULT_PAGE_SIZE; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
104 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
105 Rectangle page = PageSize.getRectangle(pageFormat); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
106 int pageWidth = (int) (page.getRight(marginRight) - page.getLeft(marginLeft)); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
107 int pageHeight = (int) (page.getTop(marginTop) - page.getBottom(marginBottom)); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
108 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
109 Document document = null; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
110 if (landscape) { |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
111 document = new Document(page.rotate()); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
112 log.debug("Create landscape pdf."); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
113 } |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
114 else |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
115 document = new Document(page); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
116 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
117 try { |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
118 PdfWriter writer = PdfWriter.getInstance(document, out); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
119 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
120 document.addSubject(chart.getTitle().getText()); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
121 document.addCreationDate(); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
122 document.open(); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
123 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
124 PdfContentByte content = writer.getDirectContent(); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
125 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
126 int width = 0; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
127 int height = 0; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
128 if (landscape) { |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
129 width = pageHeight; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
130 height = pageWidth; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
131 } |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
132 else { |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
133 width = pageWidth; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
134 height = pageHeight; |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
135 } |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
136 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
137 PdfTemplate template = content.createTemplate(width, height); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
138 Graphics2D graphics = template.createGraphics(width, height); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
139 Rectangle2D area = new Rectangle2D.Double(0.0D, 0.0D,width,height); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
140 |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
141 chart.draw(graphics, area); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
142 graphics.dispose(); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
143 content.addTemplate(template, marginLeft, marginBottom); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
144 } |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
145 catch (DocumentException de) { |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
146 log.error("Error while exporting chart to pdf.", de); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
147 } |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
148 finally { |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
149 document.close(); |
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
150 } |
318
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 } |
5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 } |
320
18302372703f
Implemented pdf export of charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
318
diff
changeset
|
153 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |