📄 polarplot.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.]
*
* --------------
* PolarPlot.java
* --------------
* (C) Copyright 2004, by Solution Engineering, Inc. and Contributors.
*
* Original Author: Daniel Bridenbecker, Solution Engineering, Inc.;
* Contributor(s): David Gilbert (for Object Refinery Limited);
*
* $Id: PolarPlot.java,v 1.1 2004/08/31 14:39:21 mungady Exp $
*
* Changes
* -------
* 19-Jan-2004 : Version 1, contributed by DB with minor changes by DG (DG);
* 07-Apr-2004 : Changed text bounds calculation (DG);
*
*/
package org.jfree.chart.plot;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.Point;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Rectangle2D;
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 java.util.ResourceBundle;
import org.jfree.chart.LegendItem;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.axis.AxisState;
import org.jfree.chart.axis.NumberTick;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.event.RendererChangeEvent;
import org.jfree.chart.event.RendererChangeListener;
import org.jfree.chart.renderer.PolarItemRenderer;
import org.jfree.data.Range;
import org.jfree.data.general.DatasetChangeEvent;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import org.jfree.io.SerialUtilities;
import org.jfree.text.TextUtilities;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.TextAnchor;
import org.jfree.util.ObjectUtils;
/**
* Plots data that is in (theta, radius) pairs where
* theta equal to zero is due north and and increases clockwise.
*
* @author Daniel Bridenbecker, Solution Engineering, Inc.
*/
public class PolarPlot extends Plot implements ValueAxisPlot,
RendererChangeListener,
Cloneable,
Serializable {
/** The default margin. */
private static final int MARGIN = 20;
/** The annotation margin. */
private static final double ANNOTATION_MARGIN = 7.0;
/** The default grid line stroke. */
public static final Stroke DEFAULT_GRIDLINE_STROKE
= new BasicStroke(
0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL,
0.0f, new float[]{2.0f, 2.0f}, 0.0f
);
/** The default grid line paint. */
public static final Paint DEFAULT_GRIDLINE_PAINT = Color.gray;
/** The resourceBundle for the localization. */
protected static ResourceBundle localizationResources = ResourceBundle.getBundle(
"org.jfree.chart.plot.LocalizationBundle"
);
// ------------------------
// --- Member Variables ---
// ------------------------
/** The angles that are marked with gridlines. */
private List angleTicks;
/** The radius axis (used for the y-values). */
private ValueAxis radiusAxis;
/** The dataset. */
private XYDataset dataset;
/** Object responsible for drawing the visual representation of each point on the plot. */
private PolarItemRenderer renderer;
/** A flag that controls whether or not the angle labels are visible. */
private boolean angleLabelsVisible = true;
/** The font used to display the angle labels. */
private Font angleLabelFont = new Font("SansSerif", Font.PLAIN, 12);
/** The paint used to display the angle labels. */
private Paint angleLabelPaint = Color.black;
/** A flag that controls whether the angular grid-lines are visible. */
private boolean angleGridlinesVisible;
/** The stroke used to draw the angular grid-lines. */
private transient Stroke angleGridlineStroke;
/** The paint used to draw the angular grid-lines. */
private transient Paint angleGridlinePaint;
/** A flag that controls whether the radius grid-lines are visible. */
private boolean radiusGridlinesVisible;
/** The stroke used to draw the radius grid-lines. */
private transient Stroke radiusGridlineStroke;
/** The paint used to draw the radius grid-lines. */
private transient Paint radiusGridlinePaint;
/** The annotations for the plot. */
private List cornerTextItems = new ArrayList();
// --------------------
// --- Constructors ---
// --------------------
/**
* Default constructor.
*/
public PolarPlot() {
this(null, null, null);
}
/**
* Creates a new plot.
*
* @param dataset the m_Dataset (<code>null</code> permitted).
* @param radiusAxis the radius axis (<code>null</code> permitted).
* @param renderer the m_Renderer (<code>null</code> permitted).
*/
public PolarPlot(XYDataset dataset,
ValueAxis radiusAxis,
PolarItemRenderer renderer) {
super();
this.dataset = dataset;
if (this.dataset != null) {
this.dataset.addChangeListener(this);
}
this.angleTicks = new java.util.ArrayList();
this.angleTicks.add(
new NumberTick(new Double(0.0), "0", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.angleTicks.add(
new NumberTick(new Double(45.0), "45", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.angleTicks.add(
new NumberTick(new Double(90.0), "90", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.angleTicks.add(
new NumberTick(new Double(135.0), "135", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.angleTicks.add(
new NumberTick(new Double(180.0), "180", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.angleTicks.add(
new NumberTick(new Double(225.0), "225", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.angleTicks.add(
new NumberTick(new Double(270.0), "270", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.angleTicks.add(
new NumberTick(new Double(315.0), "315", TextAnchor.CENTER, TextAnchor.CENTER, 0.0)
);
this.radiusAxis = radiusAxis;
if (this.radiusAxis != null) {
this.radiusAxis.setPlot(this);
this.radiusAxis.addChangeListener(this);
}
this.renderer = renderer;
if (this.renderer != null) {
this.renderer.setPlot(this);
this.renderer.addChangeListener(this);
}
this.angleGridlinesVisible = true;
this.angleGridlineStroke = DEFAULT_GRIDLINE_STROKE;
this.angleGridlinePaint = DEFAULT_GRIDLINE_PAINT;
this.radiusGridlinesVisible = true;
this.radiusGridlineStroke = DEFAULT_GRIDLINE_STROKE;
this.radiusGridlinePaint = DEFAULT_GRIDLINE_PAINT;
}
/**
* Add text to be displayed in the lower right hand corner.
*
* @param text the text to display.
*/
public void addCornerTextItem(String text) {
this.cornerTextItems.add(text);
}
/**
* Remove the given text from the list of corner text items.
*
* @param text the text to remove.
*/
public void removeCornerTextItem(String text) {
this.cornerTextItems.remove(text);
}
/**
* Clear the list of corner text items.
*/
public void clearCornerTextItem() {
this.cornerTextItems.clear();
}
/**
* Returns the plot type as a string.
*
* @return A short string describing the type of plot.
*/
public String getPlotType() {
return PolarPlot.localizationResources.getString("Polar_Plot");
}
/**
* Returns the radius axis for the plot. If the radius axis for this plot is
* null, then the method will return the parent plot's radius axis (if
* there is a parent plot).
*
* @return the radius axis.
*/
public ValueAxis getRadialAxis() {
ValueAxis result = this.radiusAxis;
if (result == null) {
Plot parent = getParent();
if (parent instanceof PolarPlot) {
PolarPlot polar = (PolarPlot) parent;
result = polar.getRadialAxis();
}
}
return result;
}
/**
* Sets the radius axis for the plot.
* <P>
* An exception is thrown if the new axis and the plot are not mutually compatible.
*
* @param axis the new axis (null permitted).
*
*/
public void setRadialAxis(ValueAxis axis) {
if (axis != null) {
axis.setPlot(this);
}
// plot is likely registered as a listener with the existing axis...
if (this.radiusAxis != null) {
this.radiusAxis.removeChangeListener(this);
}
this.radiusAxis = axis;
if (this.radiusAxis != null) {
this.radiusAxis.configure();
this.radiusAxis.addChangeListener(this);
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the primary dataset for the plot.
*
* @return The primary dataset (possibly <code>null</code>).
*/
public XYDataset getDataset() {
return this.dataset;
}
/**
* Sets the dataset for the plot, replacing the existing dataset if there is one.
*
* @param dataset the dataset (<code>null</code> permitted).
*/
public void setDataset(XYDataset dataset) {
// if there is an existing dataset, remove the plot from the list of change listeners...
XYDataset existing = this.dataset;
if (existing != null) {
existing.removeChangeListener(this);
}
// set the new m_Dataset, and register the chart as a change listener...
this.dataset = dataset;
if (this.dataset != null) {
setDatasetGroup(this.dataset.getGroup());
this.dataset.addChangeListener(this);
}
// send a m_Dataset change event to self...
DatasetChangeEvent event = new DatasetChangeEvent(this, this.dataset);
datasetChanged(event);
}
/**
* Returns the item renderer.
*
* @return The renderer (possibly <code>null</code>).
*/
public PolarItemRenderer getRenderer() {
return this.renderer;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -