comparison artifacts/src/main/java/org/dive4elements/river/jfree/XYStyle.java @ 9325:094ed9d1f2ad

Fixed: change of point style of interpolated data did not change in WQ chart of fixanalysis Fixed: change of point style of interpolated data did not change in dWt chart of fixanalysis; also had duplicate legend entries
author gernotbelger
date Fri, 27 Jul 2018 14:33:41 +0200
parents 5e38e2924c07
children ddcd52d239cd
comparison
equal deleted inserted replaced
9324:058701d91552 9325:094ed9d1f2ad
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.jfree; 9 package org.dive4elements.river.jfree;
10 10
11 import org.dive4elements.river.themes.ThemeDocument;
12
13 import java.awt.BasicStroke; 11 import java.awt.BasicStroke;
14 import java.awt.Color; 12 import java.awt.Color;
15 import java.awt.Shape; 13 import java.awt.Shape;
16 import java.awt.geom.Ellipse2D; 14 import java.awt.geom.Ellipse2D;
17 15
18 import org.apache.log4j.Logger; 16 import org.dive4elements.river.themes.ThemeDocument;
19 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 17 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
20
21 18
22 /** 19 /**
23 * Utility to apply theme-settings to a renderer. 20 * Utility to apply theme-settings to a renderer.
21 *
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
25 */ 23 */
26 public class XYStyle implements Style { 24 public final class XYStyle implements Style {
27 25
28 private static Logger log = Logger.getLogger(XYStyle.class); 26 private final ThemeDocument theme;
29 27
30 protected ThemeDocument theme; 28 private XYLineAndShapeRenderer renderer;
31 29
32 protected XYLineAndShapeRenderer renderer; 30 private final Shape shape;
33 31
34 protected Shape shape; 32 public XYStyle(final ThemeDocument theme) {
35 33 this(theme, null);
36 34 }
37 public XYStyle(ThemeDocument theme) { 35
38 this.theme = theme; 36 public XYStyle(final ThemeDocument theme, final Shape shape) {
39 }
40
41 public XYStyle(ThemeDocument theme, Shape shape) {
42 this.theme = theme; 37 this.theme = theme;
43 this.shape = shape; 38 this.shape = shape;
44 } 39 }
45 40
46
47 /** 41 /**
48 * Applies line color, size and type attributes to renderer, also 42 * Applies line color, size and type attributes to renderer, also
49 * whether to draw lines and/or points. 43 * whether to draw lines and/or points.
50 */ 44 */
51 @Override 45 @Override
52 public XYLineAndShapeRenderer applyTheme( 46 public XYLineAndShapeRenderer applyTheme(final XYLineAndShapeRenderer r, final int idx) {
53 XYLineAndShapeRenderer r,
54 int idx
55 ) {
56 this.renderer = r; 47 this.renderer = r;
57 if (shape != null) { 48
58 r.setShape(shape); 49 if (this.shape != null)
59 } 50 r.setShape(this.shape);
60 if (theme == null) { 51
61 // Hurray we already applied nothing :) 52 if (this.theme == null)
62 return r; 53 return r;
63 } 54
64 applyUseFillPaint(r);
65 applyLineColor(r, idx); 55 applyLineColor(r, idx);
66 applyLineSize(r, idx); 56 applyLineSize(r, idx);
67 applyLineType(r, idx); 57 applyLineType(r, idx);
68 applyShowLine(r, idx); 58 applyShowLine(r, idx);
69 applyShowPoints(r, idx); 59
70 applyPointSize(r, idx); 60 applyPointStyles(r, idx);
71 applyPointColor(r, idx); 61
72 applyShowMinimum(r, idx); 62 applyShowMinimum(r, idx);
73 applyShowMaximum(r, idx); 63 applyShowMaximum(r, idx);
74 64
75 // Line label styles 65 // Line label styles
76 applyShowLineLabel(r, idx); 66 applyShowLineLabel(r, idx);
81 71
82 // Point label styles 72 // Point label styles
83 // TODO: Currently point label are annotations and 73 // TODO: Currently point label are annotations and
84 // are not drawn this way 74 // are not drawn this way
85 /* 75 /*
86 applyShowPointLabelBG(r, idx); 76 * applyShowPointLabelBG(r, idx);
87 applyLinePointFont(r, idx); 77 * applyLinePointFont(r, idx);
88 applyLinePointColor(r, idx); 78 * applyLinePointColor(r, idx);
89 applyLinePointBGColor(r, idx);*/ 79 * applyLinePointBGColor(r, idx);
80 */
90 81
91 return r; 82 return r;
92 } 83 }
93 84
94 protected void applyUseFillPaint(XYLineAndShapeRenderer r) {
95 Boolean use = theme.parseUseFillPaint();
96 if (use != null) {
97 r.setUseFillPaint(use);
98 }
99 }
100
101
102 /** Set line color to renderer. */ 85 /** Set line color to renderer. */
103 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { 86 private void applyLineColor(final XYLineAndShapeRenderer r, final int idx) {
104 Color c = theme.parseLineColorField(); 87 final Color c = this.theme.parseLineColorField();
105 if (c != null) { 88 if (c != null) {
106 r.setSeriesPaint(idx, c); 89 r.setSeriesPaint(idx, c);
107 } 90 }
108 } 91 }
109 92
110
111 /** Tells the renderer whether or not to add a label to a line. */ 93 /** Tells the renderer whether or not to add a label to a line. */
112 protected void applyShowLineLabel(XYLineAndShapeRenderer r, int idx) { 94 private void applyShowLineLabel(final XYLineAndShapeRenderer r, final int idx) {
113 if (!(r instanceof EnhancedLineAndShapeRenderer)) { 95 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
114 return; 96 return;
115 } 97 }
116 boolean showLabelLine = theme.parseShowLineLabel(); 98 final boolean showLabelLine = this.theme.parseShowLineLabel();
117 boolean anyLabel = showLabelLine || theme.parseShowWidth() || 99 final boolean anyLabel = showLabelLine || this.theme.parseShowWidth() || this.theme.parseShowLevel() || this.theme.parseShowMiddleHeight();
118 theme.parseShowLevel() || 100 ((EnhancedLineAndShapeRenderer) r).setShowLineLabel(anyLabel, idx);
119 theme.parseShowMiddleHeight(); 101 }
120 ((EnhancedLineAndShapeRenderer)r).setShowLineLabel(anyLabel, idx);
121 }
122
123 102
124 /** Tells the renderer whether or not to fill the bg of a lines label. */ 103 /** Tells the renderer whether or not to fill the bg of a lines label. */
125 protected void applyShowLineLabelBG(XYLineAndShapeRenderer r, int idx) { 104 private void applyShowLineLabelBG(final XYLineAndShapeRenderer r, final int idx) {
126 if (!(r instanceof EnhancedLineAndShapeRenderer)) { 105 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
127 return; 106 return;
128 } 107 }
129 boolean showLabelLine = theme.parseLabelShowBackground(); 108 final boolean showLabelLine = this.theme.parseLabelShowBackground();
130 ((EnhancedLineAndShapeRenderer)r).setShowLineLabelBG( 109 ((EnhancedLineAndShapeRenderer) r).setShowLineLabelBG(idx, showLabelLine);
131 idx, showLabelLine); 110 }
132 } 111
133 112 /**
134 /** Tell the renderer which font (and -size and -style) to use for 113 * Tell the renderer which font (and -size and -style) to use for
135 * linelabels. */ 114 * linelabels.
136 protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) { 115 */
137 if (!(r instanceof EnhancedLineAndShapeRenderer)) { 116 private void applyLineLabelFont(final XYLineAndShapeRenderer r, final int idx) {
138 return; 117 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
139 } 118 return;
140 ((EnhancedLineAndShapeRenderer)r).setLineLabelFont( 119 }
141 theme.parseTextFont(), idx); 120 ((EnhancedLineAndShapeRenderer) r).setLineLabelFont(this.theme.parseTextFont(), idx);
142 } 121 }
143 122
144 /** Tell the renderer which color to use for 123 /**
145 * linelabels. */ 124 * Tell the renderer which color to use for
146 protected void applyLineLabelColor(XYLineAndShapeRenderer r, int idx) { 125 * linelabels.
147 if (!(r instanceof EnhancedLineAndShapeRenderer)) { 126 */
148 return; 127 private void applyLineLabelColor(final XYLineAndShapeRenderer r, final int idx) {
149 } 128 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
150 ((EnhancedLineAndShapeRenderer)r).setLineLabelTextColor( 129 return;
151 idx, theme.parseTextColor()); 130 }
152 } 131 ((EnhancedLineAndShapeRenderer) r).setLineLabelTextColor(idx, this.theme.parseTextColor());
153 132 }
154 /** Tell the renderer which color to use for bg of 133
155 * linelabels. */ 134 /**
156 protected void applyLineLabelBGColor(XYLineAndShapeRenderer r, int idx) { 135 * Tell the renderer which color to use for bg of
157 if (!(r instanceof EnhancedLineAndShapeRenderer)) { 136 * linelabels.
158 return; 137 */
159 } 138 private void applyLineLabelBGColor(final XYLineAndShapeRenderer r, final int idx) {
160 ((EnhancedLineAndShapeRenderer)r).setLineLabelBGColor(idx, 139 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
161 theme.parseTextBackground()); 140 return;
141 }
142 ((EnhancedLineAndShapeRenderer) r).setLineLabelBGColor(idx, this.theme.parseTextBackground());
162 } 143 }
163 144
164 /** Set stroke of series. */ 145 /** Set stroke of series. */
165 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { 146 private void applyLineSize(final XYLineAndShapeRenderer r, final int idx) {
166 int size = theme.parseLineWidth(); 147 final int size = this.theme.parseLineWidth();
167 r.setSeriesStroke( 148 r.setSeriesStroke(idx, new BasicStroke(size));
168 idx, 149 }
169 new BasicStroke(size));
170 }
171
172 150
173 /** Set stroke strength of series. */ 151 /** Set stroke strength of series. */
174 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { 152 private void applyLineType(final XYLineAndShapeRenderer r, final int idx) {
175 int size = theme.parseLineWidth(); 153 final int size = this.theme.parseLineWidth();
176 float[] dashes = theme.parseLineStyle(); 154 final float[] dashes = this.theme.parseLineStyle();
177 155
178 // Do not apply the dashed style. 156 // Do not apply the dashed style.
179 if (dashes.length <= 1) { 157 if (dashes.length <= 1) {
180 return; 158 return;
181 } 159 }
182 160
183 r.setSeriesStroke( 161 r.setSeriesStroke(idx, new BasicStroke(size, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dashes, 0.0f));
184 idx, 162 }
185 new BasicStroke(size, 163
186 BasicStroke.CAP_BUTT, 164 private void applyPointStyles(final XYLineAndShapeRenderer r, final int idx) {
187 BasicStroke.JOIN_ROUND, 165 applyPointSize(r, idx);
188 1.0f, 166
189 dashes, 167 final Color c = this.theme.parsePointColor();
190 0.0f)); 168 final boolean show = this.theme.parseShowPoints();
191 } 169 final boolean showOutline = this.theme.parseShowPointsOutline();
192 170
193 171 if (c != null)
194 protected void applyPointSize(XYLineAndShapeRenderer r, int idx) { 172 r.setSeriesFillPaint(idx, c);
195 int size = theme.parsePointWidth(); 173 r.setUseFillPaint(c!= null);
196 int dim = 2 * size; 174
175 r.setSeriesShapesFilled(idx, show);
176
177 r.setSeriesOutlinePaint(idx, c);
178 r.setDrawOutlines(showOutline);
179 r.setUseOutlinePaint(c != null);
180
181 r.setSeriesShapesVisible(idx, show || showOutline);
182
183 // applyShowPoints(r, idx);
184 // applyPointColor(r, idx);
185
186 // applyUseFillPaint(r);
187 }
188
189 private void applyPointSize(final XYLineAndShapeRenderer r, final int idx) {
190 final int size = this.theme.parsePointWidth();
191 final int dim = 2 * size;
197 192
198 r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim)); 193 r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim));
199 } 194 }
200 195
201 196 private void applyPointColor(final XYLineAndShapeRenderer r, final int idx) {
202 protected void applyPointColor(XYLineAndShapeRenderer r, int idx) { 197 final Color c = this.theme.parsePointColor();
203 Color c = theme.parsePointColor(); 198
204 199 boolean alt = false;
205 if (c != null) { 200 if (alt) {
201
202 if (c != null) {
203 r.setSeriesFillPaint(idx, c);
204
205 r.setUseFillPaint(true);
206 r.setDrawOutlines(false);
207 }
208 } else {
209 // if (c != null) {
206 r.setSeriesFillPaint(idx, c); 210 r.setSeriesFillPaint(idx, c);
207 r.setUseFillPaint(true); 211 r.setUseFillPaint(c != null);
208 r.setDrawOutlines(false); 212
209 } 213 r.setSeriesOutlinePaint(idx, c);
210 } 214 r.setDrawOutlines(c != null);
211 215 // }
216 }
217 }
212 218
213 /** 219 /**
214 * Sets form and visibility of points. 220 * Sets form and visibility of points.
215 */ 221 */
216 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { 222 private void applyShowPoints(final XYLineAndShapeRenderer r, final int idx) {
217 boolean show = theme.parseShowPoints(); 223 final boolean show = this.theme.parseShowPoints();
218 224
219 r.setSeriesShapesVisible(idx, show); 225 r.setSeriesShapesVisible(idx, show);
220 r.setDrawOutlines(true); 226 r.setDrawOutlines(true);
221 } 227 }
222 228
223 229 // private void applyUseFillPaint(final XYLineAndShapeRenderer r) {
224 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { 230 // final Boolean use = this.theme.parseUseFillPaint();
225 boolean show = theme.parseShowLine(); 231 // if (use != null) {
232 // r.setUseFillPaint(use);
233 // }
234 // }
235
236 private void applyShowLine(final XYLineAndShapeRenderer r, final int idx) {
237 final boolean show = this.theme.parseShowLine();
226 r.setSeriesLinesVisible(idx, show); 238 r.setSeriesLinesVisible(idx, show);
227 } 239 }
228 240
229 241 private void applyShowMinimum(final XYLineAndShapeRenderer r, final int idx) {
230 protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) { 242 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
231 if (!(r instanceof EnhancedLineAndShapeRenderer)) { 243 return;
232 return; 244 }
233 } 245
234 246 final boolean visible = this.theme.parseShowMinimum();
235 boolean visible = theme.parseShowMinimum(); 247
236 248 final EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
237 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
238 er.setIsMinimumShapeVisisble(idx, visible); 249 er.setIsMinimumShapeVisisble(idx, visible);
239 } 250 }
240 251
241 252 private void applyShowMaximum(final XYLineAndShapeRenderer r, final int idx) {
242 protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) { 253 if (!(r instanceof EnhancedLineAndShapeRenderer)) {
243 if (!(r instanceof EnhancedLineAndShapeRenderer)) { 254 return;
244 return; 255 }
245 } 256
246 257 final boolean visible = this.theme.parseShowMaximum();
247 boolean visible = theme.parseShowMaximum(); 258
248 259 final EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
249 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
250 er.setIsMaximumShapeVisible(idx, visible); 260 er.setIsMaximumShapeVisible(idx, visible);
251 } 261 }
252
253 262
254 @Override 263 @Override
255 public XYLineAndShapeRenderer getRenderer() { 264 public XYLineAndShapeRenderer getRenderer() {
256 return this.renderer; 265 return this.renderer;
257 } 266 }
258 } 267 }
259 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org