📄 minmaxcategoryrenderer.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.]
*
* ---------------------------
* MinMaxCategoryRenderer.java
* ---------------------------
* (C) Copyright 2002-2007, by Object Refinery Limited.
*
* Original Author: Tomer Peretz;
* Contributor(s): David Gilbert (for Object Refinery Limited);
* Christian W. Zuckschwerdt;
* Nicolas Brodu (for Astrium and EADS Corporate Research
* Center);
*
* $Id: MinMaxCategoryRenderer.java,v 1.6.2.8 2007/06/01 15:12:15 mungady Exp $
*
* Changes:
* --------
* 29-May-2002 : Version 1 (TP);
* 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 24-Oct-2002 : Amendments for changes in CategoryDataset interface and
* CategoryToolTipGenerator interface (DG);
* 05-Nov-2002 : Base dataset is now TableDataset not CategoryDataset (DG);
* 17-Jan-2003 : Moved plot classes to a separate package (DG);
* 10-Apr-2003 : Changed CategoryDataset to KeyedValues2DDataset in drawItem()
* method (DG);
* 30-Jul-2003 : Modified entity constructor (CZ);
* 08-Sep-2003 : Implemented Serializable (NB);
* 29-Oct-2003 : Added workaround for font alignment in PDF output (DG);
* 05-Nov-2004 : Modified drawItem() signature (DG);
* 17-Nov-2005 : Added change events and argument checks (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
* 09-Mar-2007 : Fixed problem with horizontal rendering (DG);
*
*/
package org.jfree.chart.renderer.category;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.Icon;
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.CategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.io.SerialUtilities;
/**
* Renderer for drawing min max plot. This renderer draws all the series under
* the same category in the same x position using <code>objectIcon</code> and
* a line from the maximum value to the minimum value.
* <p>
* For use with the {@link org.jfree.chart.plot.CategoryPlot} class.
*/
public class MinMaxCategoryRenderer extends AbstractCategoryItemRenderer {
/** For serialization. */
private static final long serialVersionUID = 2935615937671064911L;
/** A flag indicating whether or not lines are drawn between XY points. */
private boolean plotLines = false;
/**
* The paint of the line between the minimum value and the maximum value.
*/
private transient Paint groupPaint = Color.black;
/**
* The stroke of the line between the minimum value and the maximum value.
*/
private transient Stroke groupStroke = new BasicStroke(1.0f);
/** The icon used to indicate the minimum value.*/
private transient Icon minIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0,
360, Arc2D.OPEN), null, Color.black);
/** The icon used to indicate the maximum value.*/
private transient Icon maxIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0,
360, Arc2D.OPEN), null, Color.black);
/** The icon used to indicate the values.*/
private transient Icon objectIcon = getIcon(new Line2D.Double(-4, 0, 4, 0),
false, true);
/** The last category. */
private int lastCategory = -1;
/** The minimum. */
private double min;
/** The maximum. */
private double max;
/**
* Default constructor.
*/
public MinMaxCategoryRenderer() {
super();
}
/**
* Gets whether or not lines are drawn between category points.
*
* @return boolean true if line will be drawn between sequenced categories,
* otherwise false.
*
* @see #setDrawLines(boolean)
*/
public boolean isDrawLines() {
return this.plotLines;
}
/**
* Sets the flag that controls whether or not lines are drawn to connect
* the items within a series and sends a {@link RendererChangeEvent} to
* all registered listeners.
*
* @param draw the new value of the flag.
*
* @see #isDrawLines()
*/
public void setDrawLines(boolean draw) {
if (this.plotLines != draw) {
this.plotLines = draw;
this.notifyListeners(new RendererChangeEvent(this));
}
}
/**
* Returns the paint used to draw the line between the minimum and maximum
* value items in each category.
*
* @return The paint (never <code>null</code>).
*
* @see #setGroupPaint(Paint)
*/
public Paint getGroupPaint() {
return this.groupPaint;
}
/**
* Sets the paint used to draw the line between the minimum and maximum
* value items in each category and sends a {@link RendererChangeEvent} to
* all registered listeners.
*
* @param paint the paint (<code>null</code> not permitted).
*
* @see #getGroupPaint()
*/
public void setGroupPaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.groupPaint = paint;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the stroke used to draw the line between the minimum and maximum
* value items in each category.
*
* @return The stroke (never <code>null</code>).
*
* @see #setGroupStroke(Stroke)
*/
public Stroke getGroupStroke() {
return this.groupStroke;
}
/**
* Sets the stroke of the line between the minimum value and the maximum
* value.
*
* @param groupStroke The new stroke
*/
public void setGroupStroke(Stroke groupStroke) {
this.groupStroke = groupStroke;
}
/**
* Returns the icon drawn for each data item.
*
* @return The icon (never <code>null</code>).
*
* @see #setObjectIcon(Icon)
*/
public Icon getObjectIcon() {
return this.objectIcon;
}
/**
* Sets the icon drawn for each data item.
*
* @param icon the icon.
*
* @see #getObjectIcon()
*/
public void setObjectIcon(Icon icon) {
if (icon == null) {
throw new IllegalArgumentException("Null 'icon' argument.");
}
this.objectIcon = icon;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the icon displayed for the maximum value data item within each
* category.
*
* @return The icon (never <code>null</code>).
*
* @see #setMaxIcon(Icon)
*/
public Icon getMaxIcon() {
return this.maxIcon;
}
/**
* Sets the icon displayed for the maximum value data item within each
* category and sends a {@link RendererChangeEvent} to all registered
* listeners.
*
* @param icon the icon (<code>null</code> not permitted).
*
* @see #getMaxIcon()
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -