Mercurial > dive4elements > gnv-client
changeset 318:5f2820e821e0
Implemented a helper class for exporting charts. Adapted code.
gnv-artifacts/trunk@376 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 26 Nov 2009 16:10:47 +0000 |
parents | 342cd58291f1 |
children | 251f16a083f8 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java |
diffstat | 5 files changed, 71 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo.weinzierl@intevation.de> + + * 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 <ingo.weinzierl@intevation.de> * doc/conf/products/horizontalcrosssection/conf_mesh.xml,
--- 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 :
--- 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 }
--- /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 <ingo.weinzierl@intevation.de> + */ +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)"); + } +}
--- 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<Result> 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 ); }