sascha@422: package de.intevation.gnv.jfreechart; sascha@422: sascha@422: import java.util.Map; sascha@422: import java.util.HashMap; sascha@422: sascha@422: import org.jfree.data.Range; sascha@422: import org.jfree.data.general.Series; sascha@422: sascha@422: /** sascha@422: * @author Sascha Teichmann sascha@422: * @author Ingo Weinzierl sascha@422: */ sascha@422: public class PolygonSeries sascha@422: extends Series sascha@422: { sascha@422: protected CompactXYItems [] rings; sascha@422: protected Map attributes; sascha@422: sascha@422: sascha@422: public PolygonSeries(Comparable key, CompactXYItems [] rings) { sascha@422: this(key, null, rings, new HashMap()); sascha@422: } sascha@422: sascha@422: public PolygonSeries( sascha@422: Comparable key, sascha@422: String description, sascha@422: CompactXYItems[] rings sascha@422: ) { sascha@422: this(key, description, rings, new HashMap()); sascha@422: } sascha@422: sascha@422: public PolygonSeries( sascha@422: Comparable key, sascha@422: String description, sascha@422: CompactXYItems [] rings, sascha@422: Map attributes sascha@422: ) { sascha@422: super(key, description); sascha@422: this.rings = rings; sascha@422: this.attributes = attributes; sascha@422: } sascha@422: sascha@422: sascha@422: public void setRings(CompactXYItems [] rings) { sascha@422: this.rings = rings; sascha@422: } sascha@422: sascha@422: public CompactXYItems [] getRings() { sascha@422: return rings; sascha@422: } sascha@422: sascha@422: public void addRings(CompactXYItems [] newRings) { sascha@422: if (newRings == null || newRings.length == 0) { sascha@422: return; sascha@422: } sascha@422: if (rings == null || rings.length == 0) { sascha@422: rings = newRings; sascha@422: } sascha@422: else { sascha@422: CompactXYItems [] both = sascha@422: new CompactXYItems[rings.length + newRings.length]; sascha@422: System.arraycopy(rings, 0, both, 0, rings.length); sascha@422: System.arraycopy(newRings, 0, both, rings.length, newRings.length); sascha@422: rings = both; sascha@422: } sascha@422: } sascha@422: sascha@422: public Object getAttribute(Object key) { sascha@422: return attributes.get(key); sascha@422: } sascha@422: sascha@422: sascha@422: public Object setAttribute(Object key, Object value) { sascha@422: return attributes.put(key, value); sascha@422: } sascha@422: sascha@422: sascha@422: public int getItemCount() { sascha@422: return rings.length; sascha@422: } sascha@422: sascha@422: sascha@422: public CompactXYItems getItem(int idx) { sascha@422: return rings[idx]; sascha@422: } sascha@422: sascha@422: sascha@422: public Object removeAttribute(Object key) { sascha@422: return attributes.remove(key); sascha@422: } sascha@422: sascha@422: sascha@422: public boolean hasAttribute(Object key) { sascha@422: return attributes.containsKey(key); sascha@422: } sascha@422: sascha@422: sascha@422: public Range getDomainBounds() { sascha@422: double upper = Double.NEGATIVE_INFINITY; sascha@422: double lower = Double.POSITIVE_INFINITY; sascha@422: int count = getItemCount(); sascha@422: sascha@422: for (int i = 0; i < count; i++) { sascha@422: CompactXYItems items = getItem(i); sascha@422: double minX = items.getMinX(); sascha@422: double maxX = items.getMaxX(); sascha@422: sascha@422: if (!Double.isNaN(minX)) { sascha@422: lower = Math.min(lower, minX); sascha@422: } sascha@422: sascha@422: if (!Double.isNaN(maxX)) { sascha@422: upper = Math.max(upper, maxX); sascha@422: } sascha@422: } sascha@422: sascha@422: if (lower > upper) { sascha@422: return null; sascha@422: } sascha@422: sascha@422: return new Range(lower, upper); sascha@422: } sascha@422: sascha@422: sascha@422: public Range getRangeBounds() { sascha@422: double upper = Double.NEGATIVE_INFINITY; sascha@422: double lower = Double.POSITIVE_INFINITY; sascha@422: int count = getItemCount(); sascha@422: sascha@422: for (int i = 0; i < count; i++) { sascha@422: CompactXYItems items = getItem(i); sascha@422: double minY = items.getMinY(); sascha@422: double maxY = items.getMaxY(); sascha@422: sascha@422: if (!Double.isNaN(minY)) { sascha@422: lower = Math.min(lower, minY); sascha@422: } sascha@422: sascha@422: if (!Double.isNaN(maxY)) { sascha@422: upper = Math.max(upper, maxY); sascha@422: } sascha@422: } sascha@422: sascha@422: if (lower > upper) { sascha@422: return null; sascha@422: } sascha@422: sascha@422: return new Range(lower, upper); sascha@422: } sascha@422: } sascha@422: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :