📄 categoryitemrenderer.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.]
*
* -------------------------
* CategoryItemRenderer.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);
*
* $Id: CategoryItemRenderer.java,v 1.1 2004/08/31 14:47:48 mungady Exp $
*
* Changes
* -------
* 23-Oct-2001 : Version 1 (DG);
* 16-Jan-2002 : Renamed HorizontalCategoryItemRenderer.java --> CategoryItemRenderer.java (DG);
* 05-Feb-2002 : Changed return type of the drawCategoryItem method from void to Shape, as part
* of the tooltips implementation (DG)
*
* NOTE (30-May-2002) : this has subsequently been changed back to void, tooltips
* are now collected along with entities in ChartRenderingInfo (DG);
*
* 14-Mar-2002 : Added the initialise method, and changed all bar plots to use this renderer (DG);
* 23-May-2002 : Added ChartRenderingInfo to the initialise method (DG);
* 29-May-2002 : Added the getAxisArea(Rectangle2D) method (DG);
* 06-Jun-2002 : Updated Javadoc comments (DG);
* 26-Jun-2002 : Added range axis to the initialise method (DG);
* 24-Sep-2002 : Added getLegendItem(...) method (DG);
* 23-Oct-2002 : Added methods to get/setToolTipGenerator (DG);
* 05-Nov-2002 : Replaced references to CategoryDataset with TableDataset (DG);
* 06-Nov-2002 : Added the domain axis to the drawCategoryItem method. Renamed
* drawCategoryItem(...) --> drawItem(...) (DG);
* 20-Nov-2002 : Changed signature of drawItem(...) method to reflect use of TableDataset (DG);
* 26-Nov-2002 : Replaced the isStacked() method with the getRangeType() method (DG);
* 08-Jan-2003 : Changed getSeriesCount() --> getRowCount() and
* getCategoryCount() --> getColumnCount() (DG);
* 09-Jan-2003 : Changed name of grid-line methods (DG);
* 21-Jan-2003 : Merged TableDataset with CategoryDataset (DG);
* 10-Apr-2003 : Changed CategoryDataset to KeyedValues2DDataset in drawItem(...) method (DG);
* 29-Apr-2003 : Eliminated Renderer interface (DG);
* 02-Sep-2003 : Fix for bug 790407 (DG);
* 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
* 20-Oct-2003 : Added setOutlinePaint(...) method (DG);
* 06-Feb-2004 : Added missing methods, and moved deprecated methods (DG);
* 19-Feb-2004 : Added extra setXXXLabelsVisible() methods (DG);
* 29-Apr-2004 : Changed Integer --> int in initialise() method (DG);
* 18-May-2004 : Added methods for item label paint (DG);
*
*/
package org.jfree.chart.renderer.category;
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.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.event.RendererChangeEvent;
import org.jfree.chart.event.RendererChangeListener;
import org.jfree.chart.labels.CategoryLabelGenerator;
import org.jfree.chart.labels.CategoryToolTipGenerator;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.urls.CategoryURLGenerator;
import org.jfree.data.Range;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.TextAnchor;
/**
* A plug-in object that is used by the {@link CategoryPlot} class to display individual data items
* from a {@link CategoryDataset}.
* <p>
* This interface defines the methods that must be provided by all renderers. If you are
* implementing a custom renderer, you should consider extending the
* {@link AbstractCategoryItemRenderer} class.
* <p>
* Most renderer attributes are defined using a "three layer" approach. When looking up an
* attribute (for example, the outline paint) the renderer first checks to see if there is
* a setting (in layer 0) that applies to ALL items that the renderer draws. If there is,
* that setting is used, but if it is <code>null</code> the renderer looks up the next layer,
* which contains "per series" settings for the attribute (many attributes are defined on a
* per series basis, so this is the layer that is most commonly used). If the layer 1 setting
* is <code>null</code>, the renderer will look up the final layer, which provides a default
* or "base" setting. Some attributes allow the base setting to be <code>null</code>, while
* other attributes enforce non-<code>null</code> values.
*
*/
public interface CategoryItemRenderer {
/**
* 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();
/**
* 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);
/**
* Adds a change listener.
*
* @param listener the listener.
*/
public void addChangeListener(RendererChangeListener listener);
/**
* Removes a change listener.
*
* @param listener the listener.
*/
public void removeChangeListener(RendererChangeListener listener);
/**
* Returns the range of values the renderer requires to display all the items from the
* specified dataset.
*
* @param dataset the dataset (<code>null</code> permitted).
*
* @return The range (or <code>null</code> if the dataset is <code>null</code> or empty).
*/
public Range getRangeExtent(CategoryDataset dataset);
/**
* Initialises the renderer. 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 rendererIndex the renderer index.
* @param info collects chart rendering information for return to caller.
*
* @return A state object (maintains state information relevant to one chart drawing).
*/
public CategoryItemRendererState initialise(Graphics2D g2,
Rectangle2D dataArea,
CategoryPlot plot,
int rendererIndex,
PlotRenderingInfo info);
//// PAINT ///////////////////////////////////////////////////////////////////////////////////
/**
* Returns the paint used to fill data items as they are drawn.
*
* @param row the row (or series) index (zero-based).
* @param column the column (or category) index (zero-based).
*
* @return the paint (never <code>null</code>).
*/
public Paint getItemPaint(int row, int column);
/**
* Sets the paint to be used for ALL series, and sends a {@link RendererChangeEvent} to all
* registered listeners. If this is <code>null</code>, the renderer will use the paint for
* the series.
*
* @param paint the paint (<code>null</code> permitted).
*/
public void setPaint(Paint paint);
/**
* Returns the paint used to fill an item drawn by the renderer.
*
* @param series the series index (zero-based).
*
* @return the paint (never <code>null</code>).
*/
public Paint getSeriesPaint(int series);
/**
* Sets the paint used for a series and sends a {@link RendererChangeEvent} to all registered
* listeners.
*
* @param series the series index (zero-based).
* @param paint the paint (<code>null</code> permitted).
*/
public void setSeriesPaint(int series, Paint paint);
/**
* Returns the base paint.
*
* @return the base paint (never <code>null</code>).
*/
public Paint getBasePaint();
/**
* Sets the base paint and sends a {@link RendererChangeEvent} to all registered listeners.
*
* @param paint the paint (<code>null</code> not permitted).
*/
public void setBasePaint(Paint paint);
//// OUTLINE PAINT ///////////////////////////////////////////////////////////////////////////
/**
* Returns the paint used to outline data items as they are drawn.
*
* @param row the row (or series) index (zero-based).
* @param column the column (or category) index (zero-based).
*
* @return the paint (never <code>null</code>).
*/
public Paint getItemOutlinePaint(int row, int column);
/**
* Sets the outline paint for ALL series (optional).
*
* @param paint the paint (<code>null</code> permitted).
*/
public void setOutlinePaint(Paint paint);
/**
* Returns the paint used to outline an item drawn by the renderer.
*
* @param series the series (zero-based index).
*
* @return the paint (never <code>null</code>).
*/
public Paint getSeriesOutlinePaint(int series);
/**
* Sets the paint used for a series outline and sends a {@link RendererChangeEvent} to
* all registered listeners.
*
* @param series the series index (zero-based).
* @param paint the paint (<code>null</code> permitted).
*/
public void setSeriesOutlinePaint(int series, Paint paint);
/**
* Returns the base outline paint.
*
* @return the paint (never <code>null</code>).
*/
public Paint getBaseOutlinePaint();
/**
* Sets the base outline paint and sends a {@link RendererChangeEvent} to all
* registered listeners.
*
* @param paint the paint (<code>null</code> not permitted).
*/
public void setBaseOutlinePaint(Paint paint);
//// STROKE //////////////////////////////////////////////////////////////////////////////////
/**
* Returns the stroke used to draw data items.
*
* @param row the row (or series) index (zero-based).
* @param column the column (or category) index (zero-based).
*
* @return the stroke (never <code>null</code>).
*/
public Stroke getItemStroke(int row, int column);
/**
* Sets the stroke for ALL series and sends a {@link RendererChangeEvent} to all
* registered listeners.
*
* @param stroke the stroke (<code>null</code> permitted).
*/
public void setStroke(Stroke stroke);
/**
* Returns the stroke used to draw the items in a series.
*
* @param series the series (zero-based index).
*
* @return the stroke (never <code>null</code>).
*/
public Stroke getSeriesStroke(int series);
/**
* Sets the stroke used for a series and sends a {@link RendererChangeEvent} to
* all registered listeners.
*
* @param series the series index (zero-based).
* @param stroke the stroke (<code>null</code> permitted).
*/
public void setSeriesStroke(int series, Stroke stroke);
/**
* Returns the base stroke.
*
* @return the base stroke (never <code>null</code>).
*/
public Stroke getBaseStroke();
/**
* Sets the base stroke.
*
* @param stroke the stroke (<code>null</code> not permitted).
*/
public void setBaseStroke(Stroke stroke);
//// OUTLINE STROKE //////////////////////////////////////////////////////////////////////////
/**
* Returns the stroke used to outline data items.
* <p>
* The default implementation passes control to the getSeriesOutlineStroke method.
* You can override this method if you require different behaviour.
*
* @param row the row (or series) index (zero-based).
* @param column the column (or category) index (zero-based).
*
* @return the stroke (never <code>null</code>).
*/
public Stroke getItemOutlineStroke(int row, int column);
/**
* Sets the outline stroke for ALL series and sends a {@link RendererChangeEvent} to
* all registered listeners.
*
* @param stroke the stroke (<code>null</code> permitted).
*/
public void setOutlineStroke(Stroke stroke);
/**
* Returns the stroke used to outline the items in a series.
*
* @param series the series (zero-based index).
*
* @return the stroke (never <code>null</code>).
*/
public Stroke getSeriesOutlineStroke(int series);
/**
* Sets the outline stroke used for a series and sends a {@link RendererChangeEvent}
* to all registered listeners.
*
* @param series the series index (zero-based).
* @param stroke the stroke (<code>null</code> permitted).
*/
public void setSeriesOutlineStroke(int series, Stroke stroke);
/**
* Returns the base outline stroke.
*
* @return the stroke (never <code>null</code>).
*/
public Stroke getBaseOutlineStroke();
/**
* Sets the base outline stroke and sends a {@link RendererChangeEvent} to all
* registered listeners.
*
* @param stroke the stroke (<code>null</code> not permitted).
*/
public void setBaseOutlineStroke(Stroke stroke);
//// SHAPE ///////////////////////////////////////////////////////////////////////////////////
/**
* Returns a shape used to represent a data item.
*
* @param row the row (or series) index (zero-based).
* @param column the column (or category) index (zero-based).
*
* @return the shape (never <code>null</code>).
*/
public Shape getItemShape(int row, int column);
/**
* Sets the shape for ALL series (optional) and sends a {@link RendererChangeEvent}
* to all registered listeners.
*
* @param shape the shape (<code>null</code> permitted).
*/
public void setShape(Shape shape);
/**
* Returns a shape used to represent the items in a series.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -