comparison gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents f953c9a559d8
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.jfreechart;
10
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import org.jfree.data.Range;
15
16 import org.jfree.data.general.Series;
17
18 /**
19 * This class represents a series of polygon items.
20 *
21 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha Teichmann</a>
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
23 */
24 public class PolygonSeries
25 extends Series
26 {
27 /**
28 * Polygons.
29 */
30 protected CompactXYItems [] rings;
31
32 /**
33 * A map containing attribues.
34 */
35 protected Map attributes;
36
37 /**
38 * The unique key of this series.
39 */
40 private static long uniqueKey;
41
42 /**
43 *
44 * @return a unique key.
45 */
46 protected synchronized static Long createUniqueKey() {
47 return new Long(uniqueKey++);
48 }
49
50 /**
51 * Constructor to create an empty PolygonSeries with a unique key.
52 */
53 public PolygonSeries() {
54 this(createUniqueKey(), null);
55 }
56
57 /**
58 *
59 * @param key The key used for this series.
60 * @param rings Polygons.
61 */
62 public PolygonSeries(Comparable key, CompactXYItems [] rings) {
63 this(key, null, rings, new HashMap());
64 }
65
66 /**
67 *
68 * @param key The key used for this series.
69 * @param description A description of this series.
70 * @param rings Polygons.
71 */
72 public PolygonSeries(
73 Comparable key,
74 String description,
75 CompactXYItems[] rings
76 ) {
77 this(key, description, rings, new HashMap());
78 }
79
80 /**
81 *
82 * @param key The key used for this series.
83 * @param description A description of this series.
84 * @param rings Polygons.
85 * @param attributes Some attribues.
86 */
87 public PolygonSeries(
88 Comparable key,
89 String description,
90 CompactXYItems [] rings,
91 Map attributes
92 ) {
93 super(key, description);
94 this.rings = rings;
95 this.attributes = attributes;
96 }
97
98
99 public void setRings(CompactXYItems [] rings) {
100 this.rings = rings;
101 }
102
103
104 public CompactXYItems [] getRings() {
105 return rings;
106 }
107
108
109 public void addRing(CompactXYItems newRing) {
110 if (rings == null) {
111 rings = new CompactXYItems [] { newRing };
112 }
113 else {
114 CompactXYItems [] nRings = new CompactXYItems[rings.length + 1];
115 System.arraycopy(rings, 0, nRings, 0, rings.length);
116 nRings[rings.length] = newRing;
117 rings = nRings;
118 }
119 }
120
121
122 public void addRings(CompactXYItems [] newRings) {
123 if (newRings == null || newRings.length == 0) {
124 return;
125 }
126 if (rings == null || rings.length == 0) {
127 rings = newRings;
128 }
129 else {
130 CompactXYItems [] both =
131 new CompactXYItems[rings.length + newRings.length];
132 System.arraycopy(rings, 0, both, 0, rings.length);
133 System.arraycopy(newRings, 0, both, rings.length, newRings.length);
134 rings = both;
135 }
136 }
137
138
139 public Object getAttribute(Object key) {
140 return attributes.get(key);
141 }
142
143
144 public Object setAttribute(Object key, Object value) {
145 return attributes.put(key, value);
146 }
147
148
149 public int getItemCount() {
150 return rings != null ? rings.length : 0;
151 }
152
153
154 public CompactXYItems getItem(int idx) {
155 return rings[idx];
156 }
157
158
159 public Object removeAttribute(Object key) {
160 return attributes.remove(key);
161 }
162
163
164 public boolean hasAttribute(Object key) {
165 return attributes.containsKey(key);
166 }
167
168
169 /**
170 *
171 * @return the range of the x axis.
172 */
173 public Range getDomainBounds() {
174 double upper = Double.NEGATIVE_INFINITY;
175 double lower = Double.POSITIVE_INFINITY;
176 int count = getItemCount();
177
178 for (int i = 0; i < count; i++) {
179 CompactXYItems items = getItem(i);
180 double minX = items.getMinX();
181 double maxX = items.getMaxX();
182
183 if (!Double.isNaN(minX)) {
184 lower = Math.min(lower, minX);
185 }
186
187 if (!Double.isNaN(maxX)) {
188 upper = Math.max(upper, maxX);
189 }
190 }
191
192 if (lower > upper) {
193 return null;
194 }
195
196 return new Range(lower, upper);
197 }
198
199
200 /**
201 *
202 * @return the range of the y axis.
203 */
204 public Range getRangeBounds() {
205 double upper = Double.NEGATIVE_INFINITY;
206 double lower = Double.POSITIVE_INFINITY;
207 int count = getItemCount();
208
209 for (int i = 0; i < count; i++) {
210 CompactXYItems items = getItem(i);
211 double minY = items.getMinY();
212 double maxY = items.getMaxY();
213
214 if (!Double.isNaN(minY)) {
215 lower = Math.min(lower, minY);
216 }
217
218 if (!Double.isNaN(maxY)) {
219 upper = Math.max(upper, maxY);
220 }
221 }
222
223 if (lower > upper) {
224 return null;
225 }
226
227 return new Range(lower, upper);
228 }
229 }
230 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org