📄 abstractcategoryitemrenderer.java
字号:
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------------------------
* AbstractCategoryItemRenderer.java
* ---------------------------------
* (C) Copyright 2002-2007, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Richard Atkinson;
*
* 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);
* 09-Jun-2005 : Added utility method for adding an item entity (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 01-Mar-2006 : Updated getLegendItems() to check seriesVisibleInLegend
* flags (DG);
* 20-Jul-2006 : Set dataset and series indices in LegendItem (DG);
* 23-Oct-2006 : Draw outlines for interval markers (DG);
* 24-Oct-2006 : Respect alpha setting in markers, as suggested by Sergei
* Ivanov in patch 1567843 (DG);
* 30-Nov-2006 : Added a check for series visibility in the getLegendItem()
* method (DG);
* 07-Dec-2006 : Fix for equals() method (DG);
* 22-Feb-2007 : Added createState() method (DG);
* 01-Mar-2007 : Fixed interval marker drawing (patch 1670686 thanks to
* Sergei Ivanov) (DG);
* 20-Apr-2007 : Updated getLegendItem() for renderer change, and deprecated
* itemLabelGenerator, toolTipGenerator and itemURLGenerator
* override fields (DG);
* 18-May-2007 : Set dataset and seriesKey for LegendItem (DG);
*
*/
package org.jfree.chart.renderer.category;
import java.awt.AlphaComposite;
import java.awt.Composite;
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.entity.CategoryItemEntity;
import org.jfree.chart.entity.EntityCollection;
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.
*
* @deprecated This field is redundant and deprecated as of version 1.0.6.
*/
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.
*
* @deprecated This field is redundant and deprecated as of version 1.0.6.
*/
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.
*
* @deprecated This field is redundant and deprecated as of version 1.0.6.
*/
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>).
*
* @see #setPlot(CategoryPlot)
*/
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).
*
* @see #getPlot()
*/
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>).
*
* @see #setSeriesItemLabelGenerator(int, CategoryItemLabelGenerator)
*/
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.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -