changeset 6421:aa2a0824954d

issue1370: Initial commit for new SyncNumberAxis.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 26 Jun 2013 12:25:22 +0200 (2013-06-26)
parents ab173f37fb40
children cc96f7a9f9ef
files artifacts/src/main/java/org/dive4elements/river/exports/SyncNumberAxis.java
diffstat 1 files changed, 131 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/SyncNumberAxis.java	Wed Jun 26 12:25:22 2013 +0200
@@ -0,0 +1,131 @@
+/* Copyright (C) 2011, 2012, 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;
+
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.event.AxisChangeEvent;
+import org.jfree.chart.event.AxisChangeListener;
+import org.jfree.data.Range;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Axis which is to be registered with other axis and tries
+ * to clone its range. The cloned range is transformed.
+ */
+public class SyncNumberAxis extends IdentifiableNumberAxis
+        implements AxisChangeListener
+{
+    /** The logger used in this generator. */
+    private static Logger logger =
+        Logger.getLogger(SyncNumberAxis.class);
+
+    /** The other axis to clone range from. */
+    protected NumberAxis proxyAxis;
+
+    /** Value to translate range by. */
+    protected double shift;
+
+
+    protected SyncNumberAxis(String key, String label, NumberAxis n) {
+        super(key, label);
+        this.proxyAxis = n;
+    }
+
+
+    /** Range of other axis changed, adjust own range. */
+    @Override
+    public void axisChanged(AxisChangeEvent event) {
+        logger.debug("SyncNumberAxis: axischange event");
+        this.setRange(
+            transRange(((NumberAxis)event.getAxis()).getRange()));
+    }
+
+    /** Set value by which to translate the range. */
+    protected void setShift(double shift) {
+        this.shift = shift;
+    }
+
+
+    /** Set other axis to relate to, register listener. */
+    public void setProxyAxis(NumberAxis ax) {
+        proxyAxis = ax;
+        proxyAxis.addChangeListener(this);
+    }
+
+    /** Translate range by shift, scale by 100. */
+    protected Range transRange(Range r) {
+        return new Range(100d*(r.getLowerBound()+shift),
+            100d*(r.getUpperBound()+shift));
+    }
+
+    /** Set Range. */
+    @Override
+    public void setRange(Range r) {
+        super.setRange(r);
+        logger.debug("SyncAxis: setRange");
+    }
+
+
+    /*
+    @Override
+    public Range getRange() {
+        Range r = new Range(100d*(proxyAxis.getRange().getLowerBound()+shift),
+            100d*(proxyAxis.getRange().getUpperBound()+shift));
+        return r;
+    }
+
+    @Override
+    public void setLowerBound(double max) {
+    }
+
+    @Override
+    public void setLowerMargin(double margin) {
+    }
+
+    @Override
+    public void setUpperBound(double max) {
+    }
+
+    @Override
+    public void setUpperMargin(double margin) {
+    }
+
+    @Override
+    public void setRange(double a, double b) {
+    }
+
+    @Override
+    public void setRange(Range range, boolean turnOffAutoRange, boolean notify){
+    }
+
+    @Override
+    public void setRangeAboutValue(double value, double length) {}
+
+    @Override
+    public void setRangeWithMargins(double lower, double upper) {}
+
+    @Override
+    public void setRangeWithMargins(Range range) {}
+
+    @Override
+    public void pan(double percent) {}
+
+    @Override
+    public void resizeRange(double p){}
+
+    @Override
+    public void resizeRange(double p, double a){}
+
+    @Override
+    public void resizeRange2(double p, double a){}
+
+    */
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org