comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/TimeBounds.java @ 2424:092e519ff461

merged flys-artifacts/2.6.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:26 +0200
parents 73b15736cb80
children 2f6d4f92d628
comparison
equal deleted inserted replaced
2392:8112ec686a9a 2424:092e519ff461
1 package de.intevation.flys.jfree;
2
3 import java.util.Date;
4
5 import org.jfree.chart.axis.DateAxis;
6 import org.jfree.chart.axis.ValueAxis;
7
8
9 /**
10 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
11 */
12 public class TimeBounds implements Bounds {
13
14 protected long lower;
15 protected long upper;
16
17
18 public TimeBounds(long lower, long upper) {
19 this.lower = lower;
20 this.upper = upper;
21 }
22
23
24 @Override
25 public Number getLower() {
26 return Long.valueOf(lower);
27 }
28
29
30 public Date getLowerAsDate() {
31 return new Date(lower);
32 }
33
34
35 @Override
36 public Number getUpper() {
37 return Long.valueOf(upper);
38 }
39
40
41 public Date getUpperAsDate() {
42 return new Date(upper);
43 }
44
45
46 @Override
47 public void applyBounds(ValueAxis axis) {
48 DateAxis dateAxis = (DateAxis) axis;
49
50 dateAxis.setMinimumDate(new Date(lower));
51 dateAxis.setMaximumDate(new Date(upper));
52 }
53
54
55 @Override
56 public void applyBounds(ValueAxis axis, int percent) {
57 DateAxis dateAxis = (DateAxis) axis;
58
59 long space = (upper - lower) / 100 * percent;
60
61 dateAxis.setMinimumDate(new Date(lower-space));
62 dateAxis.setMaximumDate(new Date(upper+space));
63 }
64
65
66 @Override
67 public Bounds combine(Bounds bounds) {
68 if (bounds == null) {
69 return this;
70 }
71
72 TimeBounds other = (TimeBounds) bounds;
73
74 long otherLower = other.getLower().longValue();
75 long otherUpper = other.getUpper().longValue();
76
77 return new TimeBounds(
78 otherLower < lower ? otherLower : lower,
79 otherUpper > upper ? otherUpper : upper);
80 }
81
82
83 @Override
84 public String toString() {
85 return "TimeBounds=["+ getLowerAsDate() + " ; " + getUpperAsDate() +"]";
86 }
87 }
88 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org