📄 defaultoldlegend.java
字号:
/* =========================================================== * 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.] * * --------------------- * DefaultOldLegend.java * --------------------- * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andrzej Porebski; * Luke Quinane; * Barak Naveh; * * $Id: DefaultOldLegend.java,v 1.5 2005/05/19 15:40:56 mungady Exp $ * * Changes (from 20-Jun-2001) * -------------------------- * 20-Jun-2001 : Modifications submitted by Andrzej Porebski for legend * placement; * 18-Sep-2001 : Updated header and fixed DOS encoding problem (DG); * 16-Oct-2001 : Moved data source classes to com.jrefinery.data.* (DG); * 19-Oct-2001 : Moved some methods [getSeriesPaint() etc.] from JFreeChart to * Plot (DG); * 22-Jan-2002 : Fixed bug correlating legend labels with pie data (DG); * 06-Feb-2002 : Bug fix for legends in small areas (DG); * 23-Apr-2002 : Legend item labels are now obtained from the plot, not the * chart (DG); * 20-Jun-2002 : Added outline paint and stroke attributes for the key * boxes (DG); * 18-Sep-2002 : Fixed errors reported by Checkstyle (DG); * 23-Sep-2002 : Changed the name of LegendItem --> DrawableLegendItem (DG); * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 16-Oct-2002 : Adjusted vertical text position in legend item (DG); * 17-Oct-2002 : Fixed bug where legend items are not using the font that has * been set (DG); * 11-Feb-2003 : Added title code by Donald Mitchell, removed unnecessary * constructor (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 22-Sep-2003 : Added nullpointer checks (TM); * 23-Sep-2003 : Fixed bug in equals() method (DG); * 08-Oct-2003 : Applied patch for displaying series line style, contributed * by Luke Quinane (DG); * 23-Dec-2003 : Added scale factors (x and y) for shapes displayed in * legend (DG); * 26-Mar-2004 : Added option to control item order, contributed by Angel (DG); * 26-Mar-2004 : Added support for 8 more anchor points (BN); * 27-Mar-2004 : Added support for round corners of bounding box (BN); * 07-Apr-2004 : Changed text bounds calculation (DG); * 21-Apr-2004 : Barak Naveh has contributed word-wrapping for legend * items (BN); * 25-Nov-2004 : Small update due to changes in LegendItem class (DG); * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG); * 27-Jan-2005 : Legend now picks up more info from the renderer of each * series (DG); * 22-Feb-2005 : Renamed outerGap --> margin (DG); * 28-Mar-2005 : Renamed StandardLegend --> DefaultOldLegend (DG); * 20-Apr-2005 : Updated for changes in LegendItem (DG); * 26-Apr-2005 : Removed LOGGER (DG); * */package org.jfree.chart;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Shape;import java.awt.Stroke;import java.awt.font.LineMetrics;import java.awt.geom.AffineTransform;import java.awt.geom.Line2D;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.awt.geom.RectangularShape;import java.awt.geom.RoundRectangle2D;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.jfree.chart.entity.EntityCollection;import org.jfree.chart.entity.LegendItemEntity;import org.jfree.chart.event.LegendChangeEvent;import org.jfree.io.SerialUtilities;import org.jfree.text.TextUtilities;import org.jfree.ui.RectangleInsets;import org.jfree.ui.TextAnchor;import org.jfree.util.ObjectUtilities;/** * A chart legend shows the names and visual representations of the series * that are plotted in a chart. If possible, use * {@link org.jfree.chart.title.LegendTitle} rather than this class. */public class DefaultOldLegend extends OldLegend implements Serializable { /** For serialization. */ private static final long serialVersionUID = -5466149184220837922L; /** The default margin (space around the outside of the legend). */ public static final RectangleInsets DEFAULT_MARGIN = new RectangleInsets(3, 3, 3, 3); /** The default inner gap. */ public static final RectangleInsets DEFAULT_PADDING = new RectangleInsets(2, 2, 2, 2); /** The default outline stroke. */ public static final Stroke DEFAULT_OUTLINE_STROKE = new BasicStroke(); /** The default outline paint. */ public static final Paint DEFAULT_OUTLINE_PAINT = Color.gray; /** The default background paint. */ public static final Paint DEFAULT_BACKGROUND_PAINT = Color.white; /** The default title font. */ public static final Font DEFAULT_TITLE_FONT = new Font("SansSerif", Font.BOLD, 11); /** The default item font. */ public static final Font DEFAULT_ITEM_FONT = new Font("SansSerif", Font.PLAIN, 10); /** * Used with {@link #setPreferredWidth(double)} to indicate that no * preferred width is desired and defaults are to be used. */ public static final double NO_PREFERRED_WIDTH = Double.MAX_VALUE; /** Reported when illegal legend is unexpectedly found. */ private static final String UNEXPECTED_LEGEND_ANCHOR = "Unexpected legend anchor"; /** The amount of blank space around the legend. */ private RectangleInsets margin; /** The stroke used to draw the outline of the legend. */ private transient Stroke outlineStroke; /** The paint used to draw the outline of the legend. */ private transient Paint outlinePaint; /** The paint used to draw the background of the legend. */ private transient Paint backgroundPaint; /** The blank space inside the legend box. */ private RectangleInsets padding; /** An optional title for the legend. */ private String title; /** The font used to display the legend title. */ private Font titleFont; /** The font used to display the legend item names. */ private Font itemFont; /** The paint used to display the legend item names. */ private transient Paint itemPaint; /** The x scale factor for shapes displayed in the legend. */ private double shapeScaleX = 1.0; /** The y scale factor for shapes displayed in the legend. */ private double shapeScaleY = 1.0; /** The order of the legend items. */ private LegendRenderingOrder renderingOrder = LegendRenderingOrder.STANDARD; /** * The width of the arc used to round off the corners of the bounding box. */ private int boundingBoxArcWidth = 0; /** * The height of the arc used to round off the corners of the bounding box. */ private int boundingBoxArcHeight = 0; /** The preferred width of the legend bounding box. */ private double preferredWidth = NO_PREFERRED_WIDTH; /** * Constructs a new legend with default settings. */ public DefaultOldLegend() { this.margin = DEFAULT_MARGIN; this.padding = DEFAULT_PADDING; this.backgroundPaint = DEFAULT_BACKGROUND_PAINT; this.outlineStroke = DEFAULT_OUTLINE_STROKE; this.outlinePaint = DEFAULT_OUTLINE_PAINT; this.title = null; this.titleFont = DEFAULT_TITLE_FONT; this.itemFont = DEFAULT_ITEM_FONT; this.itemPaint = Color.black; } /** * Returns the margin for the legend. This is the amount of blank space * around the outside of the legend. * * @return The gap (never <code>null</code>). */ public RectangleInsets getMargin() { return this.margin; } /** * Sets the margin for the legend and sends a {@link LegendChangeEvent} to * all registered listeners. * * @param margin the margin (<code>null</code> not permitted). */ public void setMargin(RectangleInsets margin) { if (margin == null) { throw new NullPointerException("Null 'margin' argument."); } this.margin = margin; notifyListeners(new LegendChangeEvent(this)); } /** * Returns the padding for the legend. This is the amount of blank space * around the inside of the legend. * * @return The gap (never <code>null</code>). */ public RectangleInsets getPadding() { return this.padding; } /** * Sets the padding for the legend and sends a {@link LegendChangeEvent} * to all registered listeners. * * @param padding the padding (<code>null</code> not permitted). */ public void setPadding(RectangleInsets padding) { if (padding == null) { throw new NullPointerException("Null 'padding' argument."); } this.padding = padding; notifyListeners(new LegendChangeEvent(this)); } /** * Returns the background paint for the legend. * * @return The background paint (never <code>null</code>). */ public Paint getBackgroundPaint() { return this.backgroundPaint; } /** * Sets the background paint for the legend and sends a * {@link LegendChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). */ public void setBackgroundPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.backgroundPaint = paint; notifyListeners(new LegendChangeEvent(this)); } /** * Returns the outline stroke. * * @return The outline stroke (never <code>null</code>). */ public Stroke getOutlineStroke() { return this.outlineStroke; } /** * Sets the outline stroke and sends a {@link LegendChangeEvent} to all * registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). */ public void setOutlineStroke(Stroke stroke) { if (stroke == null) { throw new NullPointerException("Null 'stroke' argument."); } this.outlineStroke = stroke; notifyListeners(new LegendChangeEvent(this)); } /** * Returns the outline paint. * * @return The outline paint (never <code>null</code>). */ public Paint getOutlinePaint() { return this.outlinePaint; } /** * Sets the outline paint and sends a {@link LegendChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). */ public void setOutlinePaint(Paint paint) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -