Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 92b7ccbf6163 |
children | b1f5f2a8840f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java Fri Sep 28 12:13:53 2012 +0200 @@ -0,0 +1,172 @@ +package de.intevation.gnv.jfreechart; + +import java.util.Map; +import java.util.HashMap; + +import org.jfree.data.Range; +import org.jfree.data.general.Series; + +/** + * @author Sascha Teichmann <sascha.teichmann@intevation.de> + * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + */ +public class PolygonSeries +extends Series +{ + protected CompactXYItems [] rings; + protected Map attributes; + + private static long uniqueKey; + + protected synchronized static Long createUniqueKey() { + return new Long(uniqueKey++); + } + + public PolygonSeries() { + this(createUniqueKey(), null); + } + + public PolygonSeries(Comparable key, CompactXYItems [] rings) { + this(key, null, rings, new HashMap()); + } + + public PolygonSeries( + Comparable key, + String description, + CompactXYItems[] rings + ) { + this(key, description, rings, new HashMap()); + } + + public PolygonSeries( + Comparable key, + String description, + CompactXYItems [] rings, + Map attributes + ) { + super(key, description); + this.rings = rings; + this.attributes = attributes; + } + + + public void setRings(CompactXYItems [] rings) { + this.rings = rings; + } + + public CompactXYItems [] getRings() { + return rings; + } + + public void addRing(CompactXYItems newRing) { + if (rings == null) { + rings = new CompactXYItems [] { newRing }; + } + else { + CompactXYItems [] nRings = new CompactXYItems[rings.length + 1]; + System.arraycopy(rings, 0, nRings, 0, rings.length); + nRings[rings.length] = newRing; + rings = nRings; + } + } + + public void addRings(CompactXYItems [] newRings) { + if (newRings == null || newRings.length == 0) { + return; + } + if (rings == null || rings.length == 0) { + rings = newRings; + } + else { + CompactXYItems [] both = + new CompactXYItems[rings.length + newRings.length]; + System.arraycopy(rings, 0, both, 0, rings.length); + System.arraycopy(newRings, 0, both, rings.length, newRings.length); + rings = both; + } + } + + public Object getAttribute(Object key) { + return attributes.get(key); + } + + + public Object setAttribute(Object key, Object value) { + return attributes.put(key, value); + } + + + public int getItemCount() { + return rings != null ? rings.length : 0; + } + + + public CompactXYItems getItem(int idx) { + return rings[idx]; + } + + + public Object removeAttribute(Object key) { + return attributes.remove(key); + } + + + public boolean hasAttribute(Object key) { + return attributes.containsKey(key); + } + + + public Range getDomainBounds() { + double upper = Double.NEGATIVE_INFINITY; + double lower = Double.POSITIVE_INFINITY; + int count = getItemCount(); + + for (int i = 0; i < count; i++) { + CompactXYItems items = getItem(i); + double minX = items.getMinX(); + double maxX = items.getMaxX(); + + if (!Double.isNaN(minX)) { + lower = Math.min(lower, minX); + } + + if (!Double.isNaN(maxX)) { + upper = Math.max(upper, maxX); + } + } + + if (lower > upper) { + return null; + } + + return new Range(lower, upper); + } + + + public Range getRangeBounds() { + double upper = Double.NEGATIVE_INFINITY; + double lower = Double.POSITIVE_INFINITY; + int count = getItemCount(); + + for (int i = 0; i < count; i++) { + CompactXYItems items = getItem(i); + double minY = items.getMinY(); + double maxY = items.getMaxY(); + + if (!Double.isNaN(minY)) { + lower = Math.min(lower, minY); + } + + if (!Double.isNaN(maxY)) { + upper = Math.max(upper, maxY); + } + } + + if (lower > upper) { + return null; + } + + return new Range(lower, upper); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :