comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1679:69929c471646

Improved the creation/rendering of annotations (km favorites, mainvalues). flys-artifacts/trunk@2896 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 05 Oct 2011 14:23:53 +0000
parents 5b38cdf65307
children bdb05dc9b763
comparison
equal deleted inserted replaced
1678:03fbf1b30e72 1679:69929c471646
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2
2 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
3
4 import java.util.ArrayList;
5 import java.util.List;
6 4
7 import org.w3c.dom.Document; 5 import org.w3c.dom.Document;
8 6
9 import java.awt.Color;
10 import org.jfree.chart.JFreeChart; 7 import org.jfree.chart.JFreeChart;
11 import org.jfree.chart.annotations.XYAnnotation;
12 import org.jfree.chart.title.TextTitle; 8 import org.jfree.chart.title.TextTitle;
13 import org.jfree.chart.plot.XYPlot;
14 import org.jfree.data.xy.XYSeries; 9 import org.jfree.data.xy.XYSeries;
15 import org.jfree.data.xy.XYSeriesCollection;
16 10
17 import de.intevation.artifacts.Artifact; 11 import de.intevation.artifacts.Artifact;
18 12
19 import de.intevation.artifactdatabase.state.Facet; 13 import de.intevation.artifactdatabase.state.Facet;
20 14
21 import de.intevation.flys.artifacts.FLYSArtifact; 15 import de.intevation.flys.artifacts.FLYSArtifact;
22 import de.intevation.flys.artifacts.model.NamedDouble;
23 import de.intevation.flys.artifacts.model.FacetTypes; 16 import de.intevation.flys.artifacts.model.FacetTypes;
24 import de.intevation.flys.artifacts.model.WQKms; 17 import de.intevation.flys.artifacts.model.WQKms;
25 18
26 import de.intevation.flys.jfree.StickyAxisAnnotation; 19 import de.intevation.flys.jfree.FLYSAnnotation;
27
28 import de.intevation.flys.utils.ThemeUtil;
29 20
30 21
31 /** 22 /**
32 * An OutGenerator that generates discharge curves. 23 * An OutGenerator that generates discharge curves.
33 * 24 *
54 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; 45 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
55 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; 46 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
56 public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)"; 47 public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)";
57 public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)"; 48 public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)";
58 49
59 /** List of Annotations (specifically, Main Values). */
60 protected List<XYAnnotation> annotations;
61
62 /** Pseudo-Dataseries to have a legend for annotations. */
63 protected XYSeriesCollection pseudoAnnotationData = null;
64
65 50
66 /** Trivial Constructor. */ 51 /** Trivial Constructor. */
67 public ComputedDischargeCurveGenerator () { 52 public ComputedDischargeCurveGenerator () {
68 super(); 53 super();
69 annotations = new ArrayList<XYAnnotation>();
70 } 54 }
71 55
72 56
73 @Override 57 @Override
74 protected String getChartTitle() { 58 protected String getChartTitle() {
129 /** 113 /**
130 * Store W MainValues as annotations for later plotting. 114 * Store W MainValues as annotations for later plotting.
131 */ 115 */
132 protected void doMainValueWAnnotations(Object o, Document theme) { 116 protected void doMainValueWAnnotations(Object o, Document theme) {
133 logger.debug("ComputedDischargeCurveGenerator set W MainValues."); 117 logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
134 if (pseudoAnnotationData == null) {
135 pseudoAnnotationData = new XYSeriesCollection();
136 }
137 118
138 Color color = ThemeUtil.parseLineColorField(theme); 119 FLYSAnnotation fa = (FLYSAnnotation) o;
139 if (color == null) { 120 fa.setTheme(theme);
140 color = Color.black; 121 addAnnotations(fa);
141 }
142
143 List<NamedDouble> mainValuesW = (List<NamedDouble>) o;
144 for (NamedDouble mv: mainValuesW) {
145 float pos = (float) mv.getValue();
146 String text = mv.getName();
147 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
148 StickyAxisAnnotation.SimpleAxis.Y_AXIS);
149 ta.setPaint(color);
150 this.annotations.add(ta);
151 }
152 String label = msg(I18N_MAINVALUES_W_LABEL, I18N_MAINVALUES_W_LABEL, null);
153 pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
154 } 122 }
155 123
156 124
157 /** 125 /**
158 * Store Q MainValues as annotations for later plotting. 126 * Store Q MainValues as annotations for later plotting.
159 */ 127 */
160 protected void doMainValueQAnnotations(Object o, Document theme) { 128 protected void doMainValueQAnnotations(Object o, Document theme) {
161 logger.debug("ComputedDischargeCurveGenerator set Q MainValues."); 129 logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
162 130
163 Color color = ThemeUtil.parseLineColorField(theme); 131 FLYSAnnotation fa = (FLYSAnnotation) o;
164 if (color == null) { 132 fa.setTheme(theme);
165 color = Color.black; 133 addAnnotations(fa);
166 }
167
168 if (pseudoAnnotationData == null) {
169 pseudoAnnotationData = new XYSeriesCollection();
170 }
171
172 List<NamedDouble> mainValuesQ = (List<NamedDouble>) o;
173 for (NamedDouble mv: mainValuesQ) {
174 float pos = (float) mv.getValue();
175 String text = mv.getName();
176 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos);
177 ta.setPaint(color);
178 this.annotations.add(ta);
179 }
180 String label = msg(I18N_MAINVALUES_Q_LABEL, I18N_MAINVALUES_Q_LABEL, null);
181 pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
182 }
183
184
185 /** Generate Chart with annotations. */
186 @Override
187 public JFreeChart generateChart() {
188 JFreeChart c = super.generateChart();
189 XYPlot p = (XYPlot) c.getPlot();
190 redoAnnotations(p);
191 return c;
192 }
193
194
195 /**
196 * Recalculate some annotation positions and add them to plot.
197 * Annotations represent MainValues.
198 * @param plot Plot to add annotations to.
199 */
200 protected void redoAnnotations(XYPlot plot) {
201 plot.clearAnnotations();
202
203 for (XYAnnotation a: annotations) {
204 plot.addAnnotation(a, false);
205 }
206 } 134 }
207 135
208 136
209 /** 137 /**
210 * Add Q-Series to plot. 138 * Add Q-Series to plot.
225 addFirstAxisSeries(series); 153 addFirstAxisSeries(series);
226 } 154 }
227 155
228 156
229 /** 157 /**
230 * Add datasets to plot.
231 * @param plot plot to add datasets to.
232 * @todo merge with LongitudinalSectionGenerator/superclass.
233 */
234 @Override
235 protected void addDatasets(XYPlot plot) {
236 super.addDatasets(plot);
237 if (pseudoAnnotationData != null) {
238 plot.setDataset(2, pseudoAnnotationData);
239 }
240 }
241
242
243 /**
244 * Get the series name to display in legend. 158 * Get the series name to display in legend.
245 */ 159 */
246 protected String getSeriesName(WQKms wqkms) { 160 protected String getSeriesName(WQKms wqkms) {
247 Object[] args = new Object[] { 161 Object[] args = new Object[] {
248 getRiverName(), 162 getRiverName(),

http://dive4elements.wald.intevation.org