# HG changeset patch # User Felix Wolfsteller # Date 1372242322 -7200 # Node ID aa2a0824954dab3b1bcdd529c413abb695314a8e # Parent ab173f37fb40f75adc2089915e4ee56caa2c670b issue1370: Initial commit for new SyncNumberAxis. diff -r ab173f37fb40 -r aa2a0824954d artifacts/src/main/java/org/dive4elements/river/exports/SyncNumberAxis.java --- /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 :