sascha@422: package de.intevation.gnv.jfreechart; sascha@422: sascha@779: import java.util.HashMap; sascha@422: import java.util.Map; sascha@422: sascha@422: import org.jfree.data.Range; sascha@779: sascha@422: import org.jfree.data.general.Series; sascha@422: sascha@422: /** ingo@795: * This class represents a series of polygon items. ingo@795: * sascha@780: * @author Sascha Teichmann sascha@780: * @author Ingo Weinzierl sascha@422: */ sascha@422: public class PolygonSeries sascha@422: extends Series sascha@422: { ingo@795: /** ingo@795: * Polygons. ingo@795: */ sascha@422: protected CompactXYItems [] rings; ingo@795: ingo@795: /** ingo@795: * A map containing attribues. ingo@795: */ sascha@422: protected Map attributes; sascha@422: ingo@795: /** ingo@795: * The unique key of this series. ingo@795: */ sascha@436: private static long uniqueKey; sascha@436: ingo@795: /** ingo@795: * ingo@795: * @return a unique key. ingo@795: */ sascha@436: protected synchronized static Long createUniqueKey() { sascha@436: return new Long(uniqueKey++); sascha@436: } sascha@436: ingo@795: /** ingo@795: * Constructor to create an empty PolygonSeries with a unique key. ingo@795: */ sascha@436: public PolygonSeries() { sascha@436: this(createUniqueKey(), null); sascha@436: } sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param key The key used for this series. ingo@795: * @param rings Polygons. ingo@795: */ sascha@422: public PolygonSeries(Comparable key, CompactXYItems [] rings) { sascha@422: this(key, null, rings, new HashMap()); sascha@422: } sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param key The key used for this series. ingo@795: * @param description A description of this series. ingo@795: * @param rings Polygons. ingo@795: */ 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: ingo@795: /** ingo@795: * ingo@795: * @param key The key used for this series. ingo@795: * @param description A description of this series. ingo@795: * @param rings Polygons. ingo@795: * @param attributes Some attribues. ingo@795: */ 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: ingo@795: /** ingo@795: * ingo@795: * @param rings ingo@795: */ sascha@422: public void setRings(CompactXYItems [] rings) { sascha@422: this.rings = rings; sascha@422: } sascha@422: ingo@795: /** ingo@795: * ingo@795: * @return ingo@795: */ sascha@422: public CompactXYItems [] getRings() { sascha@422: return rings; sascha@422: } sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param newRing ingo@795: */ sascha@436: public void addRing(CompactXYItems newRing) { sascha@436: if (rings == null) { sascha@436: rings = new CompactXYItems [] { newRing }; sascha@436: } sascha@436: else { sascha@436: CompactXYItems [] nRings = new CompactXYItems[rings.length + 1]; sascha@436: System.arraycopy(rings, 0, nRings, 0, rings.length); sascha@436: nRings[rings.length] = newRing; sascha@436: rings = nRings; sascha@436: } sascha@436: } sascha@436: ingo@795: /** ingo@795: * ingo@795: * @param newRings ingo@795: */ 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: ingo@795: /** ingo@795: * ingo@795: * @param key ingo@795: * @return ingo@795: */ sascha@422: public Object getAttribute(Object key) { sascha@422: return attributes.get(key); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param key ingo@795: * @param value ingo@795: * @return ingo@795: */ sascha@422: public Object setAttribute(Object key, Object value) { sascha@422: return attributes.put(key, value); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @return ingo@795: */ sascha@422: public int getItemCount() { sascha@447: return rings != null ? rings.length : 0; sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param idx ingo@795: * @return ingo@795: */ sascha@422: public CompactXYItems getItem(int idx) { sascha@422: return rings[idx]; sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param key ingo@795: * @return ingo@795: */ sascha@422: public Object removeAttribute(Object key) { sascha@422: return attributes.remove(key); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param key ingo@795: * @return ingo@795: */ sascha@422: public boolean hasAttribute(Object key) { sascha@422: return attributes.containsKey(key); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @return the range of the x axis. ingo@795: */ 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: ingo@795: /** ingo@795: * ingo@795: * @return the range of the y axis. ingo@795: */ 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 :