Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java @ 9312:740d65e4aa14
Q [m³/s] one message
author | gernotbelger |
---|---|
date | Thu, 26 Jul 2018 15:54:20 +0200 |
parents | 1cc7653ca84f |
children | 9b8e8fc1f408 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java Thu Jul 26 11:16:06 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java Thu Jul 26 15:54:20 2018 +0200 @@ -8,6 +8,7 @@ package org.dive4elements.river.exports; +import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifactdatabase.state.Facet; import org.dive4elements.artifacts.CallContext; @@ -17,90 +18,72 @@ import org.dive4elements.river.artifacts.model.FacetTypes; import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.artifacts.model.WQKms; - -import org.dive4elements.river.exports.process.Processor; +import org.dive4elements.river.exports.process.AnnotationProcessor; import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor; import org.dive4elements.river.exports.process.BedDiffYearProcessor; +import org.dive4elements.river.exports.process.Processor; import org.dive4elements.river.exports.process.QOutProcessor; import org.dive4elements.river.exports.process.WOutProcessor; -import org.dive4elements.river.exports.process.AnnotationProcessor; - import org.dive4elements.river.jfree.StyledAreaSeriesCollection; import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.themes.ThemeDocument; import org.dive4elements.river.utils.RiverUtils; -import org.apache.log4j.Logger; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.XYSeries; - /** * An OutGenerator that generates longitudinal section curves. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class LongitudinalSectionGenerator -extends XYChartGenerator -implements FacetTypes -{ +public class LongitudinalSectionGenerator extends XYChartGenerator implements FacetTypes { public enum YAXIS { - W(0), - D(1), - Q(2); + W(0), D(1), Q(2); protected int idx; - private YAXIS(int c) { - idx = c; + + private YAXIS(final int c) { + this.idx = c; } } /** The log that is used in this generator. */ - private static Logger log = - Logger.getLogger(LongitudinalSectionGenerator.class); + private static Logger log = Logger.getLogger(LongitudinalSectionGenerator.class); /** Key to look up internationalized String for annotations label. */ - public static final String I18N_ANNOTATIONS_LABEL = - "chart.longitudinal.annotations.label"; + public static final String I18N_ANNOTATIONS_LABEL = "chart.longitudinal.annotations.label"; /** * Key to look up internationalized String for LongitudinalSection diagrams * titles. */ - public static final String I18N_CHART_TITLE = - "chart.longitudinal.section.title"; + public static final String I18N_CHART_TITLE = "chart.longitudinal.section.title"; /** * Key to look up internationalized String for LongitudinalSection diagrams * subtitles. */ - public static final String I18N_CHART_SUBTITLE = - "chart.longitudinal.section.subtitle"; + public static final String I18N_CHART_SUBTITLE = "chart.longitudinal.section.subtitle"; /** * Key to look up internationalized String for LongitudinalSection diagrams * short subtitles. */ - public static final String I18N_CHART_SHORT_SUBTITLE = - "chart.longitudinal.section.shortsubtitle"; - - public static final String I18N_XAXIS_LABEL = - "chart.longitudinal.section.xaxis.label"; + public static final String I18N_CHART_SHORT_SUBTITLE = "chart.longitudinal.section.shortsubtitle"; - public static final String I18N_YAXIS_LABEL = - "chart.longitudinal.section.yaxis.label"; + public static final String I18N_XAXIS_LABEL = "chart.longitudinal.section.xaxis.label"; - public static final String I18N_2YAXIS_LABEL = - "chart.longitudinal.section.yaxis.second.label"; + public static final String I18N_YAXIS_LABEL = "chart.longitudinal.section.yaxis.label"; - public static final String I18N_CHART_TITLE_DEFAULT = - "W-L\u00e4ngsschnitt"; - public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; - public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; + public static final String I18N_2YAXIS_LABEL = "common.export.csv.header.q"; + + public static final String I18N_CHART_TITLE_DEFAULT = "W-L\u00e4ngsschnitt"; + public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; + public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; - public final static String I18N_WDIFF_YAXIS_LABEL = - "chart.w_differences.yaxis.label"; + public final static String I18N_WDIFF_YAXIS_LABEL = "chart.w_differences.yaxis.label"; public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m"; @@ -108,7 +91,6 @@ super(); } - @Override protected YAxisWalker getYAxisWalker() { return new YAxisWalker() { @@ -118,14 +100,13 @@ } @Override - public String getId(int idx) { - YAXIS[] yaxes = YAXIS.values(); + public String getId(final int idx) { + final YAXIS[] yaxes = YAXIS.values(); return yaxes[idx].toString(); } }; } - /** * Return left most data points x value (on first axis). * Overridden because axis could be inverted. @@ -133,12 +114,11 @@ @Override protected double getLeftX() { if (isInverted()) { - return (Double)getXBounds(0).getUpper(); + return (Double) getXBounds(0).getUpper(); } - return (Double)getXBounds(0).getLower(); + return (Double) getXBounds(0).getLower(); } - /** * Return right most data points x value (on first axis). * Overridden because axis could be inverted. @@ -146,12 +126,11 @@ @Override protected double getRightX() { if (isInverted()) { - return (Double)getXBounds(0).getLower(); + return (Double) getXBounds(0).getLower(); } - return (Double)getXBounds(0).getUpper(); + return (Double) getXBounds(0).getUpper(); } - /** * Returns the default title for this chart. * @@ -169,109 +148,91 @@ */ @Override protected String getDefaultChartSubtitle(final CallContext context) { - double[] dist = getRange(); + final double[] dist = getRange(); Object[] args = null; if (dist == null) { - args = new Object[] {getRiverName()}; + args = new Object[] { getRiverName() }; return msg(getChartShortSubtitleKey(), "", args); } - args = new Object[] { - getRiverName(), - dist[0], - dist[1] - }; + args = new Object[] { getRiverName(), dist[0], dist[1] }; return msg(getChartSubtitleKey(), "", args); } - /** * Gets key to look up internationalized String for the charts subtitle. + * * @return key to look up translated subtitle. */ protected String getChartSubtitleKey() { return I18N_CHART_SUBTITLE; } - /** * Gets key to look up internationalized String for the charts short * subtitle. + * * @return key to look up translated subtitle. */ protected String getChartShortSubtitleKey() { return I18N_CHART_SHORT_SUBTITLE; } - /** * Get internationalized label for the x axis. */ @Override - protected String getDefaultXAxisLabel(CallContext context) { - D4EArtifact flys = getArtifact(); + protected String getDefaultXAxisLabel(final CallContext context) { + final D4EArtifact flys = getArtifact(); - return msg( - I18N_XAXIS_LABEL, - I18N_XAXIS_LABEL_DEFAULT, - new Object[] { RiverUtils.getRiver(flys).getName() }); + return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT, new Object[] { RiverUtils.getRiver(flys).getName() }); } - @Override - protected String getDefaultYAxisLabel(int index) { + protected String getDefaultYAxisLabel(final int index) { String label = "default"; if (index == YAXIS.W.idx) { label = getWAxisLabel(); - } - else if (index == YAXIS.Q.idx) { + } else if (index == YAXIS.Q.idx) { label = msg(getQAxisLabelKey(), getQAxisDefaultLabel()); - } - else if (index == YAXIS.D.idx) { - label = msg( - I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT); + } else if (index == YAXIS.D.idx) { + label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT); } return label; } - /** * Get internationalized label for the y axis. */ protected String getWAxisLabel() { - D4EArtifact flys = getArtifact(); - - String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); + final D4EArtifact flys = getArtifact(); - return msg( - I18N_YAXIS_LABEL, - I18N_YAXIS_LABEL_DEFAULT, - new Object[] { unit }); + final String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); + + return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT, new Object[] { unit }); } - /** * Create Axis for given index. + * * @return axis with according internationalized label. */ @Override - protected NumberAxis createYAxis(int index) { - NumberAxis axis = super.createYAxis(index); + protected NumberAxis createYAxis(final int index) { + final NumberAxis axis = super.createYAxis(index); // "Q" Axis shall include 0. if (index == YAXIS.Q.idx) { axis.setAutoRangeIncludesZero(true); - } - else { + } else { axis.setAutoRangeIncludesZero(false); } return axis; } - /** * Get default value for the second Y-Axis' label (if no translation was * found). @@ -280,7 +241,6 @@ return I18N_2YAXIS_LABEL_DEFAULT; } - /** * Get key for internationalization of the second Y-Axis' label. */ @@ -288,44 +248,41 @@ return I18N_2YAXIS_LABEL; } - /** * Trigger inversion. */ @Override - protected void adjustAxes(XYPlot plot) { + protected void adjustAxes(final XYPlot plot) { super.adjustAxes(plot); invertXAxis(plot.getDomainAxis()); } - /** * This method inverts the x-axis based on the kilometer information of the * selected river. If the head of the river is at kilometer 0, the axis is * not inverted, otherwise it is. * - * @param xaxis The domain axis. + * @param xaxis + * The domain axis. */ - protected void invertXAxis(ValueAxis xaxis) { + protected void invertXAxis(final ValueAxis xaxis) { if (isInverted()) { log.debug("X-Axis.setInverted(true)"); xaxis.setInverted(true); } } - /** * Produce output. - * @param artifactAndFacet current facet and artifact. - * @param attr theme for facet + * + * @param artifactAndFacet + * current facet and artifact. + * @param attr + * theme for facet */ @Override - public void doOut( - ArtifactAndFacet artifactAndFacet, - ThemeDocument attr, - boolean visible - ) { - String name = artifactAndFacet.getFacetName(); + public void doOut(final ArtifactAndFacet artifactAndFacet, final ThemeDocument attr, final boolean visible) { + final String name = artifactAndFacet.getFacetName(); log.debug("LongitudinalSectionGenerator.doOut: " + name); @@ -334,63 +291,38 @@ return; } - Facet facet = artifactAndFacet.getFacet(); + final Facet facet = artifactAndFacet.getFacet(); if (facet == null) { return; } - CallContext context = getContext(); - - Processor wProcessor = new WOutProcessor(); - Processor qProcessor = new QOutProcessor(); - Processor bdyProcessor = new BedDiffYearProcessor(); - Processor bdhyProcessor = new BedDiffHeightYearProcessor(); - Processor annotationProcessor = new AnnotationProcessor(); + final CallContext context = getContext(); + + final Processor wProcessor = new WOutProcessor(); + final Processor qProcessor = new QOutProcessor(); + final Processor bdyProcessor = new BedDiffYearProcessor(); + final Processor bdhyProcessor = new BedDiffHeightYearProcessor(); + final Processor annotationProcessor = new AnnotationProcessor(); if (wProcessor.canHandle(name)) { - wProcessor.doOut( - this, artifactAndFacet, attr, visible, YAXIS.W.idx); + wProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); } if (qProcessor.canHandle(name)) { - qProcessor.doOut( - this, artifactAndFacet, attr, visible, YAXIS.Q.idx); - } - else if (bdyProcessor.canHandle(name)) { - bdyProcessor.doOut( - this, artifactAndFacet, attr, visible, YAXIS.W.idx); - } - else if (bdhyProcessor.canHandle(name)) { - bdhyProcessor.doOut( - this, artifactAndFacet, attr, visible, YAXIS.W.idx); - } - else if (annotationProcessor.canHandle(name)) { - annotationProcessor.doOut( - this, artifactAndFacet, attr, visible, 0); - } - else if (name.equals(W_DIFFERENCES)) { - doWDifferencesOut( - (WKms) artifactAndFacet.getData(context), - artifactAndFacet, - attr, - visible); - } - else if (FacetTypes.IS.AREA(name)) { - doArea( - artifactAndFacet.getData(context), - artifactAndFacet, - attr, - visible); - } - else if (FacetTypes.IS.MANUALPOINTS(name)) { - doPoints( - artifactAndFacet.getData(context), - artifactAndFacet, - attr, - visible, - YAXIS.W.idx); - } - else { + qProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.Q.idx); + } else if (bdyProcessor.canHandle(name)) { + bdyProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); + } else if (bdhyProcessor.canHandle(name)) { + bdhyProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx); + } else if (annotationProcessor.canHandle(name)) { + annotationProcessor.doOut(this, artifactAndFacet, attr, visible, 0); + } else if (name.equals(W_DIFFERENCES)) { + doWDifferencesOut((WKms) artifactAndFacet.getData(context), artifactAndFacet, attr, visible); + } else if (FacetTypes.IS.AREA(name)) { + doArea(artifactAndFacet.getData(context), artifactAndFacet, attr, visible); + } else if (FacetTypes.IS.MANUALPOINTS(name)) { + doPoints(artifactAndFacet.getData(context), artifactAndFacet, attr, visible, YAXIS.W.idx); + } else { log.warn("Unknown facet name: " + name); return; } @@ -399,20 +331,14 @@ /** * Add items to dataseries which describes the differences. */ - protected void doWDifferencesOut( - WKms wkms, - ArtifactAndFacet aandf, - ThemeDocument theme, - boolean visible - ) { + protected void doWDifferencesOut(final WKms wkms, final ArtifactAndFacet aandf, final ThemeDocument theme, final boolean visible) { log.debug("WDifferencesCurveGenerator.doWDifferencesOut"); if (wkms == null) { log.warn("No data to add to WDifferencesChart."); return; - } + } - XYSeries series = - new StyledXYSeries(aandf.getFacetDescription(), theme); + final XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); if (log.isDebugEnabled()) { if (wkms.size() > 0) { @@ -428,83 +354,65 @@ addAxisSeries(series, YAXIS.D.idx, visible); } - /** * Get name of series (displayed in legend). + * * @return name of the series. */ - protected String getSeriesName(WQKms wqkms, String mode) { - String name = wqkms.getName(); - String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode; + protected String getSeriesName(final WQKms wqkms, final String mode) { + final String name = wqkms.getName(); + final String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode; - return prefix != null && prefix.length() > 0 - ? prefix + "(" + name +")" - : name; + return prefix != null && prefix.length() > 0 ? prefix + "(" + name + ")" : name; } - /** Look up the axis identifier for a given facet type. */ - public int axisIdxForFacet(String facetName) { + public int axisIdxForFacet(final String facetName) { if (FacetTypes.IS.W(facetName)) { return YAXIS.W.idx; - } - else if (FacetTypes.IS.Q(facetName)) { + } else if (FacetTypes.IS.Q(facetName)) { return YAXIS.Q.idx; - } - else { + } else { log.warn("Could not find axis for facet " + facetName); return YAXIS.W.idx; } } - /** * Do Area out. - * @param theme styling information. - * @param visible whether or not visible. + * + * @param theme + * styling information. + * @param visible + * whether or not visible. */ - protected void doArea( - Object o, - ArtifactAndFacet aandf, - ThemeDocument theme, - boolean visible - ) { + protected void doArea(final Object o, final ArtifactAndFacet aandf, final ThemeDocument theme, final boolean visible) { log.debug("LongitudinalSectionGenerator.doArea"); - StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); + final StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); - String seriesName = aandf.getFacetDescription(); + final String seriesName = aandf.getFacetDescription(); - AreaFacet.Data data = (AreaFacet.Data) o; + final AreaFacet.Data data = (AreaFacet.Data) o; - XYSeries up = null; + XYSeries up = null; XYSeries down = null; if (data.getUpperData() != null) { up = new StyledXYSeries(seriesName, false, theme); if (data.getUpperData() instanceof WQKms) { if (FacetTypes.IS.Q(data.getUpperFacetName())) { - StyledSeriesBuilder.addPointsKmQ( - up, (WQKms)data.getUpperData()); - } - else { - StyledSeriesBuilder.addPoints( - up, (WKms) data.getUpperData()); + StyledSeriesBuilder.addPointsKmQ(up, (WQKms) data.getUpperData()); + } else { + StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData()); } - } - else if (data.getUpperData() instanceof double[][]) { - StyledSeriesBuilder.addPoints( - up, (double [][]) data.getUpperData(), false); - } - else if (data.getUpperData() instanceof WKms) { + } else if (data.getUpperData() instanceof double[][]) { + StyledSeriesBuilder.addPoints(up, (double[][]) data.getUpperData(), false); + } else if (data.getUpperData() instanceof WKms) { StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData()); - } - else if (data.getUpperData() instanceof Lines.LineData) { - StyledSeriesBuilder.addPoints( - up, ((Lines.LineData) data.getUpperData()).points, false); - } - else { - log.error("Do not know how to deal with (up) area info from: " - + data.getUpperData()); + } else if (data.getUpperData() instanceof Lines.LineData) { + StyledSeriesBuilder.addPoints(up, ((Lines.LineData) data.getUpperData()).points, false); + } else { + log.error("Do not know how to deal with (up) area info from: " + data.getUpperData()); } } @@ -517,32 +425,18 @@ down = new StyledXYSeries(seriesName + " ", false, theme); if (data.getLowerData() instanceof WQKms) { if (FacetTypes.IS.Q(data.getLowerFacetName())) { - StyledSeriesBuilder.addPointsKmQ( - down, (WQKms) data.getLowerData()); - } - else { - StyledSeriesBuilder.addPoints( - down, (WQKms) data.getLowerData()); + StyledSeriesBuilder.addPointsKmQ(down, (WQKms) data.getLowerData()); + } else { + StyledSeriesBuilder.addPoints(down, (WQKms) data.getLowerData()); } - } - else if (data.getLowerData() instanceof double[][]) { - StyledSeriesBuilder.addPoints( - down, (double[][]) data.getLowerData(), false); - } - else if (data.getLowerData() instanceof WKms) { - StyledSeriesBuilder.addPoints( - down, (WKms) data.getLowerData()); - } - else if (data.getLowerData() instanceof Lines.LineData) { - StyledSeriesBuilder.addPoints( - down, - ((Lines.LineData) data.getLowerData()).points, - false); - } - else { - log.error( - "Do not know how to deal with (down) area info from: " - + data.getLowerData()); + } else if (data.getLowerData() instanceof double[][]) { + StyledSeriesBuilder.addPoints(down, (double[][]) data.getLowerData(), false); + } else if (data.getLowerData() instanceof WKms) { + StyledSeriesBuilder.addPoints(down, (WKms) data.getLowerData()); + } else if (data.getLowerData() instanceof Lines.LineData) { + StyledSeriesBuilder.addPoints(down, ((Lines.LineData) data.getLowerData()).points, false); + } else { + log.error("Do not know how to deal with (down) area info from: " + data.getLowerData()); } } @@ -551,26 +445,21 @@ down.setKey(seriesName); area.addSeries(down); area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(down)); - } - else if (up != null && down == null) { + } else if (up != null && down == null) { area.setMode(StyledAreaSeriesCollection.FILL_MODE.UNDER); area.addSeries(up); area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(up)); - } - else if (up != null && down != null) { + } else if (up != null && down != null) { if (data.doPaintBetween()) { area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); - } - else { + } else { area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE); } area.addSeries(up); area.addSeries(down); } // Add area to the respective axis. - String facetAxisName = data.getUpperFacetName() == null - ? data.getLowerFacetName() - : data.getUpperFacetName(); + final String facetAxisName = data.getUpperFacetName() == null ? data.getLowerFacetName() : data.getUpperFacetName(); addAreaSeries(area, axisIdxForFacet(facetAxisName), visible); } }