?? combinedrangexyplot.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.
*
* ------------------------
* CombinedRangeXYPlot.java
* ------------------------
* (C) Copyright 2001-2003, by Bill Kelemen and Contributors.
*
* Original Author: Bill Kelemen;
* Contributor(s): David Gilbert (for Object Refinery Limited);
* Anthony Boulestreau;
* David Basten;
* Kevin Frechette (for ISTI);
* Arnaud Lelievre;
*
* $Id: CombinedRangeXYPlot.java,v 1.14 2003/09/08 22:08:02 mungady Exp $
*
* Changes:
* --------
* 06-Dec-2001 : Version 1 (BK);
* 12-Dec-2001 : Removed unnecessary 'throws' clause from constructor (DG);
* 18-Dec-2001 : Added plotArea attribute and get/set methods (BK);
* 22-Dec-2001 : Fixed bug in chartChanged with multiple combinations of CombinedPlots (BK);
* 08-Jan-2002 : Moved to new package com.jrefinery.chart.combination (DG);
* 25-Feb-2002 : Updated import statements (DG);
* 28-Feb-2002 : Readded "this.plotArea = plotArea" that was deleted from draw() method (BK);
* 26-Mar-2002 : Added an empty zoom method (this method needs to be written so that combined
* plots will support zooming (DG);
* 29-Mar-2002 : Changed the method createCombinedAxis adding the creation of OverlaidSymbolicAxis
* and CombinedSymbolicAxis(AB);
* 23-Apr-2002 : Renamed CombinedPlot-->MultiXYPlot, and simplified the structure (DG);
* 23-May-2002 : Renamed (again) MultiXYPlot-->CombinedXYPlot (DG);
* 19-Jun-2002 : Added get/setGap() methods suggested by David Basten (DG);
* 25-Jun-2002 : Removed redundant imports (DG);
* 16-Jul-2002 : Draws shared axis after subplots (to fix missing gridlines),
* added overrides of 'setSeriesPaint()' and 'setXYItemRenderer()'
* that pass changes down to subplots (KF);
* 09-Oct-2002 : Added add(XYPlot) method (DG);
* 26-Mar-2003 : Implemented Serializable (DG);
* 16-May-2003 : Renamed CombinedXYPlot --> CombinedRangeXYPlot (DG);
* 26-Jun-2003 : Fixed bug 755547 (DG);
* 16-Jul-2003 : Removed getSubPlots() method (duplicate of getSubplots()) (DG);
* 08-Aug-2003 : Adjusted totalWeight in remove(...) method (DG);
* 21-Aug-2003 : Implemented Cloneable (DG);
* 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL);
*
*/
package org.jfree.chart.plot;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.renderer.XYItemRenderer;
import org.jfree.data.Range;
import org.jfree.ui.RectangleEdge;
import org.jfree.util.ObjectUtils;
/**
* An extension of {@link XYPlot} that contains multiple subplots that share a common range axis.
*
* @author Bill Kelemen (bill@kelemen-usa.com).
* @author David Gilbert.
*/
public class CombinedRangeXYPlot extends XYPlot implements Cloneable, Serializable {
/** Storage for the subplot references. */
private List subplots;
/** Total weight of all charts. */
private int totalWeight = 0;
/** The gap between subplots. */
private double gap = 5.0;
/** Temporary storage for the subplot areas. */
private transient Rectangle2D[] subplotAreas;
/** The resourceBundle for the localization. */
static protected ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/**
* Default constructor.
*/
public CombinedRangeXYPlot() {
this(new NumberAxis());
}
/**
* Creates a new plot.
*
* @param rangeAxis the shared axis.
*/
public CombinedRangeXYPlot(ValueAxis rangeAxis) {
super(null, // no data in the parent plot
null,
rangeAxis,
null);
this.subplots = new java.util.ArrayList();
}
/**
* Returns a string describing the type of plot.
*
* @return the type of plot.
*/
public String getPlotType() {
return localizationResources.getString("Combined_Range_XYPlot");
}
/**
* Returns the space between subplots.
*
* @return the gap
*/
public double getGap() {
return gap;
}
/**
* Sets the amount of space between subplots.
*
* @param gap the gap between subplots
*/
public void setGap(double gap) {
this.gap = gap;
}
/**
* Adds a subplot, with a default 'weight' of 1.
*
* @param subplot the subplot.
*/
public void add(XYPlot subplot) {
add(subplot, 1);
}
/**
* Adds a subplot with a particular weight (greater than or equal to one). The weight
* determines how much space is allocated to the subplot relative to all the other subplots.
*
* @param subplot the subplot.
* @param weight the weight (must be 1 or greater).
*/
public void add(XYPlot subplot, int weight) {
// verify valid weight
if (weight <= 0) {
String msg = "CombinedRangeXYPlot.add(...): weight must be positive.";
throw new IllegalArgumentException(msg);
}
// store the plot and its weight
subplot.setParent(this);
subplot.setWeight(weight);
subplot.setInsets(new Insets(0, 0, 0, 0));
subplot.setRangeAxis(null);
this.subplots.add(subplot);
// keep track of total weights
this.totalWeight += weight;
// configure the range axis...
ValueAxis axis = getRangeAxis();
if (axis != null) {
axis.configure();
}
configureSecondaryRangeAxes();
notifyListeners(new PlotChangeEvent(this));
}
/**
* Removes a subplot from the combined chart.
*
* @param subplot the subplot.
*/
public void remove(XYPlot subplot) {
subplots.remove(subplot);
subplot.setParent(null);
this.totalWeight -= subplot.getWeight();
ValueAxis range = getRangeAxis();
if (range != null) {
range.configure();
}
configureSecondaryRangeAxes();
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the list of subplots.
*
* @return the list of subplots.
*/
public List getSubplots() {
return Collections.unmodifiableList(this.subplots);
}
/**
* Calculates the space required for the axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
*
* @return The space required for the axes.
*/
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
AxisSpace space = new AxisSpace();
PlotOrientation orientation = getOrientation();
// work out the space required by the domain axis...
AxisSpace fixed = getFixedRangeAxisSpace();
if (fixed != null) {
if (orientation == PlotOrientation.VERTICAL) {
space.setLeft(fixed.getLeft());
space.setRight(fixed.getRight());
}
else if (orientation == PlotOrientation.HORIZONTAL) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -