Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java @ 2414:b5f5af53a526
Make it compileable again
flys-artifacts/trunk@4045 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 13 Feb 2012 17:48:14 +0000 |
parents | 8e2ae8813a06 |
children | 664f97b6d48f |
line wrap: on
line source
package de.intevation.flys.exports; import org.w3c.dom.Document; import org.apache.log4j.Logger; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.title.TextTitle; import org.jfree.data.xy.XYSeries; import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WW; import de.intevation.flys.artifacts.model.WW.ApplyFunctionIterator; import de.intevation.flys.artifacts.model.WWAxisTypes; import de.intevation.flys.jfree.StyledXYSeries; /** * An OutGenerator that generates reference curves. */ public class ReferenceCurveGenerator extends XYChartGenerator implements FacetTypes { public static enum YAXIS { W(0); public int idx; private YAXIS(int c) { idx = c; } } /** House logger. */ private static Logger logger = Logger.getLogger(ReferenceCurveGenerator.class); public static final String I18N_CHART_TITLE = "chart.reference.curve.title"; public static final String I18N_CHART_SUBTITLE = "chart.reference.curve.subtitle"; public static final String I18N_X_AXIS_IN_CM = "chart.reference.curve.x.axis.in.cm"; public static final String I18N_X_AXIS_IN_M = "chart.reference.curve.x.axis.in.m"; public static final String I18N_Y_AXIS_IN_CM = "chart.reference.curve.y.axis.in.cm"; public static final String I18N_Y_AXIS_IN_M = "chart.reference.curve.y.axis.in.m"; public static final String I18N_CHART_TITLE_DEFAULT = "Bezugslinie"; public ReferenceCurveGenerator() { } /** * Create Axis for given index. * @return axis with according internationalized label. */ @Override protected NumberAxis createYAxis(int index) { NumberAxis axis = super.createYAxis(index); axis.setAutoRangeIncludesZero(false); return axis; } /** Get default chart title. */ @Override protected String getDefaultChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); } @Override protected String getDefaultChartSubtitle() { Object[] args = new Object[] { getRiverName(), }; return msg(I18N_CHART_SUBTITLE, "", args); } @Override protected void addSubtitles(JFreeChart chart) { String subtitle = getChartSubtitle(); if (subtitle != null && subtitle.length() > 0) { chart.addSubtitle(new TextTitle(subtitle)); } } protected boolean getInCm(int index) { Object obj = context.getContextValue("reference.curve.axis.scale"); return obj instanceof WWAxisTypes && ((WWAxisTypes)obj).getInCm(index); } /** Get Label for X-axis (W). */ @Override protected String getDefaultXAxisLabel() { return msg(getInCm(0) ? I18N_X_AXIS_IN_CM : I18N_X_AXIS_IN_M); } /** * Get Label for primary and other Y Axes. * @param index Axis-Index (0-based). */ @Override protected String getDefaultYAxisLabel(int index) { return msg(getInCm(1) ? I18N_Y_AXIS_IN_CM : I18N_Y_AXIS_IN_M); } protected String facetName() { return REFERENCE_CURVE; } /** * Called for each facet/them in the out mapped to this generator. * @param artifactFacet artifact and facet for this theme. * @param theme styling info. * @param visible Whether or not the theme is visible. */ @Override public void doOut( ArtifactAndFacet artifactFacet, Document theme, boolean visible ) { String name = artifactFacet.getFacetName(); logger.debug("ReferenceCurveGenerator.doOut: " + name); if (name == null || name.length() == 0) { logger.error("No facet given. Cannot create dataset."); return; } if (name.equals(facetName())) { doReferenceOut(artifactFacet.getData(context), theme, visible); } else if (FacetTypes.IS.MANUALPOINTS(name)) { doPoints( artifactFacet.getData(context), artifactFacet, theme, visible, YAXIS.W.idx); } else { logger.warn("Unknown facet name: " + name); } } protected boolean doNormalize() { return false; } /** Register DataSeries with (maybe transformed) points. */ public void doReferenceOut( Object data, Document theme, boolean visible ) { WW ww = (WW)data; Object obj = context.getContextValue("reference.curve.axis.scale"); WWAxisTypes wwat = obj instanceof WWAxisTypes ? (WWAxisTypes)obj : new WWAxisTypes(ww); ApplyFunctionIterator iter = wwat.transform(ww, doNormalize()); XYSeries series = new StyledXYSeries( ww.getName(), false, theme); double [] values = new double[2]; while (iter.hasNext()) { iter.next(values); series.add(values[0], values[1], false); } addAxisSeries(series, YAXIS.W.idx, visible); } /** Get Walker to iterate over all axes. */ @Override protected YAxisWalker getYAxisWalker() { return new YAxisWalker() { /** Get number of items. */ @Override public int length() { return YAXIS.values().length; } /** Get identifier for this index. */ @Override public String getId(int idx) { YAXIS[] yaxes = YAXIS.values(); return yaxes[idx].toString(); } }; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :