comparison gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java @ 422:f426f55d4f7a

Added Ingo Weinzierl's special JFreeChart classes. gnv-artifacts/trunk@470 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Dec 2009 16:47:45 +0000
parents
children 6642ab6c583c
comparison
equal deleted inserted replaced
421:fd71ee76fa58 422:f426f55d4f7a
1 package de.intevation.gnv.jfreechart;
2
3 import java.util.Map;
4 import java.util.HashMap;
5
6 import org.jfree.data.Range;
7 import org.jfree.data.general.Series;
8
9 /**
10 * @author Sascha Teichmann <sascha.teichmann@intevation.de>
11 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
12 */
13 public class PolygonSeries
14 extends Series
15 {
16 protected CompactXYItems [] rings;
17 protected Map attributes;
18
19
20 public PolygonSeries(Comparable key, CompactXYItems [] rings) {
21 this(key, null, rings, new HashMap());
22 }
23
24 public PolygonSeries(
25 Comparable key,
26 String description,
27 CompactXYItems[] rings
28 ) {
29 this(key, description, rings, new HashMap());
30 }
31
32 public PolygonSeries(
33 Comparable key,
34 String description,
35 CompactXYItems [] rings,
36 Map attributes
37 ) {
38 super(key, description);
39 this.rings = rings;
40 this.attributes = attributes;
41 }
42
43
44 public void setRings(CompactXYItems [] rings) {
45 this.rings = rings;
46 }
47
48 public CompactXYItems [] getRings() {
49 return rings;
50 }
51
52 public void addRings(CompactXYItems [] newRings) {
53 if (newRings == null || newRings.length == 0) {
54 return;
55 }
56 if (rings == null || rings.length == 0) {
57 rings = newRings;
58 }
59 else {
60 CompactXYItems [] both =
61 new CompactXYItems[rings.length + newRings.length];
62 System.arraycopy(rings, 0, both, 0, rings.length);
63 System.arraycopy(newRings, 0, both, rings.length, newRings.length);
64 rings = both;
65 }
66 }
67
68 public Object getAttribute(Object key) {
69 return attributes.get(key);
70 }
71
72
73 public Object setAttribute(Object key, Object value) {
74 return attributes.put(key, value);
75 }
76
77
78 public int getItemCount() {
79 return rings.length;
80 }
81
82
83 public CompactXYItems getItem(int idx) {
84 return rings[idx];
85 }
86
87
88 public Object removeAttribute(Object key) {
89 return attributes.remove(key);
90 }
91
92
93 public boolean hasAttribute(Object key) {
94 return attributes.containsKey(key);
95 }
96
97
98 public Range getDomainBounds() {
99 double upper = Double.NEGATIVE_INFINITY;
100 double lower = Double.POSITIVE_INFINITY;
101 int count = getItemCount();
102
103 for (int i = 0; i < count; i++) {
104 CompactXYItems items = getItem(i);
105 double minX = items.getMinX();
106 double maxX = items.getMaxX();
107
108 if (!Double.isNaN(minX)) {
109 lower = Math.min(lower, minX);
110 }
111
112 if (!Double.isNaN(maxX)) {
113 upper = Math.max(upper, maxX);
114 }
115 }
116
117 if (lower > upper) {
118 return null;
119 }
120
121 return new Range(lower, upper);
122 }
123
124
125 public Range getRangeBounds() {
126 double upper = Double.NEGATIVE_INFINITY;
127 double lower = Double.POSITIVE_INFINITY;
128 int count = getItemCount();
129
130 for (int i = 0; i < count; i++) {
131 CompactXYItems items = getItem(i);
132 double minY = items.getMinY();
133 double maxY = items.getMaxY();
134
135 if (!Double.isNaN(minY)) {
136 lower = Math.min(lower, minY);
137 }
138
139 if (!Double.isNaN(maxY)) {
140 upper = Math.max(upper, maxY);
141 }
142 }
143
144 if (lower > upper) {
145 return null;
146 }
147
148 return new Range(lower, upper);
149 }
150 }
151 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org