[PATCH 1 of 6] Add SedimentLoadProcessor

Wald Commits scm-commit at wald.intevation.org
Thu Sep 26 09:59:49 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1380123643 -7200
# Node ID fdf2d31b895577811792c68f53cb1bae399bb63f
# Parent  8c169743f4d0c75f30247062cc98a518b9830f14
Add SedimentLoadProcessor

diff -r 8c169743f4d0 -r fdf2d31b8955 artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java	Wed Sep 25 17:40:43 2013 +0200
@@ -0,0 +1,98 @@
+/* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.exports.process;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+import org.dive4elements.river.artifacts.D4EArtifact;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.access.SedimentLoadAccess;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
+
+public class SedimentLoadProcessor extends DefaultProcessor {
+
+    private final static Logger logger =
+            Logger.getLogger(SedimentLoadProcessor.class);
+
+    public static final String I18N_YAXIS_LABEL_1 =
+        "chart.sedimentload.ls.yaxis.label.tpera";
+    public static final String I18N_YAXIS_LABEL_2 =
+        "chart.sedimentload.ls.yaxis.label.m3pera";
+    public static final String I18N_YAXIS_LABEL_DEFAULT_1 = "[t/a]";
+    public static final String I18N_YAXIS_LABEL_DEFAULT_2 = "[m\u00b3/a]";
+
+    @Override
+    public void doOut(
+            DiagramGenerator generator,
+            ArtifactAndFacet bundle,
+            ThemeDocument    theme,
+            boolean          visible) {
+        CallContext context = generator.getCallContext();
+        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
+                theme);
+        Object data = bundle.getData(context);
+        String facetName = bundle.getFacetName();
+        double [][] points;
+
+        if (FacetTypes.IS.SEDIMENT_LOAD(facetName)) {
+            points = (double[][]) data;
+        } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) {
+            SedimentLoad load = (SedimentLoad) data;
+            Set<Double> kms = load.getKms();
+            points = new double[2][kms.size()];
+            int counter = 0;
+            for (Double km: kms) {
+                SedimentLoadFraction fraction = load.getFraction(km);
+                points[0][counter] = km;
+                points[1][counter] = fraction.getUnknown();
+                counter++;
+            }
+        } else {
+            logger.error("Unknown facet name: " + facetName);
+            return;
+        }
+        StyledSeriesBuilder.addPoints(series, points, true);
+
+        generator.addAxisSeries(series, axisName, visible);
+    }
+
+    @Override
+    public boolean canHandle(String facettype) {
+        return FacetTypes.IS.SEDIMENT_LOAD(facettype) ||
+            FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facettype);
+    }
+
+    @Override
+    public String getAxisLabel(DiagramGenerator generator) {
+        SedimentLoadAccess slaccess =
+            new SedimentLoadAccess((D4EArtifact) generator.getMaster());
+        String unit = slaccess.getUnit();
+        if (unit != null && unit.equals("m3_per_a")) {
+            return generator.msg(I18N_YAXIS_LABEL_2, I18N_YAXIS_LABEL_DEFAULT_2);
+        }
+        else {
+            return generator.msg(I18N_YAXIS_LABEL_1, I18N_YAXIS_LABEL_DEFAULT_1);
+        }
+    }
+}
+
+
+


More information about the Dive4elements-commits mailing list