comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java @ 2074:a026d005accd

Moved JFreeChart specific classes to de.intevation.flys.jfree and added required imports. flys-artifacts/trunk@3585 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 04 Jan 2012 14:43:48 +0000
parents
children 41037d51c8b6
comparison
equal deleted inserted replaced
2073:27ada2e4243d 2074:a026d005accd
1 package de.intevation.flys.jfree;
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 applyShowMinimum(r, idx);
57 applyShowMaximum(r, idx);
58
59 return r;
60 }
61
62
63 /** Set line color to renderer. */
64 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) {
65 Color c = ThemeUtil.parseLineColorField(theme);
66 r.setSeriesPaint(idx, c);
67 }
68
69
70 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
71 int size = ThemeUtil.parseLineWidth(theme);
72 r.setSeriesStroke(
73 idx,
74 new BasicStroke(Integer.valueOf(size)));
75 }
76
77
78 protected void applyLineType(XYLineAndShapeRenderer r, int idx) {
79 int size = ThemeUtil.parseLineWidth(theme);
80 float[] dashes = ThemeUtil.parseLineStyle(theme);
81
82 // Do not apply the dashed style.
83 if (dashes.length <= 1) {
84 return;
85 }
86
87 r.setSeriesStroke(
88 idx,
89 new BasicStroke(Integer.valueOf(size),
90 BasicStroke.CAP_BUTT,
91 BasicStroke.JOIN_ROUND,
92 1.0f,
93 dashes,
94 0.0f));
95 }
96
97
98 /**
99 * Sets form and visibility of points.
100 */
101 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) {
102 boolean show = ThemeUtil.parseShowPoints(theme);
103 int size = ThemeUtil.parseLineWidth(theme);
104 r.setSeriesShape(idx, new Ellipse2D.Double(- size,
105 - size,
106 2 * size,
107 2 * size));
108 r.setSeriesShapesVisible(idx, show);
109 r.setDrawOutlines(true);
110 }
111
112
113 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) {
114 boolean show = ThemeUtil.parseShowLine(theme);
115 r.setSeriesLinesVisible(idx, show);
116 }
117
118
119 protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) {
120 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
121 return;
122 }
123
124 boolean visible = ThemeUtil.parseShowMinimum(theme);
125
126 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
127 er.setIsMinimumShapeVisisble(idx, visible);
128 }
129
130
131 protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) {
132 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
133 return;
134 }
135
136 boolean visible = ThemeUtil.parseShowMaximum(theme);
137
138 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
139 er.setIsMaximumShapeVisible(idx, visible);
140 }
141 }
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org