⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xyshaperenderer.java

📁 jfreechart-1.0.12.zip 可以用来作图
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2008, 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 *
 * --------------------
 * XYShapeRenderer.java
 * --------------------
 * (C) Copyright 2008, by Andreas Haumer, xS+S and Contributors.
 *
 * Original Author:  Martin Hoeller (x Software + Systeme  xS+S - Andreas
 *                       Haumer);
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * Changes:
 * --------
 * 17-Sep-2008 : Version 1, based on a contribution from Martin Hoeller with
 *               amendments by David Gilbert (DG);
 *
 */

package org.jfree.chart.renderer.xy;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
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 org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.event.RendererChangeEvent;
import org.jfree.chart.plot.CrosshairState;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.LookupPaintScale;
import org.jfree.chart.renderer.PaintScale;
import org.jfree.data.Range;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYZDataset;
import org.jfree.io.SerialUtilities;
import org.jfree.util.PublicCloneable;
import org.jfree.util.ShapeUtilities;

/**
 * A renderer that draws shapes at (x, y) coordinates and, if the dataset
 * is an instance of {@link XYZDataset}, fills the shapes with a paint that
 * is based on the z-value (the paint is obtained from a lookup table).  The
 * renderer also allows for optional guidelines, horizontal and vertical lines
 * connecting the shape to the edges of the plot.
 * <br><br>
 * The example shown here is generated by the
 * <code>XYShapeRendererDemo1.java</code> program included in the JFreeChart
 * demo collection:
 * <br><br>
 * <img src="../../../../../images/XYShapeRendererSample.png"
 * alt="XYShapeRendererSample.png" />
 * <br><br>
 * This renderer has similarities to, but also differences from, the
 * {@link XYLineAndShapeRenderer}.
 *
 * @since 1.0.11
 */
public class XYShapeRenderer extends AbstractXYItemRenderer
        implements XYItemRenderer, Cloneable, Serializable {

    /** Auto generated serial version id. */
    private static final long serialVersionUID = 8320552104211173221L;

    /** The paint scale. */
    private PaintScale paintScale;

    /** A flag that controls whether or not the shape outlines are drawn. */
    private boolean drawOutlines;

    /**
     * A flag that controls whether or not the outline paint is used (if not,
     * the regular paint is used).
     */
    private boolean useOutlinePaint;

    /**
     * A flag that controls whether or not the fill paint is used (if not,
     * the fill paint is used).
     */
    private boolean useFillPaint;

    /** Flag indicating if guide lines should be drawn for every item. */
    private boolean guideLinesVisible;

    /** The paint used for drawing the guide lines. */
    private transient Paint guideLinePaint;

    /** The stroke used for drawing the guide lines. */
    private transient Stroke guideLineStroke;

    /**
     * Creates a new <code>XYShapeRenderer</code> instance with default
     * attributes.
     */
    public XYShapeRenderer() {
        this.paintScale = new LookupPaintScale();
        this.useFillPaint = false;
        this.drawOutlines = false;
        this.useOutlinePaint = true;
        this.guideLinesVisible = false;
        this.guideLinePaint = Color.darkGray;
        this.guideLineStroke = new BasicStroke();
        setBaseShape(new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
        setAutoPopulateSeriesShape(false);
    }

    /**
     * Returns the paint scale used by the renderer.
     *
     * @return The paint scale (never <code>null</code>).
     *
     * @see #setPaintScale(PaintScale)
     */
    public PaintScale getPaintScale() {
        return this.paintScale;
    }

    /**
     * Sets the paint scale used by the renderer and sends a
     * {@link RendererChangeEvent} to all registered listeners.
     *
     * @param scale  the scale (<code>null</code> not permitted).
     *
     * @see #getPaintScale()
     */
    public void setPaintScale(PaintScale scale) {
        if (scale == null) {
            throw new IllegalArgumentException("Null 'scale' argument.");
        }
        this.paintScale = scale;
        notifyListeners(new RendererChangeEvent(this));
    }

    /**
     * Returns <code>true</code> if outlines should be drawn for shapes, and
     * <code>false</code> otherwise.
     *
     * @return A boolean.
     *
     * @see #setDrawOutlines(boolean)
     */
    public boolean getDrawOutlines() {
        return this.drawOutlines;
    }

    /**
     * Sets the flag that controls whether outlines are drawn for
     * shapes, and sends a {@link RendererChangeEvent} to all registered
     * listeners.
     * <P>
     * In some cases, shapes look better if they do NOT have an outline, but
     * this flag allows you to set your own preference.
     *
     * @param flag  the flag.
     *
     * @see #getDrawOutlines()
     */
    public void setDrawOutlines(boolean flag) {
        this.drawOutlines = flag;
        fireChangeEvent();
    }

    /**
     * Returns <code>true</code> if the renderer should use the fill paint
     * setting to fill shapes, and <code>false</code> if it should just
     * use the regular paint.
     * <p>
     * Refer to <code>XYLineAndShapeRendererDemo2.java</code> to see the
     * effect of this flag.
     *
     * @return A boolean.
     *
     * @see #setUseFillPaint(boolean)
     * @see #getUseOutlinePaint()
     */
    public boolean getUseFillPaint() {
        return this.useFillPaint;
    }

    /**
     * Sets the flag that controls whether the fill paint is used to fill
     * shapes, and sends a {@link RendererChangeEvent} to all
     * registered listeners.
     *
     * @param flag  the flag.
     *
     * @see #getUseFillPaint()
     */
    public void setUseFillPaint(boolean flag) {
        this.useFillPaint = flag;
        fireChangeEvent();
    }

    /**
     * Returns the flag that controls whether the outline paint is used for
     * shape outlines.  If not, the regular series paint is used.
     *
     * @return A boolean.
     *
     * @see #setUseOutlinePaint(boolean)
     */
    public boolean getUseOutlinePaint() {
        return this.useOutlinePaint;
    }

    /**
     * Sets the flag that controls whether the outline paint is used for shape
     * outlines, and sends a {@link RendererChangeEvent} to all registered
     * listeners.
     *
     * @param use  the flag.
     *
     * @see #getUseOutlinePaint()
     */
    public void setUseOutlinePaint(boolean use) {
        this.useOutlinePaint = use;
        fireChangeEvent();
    }

    /**
     * Returns a flag that controls whether or not guide lines are drawn for
     * each data item (the lines are horizontal and vertical "crosshairs"
     * linking the data point to the axes).
     *
     * @return A boolean.
     *
     * @see #setGuideLinesVisible(boolean)
     */
    public boolean isGuideLinesVisible() {
        return this.guideLinesVisible;
    }

    /**
     * Sets the flag that controls whether or not guide lines are drawn for
     * each data item and sends a {@link RendererChangeEvent} to all registered
     * listeners.
     *
     * @param visible  the new flag value.
     *
     * @see #isGuideLinesVisible()
     */
    public void setGuideLinesVisible(boolean visible) {
        this.guideLinesVisible = visible;
        fireChangeEvent();
    }

    /**
     * Returns the paint used to draw the guide lines.
     *
     * @return The paint (never <code>null</code>).
     *
     * @see #setGuideLinePaint(Paint)
     */
    public Paint getGuideLinePaint() {
        return this.guideLinePaint;
    }

    /**
     * Sets the paint used to draw the guide lines and sends a
     * {@link RendererChangeEvent} to all registered listeners.
     *
     * @param paint  the paint (<code>null</code> not permitted).
     *
     * @see #getGuideLinePaint()
     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -