diff gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.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
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/PolygonDataset.java	Fri Sep 28 12:14:00 2012 +0200
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2010 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+
+package de.intevation.gnv.jfreechart;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jfree.data.Range;
+
+import org.jfree.data.general.AbstractSeriesDataset;
+
+/**
+ * An implementation of {@link org.jfree.data.xy.XYDataset} to create 2D charts.
+ * This dataset contains several <code>PolygonSeries</code> and is used by
+ * <code>PolygonRenderer</code> to draw its items into a 2D chart.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class PolygonDataset
+extends      AbstractSeriesDataset
+{
+    /**
+     * PolygonSeries included in this Dataset
+     */
+    private List data;
+
+
+    /**
+     * Constructor.
+     */
+    public PolygonDataset() {
+        data = new ArrayList();
+    }
+
+    /**
+     * Constructs a new PolygonDataset containing multiple PolygonSeries.
+     *
+     * @param series A collection containing some PolygonSeries.
+     */
+    public PolygonDataset(Collection series) {
+        data = new ArrayList(series);
+    }
+
+    /**
+     * Constructs a PolygonDataset with a single PolygonSeries.
+     *
+     * @param series A PolygonSeries.
+     */
+    public PolygonDataset(PolygonSeries series) {
+        this();
+
+        if (series != null) {
+            data.add(series);
+        }
+    }
+
+
+    /**
+     *
+     * @param series
+     */
+    public void addSeries(PolygonSeries series) {
+        if (series == null)
+            throw new IllegalArgumentException("Null 'series' argument.");
+
+        data.add(series);
+    }
+
+    /**
+     *
+     * @param series
+     */
+    public void addAllSeries(Collection<PolygonSeries> series) {
+        data.addAll(series);
+    }
+
+    /**
+     * Retrieves the x-axis range of all PolygonSeries in this dataset.
+     *
+     * @return range of the x-axis.
+     */
+    public Range getDomainBounds() {
+        double lower       = Double.POSITIVE_INFINITY;
+        double upper       = Double.NEGATIVE_INFINITY;
+        int    seriesCount = getSeriesCount();
+
+        for (int s = 0; s < seriesCount; s++) {
+            PolygonSeries series = getSeries(s);
+
+            Range domainRange = series.getDomainBounds();
+            double minX = domainRange.getLowerBound();
+            if (!Double.isNaN(minX)) {
+                lower = Math.min(lower, minX);
+            }
+
+            double maxX = domainRange.getUpperBound();
+            if (!Double.isNaN(maxX)) {
+                upper = Math.max(upper, maxX);
+            }
+        }
+
+        return new Range(lower, upper);
+    }
+
+
+    /**
+     * Retrieves the y-axis range of all PolygonSeries in this dataset.
+     *
+     * @return the y-axis range.
+     */
+    public Range getRangeBounds() {
+        double lower       = Double.POSITIVE_INFINITY;
+        double upper       = Double.NEGATIVE_INFINITY;
+        int    seriesCount = getSeriesCount();
+
+        for (int i = 0; i < seriesCount; i++) {
+            PolygonSeries series = getSeries(i);
+
+            Range range = series.getRangeBounds();
+            double minX = range.getLowerBound();
+            if (!Double.isNaN(minX)) {
+                lower = Math.min(lower, minX);
+            }
+
+            double maxX = range.getUpperBound();
+            if (!Double.isNaN(maxX)) {
+                upper = Math.max(upper, maxX);
+            }
+        }
+
+        return new Range(lower, upper);
+    }
+
+
+    /**
+     * Returns the number of series in this dataset.
+     *
+     * @return the number of series in this dataset.
+     */
+    public int getSeriesCount() {
+        return data.size();
+    }
+
+
+    /**
+     * Returns the key for a series.
+     *
+     * @param index Index of a specific series.
+     * @return the series key of the series with the given index.
+     */
+    public Comparable getSeriesKey(int index) {
+        return ((PolygonSeries)data.get(index)).getKey();
+    }
+
+
+    /**
+     *
+     * @param idx Index.
+     * @return the series with the given index.
+     */
+    public PolygonSeries getSeries(int idx) {
+        return (PolygonSeries)data.get(idx);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org