?? categoryplot.java
字號(hào):
/* ======================================
* 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.
*
* -----------------
* CategoryPlot.java
* -----------------
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Jeremy Bowman;
* Arnaud Lelievre;
*
* $Id: CategoryPlot.java,v 1.32 2003/09/11 07:27:49 mungady Exp $
*
* Changes (from 21-Jun-2001)
* --------------------------
* 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG);
* 21-Aug-2001 : Added standard header. Fixed DOS encoding problem (DG);
* 18-Sep-2001 : Updated header (DG);
* 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG);
* 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG);
* 23-Oct-2001 : Changed intro and trail gaps on bar plots to use percentage of available space
* rather than a fixed number of units (DG);
* 12-Dec-2001 : Changed constructors to protected (DG);
* 13-Dec-2001 : Added tooltips (DG);
* 16-Jan-2002 : Increased maximum intro and trail gap percents, plus added some argument checking
* code. Thanks to Taoufik Romdhane for suggesting this (DG);
* 05-Feb-2002 : Added accessor methods for the tooltip generator, incorporated alpha-transparency
* for Plot and subclasses (DG);
* 06-Mar-2002 : Updated import statements (DG);
* 14-Mar-2002 : Renamed BarPlot.java --> CategoryPlot.java, and changed code to use the
* CategoryItemRenderer interface (DG);
* 22-Mar-2002 : Dropped the getCategories() method (DG);
* 23-Apr-2002 : Moved the dataset from the JFreeChart class to the Plot class (DG);
* 29-Apr-2002 : New methods to support printing values at the end of bars, contributed by
* Jeremy Bowman (DG);
* 11-May-2002 : New methods for label visibility and overlaid plot support, contributed by
* Jeremy Bowman (DG);
* 06-Jun-2002 : Removed the tooltip generator, this is now stored with the renderer. Moved
* constants into the CategoryPlotConstants interface. Updated Javadoc
* comments (DG);
* 10-Jun-2002 : Overridden datasetChanged(...) method to update the upper and lower bound on the
* range axis (if necessary), updated Javadocs (DG);
* 25-Jun-2002 : Removed redundant imports (DG);
* 20-Aug-2002 : Changed the constructor for Marker (DG);
* 28-Aug-2002 : Added listener notification to setDomainAxis(...) and setRangeAxis(...) (DG);
* 23-Sep-2002 : Added getLegendItems() method and fixed errors reported by Checkstyle (DG);
* 28-Oct-2002 : Changes to the CategoryDataset interface (DG);
* 05-Nov-2002 : Base dataset is now TableDataset not CategoryDataset (DG);
* 07-Nov-2002 : Renamed labelXXX as valueLabelXXX (DG);
* 18-Nov-2002 : Added grid settings for both domain and range axis (previously these were set in
* the axes) (DG);
* 19-Nov-2002 : Added axis location parameters to constructor (DG);
* 17-Jan-2003 : Moved to com.jrefinery.chart.plot package (DG);
* 14-Feb-2003 : Fixed bug in auto-range calculation for secondary axis (DG);
* 26-Mar-2003 : Implemented Serializable (DG);
* 02-May-2003 : Moved render(...) method up from subclasses. Added secondary range markers.
* Added an attribute to control the dataset rendering order. Added a
* drawAnnotations(...) method. Changed the axis location from an int to an
* AxisLocation (DG);
* 07-May-2003 : Merged HorizontalCategoryPlot and VerticalCategoryPlot into this class (DG);
* 02-Jun-2003 : Removed check for range axis compatibility (DG);
* 04-Jul-2003 : Added a domain gridline position attribute (DG);
* 21-Jul-2003 : Moved DrawingSupplier to Plot superclass (DG);
* 19-Aug-2003 : Added equals(...) method and implemented Cloneable (DG);
* 01-Sep-2003 : Fixed bug 797466 (no change event when secondary dataset changes) (DG);
* 02-Sep-2003 : Fixed bug 795209 (wrong dataset checked in render2 method) and 790407 (initialise
method) (DG);
* 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL);
* 08-Sep-2003 : Fixed bug (wrong secondary range axis being used). Changed ValueAxis API (DG);
* 10-Sep-2003 : Fixed bug in setRangeAxis(...) method (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.Graphics2D;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Line2D;
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.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.LegendItem;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.Marker;
import org.jfree.chart.Spacer;
import org.jfree.chart.annotations.CategoryAnnotation;
import org.jfree.chart.axis.Axis;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.axis.CategoryAnchor;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.Tick;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.renderer.CategoryItemRenderer;
import org.jfree.chart.renderer.RangeType;
import org.jfree.data.CategoryDataset;
import org.jfree.data.DatasetChangeEvent;
import org.jfree.data.DatasetUtilities;
import org.jfree.data.Range;
import org.jfree.io.SerialUtilities;
import org.jfree.ui.RectangleEdge;
import org.jfree.util.ObjectList;
import org.jfree.util.ObjectUtils;
import org.jfree.util.PublicCloneable;
/**
* A general plotting class that uses data from a {@link CategoryDataset} and renders each data
* item using a {@link CategoryItemRenderer}.
*
* @author David Gilbert
*/
public class CategoryPlot extends Plot implements ValueAxisPlot, Cloneable, Serializable {
/** The default visibility of the grid lines plotted against the domain axis. */
public static final boolean DEFAULT_DOMAIN_GRIDLINES_VISIBLE = false;
/** The default visibility of the grid lines plotted against the range axis. */
public static final boolean DEFAULT_RANGE_GRIDLINES_VISIBLE = true;
/** 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.lightGray;
/** The default value label font. */
public static final Font DEFAULT_VALUE_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 10);
/** The plot orientation. */
private PlotOrientation orientation;
/** The offset between the data area and the axes. */
private Spacer axisOffset;
/** The domain axis. */
private CategoryAxis domainAxis;
/** The location of the domain axis. */
private AxisLocation domainAxisLocation;
/** Storage for the (optional) secondary domain axes. */
private ObjectList secondaryDomainAxes;
/** Storage for the (optional) secondary domain axis locations. */
private ObjectList secondaryDomainAxisLocations;
/**
* A flag that controls whether or not the shared domain axis is drawn (only relevant when
* the plot is being used as a subplot).
*/
private boolean drawSharedDomainAxis;
/** The range axis. */
private ValueAxis rangeAxis;
/** The range axis location. */
private AxisLocation rangeAxisLocation;
/** Storage for the (optional) secondary range axes. */
private ObjectList secondaryRangeAxes;
/** Storage for the (optional) secondary range axis locations. */
private ObjectList secondaryRangeAxisLocations;
/** The primary dataset for the plot. */
private CategoryDataset dataset;
/** Storage for the (optional) secondary datasets. */
private ObjectList secondaryDatasets;
/** Storage for keys that map secondary datasets to domain axes. */
private ObjectList secondaryDatasetDomainAxisMap;
/** Storage for keys that map secondary datasets to range axes. */
private ObjectList secondaryDatasetRangeAxisMap;
/** The renderer for the data items. */
private CategoryItemRenderer renderer;
/** Storage for the (optional) secondary renderers. */
private ObjectList secondaryRenderers;
/** The dataset rendering order. */
private DatasetRenderingOrder renderingOrder = DatasetRenderingOrder.STANDARD;
/** A flag that controls whether the grid-lines for the domain axis are visible. */
private boolean domainGridlinesVisible;
/** The position of the domain gridlines relative to the category. */
private CategoryAnchor domainGridlinePosition;
/** The stroke used to draw the domain grid-lines. */
private transient Stroke domainGridlineStroke;
/** The paint used to draw the domain grid-lines. */
private transient Paint domainGridlinePaint;
/** A flag that controls whether the grid-lines for the range axis are visible. */
private boolean rangeGridlinesVisible;
/** The stroke used to draw the range axis grid-lines. */
private transient Stroke rangeGridlineStroke;
/** The paint used to draw the range axis grid-lines. */
private transient Paint rangeGridlinePaint;
/** The anchor value. */
private double anchorValue;
/** 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 range axis. */
private transient List rangeMarkers;
/** A list of secondary markers (optional) for the secondary range axis. */
private transient List secondaryRangeMarkers;
/** A list of annotations (optional) for the plot. */
private transient List annotations;
/**
* The weight for the plot (only relevant when the plot is used as a subplot within a
* combined plot).
*/
private int weight;
/** The fixed space for the domain axis. */
private AxisSpace fixedDomainAxisSpace;
/** The fixed space for the range axis. */
private AxisSpace fixedRangeAxisSpace;
/** Temporary storage. */
private transient List axesAtTop;
/** Temporary storage. */
private transient List axesAtBottom;
/** Temporary storage. */
private transient List axesAtLeft;
/** Temporary storage. */
private transient List axesAtRight;
/** The resourceBundle for the localization. */
static protected ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/**
* Default constructor.
*/
public CategoryPlot() {
this(null, null, null, null);
}
/**
* Creates a new plot.
*
* @param dataset the dataset.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param renderer the item renderer.
*
*/
public CategoryPlot(CategoryDataset dataset,
CategoryAxis domainAxis,
ValueAxis rangeAxis,
CategoryItemRenderer renderer) {
super();
this.orientation = PlotOrientation.VERTICAL;
// allocate storage for secondary dataset, axes and renderers (all optional)
this.secondaryDomainAxes = new ObjectList();
this.secondaryDomainAxisLocations = new ObjectList();
this.secondaryRangeAxes = new ObjectList();
this.secondaryRangeAxisLocations = new ObjectList();
this.secondaryDatasets = new ObjectList();
this.secondaryDatasetDomainAxisMap = new ObjectList();
this.secondaryDatasetRangeAxisMap = new ObjectList();
this.secondaryRenderers = new ObjectList();
this.dataset = dataset;
if (dataset != null) {
dataset.addChangeListener(this);
}
this.axisOffset = new Spacer(Spacer.ABSOLUTE, 0.0, 0.0, 0.0, 0.0);
setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT, false);
setRangeAxisLocation(AxisLocation.TOP_OR_LEFT, false);
this.renderer = renderer;
if (renderer != null) {
renderer.setPlot(this);
}
this.domainAxis = domainAxis;
if (domainAxis != null) {
domainAxis.setPlot(this);
domainAxis.addChangeListener(this);
}
this.drawSharedDomainAxis = false;
this.rangeAxis = rangeAxis;
if (rangeAxis != null) {
rangeAxis.setPlot(this);
rangeAxis.addChangeListener(this);
}
this.domainGridlinesVisible = DEFAULT_DOMAIN_GRIDLINES_VISIBLE;
this.domainGridlinePosition = CategoryAnchor.MIDDLE;
this.domainGridlineStroke = DEFAULT_GRIDLINE_STROKE;
this.domainGridlinePaint = DEFAULT_GRIDLINE_PAINT;
this.rangeGridlinesVisible = DEFAULT_RANGE_GRIDLINES_VISIBLE;
this.rangeGridlineStroke = DEFAULT_GRIDLINE_STROKE;
this.rangeGridlinePaint = DEFAULT_GRIDLINE_PAINT;
this.rangeMarkers = null;
this.secondaryRangeMarkers = null;
Marker baseline = new Marker(0.0,
new Color(0.8f, 0.8f, 0.8f, 0.5f),
new java.awt.BasicStroke(1.0f),
new Color(0.85f, 0.85f, 0.95f, 0.5f), 0.6f);
addRangeMarker(baseline);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -