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

📄 xylineandshaperenderer.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ===========================================================
 * 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.]
 *
 * ---------------------------
 * XYLineAndShapeRenderer.java
 * ---------------------------
 * (C) Copyright 2004, by Object Refinery Limited.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * $Id: XYLineAndShapeRenderer.java,v 1.1 2004/08/31 14:49:29 mungady Exp $
 *
 * Changes:
 * --------
 * 27-Jan-2004 : Version 1 (DG);
 * 10-Feb-2004 : Minor change to drawItem() method to make cut-and-paste overriding easier (DG);
 * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG);
 * 25-Aug-2004 : Added support for chart entities (required for tooltips) (DG);
 *
 */

package org.jfree.chart.renderer.xy;

import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
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.data.xy.XYDataset;
import org.jfree.ui.RectangleEdge;
import org.jfree.util.BooleanList;
import org.jfree.util.BooleanUtils;
import org.jfree.util.ObjectUtils;
import org.jfree.util.PublicCloneable;

/**
 * A renderer that can be used with the {@link XYPlot} class.
 */
public class XYLineAndShapeRenderer extends AbstractXYItemRenderer 
                                    implements XYItemRenderer, 
                                               Cloneable,
                                               PublicCloneable,
                                               Serializable {

    /** A flag that controls whether or not lines are visible for ALL series. */
    private Boolean linesVisible;

    /** A table of flags that control (per series) whether or not lines are visible. */
    private BooleanList seriesLinesVisible;

    /** The default value returned by the getLinesVisible() method. */
    private boolean defaultLinesVisible;

    /** A flag that controls whether or not shapes are visible for ALL series. */
    private Boolean shapesVisible;

    /** A table of flags that control (per series) whether or not shapes are visible. */
    private BooleanList seriesShapesVisible;

    /** The default value returned by the getShapeVisible() method. */
    private boolean defaultShapesVisible;

    /** A flag that controls whether or not shapes are filled for ALL series. */
    private Boolean shapesFilled;

    /** A table of flags that control (per series) whether or not shapes are filled. */
    private BooleanList seriesShapesFilled;

    /** The default value returned by the getShapeFilled(...) method. */
    private boolean defaultShapesFilled;
    
    /** A flag that controls whether outlines are drawn for filled shapes. */
    private boolean drawOutlines;
    
    /** A flag that controls whether the outline paint is used for drawing shape outlines. */
    private boolean useOutlinePaint;

    /**
     * Creates a new renderer with default settings.
     */
    public XYLineAndShapeRenderer() {
        
        this.linesVisible = null;
        this.seriesLinesVisible = new BooleanList();
        this.defaultLinesVisible = true;
        
        this.shapesVisible = null;
        this.seriesShapesVisible = new BooleanList();
        this.defaultShapesVisible = true;
        
        this.shapesFilled = null;
        this.seriesShapesFilled = new BooleanList();
        this.defaultShapesFilled = true;

        this.drawOutlines = false;     // don't draw outlines for filled shapes
        this.useOutlinePaint = false;  // use item paint for outlines, not outline paint
        
    }
    
    /**
     * Returns the number of passes through the data that the renderer requires in order to
     * draw the chart.  Most charts will require a single pass, but some require two passes.
     * 
     * @return The pass count.
     */
    public int getPassCount() {
        return 2;
    }
    
    // LINES VISIBLE

    /**
     * Returns the flag used to control whether or not the shape for an item is visible.
     *
     * @param series  the series index (zero-based).
     * @param item  the item index (zero-based).
     *
     * @return A boolean.
     */
    public boolean getItemLineVisible(int series, int item) {
        Boolean flag = this.linesVisible;
        if (flag == null) {
            flag = getSeriesLinesVisible(series);
        }
        if (flag != null) {
            return flag.booleanValue();
        }
        else {
            return this.defaultLinesVisible;   
        }
    }

    /**
     * Returns a flag that controls whether or not lines are drawn for ALL series.  If this
     * flag is <code>null</code>, then the "per series" settings will apply.
     * 
     * @return A flag (possibly <code>null</code>).
     */
    public Boolean getLinesVisible() {
        return this.linesVisible;   
    }
    
    /**
     * Sets a flag that controls whether or not lines are drawn between the items in ALL series,
     * and sends a {@link RendererChangeEvent} to all registered listeners.  You need to set this
     * to <code>null</code> if you want the "per series" settings to apply.
     *
     * @param visible  the flag (<code>null</code> permitted).
     */
    public void setLinesVisible(Boolean visible) {
        this.linesVisible = visible;
        notifyListeners(new RendererChangeEvent(this));
    }

    /**
     * Sets a flag that controls whether or not lines are drawn between the items in ALL series,
     * and sends a {@link RendererChangeEvent} to all registered listeners.
     *
     * @param visible  the flag.
     */
    public void setLinesVisible(boolean visible) {
        setLinesVisible(BooleanUtils.valueOf(visible));
    }

    /**
     * Returns the flag used to control whether or not the lines for a series are visible.
     *
     * @param series  the series index (zero-based).
     *
     * @return The flag (possibly <code>null</code>).
     */
    public Boolean getSeriesLinesVisible(int series) {
        return this.seriesLinesVisible.getBoolean(series);
    }

    /**
     * Sets the 'lines visible' flag for a series.
     *
     * @param series  the series index (zero-based).
     * @param flag  the flag (<code>null</code> permitted).
     */
    public void setSeriesLinesVisible(int series, Boolean flag) {
        this.seriesLinesVisible.setBoolean(series, flag);
        notifyListeners(new RendererChangeEvent(this));
    }

    /**
     * Sets the 'lines visible' flag for a series.
     * 
     * @param series  the series index (zero-based).
     * @param visible  the flag.
     */
    public void setSeriesLinesVisible(int series, boolean visible) {
        setSeriesLinesVisible(series, BooleanUtils.valueOf(visible));
    }
    
    /**
     * Returns the default 'lines visible' attribute.
     *
     * @return The default flag.
     */
    public boolean getDefaultLinesVisible() {
        return this.defaultLinesVisible;
    }

    /**
     * Sets the default 'lines visible' flag.
     *
     * @param flag  the flag.
     */
    public void setDefaultLinesVisible(boolean flag) {
        this.defaultLinesVisible = flag;
        notifyListeners(new RendererChangeEvent(this));
    }

    // SHAPES VISIBLE

    /**
     * Returns the flag used to control whether or not the shape for an item is visible.
     * <p>
     * The default implementation passes control to the <code>getSeriesShapesVisible</code> method.
     * You can override this method if you require different behaviour.
     *
     * @param series  the series index (zero-based).
     * @param item  the item index (zero-based).
     *
     * @return A boolean.
     */
    public boolean getItemShapeVisible(int series, int item) {
        Boolean flag = this.shapesVisible;
        if (flag == null) {
            flag = getSeriesShapesVisible(series);
        }
        if (flag != null) {
            return flag.booleanValue();   
        }
        else {
            return this.defaultShapesVisible;
        }
    }

    /**
     * Returns the flag that controls whether the shapes are visible for the items in 
     * ALL series.
     * 
     * @return The flag (possibly <code>null</code>).
     */
    public Boolean getShapesVisible() {
        return this.shapesVisible;    
    }
    
    /**
     * Sets the 'shapes visible' for ALL series and sends a {@link RendererChangeEvent}
     * to all registered listeners.
     *
     * @param visible  the flag (<code>null</code> permitted).
     */
    public void setShapesVisible(Boolean visible) {
        this.shapesVisible = visible;
        notifyListeners(new RendererChangeEvent(this));
    }

    /**
     * Sets the 'shapes visible' for ALL series and sends a {@link RendererChangeEvent}
     * to all registered listeners.
     * 
     * @param visible  the flag.
     */
    public void setShapesVisible(boolean visible) {
        setShapesVisible(BooleanUtils.valueOf(visible));
    }

    /**
     * Returns the flag used to control whether or not the shapes for a series are visible.
     *
     * @param series  the series index (zero-based).
     *
     * @return A boolean.
     */
    public Boolean getSeriesShapesVisible(int series) {
        return this.seriesShapesVisible.getBoolean(series);
    }

    /**
     * Sets the 'shapes visible' flag for a series and sends a {@link RendererChangeEvent}
     * to all registered listeners.
     * 
     * @param series  the series index (zero-based).
     * @param visible  the flag.
     */
    public void setSeriesShapesVisible(int series, boolean visible) {
        setSeriesShapesVisible(series, BooleanUtils.valueOf(visible));
    }
    
    /**
     * Sets the 'shapes visible' flag for a series and sends a {@link RendererChangeEvent}
     * to all registered listeners.
     *
     * @param series  the series index (zero-based).
     * @param flag  the flag.
     */
    public void setSeriesShapesVisible(int series, Boolean flag) {
        this.seriesShapesVisible.setBoolean(series, flag);
        notifyListeners(new RendererChangeEvent(this));
    }

    /**
     * Returns the default 'shape visible' attribute.
     *
     * @return The default flag.
     */
    public boolean getDefaultShapesVisible() {
        return this.defaultShapesVisible;
    }

    /**
     * Sets the default 'shapes visible' flag.
     *
     * @param flag  the flag.
     */
    public void setDefaultShapesVisible(boolean flag) {
        this.defaultShapesVisible = flag;
        notifyListeners(new RendererChangeEvent(this));
    }

    // SHAPES FILLED

⌨️ 快捷键说明

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