# HG changeset patch # User Ingo Weinzierl # Date 1259251847 0 # Node ID 5f2820e821e0718bb53afcdee07a3a390a960090 # Parent 342cd58291f16a47631eb88fcee6231484675d9f Implemented a helper class for exporting charts. Adapted code. gnv-artifacts/trunk@376 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 342cd58291f1 -r 5f2820e821e0 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Thu Nov 26 15:59:25 2009 +0000 +++ b/gnv-artifacts/ChangeLog Thu Nov 26 16:10:47 2009 +0000 @@ -1,3 +1,17 @@ +2009-11-26 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/exports/ChartExportHelper.java: Helper + class to export charts. Dependencies on JFreeChart and iText are capsuled + here, no further dependencies in OutputTransitions. Export methods for + images and pdf already implemented. + + * src/main/java/de/intevation/gnv/chart/Chart.java, + src/main/java/de/intevation/gnv/chart/AbstractChart.java: Outsourcing of + export methods to ChartExportHelper. + + * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java: + Adapted current export of charts. + 2009-11-26 Ingo Weinzierl * doc/conf/products/horizontalcrosssection/conf_mesh.xml, diff -r 342cd58291f1 -r 5f2820e821e0 gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java Thu Nov 26 15:59:25 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java Thu Nov 26 16:10:47 2009 +0000 @@ -2,10 +2,6 @@ import java.util.Collection; import java.util.Locale; -import java.awt.Transparency; -import java.awt.image.BufferedImage; - -import org.apache.log4j.Logger; import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartTheme; @@ -16,8 +12,6 @@ public abstract class AbstractChart implements Chart { - private static Logger log = Logger.getLogger(AbstractChart.class); - protected JFreeChart chart; protected Locale locale; @@ -31,20 +25,5 @@ protected Collection timeGaps; public abstract JFreeChart generateChart(); - - public BufferedImage exportImage(int width, int height) { - log.info("export chart as png"); - - return chart.createBufferedImage( - width, height, Transparency.BITMASK, null); - } - - public void exportSVG() { - log.info("export chart as svg (not implemented yet)"); - } - - public void exportPDF() { - log.info("export chart as pdf (not implemented yet)"); - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 : diff -r 342cd58291f1 -r 5f2820e821e0 gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java Thu Nov 26 15:59:25 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java Thu Nov 26 16:10:47 2009 +0000 @@ -1,8 +1,5 @@ package de.intevation.gnv.chart; -import java.io.IOException; -import java.awt.image.BufferedImage; - import org.jfree.chart.JFreeChart; @@ -12,11 +9,4 @@ public interface Chart { public JFreeChart generateChart(); - - public BufferedImage exportImage(int width, int height) - throws IOException; - - public void exportSVG(); //TODO Change return value - - public void exportPDF(); //TODO Change return value } diff -r 342cd58291f1 -r 5f2820e821e0 gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java Thu Nov 26 16:10:47 2009 +0000 @@ -0,0 +1,49 @@ +package de.intevation.gnv.exports; + +import java.awt.Transparency; +import java.awt.image.BufferedImage; +import java.io.OutputStream; +import java.io.IOException; +import javax.imageio.ImageIO; + +import org.apache.log4j.Logger; + +import org.jfree.chart.JFreeChart; + +/** + * @author Ingo Weinzierl + */ +public class ChartExportHelper { + + private static final String DEFAULT_PAGE_SIZE = "A4"; + + private static Logger log = Logger.getLogger(ChartExportHelper.class); + + public static void exportImage( + OutputStream out, + JFreeChart chart, + String format, + int width, + int height + ) + throws IOException + { + log.info("export chart as png"); + + ImageIO.write( + chart.createBufferedImage( + width, height, Transparency.BITMASK, null + ), + format, + out + ); + } + + public static void exportSVG() { + log.info("export chart as svg (not implemented yet)"); + } + + public static void exportPDF() { + log.info("export chart as pdf (not implemented yet)"); + } +} diff -r 342cd58291f1 -r 5f2820e821e0 gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Thu Nov 26 15:59:25 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Thu Nov 26 16:10:47 2009 +0000 @@ -13,7 +13,6 @@ import java.util.List; import java.util.Locale; -import javax.imageio.ImageIO; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; @@ -41,6 +40,7 @@ import de.intevation.gnv.chart.TimeSeriesChart; import de.intevation.gnv.chart.XMLChartTheme; import de.intevation.gnv.chart.exception.TechnicalChartException; +import de.intevation.gnv.exports.ChartExportHelper; import de.intevation.gnv.exports.DefaultExport; import de.intevation.gnv.exports.DefaultDataCollector; import de.intevation.gnv.exports.SimpleOdvDataCollector; @@ -240,7 +240,8 @@ chartWidth, chartHeight ); - } else if (outputMode.equalsIgnoreCase("csv")) { + } + else if (outputMode.equalsIgnoreCase("csv")) { log.debug("CSV-File will be generated."); Collection chartResult = this.getChartResult(uuid); this.createCSV(outputStream, chartResult); @@ -438,10 +439,12 @@ " in " + width + "x" + height ); - ImageIO.write( - chart.exportImage(width, height), + ChartExportHelper.exportImage( + outputStream, + chart.generateChart(), exportFormat, - outputStream + width, + height ); }