Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java @ 2424:092e519ff461
merged flys-artifacts/2.6.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:26 +0200 |
parents | 991e4a5df323 |
children | 8aaa7f4ce06a |
comparison
equal
deleted
inserted
replaced
2392:8112ec686a9a | 2424:092e519ff461 |
---|---|
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 | |
8 import org.w3c.dom.Document; | |
9 | |
10 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | |
11 | |
12 import de.intevation.flys.utils.ThemeUtil; | |
13 | |
14 | |
15 /** | |
16 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
17 */ | |
18 public class XYStyle implements Style { | |
19 | |
20 protected Document theme; | |
21 | |
22 | |
23 public XYStyle(Document theme) { | |
24 this.theme = theme; | |
25 } | |
26 | |
27 | |
28 /** | |
29 * Applies line color, size and type attributes to renderer, also | |
30 * whether to draw lines and/or points. | |
31 */ | |
32 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ | |
33 applyLineColor(r, idx); | |
34 applyLineSize(r, idx); | |
35 applyLineType(r, idx); | |
36 applyShowLine(r, idx); | |
37 applyShowPoints(r, idx); | |
38 applyPointSize(r, idx); | |
39 applyShowMinimum(r, idx); | |
40 applyShowMaximum(r, idx); | |
41 | |
42 return r; | |
43 } | |
44 | |
45 | |
46 /** Set line color to renderer. */ | |
47 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { | |
48 Color c = ThemeUtil.parseLineColorField(theme); | |
49 r.setSeriesPaint(idx, c); | |
50 } | |
51 | |
52 | |
53 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { | |
54 int size = ThemeUtil.parseLineWidth(theme); | |
55 r.setSeriesStroke( | |
56 idx, | |
57 new BasicStroke(Integer.valueOf(size))); | |
58 } | |
59 | |
60 | |
61 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { | |
62 int size = ThemeUtil.parseLineWidth(theme); | |
63 float[] dashes = ThemeUtil.parseLineStyle(theme); | |
64 | |
65 // Do not apply the dashed style. | |
66 if (dashes.length <= 1) { | |
67 return; | |
68 } | |
69 | |
70 r.setSeriesStroke( | |
71 idx, | |
72 new BasicStroke(Integer.valueOf(size), | |
73 BasicStroke.CAP_BUTT, | |
74 BasicStroke.JOIN_ROUND, | |
75 1.0f, | |
76 dashes, | |
77 0.0f)); | |
78 } | |
79 | |
80 | |
81 protected void applyPointSize(XYLineAndShapeRenderer r, int idx) { | |
82 int size = ThemeUtil.parsePointWidth(theme); | |
83 int dim = 2 * size; | |
84 | |
85 r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim)); | |
86 } | |
87 | |
88 | |
89 /** | |
90 * Sets form and visibility of points. | |
91 */ | |
92 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { | |
93 boolean show = ThemeUtil.parseShowPoints(theme); | |
94 | |
95 r.setSeriesShapesVisible(idx, show); | |
96 r.setDrawOutlines(true); | |
97 } | |
98 | |
99 | |
100 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { | |
101 boolean show = ThemeUtil.parseShowLine(theme); | |
102 r.setSeriesLinesVisible(idx, show); | |
103 } | |
104 | |
105 | |
106 protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) { | |
107 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | |
108 return; | |
109 } | |
110 | |
111 boolean visible = ThemeUtil.parseShowMinimum(theme); | |
112 | |
113 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; | |
114 er.setIsMinimumShapeVisisble(idx, visible); | |
115 } | |
116 | |
117 | |
118 protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) { | |
119 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | |
120 return; | |
121 } | |
122 | |
123 boolean visible = ThemeUtil.parseShowMaximum(theme); | |
124 | |
125 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; | |
126 er.setIsMaximumShapeVisible(idx, visible); | |
127 } | |
128 } | |
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |