Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java @ 3278:c27c4e06dd87
Re-add HYK rendering code to CrossSectionGenerator
flys-artifacts/trunk@4924 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Wed, 11 Jul 2012 09:24:07 +0000 |
parents | 698d09930329 |
children | 4a70525c5b0d |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Tue Jul 10 19:28:44 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Wed Jul 11 09:24:07 2012 +0000 @@ -1,14 +1,5 @@ package de.intevation.flys.exports; -import java.text.NumberFormat; -import java.util.List; - -import org.apache.log4j.Logger; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.title.TextTitle; -import org.jfree.data.xy.XYSeries; -import org.w3c.dom.Document; - import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.artifacts.DataProvider; import de.intevation.flys.artifacts.geom.Lines; @@ -18,9 +9,27 @@ import de.intevation.flys.jfree.FLYSAnnotation; import de.intevation.flys.jfree.StyledXYSeries; import de.intevation.flys.model.FastCrossSectionLine; +import de.intevation.flys.themes.ThemeAccess; import de.intevation.flys.utils.Formatter; import de.intevation.flys.utils.ThemeUtil; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Paint; +import java.awt.Stroke; +import java.text.NumberFormat; +import java.util.List; + +import org.apache.log4j.Logger; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.LegendItemCollection; +import org.jfree.chart.annotations.XYBoxAnnotation; +import org.jfree.chart.annotations.XYTextAnnotation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.title.TextTitle; +import org.jfree.data.xy.XYSeries; +import org.w3c.dom.Document; + /** * An OutGenerator that generates cross section graphs. @@ -125,6 +134,98 @@ chart.addSubtitle(new TextTitle(subtitle)); } + /** Get color for hyk zones by their type (which is the name). */ + protected Paint colorForHYKZone(String zoneName) { + if (zoneName.startsWith("R")) { + // Brownish. + return new Color(153, 60, 0); + } + else if (zoneName.startsWith("V")) { + // Greenish. + return new Color(0, 255, 0); + } + else if (zoneName.startsWith("B")) { + // Grayish. + return new Color(128, 128, 128); + } + else if (zoneName.startsWith("H")) { + // Blueish. + return new Color(0, 0, 255); + } + else { + // Default. + logger.debug("Unknown zone type found."); + return new Color(255, 0, 0); + } + } + + @Override + protected void addAnnotationsToRenderer(XYPlot plot) { + super.addAnnotationsToRenderer(plot); + + // Paints for the boxes/lines. + Stroke basicStroke = new BasicStroke(1.0f); + + Paint linePaint = new Color(255, 0,0,60); + Paint fillPaint = new Color(0, 255,0,60); + Paint tranPaint = new Color(0, 0,0, 0); + + // OPTMIMIZE: Pre-calculate positions + ChartArea area = new ChartArea( + plot.getDomainAxis(0).getRange(), + plot.getRangeAxis().getRange()); + + for(FLYSAnnotation fa : this.annotations) { + + // Access text styling, if any. + Document theme = fa.getTheme(); + ThemeAccess.TextStyle textStyle = null; + ThemeAccess.LineStyle lineStyle = null; + + // Get Themeing information and add legend item. + if (theme != null) { + ThemeAccess themeAccess = new ThemeAccess(theme); + textStyle = themeAccess.parseTextStyle(); + lineStyle = themeAccess.parseLineStyle(); + if (fa.getLabel() != null) { + LegendItemCollection lic = new LegendItemCollection(); + LegendItemCollection old = plot.getFixedLegendItems(); + lic.add(createLegendItem(theme, fa.getLabel())); + // (Re-)Add prior legend entries. + if (old != null) { + old.addAll(lic); + } + else { + old = lic; + } + plot.setFixedLegendItems(old); + } + } + + // Hyks. + for (HYKFactory.Zone zone: fa.getBoxes()) { + // For each zone, create a box to fill with color, a box to draw + // the lines and a text to display the type. + fillPaint = colorForHYKZone(zone.getName()); + + XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), area.atGround(), + zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint); + XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), area.atGround(), + zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint); + + XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), + zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d, + area.ofGround(0.015f)); + if (textStyle != null) { + textStyle.apply(tex); + } + + plot.getRenderer().addAnnotation(boxA, org.jfree.ui.Layer.BACKGROUND); + plot.getRenderer().addAnnotation(boxB, org.jfree.ui.Layer.BACKGROUND); + plot.getRenderer().addAnnotation(tex, org.jfree.ui.Layer.BACKGROUND); + } + } + } @Override protected String getDefaultXAxisLabel() { @@ -141,6 +242,7 @@ /** * Let one facet do its job. */ + @Override public void doOut( ArtifactAndFacet artifactFacet, Document attr, @@ -201,6 +303,7 @@ /** Look up the axis identifier for a given facet type. */ + @Override public int axisIdxForFacet(String facetName) { // TODO Where to add thid axis too. return 0; @@ -229,7 +332,7 @@ series.setLabel(""); } if (ThemeUtil.parseShowWidth(theme)) { - NumberFormat nf = nf = Formatter.getMeterFormat(this.context); + NumberFormat nf = Formatter.getMeterFormat(this.context); String labelAdd = "b=" + nf.format(lines.width) + "m"; if (series.getLabel().equals("")) { series.setLabel(labelAdd); @@ -239,8 +342,8 @@ } } if (ThemeUtil.parseShowLevel(theme) && lines.points.length >0 - && lines.points[1].length > 0) { - NumberFormat nf = nf = Formatter.getMeterFormat(this.context); + && lines.points[1].length > 0) { + NumberFormat nf = Formatter.getMeterFormat(this.context); String labelAdd = "W=" + nf.format(lines.points[1][0]) + "NN+m"; if (series.getLabel().equals("")) { series.setLabel(labelAdd); @@ -250,7 +353,7 @@ } } if (ThemeUtil.parseShowMiddleHeight(theme) && lines.width != 0) { - NumberFormat nf = nf = Formatter.getMeterFormat(this.context); + NumberFormat nf = Formatter.getMeterFormat(this.context); String labelAdd = "H=" + nf.format(lines.area / lines.width) + "m"; // : " + lines.area + "/" + lines.width); if (series.getLabel().equals("")) {