Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java @ 2046:2ae0627f956e
Improved ChartSettings and depending classes to avoid a lot of casting.
flys-artifacts/trunk@3534 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 23 Dec 2011 08:51:28 +0000 |
parents | e71719483546 |
children | 3157a78e6494 |
line wrap: on
line source
package de.intevation.flys.exports; import org.apache.log4j.Logger; import java.awt.Font; import org.w3c.dom.Document; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.Range; import org.jfree.data.xy.XYSeries; import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.utils.FLYSUtils; import de.intevation.flys.jfree.FLYSAnnotation; /** * An OutGenerator that generates discharge curves. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DischargeCurveGenerator extends XYChartGenerator implements FacetTypes { public static enum YAXIS { W(0); protected int idx; private YAXIS(int c) { idx = c; } } /** The logger used in this generator. */ private static Logger logger = Logger.getLogger(DischargeCurveGenerator.class); public static final String I18N_CHART_TITLE = "chart.discharge.curve.title"; public static final String I18N_CHART_SUBTITLE = "chart.discharge.curve.subtitle"; public static final String I18N_XAXIS_LABEL = "chart.discharge.curve.xaxis.label"; public static final String I18N_YAXIS_LABEL = "chart.discharge.curve.yaxis.label"; public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurven"; public static final String I18N_XAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; public static final String I18N_YAXIS_LABEL_DEFAULT = "W [cm]"; public DischargeCurveGenerator() { super(); } @Override protected YAxisWalker getYAxisWalker() { return new YAxisWalker() { @Override public int length() { return YAXIS.values().length; } @Override public String getId(int idx) { YAXIS[] yaxes = YAXIS.values(); return yaxes[idx].toString(); } }; } protected String getChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } /** * Empty (suppress subtitle). */ @Override protected void addSubtitles(JFreeChart chart) { } /** * i18n-Label for X-Axis. */ protected String getXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } /** * i18n-Label for X-Axis (W). */ protected String getYAxisLabel() { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } @Override protected boolean zoomX(XYPlot plot, ValueAxis axis, Range range, Range x) { boolean zoomin = super.zoom(plot, axis, range, x); if (!zoomin) { axis.setLowerBound(0d); } return zoomin; } /** * Create Y-Axis. * First Axis: W. * @return Y-Axis with label. */ @Override protected NumberAxis createYAxis(int index) { Font labelFont = new Font("Tahoma", Font.BOLD, 14); String label = "default"; if (index == YAXIS.W.idx) { label = getYAxisLabel(); } NumberAxis axis = new NumberAxis(label); axis.setLabelFont(labelFont); axis.setAutoRangeIncludesZero(false); return axis; } public void doOut( ArtifactAndFacet artifactFacet, Document theme, boolean visible ) { String name = artifactFacet.getFacetName(); logger.debug("DischargeCurveGenerator.doOut: " + name); if (name.equals(DISCHARGE_CURVE)) { doDischargeOut( (WINFOArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), theme, visible); } else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q) || name.equals(MAINVALUES_Q) || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W) || name.equals(MAINVALUES_W)) { doAnnotations((FLYSAnnotation) artifactFacet.getData(context), artifactFacet.getFacet(), theme, visible); } else { logger.warn("DischargeCurveGenerator.doOut: Unknown facet name: " + name); return; } } /** * Add series with discharge curve to diagram. */ protected void doDischargeOut( WINFOArtifact artifact, Object o, String description, Document theme, boolean visible) { WQKms wqkms = (WQKms) o; String gaugeName = wqkms.getName(); River river = FLYSUtils.getRiver(artifact); if (river == null) { logger.debug("no river found"); return; } Gauge gauge = river.determineGaugeByName(gaugeName); if (gauge == null) { logger.debug("no gauge found"); return; } XYSeries series = new StyledXYSeries(description, theme); StyledSeriesBuilder.addPointsQW(series, wqkms); addAxisSeries(series, YAXIS.W.idx, visible); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :