comparison flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 1677:dd9dfe1e48fa

Bugfixes for various issues: Improved rendering process of annotations. flys-artifacts/trunk@2894 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 05 Oct 2011 11:23:18 +0000
parents 68260e38029a
children 69929c471646
comparison
equal deleted inserted replaced
1676:6e840e213fdf 1677:dd9dfe1e48fa
4 import java.util.List; 4 import java.util.List;
5 5
6 import org.apache.log4j.Logger; 6 import org.apache.log4j.Logger;
7 7
8 import org.jfree.chart.JFreeChart; 8 import org.jfree.chart.JFreeChart;
9 import org.jfree.chart.LegendItem;
10 import org.jfree.chart.LegendItemCollection;
9 import org.jfree.chart.axis.NumberAxis; 11 import org.jfree.chart.axis.NumberAxis;
10 import org.jfree.chart.axis.ValueAxis; 12 import org.jfree.chart.axis.ValueAxis;
11 import org.jfree.chart.plot.XYPlot; 13 import org.jfree.chart.plot.XYPlot;
12 import org.jfree.chart.title.TextTitle; 14 import org.jfree.chart.title.TextTitle;
13 import org.jfree.data.Range; 15 import org.jfree.data.Range;
14 import org.jfree.data.xy.XYSeries; 16 import org.jfree.data.xy.XYSeries;
15 import org.jfree.data.xy.XYSeriesCollection;
16 import org.jfree.ui.TextAnchor; 17 import org.jfree.ui.TextAnchor;
17 18
18 import org.w3c.dom.Document; 19 import org.w3c.dom.Document;
19 20
20 import de.intevation.artifacts.Artifact; 21 import de.intevation.artifacts.Artifact;
24 import de.intevation.flys.artifacts.FLYSArtifact; 25 import de.intevation.flys.artifacts.FLYSArtifact;
25 26
26 import de.intevation.flys.artifacts.model.FacetTypes; 27 import de.intevation.flys.artifacts.model.FacetTypes;
27 import de.intevation.flys.artifacts.model.WQKms; 28 import de.intevation.flys.artifacts.model.WQKms;
28 29
30 import de.intevation.flys.jfree.FLYSAnnotation;
29 import de.intevation.flys.jfree.StickyAxisAnnotation; 31 import de.intevation.flys.jfree.StickyAxisAnnotation;
30 import de.intevation.flys.model.Annotation; 32 import de.intevation.flys.model.Annotation;
31 import de.intevation.flys.utils.FLYSUtils; 33 import de.intevation.flys.utils.FLYSUtils;
32 34
33 35
69 71
70 72
71 protected boolean inverted; 73 protected boolean inverted;
72 74
73 /** List of annotations to insert in plot. */ 75 /** List of annotations to insert in plot. */
74 protected List<Annotation> annotations; 76 protected List<FLYSAnnotation> annotations;
75
76 /** Pseudo-Dataseries to have a legend for the annotations. */
77 protected XYSeriesCollection pseudoAnnotationData = null;
78 77
79 78
80 public LongitudinalSectionGenerator() { 79 public LongitudinalSectionGenerator() {
81 super(); 80 super();
82 annotations = new ArrayList<Annotation>(); 81 annotations = new ArrayList<FLYSAnnotation>();
83 } 82 }
84 83
85 84
86 protected String getChartTitle() { 85 protected String getChartTitle() {
87 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); 86 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
163 */ 162 */
164 protected void redoAnnotations(XYPlot plot, ValueAxis axis) { 163 protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
165 plot.clearAnnotations(); 164 plot.clearAnnotations();
166 // TODO Position calculation could/should be done in 165 // TODO Position calculation could/should be done in
167 // the StickyAxisAnnotation-Implementation itself. 166 // the StickyAxisAnnotation-Implementation itself.
168 ValueAxis yAxis = plot.getRangeAxis(); 167
168 int idx = 0;
169 ValueAxis yAxis = plot.getRangeAxis(idx);
170
171 if (yAxis == null) {
172 if (plot.getRangeAxisCount() >= 2) {
173 yAxis = plot.getRangeAxis(++idx);
174 }
175 }
176
177 if (yAxis == null) {
178 // XXX There is no y-axis that might be used to add annotations. If
179 // we absolutely want to display annotations, we need to create a
180 // virtual dataset for an axis.
181 return;
182 }
183
169 float posY = 140.f; 184 float posY = 140.f;
170 if (yAxis != null) { 185 posY = (float) yAxis.getRange().getLowerBound();
171 posY = (float) yAxis.getRange().getLowerBound(); 186 // Add some (2%) space between Text and axis.
172 // Add some (2%) space between Text and axis. 187 posY += 0.02f * (yAxis.getRange().getUpperBound()
173 posY += 0.02f * (yAxis.getRange().getUpperBound() 188 - yAxis.getRange().getLowerBound());
174 - yAxis.getRange().getLowerBound()); 189
175 } 190 LegendItemCollection lic = plot.getLegendItems();
176 191
177 // Add all annotations. 192 // Add all annotations.
178 for (Annotation a: annotations) { 193 for (FLYSAnnotation fa: annotations) {
179 float posX = (float) a.getRange().getA().doubleValue(); 194 lic.add(new LegendItem(fa.getLabel()));
180 String text = a.getPosition().getValue(); 195
181 196 for (Annotation a: fa.getAnnotations()) {
182 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY); 197 float posX = (float) a.getRange().getA().doubleValue();
183 double rotation = 270.0f * (Math.PI / 180.0f); 198 String text = a.getPosition().getValue();
184 ta.setRotationAngle(rotation); 199
185 ta.setRotationAnchor(TextAnchor.CENTER_LEFT); 200 StickyAxisAnnotation ta = new StickyAxisAnnotation(
186 ta.setTextAnchor(TextAnchor.CENTER_LEFT); 201 text,
187 plot.getRenderer().addAnnotation(ta); 202 posX,
188 } 203 posY);
204
205 double rotation = 270.0f * (Math.PI / 180.0f);
206 ta.setRotationAngle(rotation);
207 ta.setRotationAnchor(TextAnchor.CENTER_LEFT);
208 ta.setTextAnchor(TextAnchor.CENTER_LEFT);
209 plot.getRenderer(idx).addAnnotation(ta);
210 }
211 }
212
213 plot.setFixedLegendItems(lic);
189 } 214 }
190 215
191 216
192 /** 217 /**
193 * Create a range that includes 0 (for the Q axis). 218 * Create a range that includes 0 (for the Q axis).
269 * @param o list of annotations (data of facet). 294 * @param o list of annotations (data of facet).
270 * @param theme yet ignored. 295 * @param theme yet ignored.
271 */ 296 */
272 protected void doAnnotationsOut(Object o, Document theme) { 297 protected void doAnnotationsOut(Object o, Document theme) {
273 logger.debug("LongitudinalSectionGenerator.doAnnotationsOut"); 298 logger.debug("LongitudinalSectionGenerator.doAnnotationsOut");
274 this.annotations = (List<Annotation>) o; 299
275 300 // Add all annotations in list o to our annotation pool.
276 // Add (empty) pseudo series to have legend entry for annotations. 301 FLYSAnnotation fa = (FLYSAnnotation) o;
277 if (pseudoAnnotationData == null) { 302 annotations.add(fa);
278 pseudoAnnotationData = new XYSeriesCollection();
279 }
280 // Localized legend.
281 Object[] args = new Object[] {getRiverName()};
282 String label = msg(I18N_ANNOTATIONS_LABEL, "", args);
283 pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
284 } 303 }
285 304
286 305
287 /** 306 /**
288 * Process the output for W facets in a longitudinal section curve. 307 * Process the output for W facets in a longitudinal section curve.
351 } 370 }
352 } 371 }
353 372
354 373
355 /** 374 /**
356 * Add datasets to plot.
357 * @param plot plot to add datasets to.
358 */
359 @Override
360 protected void addDatasets(XYPlot plot) {
361 super.addDatasets(plot);
362 if (pseudoAnnotationData != null) {
363 plot.setDataset(2, pseudoAnnotationData);
364 }
365 }
366
367
368 /**
369 * Get name of series (displayed in legend). 375 * Get name of series (displayed in legend).
370 * @return name of the series. 376 * @return name of the series.
371 */ 377 */
372 protected String getSeriesName(WQKms wqkms, String mode) { 378 protected String getSeriesName(WQKms wqkms, String mode) {
373 String name = wqkms.getName(); 379 String name = wqkms.getName();

http://dive4elements.wald.intevation.org