📄 standardxyitemrenderer.java
字号:
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------------------
* StandardXYItemRenderer.java
* ---------------------------
* (C) Copyright 2001-2004, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Mark Watson (www.markwatson.com);
* Jonathan Nash;
* Andreas Schneider;
* Norbert Kiesel (for TBD Networks);
* Christian W. Zuckschwerdt;
* Bill Kelemen;
* Nicolas Brodu (for Astrium and EADS Corporate Research Center);
*
* $Id: StandardXYItemRenderer.java,v 1.1 2004/08/31 14:49:29 mungady Exp $
*
* Changes:
* --------
* 19-Oct-2001 : Version 1, based on code by Mark Watson (DG);
* 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG);
* 21-Dec-2001 : Added working line instance to improve performance (DG);
* 22-Jan-2002 : Added code to lock crosshairs to data points. Based on code by Jonathan Nash (DG);
* 23-Jan-2002 : Added DrawInfo parameter to drawItem(...) method (DG);
* 28-Mar-2002 : Added a property change listener mechanism so that the renderer no longer needs to
* be immutable (DG);
* 02-Apr-2002 : Modified to handle null values (DG);
* 09-Apr-2002 : Modified draw method to return void. Removed the translated zero from the
* drawItem method. Override the initialise() method to calculate it (DG);
* 13-May-2002 : Added code from Andreas Schneider to allow changing shapes/colors per item (DG);
* 24-May-2002 : Incorporated tooltips into chart entities (DG);
* 25-Jun-2002 : Removed redundant code (DG);
* 05-Aug-2002 : Incorporated URLs for HTML image maps into chart entities (RA);
* 08-Aug-2002 : Added discontinuous lines option contributed by Norbert Kiesel (DG);
* 20-Aug-2002 : Added user definable default values to be returned by protected methods unless
* overridden by a subclass (DG);
* 23-Sep-2002 : Updated for changes in the XYItemRenderer interface (DG);
* 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 25-Mar-2003 : Implemented Serializable (DG);
* 01-May-2003 : Modified drawItem(...) method signature (DG);
* 15-May-2003 : Modified to take into account the plot orientation (DG);
* 29-Jul-2003 : Amended code that doesn't compile with JDK 1.2.2 (DG);
* 30-Jul-2003 : Modified entity constructor (CZ);
* 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
* 24-Aug-2003 : Added null/NaN checks in drawItem (BK);
* 08-Sep-2003 : Fixed serialization (NB);
* 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
* 21-Jan-2004 : Override for getLegendItem() method (DG);
* 27-Jan-2004 : Moved working line into state object (DG);
* 10-Feb-2004 : Changed drawItem() method to make cut-and-paste overriding easier (DG);
* 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState. Renamed XYToolTipGenerator
* --> XYItemLabelGenerator (DG);
* 08-Jun-2004 : Modified to use getX() and getY() methods (DG);
* 15-Jul-2004 : Switched getX() with getXValue() and getY() with getYValue() (DG);
* 25-Aug-2004 : Created addEntity() method in superclass (DG);
*
*/
package org.jfree.chart.renderer.xy;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Point;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import org.jfree.chart.LegendItem;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.event.RendererChangeEvent;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.chart.plot.CrosshairState;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.RectangleEdge;
import org.jfree.util.BooleanList;
import org.jfree.util.ObjectUtils;
import org.jfree.util.PublicCloneable;
/**
* Standard item renderer for an {@link XYPlot}. This class can draw (a) shapes at
* each point, or (b) lines between points, or (c) both shapes and lines.
*/
public class StandardXYItemRenderer extends AbstractXYItemRenderer
implements XYItemRenderer,
Cloneable,
PublicCloneable,
Serializable {
/** Constant for the type of rendering (shapes only). */
public static final int SHAPES = 1;
/** Constant for the type of rendering (lines only). */
public static final int LINES = 2;
/** Constant for the type of rendering (shapes and lines). */
public static final int SHAPES_AND_LINES = SHAPES | LINES;
/** Constant for the type of rendering (images only). */
public static final int IMAGES = 4;
/** Constant for the type of rendering (discontinuous lines). */
public static final int DISCONTINUOUS = 8;
/** Constant for the type of rendering (discontinuous lines). */
public static final int DISCONTINUOUS_LINES = LINES | DISCONTINUOUS;
/** A flag indicating whether or not shapes are drawn at each XY point. */
private boolean plotShapes;
/** A flag indicating whether or not lines are drawn between XY points. */
private boolean plotLines;
/** A flag indicating whether or not images are drawn between XY points. */
private boolean plotImages;
/** A flag controlling whether or not discontinuous lines are used. */
private boolean plotDiscontinuous;
/** Threshold for deciding when to discontinue a line. */
private double gapThreshold = 1.0;
/** A flag that controls whether or not shapes are filled for ALL series. */
private Boolean shapesFilled;
/** A table of flags that control (per series) whether or not shapes are filled. */
private BooleanList seriesShapesFilled;
/** The default value returned by the getShapeFilled(...) method. */
private Boolean defaultShapesFilled;
/**
* Constructs a new renderer.
*/
public StandardXYItemRenderer() {
this(LINES, null);
}
/**
* Constructs a new renderer.
* <p>
* To specify the type of renderer, use one of the constants: SHAPES, LINES
* or SHAPES_AND_LINES.
*
* @param type the type.
*/
public StandardXYItemRenderer(int type) {
this(type, null);
}
/**
* Constructs a new renderer.
* <p>
* To specify the type of renderer, use one of the constants: SHAPES, LINES
* or SHAPES_AND_LINES.
*
* @param type the type of renderer.
* @param toolTipGenerator the item label generator (<code>null</code> permitted).
*/
public StandardXYItemRenderer(int type, XYToolTipGenerator toolTipGenerator) {
this(type, toolTipGenerator, null);
}
/**
* Constructs a new renderer.
* <p>
* To specify the type of renderer, use one of the constants: SHAPES, LINES or SHAPES_AND_LINES.
*
* @param type the type of renderer.
* @param toolTipGenerator the item label generator (<code>null</code> permitted).
* @param urlGenerator the URL generator.
*/
public StandardXYItemRenderer(int type,
XYToolTipGenerator toolTipGenerator,
XYURLGenerator urlGenerator) {
super();
setToolTipGenerator(toolTipGenerator);
setURLGenerator(urlGenerator);
if ((type & SHAPES) != 0) {
this.plotShapes = true;
}
if ((type & LINES) != 0) {
this.plotLines = true;
}
if ((type & IMAGES) != 0) {
this.plotImages = true;
}
if ((type & DISCONTINUOUS) != 0) {
this.plotDiscontinuous = true;
}
//this.line = new Line2D.Double(0.0, 0.0, 0.0, 0.0);
this.shapesFilled = null;
this.seriesShapesFilled = new BooleanList();
this.defaultShapesFilled = Boolean.TRUE;
}
/**
* Returns true if shapes are being plotted by the renderer.
*
* @return <code>true</code> if shapes are being plotted by the renderer.
*/
public boolean getPlotShapes() {
return this.plotShapes;
}
/**
* Sets the flag that controls whether or not a shape is plotted at each data point.
*
* @param flag the flag.
*/
public void setPlotShapes(boolean flag) {
if (this.plotShapes != flag) {
this.plotShapes = flag;
notifyListeners(new RendererChangeEvent(this));
}
}
// SHAPES FILLED
/**
* Returns the flag used to control whether or not the shape for an item is filled.
* <p>
* The default implementation passes control to the <code>getSeriesShapesFilled</code> method.
* You can override this method if you require different behaviour.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return A boolean.
*/
public boolean getItemShapeFilled(int series, int item) {
return getSeriesShapesFilled(series);
}
/**
* Returns the flag used to control whether or not the shapes for a series are filled.
*
* @param series the series index (zero-based).
*
* @return A boolean.
*/
public boolean getSeriesShapesFilled(int series) {
// return the overall setting, if there is one...
if (this.shapesFilled != null) {
return this.shapesFilled.booleanValue();
}
// otherwise look up the paint table
Boolean flag = this.seriesShapesFilled.getBoolean(series);
if (flag != null) {
return flag.booleanValue();
}
else {
return this.defaultShapesFilled.booleanValue();
}
}
/**
* Sets the 'shapes filled' for ALL series.
*
* @param filled the flag.
*/
public void setShapesFilled(boolean filled) {
if (filled) {
setShapesFilled(Boolean.TRUE);
}
else {
setShapesFilled(Boolean.FALSE);
}
//setShapesFilled(Boolean.valueOf(filled));
}
/**
* Sets the 'shapes filled' for ALL series.
*
* @param filled the flag (<code>null</code> permitted).
*/
public void setShapesFilled(Boolean filled) {
this.shapesFilled = filled;
}
/**
* Sets the 'shapes filled' flag for a series.
*
* @param series the series index (zero-based).
* @param flag the flag.
*/
public void setSeriesShapesFilled(int series, Boolean flag) {
this.seriesShapesFilled.setBoolean(series, flag);
}
/**
* Returns the default 'shape filled' attribute.
*
* @return The default flag.
*/
public Boolean getDefaultShapesFilled() {
return this.defaultShapesFilled;
}
/**
* Sets the default 'shapes filled' flag.
*
* @param flag the flag.
*/
public void setDefaultShapesFilled(Boolean flag) {
this.defaultShapesFilled = flag;
}
/**
* Returns true if lines are being plotted by the renderer.
*
* @return <code>true</code> if lines are being plotted by the renderer.
*/
public boolean getPlotLines() {
return this.plotLines;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -