annotate gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java @ 301:3ea030aafe65

Removed duplicated and needless imports. gnv-artifacts/trunk@355 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 20 Nov 2009 14:03:31 +0000
parents 3f43392df3f6
children a16d337c5678
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
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 initData();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 return chart;
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
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 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
69 log.debug("prepare axis of xychart");
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 XYPlot plot = chart.getXYPlot();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 NumberAxis axis = new NumberAxis(seriesKey);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 if (seriesKey.contains("richtung")) {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 axis.setTickUnit(new NumberTickUnit(30.0));
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 axis.setUpperBound(360.0);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 axis.setLowerBound(0.0);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 plot.setRangeAxis(idx, axis);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 else {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 axis.setFixedDimension(10.0);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 axis.setAutoRangeIncludesZero(false);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 plot.setRangeAxis(idx, axis);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 axis.configure();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 if (idx % 2 != 0)
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 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
88 else
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_LEFT);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 plot.mapDatasetToRangeAxis(idx, idx);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 StandardXYItemRenderer renderer = new StandardXYItemRenderer();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 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
94 plot.setRenderer(idx, renderer);
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
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 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
99 log.debug("find description of dataset");
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 Iterator it = values.iterator();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 while (it.hasNext()) {
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 KeyValueDescibeData data = (KeyValueDescibeData) it.next();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 if (id.equals(data.getKey()))
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 return data.getValue();
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 return "";
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 }
3f43392df3f6 Interface and abstract classes for chart creation implemented.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 :

http://dive4elements.wald.intevation.org