comparison flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 3806:881fcd01e056

merged flys-artifacts/pre2.6-2011-11-04
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:50 +0200
parents a9b690d864a7
children 6c24ffe946a5
comparison
equal deleted inserted replaced
3802:e831dc29e572 3806:881fcd01e056
1 package de.intevation.flys.exports;
2
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.geom.Ellipse2D;
6
7 import org.apache.log4j.Logger;
8
9 import org.w3c.dom.Document;
10
11 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
12 import org.jfree.data.xy.XYSeries;
13
14 import de.intevation.flys.utils.ThemeUtil;
15
16 /**
17 * Dataset in two dimensions with additional theme-document.
18 * The theme-document will later "style" the graphical representation.
19 */
20 public class StyledXYSeries extends XYSeries {
21
22 protected Document theme;
23
24 private static final Logger logger = Logger.getLogger(StyledXYSeries.class);
25
26
27 public StyledXYSeries(String key, Document theme) {
28 this(key, true, theme);
29 }
30
31
32 /**
33 * @param sorted whether or not to sort the points. Sorting will move NANs
34 * to one extrema which can cause problems in certain
35 * algorithms.
36 */
37 public StyledXYSeries(String key, boolean sorted, Document theme) {
38 super(key, sorted);
39 this.theme = theme;
40 }
41
42
43 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){
44 applyLineColor(r, idx);
45 applyLineSize(r, idx);
46 applyLineType(r, idx);
47 applyShowLine(r, idx);
48 applyShowPoints(r, idx);
49
50 return r;
51 }
52
53
54 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) {
55 Color c = ThemeUtil.parseLineColorField(theme);
56 r.setSeriesPaint(idx, c);
57 }
58
59
60 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
61 int size = ThemeUtil.parseLineWidth(theme);
62 r.setSeriesStroke(
63 idx,
64 new BasicStroke(Integer.valueOf(size)));
65 }
66
67
68 protected void applyLineType(XYLineAndShapeRenderer r, int idx) {
69 int size = ThemeUtil.parseLineWidth(theme);
70 float[] dashes = ThemeUtil.parseLineStyle(theme);
71
72 // Do not apply the dashed style.
73 if (dashes.length <= 1) {
74 return;
75 }
76
77 r.setSeriesStroke(
78 idx,
79 new BasicStroke(Integer.valueOf(size),
80 BasicStroke.CAP_BUTT,
81 BasicStroke.JOIN_ROUND,
82 1.0f,
83 dashes,
84 0.0f));
85 }
86
87
88 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) {
89 boolean show = ThemeUtil.parseShowPoints(theme);
90 r.setSeriesShape(idx, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
91 r.setSeriesShapesVisible(idx, show);
92 r.setDrawOutlines(true);
93 }
94
95
96 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) {
97 boolean show = ThemeUtil.parseShowLine(theme);
98 r.setSeriesLinesVisible(idx, show);
99 }
100 }
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org