teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.jfree; ingo@2327: ingo@2327: import java.util.Date; ingo@2327: ingo@2327: import org.jfree.chart.axis.DateAxis; ingo@2327: import org.jfree.chart.axis.ValueAxis; ingo@2327: ingo@2327: ingo@2327: /** ingo@2327: * @author Ingo Weinzierl ingo@2327: */ ingo@2327: public class TimeBounds implements Bounds { ingo@2327: ingo@2327: protected long lower; ingo@2327: protected long upper; ingo@2327: ingo@2327: ingo@2327: public TimeBounds(long lower, long upper) { ingo@2327: this.lower = lower; ingo@2327: this.upper = upper; ingo@2327: } ingo@2327: ingo@2327: ingo@2327: @Override ingo@2327: public Number getLower() { ingo@2327: return Long.valueOf(lower); ingo@2327: } ingo@2327: ingo@2327: ingo@2330: public Date getLowerAsDate() { ingo@2330: return new Date(lower); ingo@2330: } ingo@2330: ingo@2330: ingo@2327: @Override ingo@2327: public Number getUpper() { ingo@2327: return Long.valueOf(upper); ingo@2327: } ingo@2327: ingo@2327: ingo@2330: public Date getUpperAsDate() { ingo@2330: return new Date(upper); ingo@2330: } ingo@2330: ingo@2330: ingo@2327: @Override ingo@2327: public void applyBounds(ValueAxis axis) { ingo@2327: DateAxis dateAxis = (DateAxis) axis; ingo@2327: ingo@2327: dateAxis.setMinimumDate(new Date(lower)); ingo@2327: dateAxis.setMaximumDate(new Date(upper)); ingo@2327: } ingo@2327: ingo@2327: ingo@2327: @Override ingo@2330: public void applyBounds(ValueAxis axis, int percent) { ingo@2330: DateAxis dateAxis = (DateAxis) axis; ingo@2330: ingo@2330: long space = (upper - lower) / 100 * percent; ingo@2330: ingo@2330: dateAxis.setMinimumDate(new Date(lower-space)); ingo@2330: dateAxis.setMaximumDate(new Date(upper+space)); ingo@2330: } ingo@2330: ingo@2330: ingo@2330: @Override ingo@2327: public Bounds combine(Bounds bounds) { ingo@2327: if (bounds == null) { ingo@2327: return this; ingo@2327: } ingo@2327: ingo@2327: TimeBounds other = (TimeBounds) bounds; ingo@2327: ingo@2327: long otherLower = other.getLower().longValue(); ingo@2327: long otherUpper = other.getUpper().longValue(); ingo@2327: ingo@2327: return new TimeBounds( ingo@2327: otherLower < lower ? otherLower : lower, ingo@2327: otherUpper > upper ? otherUpper : upper); ingo@2327: } ingo@2327: ingo@2327: ingo@2327: @Override ingo@2327: public String toString() { ingo@2330: return "TimeBounds=["+ getLowerAsDate() + " ; " + getUpperAsDate() +"]"; ingo@2327: } ingo@2327: } ingo@2327: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :