xyitemrenderer.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,418 行 · 第 1/4 页

JAVA
1,418
字号
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2005, 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.] * * ------------------- * XYItemRenderer.java * ------------------- * (C) Copyright 2001-2005, by Object Refinery Limited and Contributors. * * Original Author:  David Gilbert (for Object Refinery Limited); * Contributor(s):   Mark Watson (www.markwatson.com); *                   Sylvain Vieujot; *                   Focus Computer Services Limited; *                   Richard Atkinson; * * $Id: XYItemRenderer.java,v 1.16 2005/04/20 22:19:10 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); * 13-Dec-2001 : Changed return type of drawItem from void --> Shape.  The area *               returned can be used as the tooltip region. * 23-Jan-2002 : Added DrawInfo parameter to drawItem() method (DG); * 28-Mar-2002 : Added a property change listener mechanism.  Now renderers do  *               not have to be immutable (DG); * 04-Apr-2002 : Added the initialise() method (DG); * 09-Apr-2002 : Removed the translated zero from the drawItem method, it can  *               be calculated inside the initialise method if it is required. *               Added a new getToolTipGenerator() method.  Changed the return  *               type for drawItem() to void (DG); * 24-May-2002 : Added ChartRenderingInfo the initialise method API (DG); * 25-Jun-2002 : Removed redundant import (DG); * 20-Aug-2002 : Added get/setURLGenerator methods to interface (DG); * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 18-Nov-2002 : Added methods for drawing grid lines (DG); * 17-Jan-2003 : Moved plot classes into a separate package (DG); * 27-Jan-2003 : Added shape lookup table (DG); * 05-Jun-2003 : Added domain and range grid bands (sponsored by Focus Computer *               Services Ltd) (DG); * 27-Jul-2003 : Added getRangeType() to support stacked XY area charts (RA); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState.  Renamed  *               XYToolTipGenerator --> XYItemLabelGenerator (DG); * 26-Feb-2004 : Added lots of new methods (DG); * 30-Apr-2004 : Added getRangeExtent() method (DG); * 06-May-2004 : Added methods for controlling item label visibility (DG); * 13-May-2004 : Removed property change listener mechanism (DG); * 18-May-2004 : Added item label font and paint methods (DG); * 10-Sep-2004 : Removed redundant getRangeType() method (DG); * 06-Oct-2004 : Replaced getRangeExtent() with findRangeBounds() and added  *               findDomainBounds (DG); * 23-Nov-2004 : Changed drawRangeGridLine() --> drawRangeLine() (DG); * 07-Jan-2005 : Removed deprecated method (DG); * 24-Feb-2005 : Now extends LegendItemSource (DG); * 20-Apr-2005 : Renamed XYLabelGenerator --> XYItemLabelGenerator (DG); * */package org.jfree.chart.renderer.xy;import java.awt.Font;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Shape;import java.awt.Stroke;import java.awt.geom.Rectangle2D;import org.jfree.chart.LegendItem;import org.jfree.chart.LegendItemSource;import org.jfree.chart.annotations.XYAnnotation;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.event.RendererChangeEvent;import org.jfree.chart.event.RendererChangeListener;import org.jfree.chart.labels.ItemLabelPosition;import org.jfree.chart.labels.XYItemLabelGenerator;import org.jfree.chart.labels.XYToolTipGenerator;import org.jfree.chart.plot.CrosshairState;import org.jfree.chart.plot.Marker;import org.jfree.chart.plot.PlotRenderingInfo;import org.jfree.chart.plot.XYPlot;import org.jfree.chart.urls.XYURLGenerator;import org.jfree.data.Range;import org.jfree.data.xy.XYDataset;import org.jfree.ui.Layer;/** * Interface for rendering the visual representation of a single (x, y) item on * an {@link XYPlot}. * <p> * To support cloning charts, it is recommended that renderers implement both  * the {@link Cloneable} and <code>PublicCloneable</code> interfaces. */public interface XYItemRenderer extends LegendItemSource {    /**     * Initialises the renderer then returns the number of 'passes' through the     * data that the renderer will require (usually just one).  This method      * will be called before the first item is rendered, giving the renderer      * an opportunity to initialise any state information it wants to maintain.     * The renderer can do nothing if it chooses.     *     * @param g2  the graphics device.     * @param dataArea  the area inside the axes.     * @param plot  the plot.     * @param dataset  the dataset.     * @param info  an optional info collection object to return data back to      *              the caller.     *     * @return The number of passes the renderer requires.     */    public XYItemRendererState initialise(Graphics2D g2,                                          Rectangle2D dataArea,                                          XYPlot plot,                                          XYDataset dataset,                                          PlotRenderingInfo info);    /**     * Returns the number of passes through the data required by the renderer.     *      * @return The pass count.     */    public int getPassCount();    /**     * Returns a boolean that indicates whether or not the specified item      * should be drawn (this is typically used to hide an entire series).     *      * @param series  the series index.     * @param item  the item index.     *      * @return A boolean.     */    public boolean getItemVisible(int series, int item);        /**     * Returns a boolean that indicates whether or not the specified series      * should be drawn (this is typically used to hide an entire series).     *      * @param series  the series index.     *      * @return A boolean.     */    public boolean isSeriesVisible(int series);        /**     * Returns the flag that controls the visibility of ALL series.  This flag      * overrides the per series and default settings - you must set it to      * <code>null</code> if you want the other settings to apply.     *      * @return The flag (possibly <code>null</code>).     */    public Boolean getSeriesVisible();        /**     * Sets the flag that controls the visibility of ALL series and sends a      * {@link RendererChangeEvent} to all registered listeners.  This flag      * overrides the per series and default settings - you must set it to      * <code>null</code> if you want the other settings to apply.     *      * @param visible  the flag (<code>null</code> permitted).     */    public void setSeriesVisible(Boolean visible);        /**     * Sets the flag that controls the visibility of ALL series and sends a      * {@link RendererChangeEvent} to all registered listeners.  This flag      * overrides the per series and default settings - you must set it to      * <code>null</code> if you want the other settings to apply.     *      * @param visible  the flag (<code>null</code> permitted).     * @param notify  notify listeners?     */    public void setSeriesVisible(Boolean visible, boolean notify);        /**     * Returns the flag that controls whether a series is visible.     *     * @param series  the series index (zero-based).     *     * @return The flag (possibly <code>null</code>).     */    public Boolean getSeriesVisible(int series);        /**     * Sets the flag that controls whether a series is visible and sends a      * {@link RendererChangeEvent} to all registered listeners.     *     * @param series  the series index (zero-based).     * @param visible  the flag (<code>null</code> permitted).     */    public void setSeriesVisible(int series, Boolean visible);        /**     * Sets the flag that controls whether a series is visible and, if      * requested, sends a {@link RendererChangeEvent} to all registered      * listeners.     *      * @param series  the series index.     * @param visible  the flag (<code>null</code> permitted).     * @param notify  notify listeners?     */    public void setSeriesVisible(int series, Boolean visible, boolean notify);    /**     * Returns the base visibility for all series.     *     * @return The base visibility.     */    public boolean getBaseSeriesVisible();    /**     * Sets the base visibility and sends a {@link RendererChangeEvent} to all     * registered listeners.     *     * @param visible  the flag.     */    public void setBaseSeriesVisible(boolean visible);        /**     * Sets the base visibility and, if requested, sends      * a {@link RendererChangeEvent} to all registered listeners.     *      * @param visible  the visibility.     * @param notify  notify listeners?     */    public void setBaseSeriesVisible(boolean visible, boolean notify);    // SERIES VISIBLE IN LEGEND (not yet respected by all renderers)        /**     * Returns <code>true</code> if the series should be shown in the legend,     * and <code>false</code> otherwise.     *      * @param series  the series index.     *      * @return A boolean.     */    public boolean isSeriesVisibleInLegend(int series);        /**     * Returns the flag that controls the visibility of ALL series in the      * legend.  This flag overrides the per series and default settings - you      * must set it to <code>null</code> if you want the other settings to      * apply.     *      * @return The flag (possibly <code>null</code>).     */    public Boolean getSeriesVisibleInLegend();        /**     * Sets the flag that controls the visibility of ALL series in the legend      * and sends a {@link RendererChangeEvent} to all registered listeners.       * This flag overrides the per series and default settings - you must set      * it to <code>null</code> if you want the other settings to apply.     *      * @param visible  the flag (<code>null</code> permitted).     */    public void setSeriesVisibleInLegend(Boolean visible);        /**     * Sets the flag that controls the visibility of ALL series in the legend      * and sends a {@link RendererChangeEvent} to all registered listeners.       * This flag overrides the per series and default settings - you must set      * it to <code>null</code> if you want the other settings to apply.     *      * @param visible  the flag (<code>null</code> permitted).     * @param notify  notify listeners?     */    public void setSeriesVisibleInLegend(Boolean visible, boolean notify);        /**     * Returns the flag that controls whether a series is visible in the      * legend.  This method returns only the "per series" settings - to      * incorporate the override and base settings as well, you need to use the      * {@link #isSeriesVisibleInLegend(int)} method.     *     * @param series  the series index (zero-based).     *     * @return The flag (possibly <code>null</code>).     */    public Boolean getSeriesVisibleInLegend(int series);        /**     * Sets the flag that controls whether a series is visible in the legend      * and sends a {@link RendererChangeEvent} to all registered listeners.     *     * @param series  the series index (zero-based).     * @param visible  the flag (<code>null</code> permitted).     */    public void setSeriesVisibleInLegend(int series, Boolean visible);        /**     * Sets the flag that controls whether a series is visible in the legend     * and, if requested, sends a {@link RendererChangeEvent} to all registered      * listeners.     *      * @param series  the series index.     * @param visible  the flag (<code>null</code> permitted).     * @param notify  notify listeners?     */    public void setSeriesVisibleInLegend(int series, Boolean visible,                                          boolean notify);    /**     * Returns the base visibility in the legend for all series.     *     * @return The base visibility.     */    public boolean getBaseSeriesVisibleInLegend();    /**     * Sets the base visibility in the legend and sends a      * {@link RendererChangeEvent} to all registered listeners.     *     * @param visible  the flag.     */    public void setBaseSeriesVisibleInLegend(boolean visible);        /**     * Sets the base visibility in the legend and, if requested, sends      * a {@link RendererChangeEvent} to all registered listeners.     *      * @param visible  the visibility.     * @param notify  notify listeners?     */    public void setBaseSeriesVisibleInLegend(boolean visible, boolean notify);    // PAINT        /**     * Returns the paint used to fill data items as they are drawn.     *     * @param row  the row (or series) index (zero-based).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?