teichmann@8165: /* Copyright (C) 2014 by Bundesanstalt für Gewässerkunde teichmann@8165: * Software engineering by Intevation GmbH teichmann@8165: * teichmann@8165: * This file is Free Software under the GNU AGPL (>=v3) teichmann@8165: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@8165: * documentation coming with Dive4Elements River for details. teichmann@8165: */ teichmann@8165: package org.dive4elements.river.exports; teichmann@8165: teichmann@8320: import java.awt.Font; teichmann@8320: teichmann@8320: import org.apache.log4j.Logger; teichmann@8320: import org.dive4elements.river.exports.injector.InjectorConstants; teichmann@8320: import org.dive4elements.river.jfree.AxisDataset; teichmann@8320: import org.jfree.chart.axis.NumberAxis; teichmann@8320: import org.jfree.chart.plot.XYPlot; teichmann@8320: import org.jfree.data.Range; teichmann@8320: teichmann@8320: public class DischargeGenerator teichmann@8320: extends DiagramGenerator teichmann@8320: implements InjectorConstants teichmann@8165: { teichmann@8323: private static Logger log = Logger.getLogger(DischargeGenerator.class); teichmann@8320: teichmann@8165: public DischargeGenerator() { teichmann@8165: } teichmann@8320: teichmann@8320: @Override teichmann@8320: public void addDatasets(XYPlot plot) { teichmann@8320: super.addDatasets(plot); teichmann@8320: teichmann@8320: Object pnp = context.getContextValue(PNP); teichmann@8320: if (!(pnp instanceof Number)) { teichmann@8320: return; teichmann@8320: } teichmann@8320: teichmann@8320: double pnpValue = ((Number)pnp).doubleValue(); teichmann@8320: teichmann@8320: int wAxisIndex = diagramAttributes.getAxisIndex("W"); teichmann@8320: if (wAxisIndex == -1) { teichmann@8320: log.warn("No W axis found."); teichmann@8320: return; teichmann@8320: } teichmann@8320: teichmann@8320: AxisDataset data = datasets.get(wAxisIndex); teichmann@8320: if (data == null) { teichmann@8320: // No W axis teichmann@8320: return; teichmann@8320: } teichmann@8320: teichmann@8320: Range range = inCm(data.getRange(), pnpValue); teichmann@8320: teichmann@8320: // Do we have an index for W in cm? teichmann@8320: NumberAxis wInCmAxis = createWinCMAxis(wAxisIndex); teichmann@8320: wInCmAxis.setRange(range.getLowerBound(), range.getUpperBound()); teichmann@8320: teichmann@8320: plot.setRangeAxis(plot.getRangeAxisCount(), wInCmAxis); teichmann@8320: } teichmann@8320: teichmann@8320: private static Range inCm(Range r, double pnpValue) { teichmann@8320: double l = r.getLowerBound(); teichmann@8320: double u = r.getUpperBound(); teichmann@8320: l = (l - pnpValue)*100d; teichmann@8320: u = (u - pnpValue)*100d; teichmann@8320: return new Range(l, u); teichmann@8320: } teichmann@8320: teichmann@8320: private NumberAxis createWinCMAxis(int wAxisIndex) { teichmann@8320: teichmann@8320: Font labelFont = new Font( teichmann@8320: DEFAULT_FONT_NAME, teichmann@8320: Font.BOLD, teichmann@8320: getYAxisFontSize(wAxisIndex)); teichmann@8320: teichmann@8320: String axisName = "W.in.cm"; teichmann@8320: teichmann@8320: // TODO: I18N teichmann@8320: IdentifiableNumberAxis axis = new IdentifiableNumberAxis( teichmann@8320: axisName, "W.in.cm"); teichmann@8320: teichmann@8320: axis.setAutoRangeIncludesZero(false); teichmann@8320: axis.setLabelFont(labelFont); teichmann@8320: axis.setTickLabelFont(labelFont); teichmann@8320: teichmann@8320: return axis; teichmann@8320: } teichmann@8165: } teichmann@8165: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :