diff flys-artifacts/src/main/java/de/intevation/flys/jfree/TimeBounds.java @ 3651:06a65baae494

merged flys-artifacts/2.9
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:43 +0200
parents 73b15736cb80
children 2f6d4f92d628
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/TimeBounds.java	Fri Sep 28 12:14:43 2012 +0200
@@ -0,0 +1,88 @@
+package de.intevation.flys.jfree;
+
+import java.util.Date;
+
+import org.jfree.chart.axis.DateAxis;
+import org.jfree.chart.axis.ValueAxis;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class TimeBounds implements Bounds {
+
+    protected long lower;
+    protected long upper;
+
+
+    public TimeBounds(long lower, long upper) {
+        this.lower = lower;
+        this.upper = upper;
+    }
+
+
+    @Override
+    public Number getLower() {
+        return Long.valueOf(lower);
+    }
+
+
+    public Date getLowerAsDate() {
+        return new Date(lower);
+    }
+
+
+    @Override
+    public Number getUpper() {
+        return Long.valueOf(upper);
+    }
+
+
+    public Date getUpperAsDate() {
+        return new Date(upper);
+    }
+
+
+    @Override
+    public void applyBounds(ValueAxis axis) {
+        DateAxis dateAxis = (DateAxis) axis;
+
+        dateAxis.setMinimumDate(new Date(lower));
+        dateAxis.setMaximumDate(new Date(upper));
+    }
+
+
+    @Override
+    public void applyBounds(ValueAxis axis, int percent) {
+        DateAxis dateAxis = (DateAxis) axis;
+
+        long space = (upper - lower) / 100 * percent;
+
+        dateAxis.setMinimumDate(new Date(lower-space));
+        dateAxis.setMaximumDate(new Date(upper+space));
+    }
+
+
+    @Override
+    public Bounds combine(Bounds bounds) {
+        if (bounds == null) {
+            return this;
+        }
+
+        TimeBounds other = (TimeBounds) bounds;
+
+        long otherLower = other.getLower().longValue();
+        long otherUpper = other.getUpper().longValue();
+
+        return new TimeBounds(
+            otherLower < lower ? otherLower : lower,
+            otherUpper > upper ? otherUpper : upper);
+    }
+
+
+    @Override
+    public String toString() {
+        return "TimeBounds=["+ getLowerAsDate() + " ; " + getUpperAsDate() +"]";
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org