abstractcategoryitemrenderer.java

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

JAVA
1,414
字号
/* =========================================================== * 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.] * * --------------------------------- * AbstractCategoryItemRenderer.java * --------------------------------- * (C) Copyright 2002-2005, by Object Refinery Limited. * * Original Author:  David Gilbert (for Object Refinery Limited); * Contributor(s):   Richard Atkinson; * * $Id: AbstractCategoryItemRenderer.java,v 1.17 2005/06/02 08:46:50 mungady Exp $ * * Changes: * -------- * 29-May-2002 : Version 1 (DG); * 06-Jun-2002 : Added accessor methods for the tool tip generator (DG); * 11-Jun-2002 : Made constructors protected (DG); * 26-Jun-2002 : Added axis to initialise method (DG); * 05-Aug-2002 : Added urlGenerator member variable plus accessors (RA); * 22-Aug-2002 : Added categoriesPaint attribute, based on code submitted by  *               Janet Banks.  This can be used when there is only one series,  *               and you want each category item to have a different color (DG); * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 29-Oct-2002 : Fixed bug where background image for plot was not being  *               drawn (DG); * 05-Nov-2002 : Replaced references to CategoryDataset with TableDataset (DG); * 26-Nov 2002 : Replaced the isStacked() method with getRangeType() (DG); * 09-Jan-2003 : Renamed grid-line methods (DG); * 17-Jan-2003 : Moved plot classes into separate package (DG); * 25-Mar-2003 : Implemented Serializable (DG); * 12-May-2003 : Modified to take into account the plot orientation (DG); * 12-Aug-2003 : Very minor javadoc corrections (DB) * 13-Aug-2003 : Implemented Cloneable (DG); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 05-Nov-2003 : Fixed marker rendering bug (833623) (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 11-Feb-2004 : Modified labelling for markers (DG); * 12-Feb-2004 : Updated clone() method (DG); * 15-Apr-2004 : Created a new CategoryToolTipGenerator interface (DG); * 05-May-2004 : Fixed bug (948310) where interval markers extend outside axis  *               range (DG); * 14-Jun-2004 : Fixed bug in drawRangeMarker() method - now uses 'paint' and  *               'stroke' rather than 'outlinePaint' and 'outlineStroke' (DG); * 15-Jun-2004 : Interval markers can now use GradientPaint (DG); * 30-Sep-2004 : Moved drawRotatedString() from RefineryUtilities  *               --> TextUtilities (DG); * 01-Oct-2004 : Fixed bug 1029697, problem with label alignment in  *               drawRangeMarker() method (DG); * 07-Jan-2005 : Renamed getRangeExtent() --> findRangeBounds() (DG); * 21-Jan-2005 : Modified return type of calculateRangeMarkerTextAnchorPoint()  *               method (DG); * 08-Mar-2005 : Fixed positioning of marker labels (DG); * 20-Apr-2005 : Added legend label, tooltip and URL generators (DG); * 01-Jun-2005 : Handle one dimension of the marker label adjustment  *               automatically (DG); *  */package org.jfree.chart.renderer.category;import java.awt.Font;import java.awt.GradientPaint;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Shape;import java.awt.Stroke;import java.awt.geom.Line2D;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.Serializable;import org.jfree.chart.LegendItem;import org.jfree.chart.LegendItemCollection;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.event.RendererChangeEvent;import org.jfree.chart.labels.CategoryItemLabelGenerator;import org.jfree.chart.labels.CategorySeriesLabelGenerator;import org.jfree.chart.labels.CategoryToolTipGenerator;import org.jfree.chart.labels.ItemLabelPosition;import org.jfree.chart.labels.StandardCategorySeriesLabelGenerator;import org.jfree.chart.plot.CategoryMarker;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.DrawingSupplier;import org.jfree.chart.plot.IntervalMarker;import org.jfree.chart.plot.Marker;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.plot.PlotRenderingInfo;import org.jfree.chart.plot.ValueMarker;import org.jfree.chart.renderer.AbstractRenderer;import org.jfree.chart.urls.CategoryURLGenerator;import org.jfree.data.Range;import org.jfree.data.category.CategoryDataset;import org.jfree.data.general.DatasetUtilities;import org.jfree.text.TextUtilities;import org.jfree.ui.GradientPaintTransformer;import org.jfree.ui.LengthAdjustmentType;import org.jfree.ui.RectangleAnchor;import org.jfree.ui.RectangleInsets;import org.jfree.util.ObjectList;import org.jfree.util.ObjectUtilities;import org.jfree.util.PublicCloneable;/** * An abstract base class that you can use to implement a new  * {@link CategoryItemRenderer}.  When you create a new  * {@link CategoryItemRenderer} you are not required to extend this class, * but it makes the job easier. */public abstract class AbstractCategoryItemRenderer extends AbstractRenderer    implements CategoryItemRenderer, Cloneable, PublicCloneable, Serializable {    /** For serialization. */    private static final long serialVersionUID = 1247553218442497391L;        /** The plot that the renderer is assigned to. */    private CategoryPlot plot;    /** The item label generator for ALL series. */    private CategoryItemLabelGenerator itemLabelGenerator;    /** A list of item label generators (one per series). */    private ObjectList itemLabelGeneratorList;    /** The base item label generator. */    private CategoryItemLabelGenerator baseItemLabelGenerator;    /** The tool tip generator for ALL series. */    private CategoryToolTipGenerator toolTipGenerator;    /** A list of tool tip generators (one per series). */    private ObjectList toolTipGeneratorList;    /** The base tool tip generator. */    private CategoryToolTipGenerator baseToolTipGenerator;    /** The URL generator. */    private CategoryURLGenerator itemURLGenerator;    /** A list of item label generators (one per series). */    private ObjectList itemURLGeneratorList;    /** The base item label generator. */    private CategoryURLGenerator baseItemURLGenerator;    /** The legend item label generator. */    private CategorySeriesLabelGenerator legendItemLabelGenerator;        /** The legend item tool tip generator. */    private CategorySeriesLabelGenerator legendItemToolTipGenerator;    /** The legend item URL generator. */    private CategorySeriesLabelGenerator legendItemURLGenerator;        /** The number of rows in the dataset (temporary record). */    private transient int rowCount;    /** The number of columns in the dataset (temporary record). */    private transient int columnCount;    /**     * Creates a new renderer with no tool tip generator and no URL generator.     * The defaults (no tool tip or URL generators) have been chosen to      * minimise the processing required to generate a default chart.  If you      * require tool tips or URLs, then you can easily add the required      * generators.     */    protected AbstractCategoryItemRenderer() {        this.itemLabelGenerator = null;        this.itemLabelGeneratorList = new ObjectList();        this.toolTipGenerator = null;        this.toolTipGeneratorList = new ObjectList();        this.itemURLGenerator = null;        this.itemURLGeneratorList = new ObjectList();        this.legendItemLabelGenerator             = new StandardCategorySeriesLabelGenerator();    }        /**     * Returns the number of passes through the dataset required by the      * renderer.  This method returns <code>1</code>, subclasses should      * override if they need more passes.     *      * @return The pass count.     */    public int getPassCount() {        return 1;    }    /**     * Returns the plot that the renderer has been assigned to (where      * <code>null</code> indicates that the renderer is not currently assigned      * to a plot).     *     * @return The plot (possibly <code>null</code>).     */    public CategoryPlot getPlot() {        return this.plot;    }    /**     * Sets the plot that the renderer has been assigned to.  This method is      * usually called by the {@link CategoryPlot}, in normal usage you      * shouldn't need to call this method directly.     *     * @param plot  the plot (<code>null</code> not permitted).     */    public void setPlot(CategoryPlot plot) {        if (plot == null) {            throw new IllegalArgumentException("Null 'plot' argument.");           }        this.plot = plot;    }        // ITEM LABEL GENERATOR    /**     * Returns the item label generator for a data item.  This implementation      * simply passes control to the {@link #getSeriesItemLabelGenerator(int)}      * method.  If, for some reason, you want a different generator for      * individual items, you can override this method.     *     * @param row  the row index (zero based).     * @param column  the column index (zero based).     *     * @return The generator (possibly <code>null</code>).     */    public CategoryItemLabelGenerator getItemLabelGenerator(int row,             int column) {        return getSeriesItemLabelGenerator(row);    }    /**     * Returns the item label generator for a series.     *     * @param series  the series index (zero based).     *     * @return The generator (possibly <code>null</code>).     */    public CategoryItemLabelGenerator getSeriesItemLabelGenerator(int series) {        // return the generator for ALL series, if there is one...        if (this.itemLabelGenerator != null) {            return this.itemLabelGenerator;        }        // otherwise look up the generator table        CategoryItemLabelGenerator generator = (CategoryItemLabelGenerator)             this.itemLabelGeneratorList.get(series);        if (generator == null) {            generator = this.baseItemLabelGenerator;        }        return generator;    }    /**     * Sets the item label generator for ALL series and sends a      * {@link RendererChangeEvent} to all registered listeners.     *     * @param generator  the generator (<code>null</code> permitted).     */    public void setItemLabelGenerator(CategoryItemLabelGenerator generator) {        this.itemLabelGenerator = generator;        notifyListeners(new RendererChangeEvent(this));    }    /**     * Sets the item label generator for a series and sends a      * {@link RendererChangeEvent} to all registered listeners.     *     * @param series  the series index (zero based).     * @param generator  the generator (<code>null</code> permitted).     */    public void setSeriesItemLabelGenerator(int series,                                         CategoryItemLabelGenerator generator) {        this.itemLabelGeneratorList.set(series, generator);        notifyListeners(new RendererChangeEvent(this));    }    /**     * Returns the base item label generator.     *     * @return The generator (possibly <code>null</code>).     */    public CategoryItemLabelGenerator getBaseItemLabelGenerator() {        return this.baseItemLabelGenerator;    }    /**     * Sets the base item label generator and sends a      * {@link RendererChangeEvent} to all registered listeners.     *     * @param generator  the generator (<code>null</code> permitted).     */    public void setBaseItemLabelGenerator(CategoryItemLabelGenerator generator)     {        this.baseItemLabelGenerator = generator;        notifyListeners(new RendererChangeEvent(this));    }    // TOOL TIP GENERATOR    /**     * Returns the tool tip generator that should be used for the specified      * item.  This method looks up the generator using the "three-layer"      * approach outlined in the general description of this interface.  You      * can override this method if you want to return a different generator per     * item.     *     * @param row  the row index (zero-based).     * @param column  the column index (zero-based).     *     * @return The generator (possibly <code>null</code>).     */    public CategoryToolTipGenerator getToolTipGenerator(int row, int column) {        CategoryToolTipGenerator result = null;        if (this.toolTipGenerator != null) {            result = this.toolTipGenerator;        }        else {            result = getSeriesToolTipGenerator(row);              if (result == null) {                result = this.baseToolTipGenerator;               }        }        return result;    }    /**

⌨️ 快捷键说明

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