comparison artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDiffBaseGenerator.java @ 6551:8c226c5089e0

BedDiff*Generator: Refactored to avoid code dupes. The problematic setting will not crash anymore, but diagram will be empty.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 10 Jul 2013 10:05:52 +0200
parents
children 87b49f9f27a1
comparison
equal deleted inserted replaced
6550:7cf3b3bcd439 6551:8c226c5089e0
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.exports.minfo;
10
11 import org.apache.log4j.Logger;
12
13 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
14 import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult;
15 import org.dive4elements.river.jfree.Bounds;
16 import org.dive4elements.river.jfree.DoubleBounds;
17 import org.dive4elements.river.exports.fixings.FixChartGenerator;
18
19 /** Base for BedDiff*Year*Generators, to avoid duplicate code of setContextBounds. */
20 public abstract class BedDiffBaseGenerator
21 extends FixChartGenerator
22 {
23 /** The logger that is used in this generator. */
24 private static Logger logger = Logger.getLogger(BedDiffBaseGenerator.class);
25
26 /** Set context values for something. */
27 public void setContextBounds(ArtifactAndFacet bundle) {
28 Bounds xBounds = getXBounds(0);
29 if (xBounds != null && getDomainAxisRange() != null) {
30 Bounds bounds =
31 calculateZoom(xBounds, getDomainAxisRange());
32 context.putContextValue("startkm", bounds.getLower());
33 context.putContextValue("endkm", bounds.getUpper());
34 }
35 else if (xBounds != null && getDomainAxisRange() == null) {
36 context.putContextValue("startkm", xBounds.getLower());
37 context.putContextValue("endkm", xBounds.getUpper());
38 }
39 else if (xBounds == null && getDomainAxisRange() == null) {
40 BedDifferencesResult data = (BedDifferencesResult)bundle.getData(context);
41 if (data.getKms().size() > 0) {
42 context.putContextValue("startkm", data.getKms().min());
43 context.putContextValue("endkm", data.getKms().max());
44 }
45 else {
46 logger.warn("No data to define start and end km");
47 }
48 }
49 else if (xBounds == null && getDomainAxisRange() != null){
50 BedDifferencesResult data = (BedDifferencesResult)bundle.getData(context);
51 Bounds b = new DoubleBounds(data.getKms().min(), data.getKms().max());
52 Bounds bounds =
53 calculateZoom(b, getDomainAxisRange());
54 context.putContextValue("startkm", bounds.getLower());
55 context.putContextValue("endkm", bounds.getUpper());
56 }
57 }
58 }

http://dive4elements.wald.intevation.org