annotate flys-artifacts/src/main/java/de/intevation/flys/jfree/DoubleBounds.java @ 2332:0ddebd4448a7

Picked rev4038 from trunk to stop Annotations break chart rendering. flys-artifacts/tags/2.6@4039 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 10 Feb 2012 16:42:41 +0000
parents 594885703687
children 2f6d4f92d628
rev   line source
2327
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.jfree;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import org.apache.log4j.Logger;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import org.jfree.chart.axis.ValueAxis;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import org.jfree.data.Range;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 /**
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 */
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 public class DoubleBounds implements Bounds {
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 protected double lower;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 protected double upper;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
2330
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
18 /**
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
19 * Default constructor. <b>A DoubleBounds has always set lower &lt;
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
20 * upper!</b>
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
21 */
2327
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 public DoubleBounds(double lower, double upper) {
2330
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
23 this.lower = Math.min(lower, upper);
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
24 this.upper = Math.max(lower, upper);
2327
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 @Override
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 public Number getLower() {
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 return Double.valueOf(lower);
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 @Override
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public Number getUpper() {
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 return Double.valueOf(upper);
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 @Override
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 public void applyBounds(ValueAxis axis) {
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 axis.setRange(new Range(lower, upper));
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 @Override
2330
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
47 public void applyBounds(ValueAxis axis, int percent) {
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
48 double space = (upper - lower) / 100 * percent;
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
49 axis.setRange(new Range(lower-space, upper+space));
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
50 }
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
51
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
52
594885703687 Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2327
diff changeset
53 @Override
2327
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public Bounds combine(Bounds bounds) {
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 if (bounds == null) {
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 return this;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 DoubleBounds other = (DoubleBounds) bounds;
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 double otherLower = other.getLower().doubleValue();
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 double otherUpper = other.getUpper().doubleValue();
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 return new DoubleBounds(
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 otherLower < lower ? otherLower : lower,
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 otherUpper > upper ? otherUpper : upper);
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 @Override
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 public String toString() {
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 return "DoubleBounds=[" + lower + " ; " + upper + "]";
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 }
07c39470e2cb Added new model classes that should be used for axes range adaption later.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org