comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java @ 2793:6310b1582f2d

merged flys-artifacts/2.7
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:30 +0200
parents bdc86e61428c
children 22def36d37b7
comparison
equal deleted inserted replaced
2548:ada02bbd3b7f 2793:6310b1582f2d
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 * Utility to apply theme-settings to a renderer.
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
18 */
19 public class XYStyle implements Style {
20
21 protected Document theme;
22
23
24 public XYStyle(Document theme) {
25 this.theme = theme;
26 }
27
28
29 /**
30 * Applies line color, size and type attributes to renderer, also
31 * whether to draw lines and/or points.
32 */
33 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){
34 applyLineColor(r, idx);
35 applyLineSize(r, idx);
36 applyLineType(r, idx);
37 applyShowLine(r, idx);
38 applyShowPoints(r, idx);
39 applyPointSize(r, idx);
40 applyShowMinimum(r, idx);
41 applyShowMaximum(r, idx);
42 applyShowLineLabel(r, idx);
43 applyLineLabelFont(r, idx);
44 applyLineLabelColor(r, idx);
45 applyShowLineLabelBG(r, idx);
46 applyLineLabelBGColor(r, idx);
47
48 return r;
49 }
50
51
52 /** Set line color to renderer. */
53 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) {
54 Color c = ThemeUtil.parseLineColorField(theme);
55 r.setSeriesPaint(idx, c);
56 }
57
58
59 /** Tells the renderer whether or not to add a label to a line. */
60 protected void applyShowLineLabel(XYLineAndShapeRenderer r, int idx) {
61 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
62 return;
63 }
64 boolean showLabelLine = ThemeUtil.parseShowLineLabel(theme);
65 ((EnhancedLineAndShapeRenderer)r).setShowLineLabel(showLabelLine, idx);
66 }
67
68
69 /** Tells the renderer whether or not to fill the bg of a lines label. */
70 protected void applyShowLineLabelBG(XYLineAndShapeRenderer r, int idx) {
71 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
72 return;
73 }
74 boolean showLabelLine = ThemeUtil.parseShowLineLabelBG(theme);
75 ((EnhancedLineAndShapeRenderer)r).setShowLineLabelBG(idx, showLabelLine);
76 }
77
78 /** Tell the renderer which font (and -size and -style) to use for
79 * linelabels. */
80 protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) {
81 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
82 return;
83 }
84 ((EnhancedLineAndShapeRenderer)r).setLineLabelFont(ThemeUtil.parseLineLabelFont(theme), idx);
85 }
86
87 /** Tell the renderer which color to use for
88 * linelabels. */
89 protected void applyLineLabelColor(XYLineAndShapeRenderer r, int idx) {
90 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
91 return;
92 }
93 ((EnhancedLineAndShapeRenderer)r).setLineLabelTextColor(idx, ThemeUtil.parseLineLabelTextColor(theme));
94 }
95
96 /** Tell the renderer which color to use for bg of
97 * linelabels. */
98 protected void applyLineLabelBGColor(XYLineAndShapeRenderer r, int idx) {
99 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
100 return;
101 }
102 ((EnhancedLineAndShapeRenderer)r).setLineLabelBGColor(idx,
103 ThemeUtil.parseLineLabelBGColor(theme));
104 }
105
106 /** Set stroke of series. */
107 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
108 int size = ThemeUtil.parseLineWidth(theme);
109 r.setSeriesStroke(
110 idx,
111 new BasicStroke(Integer.valueOf(size)));
112 }
113
114
115 /** Set stroke strength of series. */
116 protected void applyLineType(XYLineAndShapeRenderer r, int idx) {
117 int size = ThemeUtil.parseLineWidth(theme);
118 float[] dashes = ThemeUtil.parseLineStyle(theme);
119
120 // Do not apply the dashed style.
121 if (dashes.length <= 1) {
122 return;
123 }
124
125 r.setSeriesStroke(
126 idx,
127 new BasicStroke(Integer.valueOf(size),
128 BasicStroke.CAP_BUTT,
129 BasicStroke.JOIN_ROUND,
130 1.0f,
131 dashes,
132 0.0f));
133 }
134
135
136 protected void applyPointSize(XYLineAndShapeRenderer r, int idx) {
137 int size = ThemeUtil.parsePointWidth(theme);
138 int dim = 2 * size;
139
140 r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim));
141 }
142
143
144 /**
145 * Sets form and visibility of points.
146 */
147 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) {
148 boolean show = ThemeUtil.parseShowPoints(theme);
149
150 r.setSeriesShapesVisible(idx, show);
151 r.setDrawOutlines(true);
152 }
153
154
155 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) {
156 boolean show = ThemeUtil.parseShowLine(theme);
157 r.setSeriesLinesVisible(idx, show);
158 }
159
160
161 protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) {
162 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
163 return;
164 }
165
166 boolean visible = ThemeUtil.parseShowMinimum(theme);
167
168 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
169 er.setIsMinimumShapeVisisble(idx, visible);
170 }
171
172
173 protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) {
174 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
175 return;
176 }
177
178 boolean visible = ThemeUtil.parseShowMaximum(theme);
179
180 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
181 er.setIsMaximumShapeVisible(idx, visible);
182 }
183 }
184 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org