Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 3814:8083f6384023
merged flys-artifacts/pre2.6-2012-01-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:56 +0200 |
parents | e384d78ff78b |
children | 4cdd9c4896f6 |
comparison
equal
deleted
inserted
replaced
1491:2a00f4849738 | 3814:8083f6384023 |
---|---|
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 * Dataseries in two dimensions with additional theme-document and further | |
18 * display options. | |
19 * The theme-document will later "style" the graphical representation. | |
20 * The display options can be used to control the z-order and the axis of the | |
21 * dataseries. | |
22 */ | |
23 public class StyledXYSeries extends XYSeries { | |
24 | |
25 protected Document theme; | |
26 | |
27 private static final Logger logger = Logger.getLogger(StyledXYSeries.class); | |
28 | |
29 | |
30 public StyledXYSeries(String key, Document theme) { | |
31 this(key, true, theme); | |
32 } | |
33 | |
34 | |
35 /** | |
36 * @param sorted whether or not to sort the points. Sorting will move NANs | |
37 * to one extrema which can cause problems in certain | |
38 * algorithms. | |
39 */ | |
40 public StyledXYSeries(String key, boolean sorted, Document theme) { | |
41 super(key, sorted); | |
42 this.theme = theme; | |
43 } | |
44 | |
45 | |
46 /** | |
47 * Applies line color, size and type attributes to renderer, also | |
48 * whether to draw lines and/or points. | |
49 */ | |
50 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ | |
51 applyLineColor(r, idx); | |
52 applyLineSize(r, idx); | |
53 applyLineType(r, idx); | |
54 applyShowLine(r, idx); | |
55 applyShowPoints(r, idx); | |
56 | |
57 return r; | |
58 } | |
59 | |
60 | |
61 /** Set line color to renderer. */ | |
62 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { | |
63 Color c = ThemeUtil.parseLineColorField(theme); | |
64 r.setSeriesPaint(idx, c); | |
65 } | |
66 | |
67 | |
68 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { | |
69 int size = ThemeUtil.parseLineWidth(theme); | |
70 r.setSeriesStroke( | |
71 idx, | |
72 new BasicStroke(Integer.valueOf(size))); | |
73 } | |
74 | |
75 | |
76 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { | |
77 int size = ThemeUtil.parseLineWidth(theme); | |
78 float[] dashes = ThemeUtil.parseLineStyle(theme); | |
79 | |
80 // Do not apply the dashed style. | |
81 if (dashes.length <= 1) { | |
82 return; | |
83 } | |
84 | |
85 r.setSeriesStroke( | |
86 idx, | |
87 new BasicStroke(Integer.valueOf(size), | |
88 BasicStroke.CAP_BUTT, | |
89 BasicStroke.JOIN_ROUND, | |
90 1.0f, | |
91 dashes, | |
92 0.0f)); | |
93 } | |
94 | |
95 | |
96 /** | |
97 * Sets form and visibility of points. | |
98 */ | |
99 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { | |
100 boolean show = ThemeUtil.parseShowPoints(theme); | |
101 int size = ThemeUtil.parseLineWidth(theme); | |
102 r.setSeriesShape(idx, new Ellipse2D.Double(- size, | |
103 - size, | |
104 2 * size, | |
105 2 * size)); | |
106 r.setSeriesShapesVisible(idx, show); | |
107 r.setDrawOutlines(true); | |
108 } | |
109 | |
110 | |
111 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { | |
112 boolean show = ThemeUtil.parseShowLine(theme); | |
113 r.setSeriesLinesVisible(idx, show); | |
114 } | |
115 } | |
116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |