teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.exports.minfo; raimund@3898: raimund@3898: import org.apache.log4j.Logger; raimund@3898: import org.jfree.data.xy.XYSeries; raimund@3898: teichmann@5831: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; felix@6123: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.WKms; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.MorphologicWidth; teichmann@5831: import org.dive4elements.river.exports.StyledSeriesBuilder; felix@6570: import org.dive4elements.river.exports.process.BedDiffYearProcessor; felix@6570: import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor; teichmann@5831: import org.dive4elements.river.exports.process.KMIndexProcessor; teichmann@5831: import org.dive4elements.river.exports.process.Processor; teichmann@5831: import org.dive4elements.river.exports.process.WOutProcessor; teichmann@5864: import org.dive4elements.river.jfree.RiverAnnotation; teichmann@5831: import org.dive4elements.river.jfree.StyledXYSeries; teichmann@6905: import org.dive4elements.river.themes.ThemeDocument; teichmann@5831: import org.dive4elements.river.utils.DataUtil; felix@6123: import org.dive4elements.river.utils.RiverUtils; raimund@3898: raimund@3898: raimund@3898: public class BedDifferenceYearGenerator felix@6551: extends BedDiffBaseGenerator raimund@3898: implements FacetTypes raimund@3898: { raimund@3898: public enum YAXIS { felix@6569: D(0), M(1), H(2), dW(3), W(4); raimund@3898: raimund@3898: protected int idx; raimund@3898: raimund@3898: private YAXIS(int c) { raimund@3898: idx = c; raimund@3898: } raimund@3898: } raimund@3898: raimund@3898: /** The logger that is used in this generator. */ raimund@3898: private static Logger logger = Logger.getLogger(BedDifferenceYearGenerator.class); raimund@3898: raimund@3898: public static final String I18N_CHART_TITLE = "chart.beddifference.year.title"; raimund@3898: public static final String I18N_XAXIS_LABEL = "chart.beddifference.xaxis.label"; raimund@3898: public static final String I18N_YAXIS_LABEL = "chart.beddifference.yaxis.label.diff"; raimund@3898: public static final String I18N_SECOND_YAXIS_LABEL = "chart.beddifference.yaxis.label.morph"; raimund@3898: public static final String I18N_THIRD_YAXIS_LABEL = "chart.beddifference.yaxis.label.heights"; raimund@3898: raimund@3898: public static final String I18N_CHART_TITLE_DEFAULT = "Sohlenhöhen Differenz"; raimund@3898: public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km"; felix@6863: public static final String I18N_YAXIS_LABEL_DEFAULT = "delta S [cm]"; rrenkert@5766: public static final String I18N_SECOND_YAXIS_LABEL_DEFAULT = "Breite [m]"; raimund@3898: public static final String I18N_THIRD_YAXIS_LABEL_DEFAULT = "Höhe [m]"; bjoern@4446: public static final String I18N_DW_YAXIS_LABEL_DEFAULT = bjoern@4446: "delta W [cm]"; bjoern@4446: public static final String I18N_DW_YAXIS_LABEL = bjoern@4446: "chart.fixings.longitudinalsection.yaxis.label"; rrenkert@5681: private static final String I18N_W_YAXIS_LABEL = rrenkert@5681: "chart.longitudinal.section.yaxis.label"; rrenkert@5681: private static final String I18N_W_YAXIS_LABEL_DEFAULT = "W [NN + m]"; raimund@3898: raimund@3898: @Override raimund@3898: protected YAxisWalker getYAxisWalker() { raimund@3898: return new YAxisWalker() { raimund@3898: raimund@3898: @Override raimund@3898: public int length() { raimund@3898: return YAXIS.values().length; raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: public String getId(int idx) { raimund@3898: YAXIS[] yaxes = YAXIS.values(); raimund@3898: return yaxes[idx].toString(); raimund@3898: } raimund@3898: }; raimund@3898: } raimund@3898: felix@6550: raimund@3898: @Override teichmann@6905: public void doOut(ArtifactAndFacet bundle, ThemeDocument attr, boolean visible) { raimund@3898: String name = bundle.getFacetName(); raimund@3898: raimund@3898: logger.debug("doOut: " + name); raimund@3898: raimund@3898: if (name == null) { raimund@3898: logger.error("No facet name for doOut(). No output generated!"); raimund@3898: return; raimund@3898: } raimund@3898: raimund@3898: Facet facet = bundle.getFacet(); raimund@3898: raimund@3898: if (facet == null) { raimund@3898: return; raimund@3898: } raimund@3898: felix@6551: if (bundle.getData(context) instanceof BedDifferencesResult) { felix@6551: setContextBounds(bundle); felix@6551: } felix@6550: bjoern@4446: Processor processor = new KMIndexProcessor(); rrenkert@5681: Processor woutp = new WOutProcessor(); felix@6570: Processor bdhyProcessor = new BedDiffHeightYearProcessor(); felix@6570: Processor bdyProcessor = new BedDiffYearProcessor(); felix@6570: if (name.equals(BED_DIFFERENCE_MORPH_WIDTH)) { raimund@3898: doBedDifferenceMorphWidthOut( raimund@3898: (BedDiffYearResult) bundle.getData(context), raimund@3898: bundle, attr, visible); raimund@3898: } rrenkert@5766: else if (name.equals(MORPHOLOGIC_WIDTH)) { rrenkert@5766: doMorphologicWidthOut( rrenkert@5766: (MorphologicWidth)bundle.getData(context), rrenkert@5766: bundle, rrenkert@5766: attr, rrenkert@5766: visible, rrenkert@5766: 0); rrenkert@5766: } bjoern@4446: else if (processor.canHandle(name)) { bjoern@4446: processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx); raimund@3898: } raimund@3898: else if (name.equals(LONGITUDINAL_ANNOTATION)) { raimund@3898: doAnnotations( teichmann@5864: (RiverAnnotation) bundle.getData(context), raimund@3898: bundle, raimund@3898: attr, raimund@3898: visible); raimund@3898: } felix@6570: else if (bdyProcessor.canHandle(name)) { felix@6571: bdyProcessor.doOut(this, bundle, attr, visible, YAXIS.H.idx); felix@6570: } felix@6570: else if (bdhyProcessor.canHandle(name)) { felix@6570: bdhyProcessor.doOut(this, bundle, attr, visible, YAXIS.D.idx); felix@6570: } rrenkert@5681: else if (woutp.canHandle(name)) { rrenkert@5681: woutp.doOut(this, bundle, attr, visible, YAXIS.W.idx); rrenkert@5681: } rrenkert@5681: else if (name.equals(W_DIFFERENCES)) { rrenkert@5681: doWDifferencesOut( rrenkert@5681: (WKms) bundle.getData(context), rrenkert@5681: bundle, rrenkert@5681: attr, rrenkert@5681: visible); bjoern@4446: } bjoern@4446: else { bjoern@4446: logger.warn("Unknown facet name " + name); bjoern@4446: } raimund@3898: } raimund@3898: rrenkert@5766: private void doMorphologicWidthOut( rrenkert@5766: MorphologicWidth data, rrenkert@5766: ArtifactAndFacet bundle, teichmann@6905: ThemeDocument attr, rrenkert@5766: boolean visible, rrenkert@5766: int i) { rrenkert@5766: XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), attr); rrenkert@5766: StyledSeriesBuilder.addPoints(series, data.getAsArray(), true); rrenkert@5766: rrenkert@5766: addAxisSeries(series, YAXIS.M.idx, visible); rrenkert@5766: } rrenkert@5766: raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultChartTitle() { raimund@3898: return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultXAxisLabel() { felix@6116: return msg(I18N_XAXIS_LABEL, felix@6116: I18N_XAXIS_LABEL_DEFAULT, felix@6116: new Object[] { getRiverName() }); raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultYAxisLabel(int pos) { raimund@3898: String label = "default"; rrenkert@6227: D4EArtifact flys = (D4EArtifact) master; raimund@3898: if (pos == YAXIS.D.idx) { raimund@3898: label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); raimund@3898: } raimund@3898: else if (pos == YAXIS.M.idx) { raimund@3898: label = msg(I18N_SECOND_YAXIS_LABEL, I18N_SECOND_YAXIS_LABEL_DEFAULT); raimund@3898: } raimund@3898: else if (pos == YAXIS.H.idx) { felix@6123: label = msg(I18N_THIRD_YAXIS_LABEL, felix@6123: I18N_THIRD_YAXIS_LABEL_DEFAULT, felix@6123: new Object[] felix@6123: { RiverUtils.getRiver(flys).getWstUnit().getName() }); raimund@3898: } bjoern@4378: else if (pos == YAXIS.dW.idx) { bjoern@4378: label = msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT); bjoern@4378: } rrenkert@5681: else if (pos == YAXIS.W.idx) { rrenkert@6227: return msg(I18N_W_YAXIS_LABEL, I18N_W_YAXIS_LABEL_DEFAULT, rrenkert@6227: new Object[] rrenkert@6227: { RiverUtils.getRiver(flys).getWstUnit().getName() }); rrenkert@5681: } rrenkert@5681: raimund@3898: return label; raimund@3898: } raimund@3898: raimund@3898: raimund@3898: protected void doBedDifferenceMorphWidthOut(BedDiffYearResult data, teichmann@6905: ArtifactAndFacet aandf, ThemeDocument theme, boolean visible) { raimund@3898: logger.debug("doBedDifferencesMorphWidthOut()"); raimund@3898: raimund@3898: XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); raimund@3898: StyledSeriesBuilder.addPoints(series, data.getMorphWidthData(), true); raimund@3898: raimund@3898: addAxisSeries(series, YAXIS.M.idx, visible); raimund@3898: } rrenkert@5681: rrenkert@5681: protected void doWDifferencesOut( teichmann@6905: WKms wkms, rrenkert@5681: ArtifactAndFacet aandf, teichmann@6905: ThemeDocument theme, teichmann@6905: boolean visible rrenkert@5681: ) { rrenkert@5681: if (wkms == null) { rrenkert@5681: logger.warn("No data to add to WDifferencesChart."); rrenkert@5681: return; rrenkert@5681: } rrenkert@5681: rrenkert@5681: XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); rrenkert@5681: StyledSeriesBuilder.addPoints(series, wkms); rrenkert@5681: rrenkert@5681: addAxisSeries(series, YAXIS.D.idx, visible); rrenkert@5681: if (DataUtil.guessWaterIncreasing(wkms.allWs())) { rrenkert@5681: setInverted(true); rrenkert@5681: } rrenkert@5681: } teichmann@5864: } felix@6571: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :