diff flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 924:f7761914f745

An initial implementation to render chart series based on the XML configuration in themes.xml. flys-artifacts/trunk@2276 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 01 Jul 2011 14:46:13 +0000
parents
children 004b1b0838d6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java	Fri Jul 01 14:46:13 2011 +0000
@@ -0,0 +1,91 @@
+package de.intevation.flys.exports;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
+import org.jfree.data.xy.XYSeries;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+
+public class StyledXYSeries extends XYSeries {
+
+    public static final String XPATH_LINE_COLOR =
+        "/theme/field[@name='linecolor']/@default";
+
+    public static final String XPATH_LINE_SIZE =
+        "/theme/field[@name='linesize']/@default";
+
+
+    protected Document theme;
+
+
+    private static final Logger logger = Logger.getLogger(StyledXYSeries.class);
+
+
+
+    public StyledXYSeries(String key, Document theme) {
+        super(key);
+        this.theme = theme;
+    }
+
+
+    public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){
+        applyLineColor(r, idx);
+        applyLineSize(r, idx);
+
+        r.setSeriesLinesVisible(idx, true);
+        r.setSeriesShapesVisible(idx, false);
+
+        return r;
+    }
+
+
+    protected void applyLineColor(XYLineAndShapeRenderer r, int idx) {
+        String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null);
+
+        if (color == null || color.length() == 0) {
+            return;
+        }
+
+        String[] rgb = color.split(",");
+
+        try {
+            Color c = new Color(
+                Integer.valueOf(rgb[0].trim()),
+                Integer.valueOf(rgb[1].trim()),
+                Integer.valueOf(rgb[2].trim()));
+
+            logger.debug("Set series paint color: " + c.toString());
+
+            r.setSeriesPaint(idx, c);
+        }
+        catch (NumberFormatException nfe) {
+            logger.warn("Unable to set color from string: '" + color + "'");
+        }
+    }
+
+
+    protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
+        String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null);
+
+        if (size == null || size.length() == 0) {
+            return;
+        }
+
+        try {
+            r.setSeriesStroke(
+                idx,
+                new BasicStroke(Integer.valueOf(size)));
+        }
+        catch (NumberFormatException nfe) {
+            logger.warn("Unable to set line size from string: '" + size + "'");
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org