Mercurial > dive4elements > gnv-client
changeset 795:cdade5005cba
Added javadoc in jfreechart package.
gnv-artifacts/trunk@877 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 31 Mar 2010 13:48:07 +0000 |
parents | d0967fdee36f |
children | a5526908f92f |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/CompactXYItems.java gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/LevelOrderIndices.java gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeriesLabelGenerator.java |
diffstat | 8 files changed, 524 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/ChangeLog Wed Mar 31 13:48:07 2010 +0000 @@ -1,3 +1,14 @@ +2010-03-31 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/jfreechart/LevelOrderIndices.java, + src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java, + src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java, + src/main/java/de/intevation/gnv/jfreechart/CompactXYItems.java, + src/main/java/de/intevation/gnv/jfreechart/PolygonSeriesLabelGenerator.java, + src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java, + src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java: Added + JavaDoc. + 2010-03-31 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/exports/Export.java,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/CompactXYItems.java Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/CompactXYItems.java Wed Mar 31 13:48:07 2010 +0000 @@ -3,43 +3,93 @@ import java.io.Serializable; /** + * This class is used to represent geometries (e.g. point, line, polygon). Each + * geometry is made up of multiple xy points stored in a single array. A line + * composed by start- and endpoint is stored in the following order in that + * array: [x1, y1, x2, y2]. + * * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha Teichmann</a> * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class CompactXYItems implements Serializable { + /** + * Array storing the xy items. + */ protected double [] data; + /** + * Constructs a new CompactXYItems object with the given data. + * + * @param data An array with xy values. + */ public CompactXYItems(double [] data) { this.data = data; } + /** + * Retrieves the x coordinate of the point with the given index. + * + * @param index Index + * @return X coordinate. + */ public double getX(int index) { return data[index << 1]; } + /** + * Retrieves the y coordinate of the point with the given index. + * + * @param index Index + * @return Y coordinate. + */ public double getY(int index) { return data[(index << 1)+1]; } + /** + * Write the tupel of xy-values at a specific index into the given array. + * + * @param index Index used to specify the xy-value. + * @param xy the xy coordinate is written into this array with the following + * order: [x,y] + */ public void get(int index, double [] xy) { xy[0] = data[index = (index << 1) + 1]; xy[1] = data[index + 1]; } + /** + * + * @return the data array. + */ public double [] getData() { return data; } + /** + * + * @param data + */ public void setData(double [] data) { this.data = data; } + /** + * + * @return + */ public int size() { return data.length >> 1; } + /** + * Retrieves the bounding box spaned by the coordinates in the data array. + * + * @param bbox + * @return + */ public double [] calculateBoundingBox(double [] bbox) { for (int i = 0; i < data.length;) { double x = data[i++]; @@ -52,6 +102,11 @@ return bbox; } + /** + * + * @return the coordinates as string. + */ + @Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.length;) { @@ -66,6 +121,10 @@ } + /** + * + * @return the lowest x value. + */ public double getMinX() { double lower = Double.POSITIVE_INFINITY; @@ -81,6 +140,10 @@ } + /** + * + * @return the highest x value. + */ public double getMaxX() { double upper = Double.NEGATIVE_INFINITY; @@ -96,6 +159,10 @@ } + /** + * + * @return the lowest y value. + */ public double getMinY() { double lower = Double.POSITIVE_INFINITY; @@ -111,6 +178,10 @@ } + /** + * + * @return the highest y value. + */ public double getMaxY() { double upper = Double.NEGATIVE_INFINITY; @@ -125,4 +196,4 @@ return upper; } } -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : \ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/LevelOrderIndices.java Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/LevelOrderIndices.java Wed Mar 31 13:48:07 2010 +0000 @@ -7,25 +7,56 @@ */ public class LevelOrderIndices { + /** + * + */ public interface Visitor { + /** + * + * @param index + * @return + */ Object visit(int index); } + /** + * + */ protected int from; + /** + * + */ protected int to; + /** + * + */ public LevelOrderIndices() { } + /** + * + * @param to + */ public LevelOrderIndices(int to) { this(0, to); } + /** + * + * @param from + * @param to + */ public LevelOrderIndices(int from, int to) { this.from = Math.min(from, to); this.to = Math.max(from, to); } + /** + * + * @param visitor + * @return + */ public Object visit(Visitor visitor) { LinkedList<int[]> queue = new LinkedList<int[]>();
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java Wed Mar 31 13:48:07 2010 +0000 @@ -9,23 +9,42 @@ 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 */ + /** + * 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(); @@ -35,6 +54,10 @@ } + /** + * + * @param series + */ public void addSeries(PolygonSeries series) { if (series == null) throw new IllegalArgumentException("Null 'series' argument."); @@ -42,10 +65,19 @@ 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; @@ -70,6 +102,11 @@ } + /** + * 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; @@ -94,18 +131,34 @@ } + /** + * Returns the number of series in this dataset. + * + * @return the number of series in this dataset. + */ public int getSeriesCount() { return data.size(); } - public Comparable getSeriesKey(int series) { - return ((PolygonSeries)data.get(series)).getKey(); + /** + * 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 : +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : \ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java Wed Mar 31 13:48:07 2010 +0000 @@ -32,14 +32,23 @@ import org.jfree.util.ObjectList; /** + * A class for plotting polygons into a 2D chart. This plot makes use of <code> + * PolygonRenderer</code>. + * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ // TODO implement cloneable public class PolygonPlot extends Plot { + /** + * + */ public static final String PLOT_TYPE = "PolygonPlot"; + /** + * + */ public static final PlotOrientation DEFAULT_PLOT_ORIENTATION = PlotOrientation.VERTICAL; @@ -56,11 +65,23 @@ private ObjectList rangeAxes; + /** + * Constructs a new PolygonPlot with a dataset and a renderer. + * + * @param dataset Dataset containing polygons. + * @param renderer The renderer used to draw polygons. + */ public PolygonPlot(PolygonDataset dataset, PolygonRenderer renderer) { this(dataset, renderer, null, null, PlotOrientation.HORIZONTAL); } + /** + * + * @param dataset Dataset containing polygons. + * @param renderer The renderer used to draw polygons. + * @param orientation The orientation used for this plot. + */ public PolygonPlot( PolygonDataset dataset, PolygonRenderer renderer, @@ -70,6 +91,14 @@ } + /** + * + * @param dataset Dataset containing polygons. + * @param renderer The renderer used to draw polygons. + * @param domainAxis The x axis. + * @param rangeAxis The y axis. + * @param orientation The orientation used for this plot. + */ public PolygonPlot( PolygonDataset dataset, PolygonRenderer renderer, @@ -109,6 +138,9 @@ } + /** + * + */ public void configureDomainAxis() { // we just have 1 dataset Range domainAxisRange = getDataset().getDomainBounds(); @@ -123,26 +155,47 @@ } } + /** + * + * @return + */ public ValueAxis getDomainAxis() { return getDomainAxis(0); } + /** + * + * @param index + * @return + */ public ValueAxis getDomainAxis(int index) { return index < domainAxes.size() ? (ValueAxis)domainAxes.get(index) : null; } + /** + * + * @return + */ public ValueAxis getRangeAxis() { return getRangeAxis(0); } + /** + * + * @param index + * @return + */ public ValueAxis getRangeAxis(int index) { return index < rangeAxes.size() ? (ValueAxis)rangeAxes.get(index) : null; } + /** + * + */ public void configureRangeAxis() { // we just have 1 dataset Range rangeAxisRange = getDataset().getRangeBounds(); @@ -158,21 +211,42 @@ } + /** + * + * @return + */ public PolygonDataset getDataset(){ return this.dataset; } + /** + * + * @return + */ public String getPlotType() { return PLOT_TYPE; } + /** + * + * @param dataset + */ public void setDataset(PolygonDataset dataset) { this.dataset = dataset; } + /** + * This is the major method to draw the into a given Graphic2D object. + * + * @param g2 Graphics object where the plot is drawn into. + * @param area The bounds for drawing this plot. + * @param anchor An anchor point. + * @param parentState The plot state. + * @param info + */ public void draw( Graphics2D g2, Rectangle2D area, @@ -218,6 +292,14 @@ } + /** + * Method to draw the axis for this plot. + * + * @param g2 + * @param plotArea + * @param dataArea + * @param plotState + */ private void drawAxes( Graphics2D g2, Rectangle2D plotArea, @@ -290,6 +372,14 @@ } + /** + * Put some labels at data items into the plot. Uses PolygonRenderer to do + * this job. + * + * @param g2 + * @param area + * @param info + */ private void drawLabels( Graphics2D g2, Rectangle2D area, @@ -298,6 +388,14 @@ renderer.drawLabels(g2, this, area, dataset); } + + /** + * Plot the polygons. Uses PolygonRenderer to do this job. + * + * @param g2 + * @param area + * @param info + */ private void drawPolygons( Graphics2D g2, Rectangle2D area, @@ -307,6 +405,12 @@ } + /** + * + * @param g2 + * @param plotArea + * @return + */ private AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); space = calculateRangeAxisSpace(g2, plotArea, space); @@ -317,6 +421,13 @@ } + /** + * + * @param g2 + * @param plotArea + * @param space + * @return + */ private AxisSpace calculateDomainAxisSpace( Graphics2D g2, Rectangle2D plotArea, @@ -338,6 +449,13 @@ } + /** + * + * @param g2 + * @param plotArea + * @param space + * @return + */ private AxisSpace calculateRangeAxisSpace( Graphics2D g2, Rectangle2D plotArea, @@ -358,6 +476,11 @@ return space; } + + /** + * + * @return + */ public RectangleEdge getDomainAxisEdge() { return Plot.resolveDomainAxisLocation( getDomainAxisLocation(), orientation @@ -365,6 +488,11 @@ } + /** + * + * @param idx + * @return + */ public RectangleEdge getDomainAxisEdge(int idx) { AxisLocation location = getDomainAxisLocation(idx); RectangleEdge result = Plot.resolveDomainAxisLocation( @@ -378,6 +506,10 @@ } + /** + * + * @return + */ public RectangleEdge getRangeAxisEdge() { return Plot.resolveRangeAxisLocation( getRangeAxisLocation(), orientation @@ -385,6 +517,11 @@ } + /** + * + * @param idx + * @return + */ public RectangleEdge getRangeAxisEdge(int idx) { AxisLocation location = getRangeAxisLocation(idx); RectangleEdge result = Plot.resolveRangeAxisLocation( @@ -399,11 +536,20 @@ } + /** + * + * @return + */ public AxisLocation getDomainAxisLocation() { return (AxisLocation) domainAxisLocation.get(0); } + /** + * + * @param idx + * @return + */ public AxisLocation getDomainAxisLocation(int idx) { if (idx < domainAxisLocation.size()) return (AxisLocation) domainAxisLocation.get(idx); @@ -412,11 +558,20 @@ } + /** + * + * @return + */ public AxisLocation getRangeAxisLocation() { return (AxisLocation) rangeAxisLocation.get(0); } + /** + * + * @param idx + * @return + */ public AxisLocation getRangeAxisLocation(int idx) { if (idx < rangeAxisLocation.size()) return (AxisLocation) rangeAxisLocation.get(idx); @@ -425,6 +580,12 @@ } + /** + * + * @param dataset + * @return true, if dataset is null or if it does not contain any + * PolygonSeries, otherwise false. + */ private boolean isEmptyOrNull(PolygonDataset dataset) { if (dataset != null) { int seriesCount = dataset.getSeriesCount(); @@ -438,3 +599,4 @@ return true; } } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : \ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java Wed Mar 31 13:48:07 2010 +0000 @@ -27,6 +27,8 @@ import org.jfree.ui.RectangleEdge; /** + * This renderer is used to draw polygons into a Graphics object. + * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> */ @@ -35,40 +37,83 @@ private static Logger log = Logger.getLogger( PolygonRenderer.class); - public interface PaintLookup { + /** + * This interfaces describes a single method to retrieve a Paint object + * for a given index. + */ + public interface PaintLookup { - Paint getPaint(int index); + /** + * + * @param index Index. + * @return Paint + */ + Paint getPaint(int index); } // interface PaintLookup - public static class DefaultLabelGenerator + /** + * This class is used to generate labels for a given series. + */ + public static class DefaultLabelGenerator implements PolygonSeriesLabelGenerator { - public DefaultLabelGenerator() { + /** + * Construts an empty DefaultLabelGenerator. + */ + public DefaultLabelGenerator() { } - public String generateLabel(PolygonSeries series) { + /** + * + * @param series A PolygonSeries. + * @return The label of series. + */ + public String generateLabel(PolygonSeries series) { Object label = series.getAttribute("label"); return label != null ? toString(label) : null; } - protected String toString(Object label) { + /** + * + * @param label Object + * @return String representaton of label. + */ + protected String toString(Object label) { return label.toString(); } } // class DefaultLabelGenerator - public static final PolygonSeriesLabelGenerator + /** + * Constructor. + */ + public static final PolygonSeriesLabelGenerator DEFAULT_LABEL_GENERATOR_INSTANCE = new DefaultLabelGenerator(); - protected PaintLookup lookup; + /** + * + */ + protected PaintLookup lookup; + /** + * + */ protected PolygonSeriesLabelGenerator labelGenerator; + /** + * + * @param lookup + */ public PolygonRenderer(PaintLookup lookup) { this(lookup, null); } + /** + * + * @param lookup + * @param labelGenerator + */ public PolygonRenderer( PaintLookup lookup, PolygonSeriesLabelGenerator labelGenerator @@ -77,6 +122,16 @@ this.labelGenerator = labelGenerator; } + /** + * This method draws polygons of each series in <code>dataset</code> into + * the given graphics object. If a polygon has no attribute 'fill', we + * expect that it is a line, otherwise the polygon is filled. + * + * @param graphics + * @param plot + * @param area + * @param dataset + */ public void drawPolygons( Graphics2D graphics, PolygonPlot plot, @@ -104,6 +159,15 @@ } } + /** + * Draw labels at each item of a series in the given dataset. If the series + * has no label attritue, no label is drawn. + * + * @param graphics + * @param plot + * @param area + * @param dataset + */ public void drawLabels( final Graphics2D graphics, final PolygonPlot plot, @@ -169,6 +233,16 @@ } // for all series } + /** + * Creates a shape made up of the CompactXYItems object stored in the given + * series. + * + * @param plot The plot. + * @param area The boundary. + * @param series The series storing the items. + * @param close Specifies if the polygon should be closed or not. + * @return + */ protected Shape constructShape( PolygonPlot plot, Rectangle2D area, @@ -206,6 +280,12 @@ return path; } + /** + * Retrieves the bounding box of a dataset. + * + * @param dataset + * @return + */ public Rectangle2D getBoundingBox(PolygonDataset dataset) { Rectangle2D bbox = null; @@ -229,6 +309,11 @@ return bbox; } + /** + * + * @param series + * @return the bounds of a series. + */ public Rectangle2D getBounds(PolygonSeries series) { Range domain = series.getDomainBounds();
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeries.java Wed Mar 31 13:48:07 2010 +0000 @@ -8,29 +8,59 @@ import org.jfree.data.general.Series; /** + * This class represents a series of polygon items. + * * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha Teichmann</a> * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class PolygonSeries extends Series { + /** + * Polygons. + */ protected CompactXYItems [] rings; + + /** + * A map containing attribues. + */ protected Map attributes; + /** + * The unique key of this series. + */ private static long uniqueKey; + /** + * + * @return a unique key. + */ protected synchronized static Long createUniqueKey() { return new Long(uniqueKey++); } + /** + * Constructor to create an empty PolygonSeries with a unique key. + */ public PolygonSeries() { this(createUniqueKey(), null); } + /** + * + * @param key The key used for this series. + * @param rings Polygons. + */ public PolygonSeries(Comparable key, CompactXYItems [] rings) { this(key, null, rings, new HashMap()); } + /** + * + * @param key The key used for this series. + * @param description A description of this series. + * @param rings Polygons. + */ public PolygonSeries( Comparable key, String description, @@ -39,6 +69,13 @@ this(key, description, rings, new HashMap()); } + /** + * + * @param key The key used for this series. + * @param description A description of this series. + * @param rings Polygons. + * @param attributes Some attribues. + */ public PolygonSeries( Comparable key, String description, @@ -51,14 +88,26 @@ } + /** + * + * @param rings + */ public void setRings(CompactXYItems [] rings) { this.rings = rings; } + /** + * + * @return + */ public CompactXYItems [] getRings() { return rings; } + /** + * + * @param newRing + */ public void addRing(CompactXYItems newRing) { if (rings == null) { rings = new CompactXYItems [] { newRing }; @@ -71,6 +120,10 @@ } } + /** + * + * @param newRings + */ public void addRings(CompactXYItems [] newRings) { if (newRings == null || newRings.length == 0) { return; @@ -87,36 +140,70 @@ } } + /** + * + * @param key + * @return + */ public Object getAttribute(Object key) { return attributes.get(key); } + /** + * + * @param key + * @param value + * @return + */ public Object setAttribute(Object key, Object value) { return attributes.put(key, value); } + /** + * + * @return + */ public int getItemCount() { return rings != null ? rings.length : 0; } + /** + * + * @param idx + * @return + */ public CompactXYItems getItem(int idx) { return rings[idx]; } + /** + * + * @param key + * @return + */ public Object removeAttribute(Object key) { return attributes.remove(key); } + /** + * + * @param key + * @return + */ public boolean hasAttribute(Object key) { return attributes.containsKey(key); } + /** + * + * @return the range of the x axis. + */ public Range getDomainBounds() { double upper = Double.NEGATIVE_INFINITY; double lower = Double.POSITIVE_INFINITY; @@ -144,6 +231,10 @@ } + /** + * + * @return the range of the y axis. + */ public Range getRangeBounds() { double upper = Double.NEGATIVE_INFINITY; double lower = Double.POSITIVE_INFINITY;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeriesLabelGenerator.java Wed Mar 31 12:18:03 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonSeriesLabelGenerator.java Wed Mar 31 13:48:07 2010 +0000 @@ -1,10 +1,17 @@ package de.intevation.gnv.jfreechart; /** + * This interface describes a single method generating labels by given Series. + * * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> */ public interface PolygonSeriesLabelGenerator { + /** + * + * @param series The given series. + * @return A label for this series. + */ String generateLabel(PolygonSeries series); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :