Skip to content

Commit

Permalink
Add some generics and clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfree committed Feb 9, 2018
1 parent d98a34c commit a4dcd4e
Showing 1 changed file with 18 additions and 24 deletions.
Expand Up @@ -2,7 +2,7 @@
* JFreeChart : a free chart library for the Java(tm) platform * JFreeChart : a free chart library for the Java(tm) platform
* =========================================================== * ===========================================================
* *
* (C) Copyright 2000-2017, by Object Refinery Limited and Contributors. * (C) Copyright 2000-2018, by Object Refinery Limited and Contributors.
* *
* Project Info: http://www.jfree.org/jfreechart/index.html * Project Info: http://www.jfree.org/jfreechart/index.html
* *
Expand All @@ -27,7 +27,7 @@
* --------------------------- * ---------------------------
* AbstractXYItemRenderer.java * AbstractXYItemRenderer.java
* --------------------------- * ---------------------------
* (C) Copyright 2002-2017, by Object Refinery Limited and Contributors. * (C) Copyright 2002-2018, by Object Refinery Limited and Contributors.
* *
* Original Author: David Gilbert (for Object Refinery Limited); * Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Richard Atkinson; * Contributor(s): Richard Atkinson;
Expand Down Expand Up @@ -147,7 +147,6 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


Expand All @@ -170,7 +169,6 @@
import org.jfree.chart.plot.DrawingSupplier; import org.jfree.chart.plot.DrawingSupplier;
import org.jfree.chart.plot.IntervalMarker; import org.jfree.chart.plot.IntervalMarker;
import org.jfree.chart.plot.Marker; import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.ValueMarker; import org.jfree.chart.plot.ValueMarker;
Expand Down Expand Up @@ -225,13 +223,13 @@ public abstract class AbstractXYItemRenderer extends AbstractRenderer
* Annotations to be drawn in the background layer ('underneath' the data * Annotations to be drawn in the background layer ('underneath' the data
* items). * items).
*/ */
private List backgroundAnnotations; private List<XYAnnotation> backgroundAnnotations;


/** /**
* Annotations to be drawn in the foreground layer ('on top' of the data * Annotations to be drawn in the foreground layer ('on top' of the data
* items). * items).
*/ */
private List foregroundAnnotations; private List<XYAnnotation> foregroundAnnotations;


/** The legend item label generator. */ /** The legend item label generator. */
private XYSeriesLabelGenerator legendItemLabelGenerator; private XYSeriesLabelGenerator legendItemLabelGenerator;
Expand All @@ -252,8 +250,8 @@ protected AbstractXYItemRenderer() {
= new HashMap<Integer, XYItemLabelGenerator>(); = new HashMap<Integer, XYItemLabelGenerator>();
this.toolTipGeneratorMap = new HashMap<Integer, XYToolTipGenerator>(); this.toolTipGeneratorMap = new HashMap<Integer, XYToolTipGenerator>();
this.urlGenerator = null; this.urlGenerator = null;
this.backgroundAnnotations = new java.util.ArrayList(); this.backgroundAnnotations = new ArrayList<XYAnnotation>();
this.foregroundAnnotations = new java.util.ArrayList(); this.foregroundAnnotations = new ArrayList<XYAnnotation>();
this.legendItemLabelGenerator = new StandardXYSeriesLabelGenerator( this.legendItemLabelGenerator = new StandardXYSeriesLabelGenerator(
"{0}"); "{0}");
} }
Expand Down Expand Up @@ -466,8 +464,8 @@ public XYToolTipGenerator getDefaultToolTipGenerator() {
} }


/** /**
* Sets the default tool tip generator and sends a {@link RendererChangeEvent} * Sets the default tool tip generator and sends a
* to all registered listeners. * {@link RendererChangeEvent} to all registered listeners.
* *
* @param generator the generator ({@code null} permitted). * @param generator the generator ({@code null} permitted).
* *
Expand Down Expand Up @@ -566,14 +564,10 @@ public boolean removeAnnotation(XYAnnotation annotation) {
*/ */
@Override @Override
public void removeAnnotations() { public void removeAnnotations() {
for(int i = 0; i < this.foregroundAnnotations.size(); i++){ for (XYAnnotation annotation : this.foregroundAnnotations) {
XYAnnotation annotation
= (XYAnnotation) this.foregroundAnnotations.get(i);
annotation.removeChangeListener(this); annotation.removeChangeListener(this);
} }
for(int i = 0; i < this.backgroundAnnotations.size(); i++){ for (XYAnnotation annotation : this.backgroundAnnotations) {
XYAnnotation annotation
= (XYAnnotation) this.backgroundAnnotations.get(i);
annotation.removeChangeListener(this); annotation.removeChangeListener(this);
} }
this.foregroundAnnotations.clear(); this.foregroundAnnotations.clear();
Expand Down Expand Up @@ -604,8 +598,9 @@ public void annotationChanged(AnnotationChangeEvent event) {
* *
* @since 1.0.13 * @since 1.0.13
*/ */
public Collection getAnnotations() { public Collection<XYAnnotation> getAnnotations() {
List result = new java.util.ArrayList(this.foregroundAnnotations); List<XYAnnotation> result
= new ArrayList<XYAnnotation>(this.foregroundAnnotations);
result.addAll(this.backgroundAnnotations); result.addAll(this.backgroundAnnotations);
return result; return result;
} }
Expand Down Expand Up @@ -1670,20 +1665,19 @@ public void drawAnnotations(Graphics2D g2, Rectangle2D dataArea,
ValueAxis domainAxis, ValueAxis rangeAxis, Layer layer, ValueAxis domainAxis, ValueAxis rangeAxis, Layer layer,
PlotRenderingInfo info) { PlotRenderingInfo info) {


Iterator iterator = null; List<XYAnnotation> toDraw = new ArrayList<XYAnnotation>();
if (layer.equals(Layer.FOREGROUND)) { if (layer.equals(Layer.FOREGROUND)) {
iterator = this.foregroundAnnotations.iterator(); toDraw.addAll(this.foregroundAnnotations);
} }
else if (layer.equals(Layer.BACKGROUND)) { else if (layer.equals(Layer.BACKGROUND)) {
iterator = this.backgroundAnnotations.iterator(); toDraw.addAll(this.backgroundAnnotations);
} }
else { else {
// should not get here // should not get here
throw new RuntimeException("Unknown layer."); throw new RuntimeException("Unknown layer.");
} }
while (iterator.hasNext()) { int index = this.plot.getIndexOf(this);
XYAnnotation annotation = (XYAnnotation) iterator.next(); for (XYAnnotation annotation : toDraw) {
int index = this.plot.getIndexOf(this);
annotation.draw(g2, this.plot, dataArea, domainAxis, rangeAxis, annotation.draw(g2, this.plot, dataArea, domainAxis, rangeAxis,
index, info); index, info);
} }
Expand Down

0 comments on commit a4dcd4e

Please sign in to comment.