Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2234:46ec09c7f578
Refactoring: moved more base code from XYChartGenerator into its parent class ChartGenerator.
flys-artifacts/trunk@3878 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 02 Feb 2012 12:50:33 +0000 |
parents | 958a10e2e246 |
children | c2b15d9c0f43 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Feb 02 12:26:36 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Feb 02 12:50:33 2012 +0000 @@ -188,11 +188,6 @@ /** The max Y range to include all Y values of all series for each axis. */ protected Map<Integer, Range> yRanges; - public static final Color DEFAULT_GRID_COLOR = Color.GRAY; - public static final float DEFAULT_GRID_LINE_WIDTH = 0.3f; - public static final int DEFAULT_FONT_SIZE = 12; - public static final String DEFAULT_FONT_NAME = "Tahoma"; - public XYChartGenerator() { xRanges = new HashMap<Integer, Range>(); @@ -202,272 +197,6 @@ /** - * Returns the title of a chart. The return value depends on the existence - * of ChartSettings: if there are ChartSettings set, this method returns the - * chart title provided by those settings. Otherwise, this method returns - * getDefaultChartTitle(). - * - * @return the title of a chart. - */ - protected String getChartTitle() { - ChartSettings chartSettings = getChartSettings(); - - if (chartSettings != null) { - return getChartTitle(chartSettings); - } - - return getDefaultChartTitle(); - } - - - protected abstract String getDefaultChartTitle(); - - - /** - * Returns the subtitle of a chart. The return value depends on the - * existence of ChartSettings: if there are ChartSettings set, this method - * returns the chart title provided by those settings. Otherwise, this - * method returns getDefaultChartSubtitle(). - * - * @return the subtitle of a chart. - */ - protected String getChartSubtitle() { - ChartSettings chartSettings = getChartSettings(); - - if (chartSettings != null) { - return getChartSubtitle(chartSettings); - } - - return getDefaultChartSubtitle(); - } - - - /** - * This method always returns null. Override it in subclasses that require - * subtitles. - * - * @return null. - */ - protected String getDefaultChartSubtitle() { - // Override this method in subclasses - return null; - } - - - /** - * This method is used to determine, if the chart's legend is visible or - * not. If a <i>settings</i> instance is set, this instance determines the - * visibility otherwise, this method returns true as default if no - * <i>settings</i> is set. - * - * @return true, if the legend should be visible, otherwise false. - */ - protected boolean isLegendVisible() { - ChartSettings chartSettings = getChartSettings(); - if (chartSettings != null) { - return isLegendVisible(chartSettings); - } - - return true; - } - - - /** - * This method is used to determine the font size of the chart's legend. If - * a <i>settings</i> instance is set, this instance determines the font - * size, otherwise this method returns 12 as default if no <i>settings</i> - * is set or if it doesn't provide a legend font size. - * - * @return a legend font size. - */ - protected int getLegendFontSize() { - Integer fontSize = null; - - ChartSettings chartSettings = getChartSettings(); - if (chartSettings != null) { - fontSize = getLegendFontSize(chartSettings); - } - - return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; - } - - - /** - * This method is used to determine if the resulting chart should display - * grid lines or not. <b>Note: this method always returns true!</b> - * - * @return true, if the chart should display grid lines, otherwise false. - */ - protected boolean isGridVisible() { - return true; - } - - - /** - * Returns the X-Axis label of a chart. - * - * @return the X-Axis label of a chart. - */ - protected String getXAxisLabel() { - ChartSettings chartSettings = getChartSettings(); - if (chartSettings == null) { - return getDefaultXAxisLabel(); - } - - AxisSection as = chartSettings.getAxisSection("X"); - if (as != null) { - String label = as.getLabel(); - - if (label != null) { - return label; - } - } - - return getDefaultXAxisLabel(); - } - - - /** - * Returns the default X-Axis label of a chart. - * - * @return the default X-Axis label of a chart. - */ - protected abstract String getDefaultXAxisLabel(); - - - /** - * This method is called to retrieve the default label for an Y axis at - * position <i>pos</i>. - * - * @param pos The position of an Y axis. - * - * @return the default Y axis label at position <i>pos</i>. - */ - protected abstract String getDefaultYAxisLabel(int pos); - - - /** - * This method returns the font size for the X axis. If the font size is - * specified in ChartSettings (if <i>chartSettings</i> is set), this size is - * returned. Otherwise the default font size 12 is returned. - * - * @return the font size for the x axis. - */ - protected int getXAxisLabelFontSize() { - ChartSettings chartSettings = getChartSettings(); - if (chartSettings == null) { - return DEFAULT_FONT_SIZE; - } - - AxisSection as = chartSettings.getAxisSection("X"); - Integer fontSize = as.getFontSize(); - - return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; - } - - - /** - * This method returns the font size for an Y axis. If the font size is - * specified in ChartSettings (if <i>chartSettings</i> is set), this size is - * returned. Otherwise the default font size 12 is returned. - * - * @return the font size for the x axis. - */ - protected int getYAxisFontSize(int pos) { - ChartSettings chartSettings = getChartSettings(); - if (chartSettings == null) { - return DEFAULT_FONT_SIZE; - } - - YAxisWalker walker = getYAxisWalker(); - - AxisSection as = chartSettings.getAxisSection(walker.getId(pos)); - Integer fontSize = as.getFontSize(); - - return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; - } - - - /** - * This method returns the export dimension specified in ChartSettings as - * int array [width,height]. - * - * @return an int array with [width,height]. - */ - protected int[] getExportDimension() { - ChartSettings chartSettings = getChartSettings(); - if (chartSettings == null) { - return new int[] { 600, 400 }; - } - - ExportSection export = chartSettings.getExportSection(); - Integer width = export.getWidth(); - Integer height = export.getHeight(); - - if (width != null && height != null) { - return new int[] { width, height }; - } - - return new int[] { 600, 400 }; - } - - - /** - * Generate chart. - */ - public void generate() - throws IOException - { - logger.debug("XYChartGenerator.generate"); - - JFreeChart chart = generateChart(); - - String format = getFormat(); - int[] size = getSize(); - - if (size == null) { - size = getExportDimension(); - } - - context.putContextValue("chart.width", size[0]); - context.putContextValue("chart.height", size[1]); - - if (format.equals(ChartExportHelper.FORMAT_PNG)) { - context.putContextValue("chart.image.format", "png"); - - ChartExportHelper.exportImage( - out, - chart, - context); - } - else if (format.equals(ChartExportHelper.FORMAT_PDF)) { - preparePDFContext(context); - - ChartExportHelper.exportPDF( - out, - chart, - context); - } - else if (format.equals(ChartExportHelper.FORMAT_SVG)) { - prepareSVGContext(context); - - ChartExportHelper.exportSVG( - out, - chart, - context); - } - else if (format.equals(ChartExportHelper.FORMAT_CSV)) { - context.putContextValue("chart.image.format", "csv"); - - ChartExportHelper.exportCSV( - out, - chart, - context); - } - } - - - /** * Generate the chart anew (including localized axis and all). */ public JFreeChart generateChart() { @@ -511,32 +240,6 @@ } - protected void preparePDFContext(CallContext context) { - int[] dimension = getExportDimension(); - - context.putContextValue("chart.width", dimension[0]); - context.putContextValue("chart.height", dimension[1]); - context.putContextValue("chart.marginLeft", 5f); - context.putContextValue("chart.marginRight", 5f); - context.putContextValue("chart.marginTop", 5f); - context.putContextValue("chart.marginBottom", 5f); - context.putContextValue( - "chart.page.format", - ChartExportHelper.DEFAULT_PAGE_SIZE); - } - - - protected void prepareSVGContext(CallContext context) { - int[] dimension = getExportDimension(); - - context.putContextValue("chart.width", dimension[0]); - context.putContextValue("chart.height", dimension[1]); - context.putContextValue( - "chart.encoding", - ChartExportHelper.DEFAULT_ENCODING); - } - - /** * Put debug output about datasets. */