Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
923:7ca4a287cd0e | 924:f7761914f745 |
---|---|
1 package de.intevation.flys.exports; | |
2 | |
3 import java.awt.BasicStroke; | |
4 import java.awt.Color; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.w3c.dom.Document; | |
9 | |
10 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | |
11 import org.jfree.data.xy.XYSeries; | |
12 | |
13 import de.intevation.artifacts.common.utils.XMLUtils; | |
14 | |
15 | |
16 public class StyledXYSeries extends XYSeries { | |
17 | |
18 public static final String XPATH_LINE_COLOR = | |
19 "/theme/field[@name='linecolor']/@default"; | |
20 | |
21 public static final String XPATH_LINE_SIZE = | |
22 "/theme/field[@name='linesize']/@default"; | |
23 | |
24 | |
25 protected Document theme; | |
26 | |
27 | |
28 private static final Logger logger = Logger.getLogger(StyledXYSeries.class); | |
29 | |
30 | |
31 | |
32 public StyledXYSeries(String key, Document theme) { | |
33 super(key); | |
34 this.theme = theme; | |
35 } | |
36 | |
37 | |
38 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ | |
39 applyLineColor(r, idx); | |
40 applyLineSize(r, idx); | |
41 | |
42 r.setSeriesLinesVisible(idx, true); | |
43 r.setSeriesShapesVisible(idx, false); | |
44 | |
45 return r; | |
46 } | |
47 | |
48 | |
49 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { | |
50 String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); | |
51 | |
52 if (color == null || color.length() == 0) { | |
53 return; | |
54 } | |
55 | |
56 String[] rgb = color.split(","); | |
57 | |
58 try { | |
59 Color c = new Color( | |
60 Integer.valueOf(rgb[0].trim()), | |
61 Integer.valueOf(rgb[1].trim()), | |
62 Integer.valueOf(rgb[2].trim())); | |
63 | |
64 logger.debug("Set series paint color: " + c.toString()); | |
65 | |
66 r.setSeriesPaint(idx, c); | |
67 } | |
68 catch (NumberFormatException nfe) { | |
69 logger.warn("Unable to set color from string: '" + color + "'"); | |
70 } | |
71 } | |
72 | |
73 | |
74 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { | |
75 String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null); | |
76 | |
77 if (size == null || size.length() == 0) { | |
78 return; | |
79 } | |
80 | |
81 try { | |
82 r.setSeriesStroke( | |
83 idx, | |
84 new BasicStroke(Integer.valueOf(size))); | |
85 } | |
86 catch (NumberFormatException nfe) { | |
87 logger.warn("Unable to set line size from string: '" + size + "'"); | |
88 } | |
89 } | |
90 } | |
91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |