xyarearenderer2.java

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

JAVA
473
字号
/* =========================================================== * 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.] * * -------------------- * XYAreaRenderer2.java * -------------------- * (C) Copyright 2004, 2005, by Hari and Contributors. * * Original Author:  Hari (ourhari@hotmail.com); * Contributor(s):   David Gilbert (for Object Refinery Limited); *                   Richard Atkinson; *                   Christian W. Zuckschwerdt; * * $Id: XYAreaRenderer2.java,v 1.12 2005/06/02 09:07:32 mungady Exp $ * * Changes: * -------- * 03-Apr-2002 : Version 1, contributed by Hari.  This class is based on the  *               StandardXYItemRenderer class (DG); * 09-Apr-2002 : Removed the translated zero from the drawItem method -  *               overridden the initialise() method to calculate it (DG); * 30-May-2002 : Added tool tip generator to constructor to match super  *               class (DG); * 25-Jun-2002 : Removed unnecessary local variable (DG); * 05-Aug-2002 : Small modification to drawItem method to support URLs for  *               HTML image maps (RA); * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 07-Nov-2002 : Renamed AreaXYItemRenderer --> XYAreaRenderer (DG); * 25-Mar-2003 : Implemented Serializable (DG); * 01-May-2003 : Modified drawItem() method signature (DG); * 27-Jul-2003 : Made line and polygon properties protected rather than  *               private (RA); * 30-Jul-2003 : Modified entity constructor (CZ); * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 07-Oct-2003 : Added renderer state (DG); * 08-Dec-2003 : Modified hotspot for chart entity (DG); * 10-Feb-2004 : Changed the drawItem() method to make cut-and-paste  *               overriding easier.  Also moved state class into this  *               class (DG); * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState.  Renamed  *               XYToolTipGenerator --> XYItemLabelGenerator (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with  *               getYValue() (DG); * 11-Nov-2004 : Now uses ShapeUtilities to translate shapes (DG); * 19-Jan-2005 : Now accesses only primitives from the dataset (DG); * 21-Mar-2005 : Override getLegendItem() (DG); * 20-Apr-2005 : Use generators for legend tooltips and URLs (DG); *  */package org.jfree.chart.renderer.xy;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Polygon;import java.awt.Shape;import java.awt.Stroke;import java.awt.geom.GeneralPath;import java.awt.geom.Rectangle2D;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;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.entity.XYItemEntity;import org.jfree.chart.event.RendererChangeEvent;import org.jfree.chart.labels.XYSeriesLabelGenerator;import org.jfree.chart.labels.XYToolTipGenerator;import org.jfree.chart.plot.CrosshairState;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.io.SerialUtilities;import org.jfree.util.PublicCloneable;/** * Area item renderer for an {@link XYPlot}.   */public class XYAreaRenderer2 extends AbstractXYItemRenderer                              implements XYItemRenderer,                                         Cloneable,                                        PublicCloneable,                                        Serializable {    /** For serialization. */    private static final long serialVersionUID = -7378069681579984133L;    /** A flag indicating whether or not lines are drawn between XY points. */    private boolean plotLines;    /** A flag that controls whether or not the outline is shown. */    private boolean showOutline;    /**      * The shape used to represent an area in each legend item (this should      * never be <code>null</code>).      */    private transient Shape legendArea;    /**     * Constructs a new renderer.     */    public XYAreaRenderer2() {        this(null, null);    }    /**     * Constructs a new renderer.     * <p>     * To specify the type of renderer, use one of the constants: SHAPES, LINES,     * SHAPES_AND_LINES, AREA or AREA_AND_SHAPES.     *     * @param labelGenerator  the tool tip generator to use.  <code>null</code>      *                        is none.     * @param urlGenerator  the URL generator (null permitted).     */    public XYAreaRenderer2(XYToolTipGenerator labelGenerator,                            XYURLGenerator urlGenerator) {        super();        this.plotLines = false;        this.showOutline = false;        setBaseToolTipGenerator(labelGenerator);        setURLGenerator(urlGenerator);        GeneralPath area = new GeneralPath();        area.moveTo(0.0f, -4.0f);        area.lineTo(3.0f, -2.0f);        area.lineTo(4.0f, 4.0f);        area.lineTo(-4.0f, 4.0f);        area.lineTo(-3.0f, -2.0f);        area.closePath();        this.legendArea = area;    }    /**     * Returns a flag that controls whether or not outlines of the areas are      * drawn.     *     * @return The flag.     */    public boolean isOutline() {        return this.showOutline;    }    /**     * Sets a flag that controls whether or not outlines of the areas are drawn.     *     * @param show  the flag.     */    public void setOutline(boolean show) {        this.showOutline = show;    }    /**     * 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;    }    /**     * Returns the shape used to represent an area in the legend.     *      * @return The legend area (never <code>null</code>).     */    public Shape getLegendArea() {        return this.legendArea;       }        /**     * Sets the shape used as an area in each legend item and sends a      * {@link RendererChangeEvent} to all registered listeners.     *      * @param area  the area (<code>null</code> not permitted).     */    public void setLegendArea(Shape area) {        if (area == null) {            throw new IllegalArgumentException("Null 'area' argument.");           }        this.legendArea = area;        notifyListeners(new RendererChangeEvent(this));    }    /**     * Returns a default legend item for the specified series.  Subclasses      * should override this method to generate customised items.     *     * @param datasetIndex  the dataset index (zero-based).     * @param series  the series index (zero-based).     *     * @return A legend item for the series.     */    public LegendItem getLegendItem(int datasetIndex, int series) {        LegendItem result = null;        XYPlot xyplot = getPlot();        if (xyplot != null) {            XYDataset dataset = xyplot.getDataset(datasetIndex);            if (dataset != null) {                XYSeriesLabelGenerator lg = getLegendItemLabelGenerator();                String label = lg.generateLabel(dataset, series);                String description = label;                String toolTipText = null;                if (getLegendItemToolTipGenerator() != null) {                    toolTipText = getLegendItemToolTipGenerator().generateLabel(                        dataset, series                    );                }                String urlText = null;

⌨️ 快捷键说明

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