annotate gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java @ 308:677da0e143cc

Added dependencies for esri and ibm libraries required for unit tests. gnv-artifacts/trunk@366 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 24 Nov 2009 14:40:53 +0000
parents f0f106c7b906
children 63f8b3fb7d9a
rev   line source
297
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.chart;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.awt.Color;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.util.Collection;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.util.Iterator;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import org.apache.log4j.Logger;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import org.jfree.chart.JFreeChart;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import org.jfree.chart.ChartFactory;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import org.jfree.chart.axis.NumberAxis;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import org.jfree.chart.axis.NumberTickUnit;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import org.jfree.chart.axis.AxisLocation;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import org.jfree.chart.plot.PlotOrientation;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.jfree.chart.plot.XYPlot;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import org.jfree.data.general.Series;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import de.intevation.gnv.geobackend.base.Result;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 /**
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 */
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 public abstract class AbstractXYLineChart
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 extends AbstractChart
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 private static Logger log = Logger.getLogger(AbstractXYLineChart.class);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 protected static Color[] COLOR = {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 Color.black, Color.red, Color.green, Color.blue
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 };
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 protected PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 protected abstract void initData();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 protected abstract void addValue(Result row, Series series);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 protected abstract void addSeries(Series series, int idx);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 protected abstract String createSeriesName(
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 String breakPoint1,
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 String breakPoint2,
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 String breakPoint3
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 );
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 public JFreeChart generateChart() {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 log.debug("generate XYLineChart");
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 if (chart != null)
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 return chart;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 chart = ChartFactory.createXYLineChart(
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 labels.getTitle(),
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 labels.getDomainAxisLabel(),
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 null,
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 null,
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 PLOT_ORIENTATION,
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 true,
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 false,
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 false
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 );
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
304
a16d337c5678 The style of charts can be configured with ChartThemes using XML configuration files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 301
diff changeset
63 theme.apply(chart);
297
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 initData();
304
a16d337c5678 The style of charts can be configured with ChartThemes using XML configuration files.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 301
diff changeset
65
297
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 return chart;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 protected void prepareAxis(String seriesKey, int idx) {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 log.debug("prepare axis of xychart");
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 XYPlot plot = chart.getXYPlot();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 NumberAxis axis = new NumberAxis(seriesKey);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 if (seriesKey.contains("richtung")) {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 axis.setTickUnit(new NumberTickUnit(30.0));
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 axis.setUpperBound(360.0);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 axis.setLowerBound(0.0);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 plot.setRangeAxis(idx, axis);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 else {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 axis.setFixedDimension(10.0);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 axis.setAutoRangeIncludesZero(false);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 plot.setRangeAxis(idx, axis);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 axis.configure();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 if (idx % 2 != 0)
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_RIGHT);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 else
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_LEFT);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 plot.mapDatasetToRangeAxis(idx, idx);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 StandardXYItemRenderer renderer = new StandardXYItemRenderer();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 renderer.setSeriesPaint(idx, COLOR[idx%COLOR.length]);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 plot.setRenderer(idx, renderer);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 protected String findValueTitle(Collection values, String id) {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 log.debug("find description of dataset");
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102
307
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
103 if (values != null){
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
104 Iterator it = values.iterator();
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
105 while (it.hasNext()) {
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
106 KeyValueDescibeData data = (KeyValueDescibeData) it.next();
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
107
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
108 if (id.equals(data.getKey()))
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
109 return data.getValue();
f0f106c7b906 Fixed some broken Method-Extentions.
Tim Englich <tim.englich@intevation.de>
parents: 304
diff changeset
110 }
297
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 return "";
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 :

http://dive4elements.wald.intevation.org