?? contourplot.java
字號:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* 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.
*
* ----------------
* ContourPlot.java
* ----------------
* (C) Copyright 2002, 2003, by David M. O'Donnell and Contributors.
*
* Original Author: David M. O'Donnell;
* Contributor(s): David Gilbert (for Object Refinery Limited);
* Arnaud Lelievre;
*
* $Id: ContourPlot.java,v 1.18 2003/09/08 22:08:02 mungady Exp $
*
* Changes
* -------
* 26-Nov-2002 : Version 1 contributed by David M. O'Donnell (DG);
* 14-Jan-2003 : Added crosshair attributes (DG);
* 23-Jan-2003 : Removed two constructors (DG);
* 21-Mar-2003 : Bug fix 701744 (DG);
* 26-Mar-2003 : Implemented Serializable (DG);
* 09-Jul-2003 : Changed ColorBar from extending axis classes to enclosing them (DG);
* 05-Aug-2003 : Applied changes in bug report 780298 (DG);
* 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL);
*
*/
package org.jfree.chart.plot;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ClipPath;
import org.jfree.chart.CrosshairInfo;
import org.jfree.chart.Marker;
import org.jfree.chart.annotations.XYAnnotation;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.axis.ColorBar;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.ContourEntity;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.event.AxisChangeEvent;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.labels.ContourToolTipGenerator;
import org.jfree.chart.labels.StandardContourToolTipGenerator;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.ContourDataset;
import org.jfree.data.DatasetChangeEvent;
import org.jfree.data.DatasetUtilities;
import org.jfree.data.DefaultContourDataset;
import org.jfree.data.Range;
import org.jfree.ui.RectangleEdge;
/**
* A class for creating shaded contours.
*
* @author David M. O'Donnell
*/
public class ContourPlot extends Plot implements ContourValuePlot,
ValueAxisPlot,
PropertyChangeListener,
Serializable {
/** The default insets. */
protected static final Insets DEFAULT_INSETS = new Insets(2, 2, 100, 10);
/** The domain axis (used for the x-values). */
private ValueAxis domainAxis;
/** The range axis (used for the y-values). */
private ValueAxis rangeAxis;
/** The dataset. */
private ContourDataset dataset;
/** The colorbar axis (used for the z-values). */
private ColorBar colorBar = null;
/** The color bar location. */
private RectangleEdge colorBarLocation;
/** A flag that controls whether or not a domain crosshair is drawn..*/
private boolean domainCrosshairVisible;
/** The domain crosshair value. */
private double domainCrosshairValue;
/** The pen/brush used to draw the crosshair (if any). */
private transient Stroke domainCrosshairStroke;
/** The color used to draw the crosshair (if any). */
private transient Paint domainCrosshairPaint;
/** A flag that controls whether or not the crosshair locks onto actual data points. */
private boolean domainCrosshairLockedOnData = true;
/** A flag that controls whether or not a range crosshair is drawn..*/
private boolean rangeCrosshairVisible;
/** The range crosshair value. */
private double rangeCrosshairValue;
/** The pen/brush used to draw the crosshair (if any). */
private transient Stroke rangeCrosshairStroke;
/** The color used to draw the crosshair (if any). */
private transient Paint rangeCrosshairPaint;
/** A flag that controls whether or not the crosshair locks onto actual data points. */
private boolean rangeCrosshairLockedOnData = true;
/** A list of markers (optional) for the domain axis. */
private List domainMarkers;
/** A list of markers (optional) for the range axis. */
private List rangeMarkers;
/** A list of annotations (optional) for the plot. */
private List annotations;
/** The tool tip generator. */
private ContourToolTipGenerator toolTipGenerator;
/** The URL text generator. */
private XYURLGenerator urlGenerator;
/** Controls whether data are render as filled rectangles or rendered as points */
private boolean renderAsPoints = false;
/** Size of points rendered when renderAsPoints = true. Size is relative to dataArea */
private double ptSizePct = 0.05;
/** Contains the a ClipPath to "trim" the contours. */
private transient ClipPath clipPath = null;
/** Set to Paint to represent missing values. */
private transient Paint missingPaint = null;
/** The resourceBundle for the localization. */
static protected ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/**
* Constructs a contour plot with the specified axes (other attributes take default values).
*
* @param dataset The dataset.
* @param domainAxis The domain axis.
* @param rangeAxis The range axis.
* @param colorBar The z-axis axis.
*/
public ContourPlot(ContourDataset dataset,
ValueAxis domainAxis, ValueAxis rangeAxis, ColorBar colorBar) {
super();
this.dataset = dataset;
if (dataset != null) {
dataset.addChangeListener(this);
}
this.domainAxis = domainAxis;
if (domainAxis != null) {
domainAxis.setPlot(this);
domainAxis.addChangeListener(this);
}
this.rangeAxis = rangeAxis;
if (rangeAxis != null) {
rangeAxis.setPlot(this);
rangeAxis.addChangeListener(this);
}
this.colorBar = colorBar;
if (colorBar != null) {
colorBar.getAxis().setPlot(this);
colorBar.getAxis().addChangeListener(this);
colorBar.configure(this);
}
this.colorBarLocation = RectangleEdge.LEFT;
toolTipGenerator = new StandardContourToolTipGenerator();
}
/**
* Returns the color bar location.
*
* @return The color bar location.
*/
public RectangleEdge getColorBarLocation() {
return this.colorBarLocation;
}
/**
* Sets the color bar location.
*
* @param edge the location.
*/
public void setColorBarLocation(RectangleEdge edge) {
this.colorBarLocation = edge;
this.notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the primary dataset for the plot.
*
* @return The primary dataset (possibly <code>null</code>).
*/
public ContourDataset 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(ContourDataset dataset) {
// if there is an existing dataset, remove the plot from the list of change listeners...
ContourDataset existing = this.dataset;
if (existing != null) {
existing.removeChangeListener(this);
}
// set the new dataset, and register the chart as a change listener...
this.dataset = dataset;
if (dataset != null) {
setDatasetGroup(dataset.getGroup());
dataset.addChangeListener(this);
}
// send a dataset change event to self...
DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
datasetChanged(event);
}
/**
* A convenience method that returns the dataset for the plot, cast as a ContourDataset.
*
* @return The dataset for the plot, cast as an ContourDataset.
*
* @deprecated Use the getDataset() method instead.
*/
public ContourDataset getContourDataset() {
return (ContourDataset) getDataset();
}
/**
* Returns the domain axis for the plot.
*
* @return The domain axis.
*/
public ValueAxis getDomainAxis() {
ValueAxis result = domainAxis;
return result;
}
/**
* Sets the domain axis for the plot (this must be compatible with the plot
* type or an exception is thrown).
*
* @param axis The new axis.
*/
public void setDomainAxis(ValueAxis axis) {
if (isCompatibleDomainAxis(axis)) {
if (axis != null) {
try {
axis.setPlot(this);
}
catch (PlotNotCompatibleException e) {
}
axis.addChangeListener(this);
}
// plot is likely registered as a listener with the existing axis...
if (this.domainAxis != null) {
this.domainAxis.removeChangeListener(this);
}
this.domainAxis = axis;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the range axis for the plot.
*
* @return The range axis.
*/
public ValueAxis getRangeAxis() {
ValueAxis result = rangeAxis;
return result;
}
/**
* Sets the range 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 setRangeAxis(ValueAxis axis) {
if (axis != null) {
try {
axis.setPlot(this);
}
catch (PlotNotCompatibleException e) {
}
axis.addChangeListener(this);
}
// plot is likely registered as a listener with the existing axis...
if (this.rangeAxis != null) {
this.rangeAxis.removeChangeListener(this);
}
this.rangeAxis = axis;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Sets the colorbar for the plot.
*
* @param axis The new axis (null permitted).
*/
public void setColorBarAxis(ColorBar axis) {
this.colorBar = axis;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Adds a marker for the domain axis.
* <P>
* Typically a marker will be drawn by the renderer as a line perpendicular
* to the range axis, however this is entirely up to the renderer.
*
* @param marker the marker.
*/
public void addDomainMarker(Marker marker) {
if (this.domainMarkers == null) {
this.domainMarkers = new java.util.ArrayList();
}
this.domainMarkers.add(marker);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears all the domain markers.
*/
public void clearDomainMarkers() {
if (this.domainMarkers != null) {
this.domainMarkers.clear();
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Adds a marker for the range axis.
* <P>
* Typically a marker will be drawn by the renderer as a line perpendicular
* to the range axis, however this is entirely up to the renderer.
*
* @param marker The marker.
*/
public void addRangeMarker(Marker marker) {
if (this.rangeMarkers == null) {
this.rangeMarkers = new java.util.ArrayList();
}
this.rangeMarkers.add(marker);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears all the range markers.
*/
public void clearRangeMarkers() {
if (this.rangeMarkers != null) {
this.rangeMarkers.clear();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -