comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/XMLChartTheme.java @ 617:3d13fa281a7e

Added new ouput mode: histogram. gnv-artifacts/trunk@688 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 15 Feb 2010 11:44:01 +0000
parents 22a6493e8460
children 79401c871da4
comparison
equal deleted inserted replaced
616:93978859fa9e 617:3d13fa281a7e
1 package de.intevation.gnv.chart; 1 package de.intevation.gnv.chart;
2 2
3 import java.awt.Font; 3 import java.awt.Font;
4 import java.awt.Color; 4 import java.awt.Color;
5 import java.awt.Paint;
5 import java.awt.geom.Ellipse2D; 6 import java.awt.geom.Ellipse2D;
6 import java.lang.NumberFormatException; 7 import java.lang.NumberFormatException;
7 8
8 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
9 10
10 import org.jfree.chart.StandardChartTheme; 11 import org.jfree.chart.StandardChartTheme;
11 import org.jfree.chart.plot.XYPlot; 12 import org.jfree.chart.plot.XYPlot;
13 import org.jfree.chart.renderer.xy.AbstractXYItemRenderer;
14 import org.jfree.chart.renderer.xy.XYBarRenderer;
12 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 15 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
13 import org.jfree.ui.RectangleInsets; 16 import org.jfree.ui.RectangleInsets;
14 import org.jfree.util.UnitType; 17 import org.jfree.util.UnitType;
15 18
16 19
34 protected boolean renderShapes; 37 protected boolean renderShapes;
35 38
36 protected int pointWidth; 39 protected int pointWidth;
37 protected int pointHeight; 40 protected int pointHeight;
38 41
42 protected Paint histogramBasePaint;
43
39 44
40 public XMLChartTheme(String name) { 45 public XMLChartTheme(String name) {
41 super(name); 46 super(name);
42 } 47 }
43 48
57 } 62 }
58 63
59 64
60 public void setRangeCrosshairVisible(boolean visible) { 65 public void setRangeCrosshairVisible(boolean visible) {
61 this.rangeCrosshairVisible = visible; 66 this.rangeCrosshairVisible = visible;
67 }
68
69
70 public void setHistogramBasePaint(Color c) {
71 this.histogramBasePaint = c;
72 }
73
74
75 public Paint getHistogramBasePaint() {
76 return histogramBasePaint;
62 } 77 }
63 78
64 79
65 public void applyXMLConfiguration(Document document) { 80 public void applyXMLConfiguration(Document document) {
66 log.debug("create XMLChartTheme"); 81 log.debug("create XMLChartTheme");
77 initSubtitleParameters(document); 92 initSubtitleParameters(document);
78 initPlotParameters(document); 93 initPlotParameters(document);
79 initAxisParameters(document); 94 initAxisParameters(document);
80 initLegendParameters(document); 95 initLegendParameters(document);
81 initRenderer(document); 96 initRenderer(document);
97 initHistogramColor(document);
82 } 98 }
83 99
84 100
85 private void initTitleParameters(Document document) { 101 private void initTitleParameters(Document document) {
86 log.debug("init title parameters."); 102 log.debug("init title parameters.");
211 document, "theme/plot/itemrenderer/renderPoints/@value" 227 document, "theme/plot/itemrenderer/renderPoints/@value"
212 ); 228 );
213 } 229 }
214 230
215 231
232 private void initHistogramColor(Document document) {
233 log.debug("init histogram color");
234 String tmp = getString(document, "theme/histogram/bar/color/@value");
235 Color c = decodeColor(tmp);
236
237 if (c != null)
238 setHistogramBasePaint(c);
239 }
240
241
216 private static String getString(Document document, String xpath) { 242 private static String getString(Document document, String xpath) {
217 return Config.getStringXPath(document, xpath); 243 return Config.getStringXPath(document, xpath);
218 } 244 }
219 245
220 246
269 295
270 super.applyToXYPlot(plot); 296 super.applyToXYPlot(plot);
271 plot.setDomainCrosshairVisible(this.domainCrosshairVisible); 297 plot.setDomainCrosshairVisible(this.domainCrosshairVisible);
272 plot.setRangeCrosshairVisible(this.rangeCrosshairVisible); 298 plot.setRangeCrosshairVisible(this.rangeCrosshairVisible);
273 299
274 applyToXYLineAndShapeRenderer(plot); 300 AbstractXYItemRenderer renderer = (AbstractXYItemRenderer)
301 plot.getRenderer();
302
303 if (renderer instanceof XYLineAndShapeRenderer)
304 applyToXYLineAndShapeRenderer(plot);
305
306 if (renderer instanceof XYBarRenderer)
307 applyToXYBarRenderer(plot);
275 } 308 }
276 309
277 310
278 protected void applyToXYLineAndShapeRenderer(XYPlot plot) { 311 protected void applyToXYLineAndShapeRenderer(XYPlot plot) {
279 if (plot == null) 312 if (plot == null)
290 renderer.setSeriesShapesVisible(0, renderShapes); 323 renderer.setSeriesShapesVisible(0, renderShapes);
291 renderer.setSeriesLinesVisible(0, renderLines); 324 renderer.setSeriesLinesVisible(0, renderLines);
292 325
293 plot.setRenderer(renderer); 326 plot.setRenderer(renderer);
294 } 327 }
328
329
330 protected void applyToXYBarRenderer(XYPlot plot) {
331 if (plot == null)
332 return;
333
334 XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
335
336 renderer.setSeriesPaint(0, histogramBasePaint);
337 }
295 } 338 }

http://dive4elements.wald.intevation.org