Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Wed Oct 05 10:36:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Wed Oct 05 11:23:18 2011 +0000 @@ -6,13 +6,14 @@ import org.apache.log4j.Logger; import org.jfree.chart.JFreeChart; +import org.jfree.chart.LegendItem; +import org.jfree.chart.LegendItemCollection; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.TextTitle; import org.jfree.data.Range; import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.TextAnchor; import org.w3c.dom.Document; @@ -26,6 +27,7 @@ import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WQKms; +import de.intevation.flys.jfree.FLYSAnnotation; import de.intevation.flys.jfree.StickyAxisAnnotation; import de.intevation.flys.model.Annotation; import de.intevation.flys.utils.FLYSUtils; @@ -71,15 +73,12 @@ protected boolean inverted; /** List of annotations to insert in plot. */ - protected List<Annotation> annotations; - - /** Pseudo-Dataseries to have a legend for the annotations. */ - protected XYSeriesCollection pseudoAnnotationData = null; + protected List<FLYSAnnotation> annotations; public LongitudinalSectionGenerator() { super(); - annotations = new ArrayList<Annotation>(); + annotations = new ArrayList<FLYSAnnotation>(); } @@ -165,27 +164,53 @@ plot.clearAnnotations(); // TODO Position calculation could/should be done in // the StickyAxisAnnotation-Implementation itself. - ValueAxis yAxis = plot.getRangeAxis(); + + int idx = 0; + ValueAxis yAxis = plot.getRangeAxis(idx); + + if (yAxis == null) { + if (plot.getRangeAxisCount() >= 2) { + yAxis = plot.getRangeAxis(++idx); + } + } + + if (yAxis == null) { + // XXX There is no y-axis that might be used to add annotations. If + // we absolutely want to display annotations, we need to create a + // virtual dataset for an axis. + return; + } + float posY = 140.f; - if (yAxis != null) { - posY = (float) yAxis.getRange().getLowerBound(); - // Add some (2%) space between Text and axis. - posY += 0.02f * (yAxis.getRange().getUpperBound() - - yAxis.getRange().getLowerBound()); - } + posY = (float) yAxis.getRange().getLowerBound(); + // Add some (2%) space between Text and axis. + posY += 0.02f * (yAxis.getRange().getUpperBound() + - yAxis.getRange().getLowerBound()); + + LegendItemCollection lic = plot.getLegendItems(); // Add all annotations. - for (Annotation a: annotations) { - float posX = (float) a.getRange().getA().doubleValue(); - String text = a.getPosition().getValue(); + for (FLYSAnnotation fa: annotations) { + lic.add(new LegendItem(fa.getLabel())); - StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY); - double rotation = 270.0f * (Math.PI / 180.0f); - ta.setRotationAngle(rotation); - ta.setRotationAnchor(TextAnchor.CENTER_LEFT); - ta.setTextAnchor(TextAnchor.CENTER_LEFT); - plot.getRenderer().addAnnotation(ta); + for (Annotation a: fa.getAnnotations()) { + float posX = (float) a.getRange().getA().doubleValue(); + String text = a.getPosition().getValue(); + + StickyAxisAnnotation ta = new StickyAxisAnnotation( + text, + posX, + posY); + + double rotation = 270.0f * (Math.PI / 180.0f); + ta.setRotationAngle(rotation); + ta.setRotationAnchor(TextAnchor.CENTER_LEFT); + ta.setTextAnchor(TextAnchor.CENTER_LEFT); + plot.getRenderer(idx).addAnnotation(ta); + } } + + plot.setFixedLegendItems(lic); } @@ -271,16 +296,10 @@ */ protected void doAnnotationsOut(Object o, Document theme) { logger.debug("LongitudinalSectionGenerator.doAnnotationsOut"); - this.annotations = (List<Annotation>) o; - // Add (empty) pseudo series to have legend entry for annotations. - if (pseudoAnnotationData == null) { - pseudoAnnotationData = new XYSeriesCollection(); - } - // Localized legend. - Object[] args = new Object[] {getRiverName()}; - String label = msg(I18N_ANNOTATIONS_LABEL, "", args); - pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme)); + // Add all annotations in list o to our annotation pool. + FLYSAnnotation fa = (FLYSAnnotation) o; + annotations.add(fa); } @@ -353,19 +372,6 @@ /** - * Add datasets to plot. - * @param plot plot to add datasets to. - */ - @Override - protected void addDatasets(XYPlot plot) { - super.addDatasets(plot); - if (pseudoAnnotationData != null) { - plot.setDataset(2, pseudoAnnotationData); - } - } - - - /** * Get name of series (displayed in legend). * @return name of the series. */