comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/DoubleBounds.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents 73b15736cb80
children cbe2febe30cc
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
1 package de.intevation.flys.jfree;
2
3
4 import org.jfree.chart.axis.ValueAxis;
5 import org.jfree.data.Range;
6
7
8 /**
9 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
10 */
11 public class DoubleBounds implements Bounds {
12
13 protected double lower;
14 protected double upper;
15
16
17 /**
18 * Default constructor. <b>A DoubleBounds has always set lower &lt;
19 * upper!</b>
20 */
21 public DoubleBounds(double lower, double upper) {
22 this.lower = Math.min(lower, upper);
23 this.upper = Math.max(lower, upper);
24 }
25
26
27 @Override
28 public Number getLower() {
29 return Double.valueOf(lower);
30 }
31
32
33 @Override
34 public Number getUpper() {
35 return Double.valueOf(upper);
36 }
37
38
39 @Override
40 public void applyBounds(ValueAxis axis) {
41 axis.setRange(new Range(lower, upper));
42 }
43
44
45 @Override
46 public void applyBounds(ValueAxis axis, int percent) {
47 double space = (upper - lower) / 100 * percent;
48 axis.setRange(new Range(lower-space, upper+space));
49 }
50
51
52 @Override
53 public Bounds combine(Bounds bounds) {
54 if (bounds == null) {
55 return this;
56 }
57
58 DoubleBounds other = (DoubleBounds) bounds;
59
60 double otherLower = other.getLower().doubleValue();
61 double otherUpper = other.getUpper().doubleValue();
62
63 return new DoubleBounds(
64 otherLower < lower ? otherLower : lower,
65 otherUpper > upper ? otherUpper : upper);
66 }
67
68
69 @Override
70 public String toString() {
71 return "DoubleBounds=[" + lower + " ; " + upper + "]";
72 }
73 }
74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org