Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java @ 9123:1cc7653ca84f
Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
author | gernotbelger |
---|---|
date | Tue, 05 Jun 2018 19:21:16 +0200 |
parents | 5e38e2924c07 |
children | bd5f5d2220fa |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java Tue Jun 05 19:10:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java Tue Jun 05 19:21:16 2018 +0200 @@ -16,13 +16,8 @@ import java.util.List; import org.apache.log4j.Logger; -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.data.xy.XYSeries; - import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; +import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.DataProvider; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.geom.Lines; @@ -35,8 +30,13 @@ import org.dive4elements.river.model.FastCrossSectionLine; import org.dive4elements.river.themes.TextStyle; import org.dive4elements.river.themes.ThemeDocument; +import org.dive4elements.river.utils.Formatter; import org.dive4elements.river.utils.RiverUtils; -import org.dive4elements.river.utils.Formatter; +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.data.xy.XYSeries; /** @@ -93,7 +93,7 @@ * Get localized chart title. */ @Override - public String getDefaultChartTitle() { + public String getDefaultChartTitle(final CallContext context) { Object[] i18n_msg_args = new Object[] { getRiverName() }; @@ -103,19 +103,19 @@ /** Always return default subtitle. */ @Override - protected String getChartSubtitle() { + protected String getChartSubtitle(CallContext context) { // XXX NOTE: overriding this method disables ChartSettings subtitle! // The default implementation of this method in ChartGenerator returns // the subtitle changed via the chart settings dialog. This method // always returns the subtitle containing river and km, NEVER the // ChartSettings subtitle! - return getDefaultChartSubtitle(); + return getDefaultChartSubtitle(context); } - + /** Get Charts default subtitle. */ @Override - protected String getDefaultChartSubtitle() { + protected String getDefaultChartSubtitle(final CallContext context) { List<DataProvider> providers = context.getDataProvider( CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); @@ -164,8 +164,7 @@ } @Override - protected void addAnnotationsToRenderer(XYPlot plot) { - super.addAnnotationsToRenderer(plot); + protected void doAddFurtherAnnotations(XYPlot plot, List<RiverAnnotation> annotations) { // Paints for the boxes/lines. Stroke basicStroke = new BasicStroke(1.0f); @@ -179,7 +178,7 @@ plot.getDomainAxis(0), plot.getRangeAxis()); - for(RiverAnnotation fa : this.annotations) { + for(RiverAnnotation fa : annotations) { // Access text styling, if any. ThemeDocument theme = fa.getTheme(); @@ -245,14 +244,14 @@ } @Override - protected String getDefaultXAxisLabel() { + protected String getDefaultXAxisLabel(final CallContext context) { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } @Override protected String getDefaultYAxisLabel(int pos) { - D4EArtifact flys = (D4EArtifact) master; + D4EArtifact flys = getArtifact(); String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); @@ -279,6 +278,8 @@ log.error("No facet name for doOut(). No output generated!"); return; } + + CallContext context = getContext(); if (name.equals(CROSS_SECTION)) { doCrossSectionOut( @@ -351,11 +352,13 @@ // DO NOT SORT DATA! This destroys the gaps indicated by NaNs. StyledXYSeries series = new StyledXYSeries(seriesName, false, theme); + CallContext context = getContext(); + if (!theme.parseShowLineLabel()) { series.setLabel(""); } if (theme.parseShowWidth()) { - NumberFormat nf = Formatter.getMeterFormat(this.context); + NumberFormat nf = Formatter.getMeterFormat(context); String labelAdd = "b=" + nf.format(lines.width) + "m"; if (series.getLabel().length() == 0) { series.setLabel(labelAdd); @@ -366,8 +369,8 @@ } if (theme.parseShowLevel() && lines.points.length > 1 && lines.points[1].length > 0) { - NumberFormat nf = Formatter.getMeterFormat(this.context); - D4EArtifact flys = (D4EArtifact) master; + NumberFormat nf = Formatter.getMeterFormat(context); + D4EArtifact flys = getArtifact(); String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); @@ -380,7 +383,7 @@ } } if (theme.parseShowMiddleHeight() && lines.width != 0) { - NumberFormat nf = Formatter.getMeterFormat(this.context); + NumberFormat nf = Formatter.getMeterFormat(context); String labelAdd = "T=" + nf.format(lines.area / lines.width) + "m"; // : " + lines.area + "/" + lines.width); if (series.getLabel().length() == 0) { @@ -450,9 +453,9 @@ * @return a new <i>ChartSection</i>. */ @Override - protected ChartSection buildChartSection() { + protected ChartSection buildChartSection(final CallContext context) { ChartSection chartSection = new ChartSection(); - chartSection.setTitle(getChartTitle()); + chartSection.setTitle(getChartTitle(context)); chartSection.setDisplayGrid(isGridVisible()); chartSection.setDisplayLogo(showLogo()); chartSection.setLogoVPlacement(logoVPlace());