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

📄 abstractrenderer.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* ======================================
 * 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.
 *
 * ---------------------
 * AbstractRenderer.java
 * ---------------------
 * (C) Copyright 2002, 2003 by Object Refinery Limited.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * $Id: AbstractRenderer.java,v 1.17 2003/08/01 09:47:29 mungady Exp $
 *
 * Changes:
 * --------
 * 22-Aug-2002 : Version 1, draws code out of AbstractXYItemRenderer to share with
 *               AbstractCategoryItemRenderer (DG);
 * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG);
 * 06-Nov-2002 : Moved to the com.jrefinery.chart.renderer package (DG);
 * 21-Nov-2002 : Added a paint table for the renderer to use (DG);
 * 17-Jan-2003 : Moved plot classes into a separate package (DG);
 * 25-Mar-2003 : Implemented Serializable (DG);
 * 29-Apr-2003 : Added valueLabelFont and valueLabelPaint attributes, based on code from
 *               Arnaud Lelievre (DG);
 * 29-Jul-2003 : Amended code that doesn't compile with JDK 1.2.2 (DG);
 * 
 */

package org.jfree.chart.renderer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.plot.DrawingSupplier;
import org.jfree.io.SerialUtilities;
import org.jfree.ui.TextAnchor;
import org.jfree.util.BooleanList;
import org.jfree.util.FontTable;
import org.jfree.util.NumberTable;
import org.jfree.util.ObjectUtils;
import org.jfree.util.PaintTable;
import org.jfree.util.ShapeTable;
import org.jfree.util.StrokeTable;

/**
 * Base class providing common services for renderers.
 *
 * @author David Gilbert
 */
public abstract class AbstractRenderer implements Serializable {

    /** The default paint. */
    public static final Paint DEFAULT_PAINT = Color.blue;

    /** The default outline paint. */
    public static final Paint DEFAULT_OUTLINE_PAINT = Color.gray;

    /** The default stroke. */
    public static final Stroke DEFAULT_STROKE = new BasicStroke(1.0f);

    /** The default outline stroke. */
    public static final Stroke DEFAULT_OUTLINE_STROKE = new BasicStroke(1.0f);

    /** The default shape. */
    public static final Shape DEFAULT_SHAPE = new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0);

    /** The default value label font. */
    public static final Font DEFAULT_VALUE_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 10);

    /** The default value label pant. */
    public static final Paint DEFAULT_VALUE_LABEL_PAINT = Color.black;

    /** The paint for ALL series (optional). */
    private transient Paint paint;

    /** The paint list. */
    private PaintTable paintList;

    /** The base paint. */
    private transient Paint basePaint;

    /** The outline paint for ALL series (optional). */
    private transient Paint outlinePaint;

    /** The outline paint list. */
    private PaintTable outlinePaintList;

    /** The base outline paint. */
    private transient Paint baseOutlinePaint;

    /** The stroke for ALL series (optional). */
    private transient Stroke stroke;

    /** The stroke list. */
    private StrokeTable strokeList;

    /** The base stroke. */
    private transient Stroke baseStroke;

    /** The outline stroke for ALL series (optional). */
    private transient Stroke outlineStroke;

    /** The outline stroke list. */
    private StrokeTable outlineStrokeList;

    /** The base outline stroke. */
    private transient Stroke baseOutlineStroke;

    /** The shape for ALL series (optional). */
    private transient Shape shape;

    /** A shape list. */
    private ShapeTable shapeList;

    /** The base shape. */
    private transient Shape baseShape;

    /** Visibility of the item labels for ALL series (optional). */
    private Boolean itemLabelsVisible;

    /** Visibility of the item labels PER series. */
    private BooleanList itemLabelsVisibleList;

    /** The base item labels visible. */
    private Boolean baseItemLabelsVisible;

    /** The item label font for ALL series (optional). */
    private Font itemLabelFont;

    /** The item label font list (one font per series). */
    private FontTable itemLabelFontList;

    /** The base item label font. */
    private Font baseItemLabelFont;

    /** The item label paint for ALL series. */
    private transient Paint itemLabelPaint;

    /** The item label paint list (one paint per series). */
    private PaintTable itemLabelPaintList;

    /** The base item label paint. */
    private transient Paint baseItemLabelPaint;

    /** The item label anchor. */
    private ItemLabelAnchor itemLabelAnchor;

    /** The item label anchor list (one anchor per series). */
    private ItemLabelAnchorTable itemLabelAnchorList;

    /** The base item label anchor. */
    private ItemLabelAnchor baseItemLabelAnchor;

    /** The item label text anchor. */
    private TextAnchor itemLabelTextAnchor;

    /** The item label text anchor list (one anchor per series). */
    private TextAnchorTable itemLabelTextAnchorList;

    /** The base item label text anchor. */
    private TextAnchor baseItemLabelTextAnchor;

    /** The rotation anchor. */
    private TextAnchor itemLabelRotationAnchor;

    /** The rotation anchor list (one anchor per series). */
    private TextAnchorTable itemLabelRotationAnchorList;

    /** The base rotation anchor. */
    private TextAnchor baseItemLabelRotationAnchor;

    /** The angle. */
    private Number itemLabelAngle;

    /** The angle list (one angle per series). */
    private NumberTable itemLabelAngleList;

    /** The base angle. */
    private Number baseItemLabelAngle;

    /** A temporary reference to chart rendering info (may be <code>null</code>). */
    private transient ChartRenderingInfo info;

    /** Support class for the property change listener mechanism. */
    private transient PropertyChangeSupport listeners;

    /**
     * Default constructor.
     */
    public AbstractRenderer() {

        this.paint = null;
        this.paintList = new PaintTable();
        this.basePaint = DEFAULT_PAINT;

        this.outlinePaint = null;
        this.outlinePaintList = new PaintTable();
        this.baseOutlinePaint = DEFAULT_OUTLINE_PAINT;

        this.stroke = null;
        this.strokeList = new StrokeTable();
        this.baseStroke = DEFAULT_STROKE;

        this.outlineStroke = null;
        this.outlineStrokeList = new StrokeTable();
        this.baseOutlineStroke = DEFAULT_OUTLINE_STROKE;

        this.shape = null;
        this.shapeList = new ShapeTable();
        this.baseShape = DEFAULT_SHAPE;

        this.itemLabelsVisible = null;
        this.itemLabelsVisibleList = new BooleanList();
        this.baseItemLabelsVisible = Boolean.FALSE;

        this.itemLabelFont = null;
        this.itemLabelFontList = new FontTable();
        this.baseItemLabelFont = new Font("SansSerif", Font.PLAIN, 10);

        this.itemLabelPaint = null;
        this.itemLabelPaintList = new PaintTable();
        this.baseItemLabelPaint = Color.black;

        this.itemLabelAnchor = null;
        this.itemLabelAnchorList = new ItemLabelAnchorTable();
        this.baseItemLabelAnchor = ItemLabelAnchor.OUTSIDE12;

        this.itemLabelTextAnchor = null;
        this.itemLabelTextAnchorList = new TextAnchorTable();
        this.baseItemLabelTextAnchor = TextAnchor.BOTTOM_CENTER;

        this.itemLabelRotationAnchor = null;
        this.itemLabelRotationAnchorList = new TextAnchorTable();
        this.baseItemLabelRotationAnchor = TextAnchor.CENTER;

        this.itemLabelAngle = null;
        this.itemLabelAngleList = new NumberTable();
        this.baseItemLabelAngle = new Double(0.0);

        this.info = null;
        this.listeners = new PropertyChangeSupport(this);

    }

    /**
     * Returns the chart rendering info.
     *
     * @return the chart rendering info.
     */
    public ChartRenderingInfo getInfo() {
        return this.info;
    }

    /**
     * Sets the chart rendering info.
     *
     * @param info  the chart rendering info.
     */
    public void setInfo(ChartRenderingInfo info) {
        this.info = info;
    }

    /**
     * Returns the drawing supplier from the plot.
     * 
     * @return The drawing supplier.
     */
    public abstract DrawingSupplier getDrawingSupplier();
    
    // PAINT
    
    /**
     * Returns the paint used to fill data items as they are drawn.
     * <p>
     * The default implementation passes control to the <code>getSeriesPaint</code> method.
     * You can override this method if you require different behaviour.
     *
     * @param row  the row (or series) index (zero-based).
     * @param column  the column (or category) index (zero-based).
     *
     * @return  The paint.
     */
    public Paint getItemPaint(int row, int column) {
        return getSeriesPaint(row);
    }

    /**
     * Returns the color used to fill an item drawn by the renderer.
     *
     * @param series  the series index (zero-based).
     *
     * @return  The paint.
     */
    public Paint getSeriesPaint(int series) {

        // return the override, if there is one...
        if (this.paint != null) {
            return this.paint;
        }

        // otherwise look up the paint list
        Paint paint = this.paintList.getPaint(0, series);
        if (paint == null) {
            DrawingSupplier supplier = getDrawingSupplier();
            if (supplier != null) {
                paint = supplier.getNextPaint();
                this.paintList.setPaint(0, series, paint);
            }
            else {
                paint = this.basePaint;
            }
        }
        return paint;

    }

    /**
     * Sets the paint to be used for ALL series.  Most of the time, you will want to leave this
     * set to <code>null</code> so that the paint lookup table is used instead.
     * 
     * @param paint  the paint (<code>null</code> permitted).
     */
    public void setPaint(Paint paint) {
        this.paint = paint;
    }
    
    /**
     * Sets the paint used for a series.
     *
     * @param series  the series index (zero-based).
     * @param paint  the paint.
     */
    public void setSeriesPaint(int series, Paint paint) {
        this.paintList.setPaint(0, series, paint);
    }

    /**
     * Returns the base paint.
     *
     * @return The base paint.
     */
    public Paint getBasePaint() {
        return this.basePaint;
    }

    /**
     * Sets the base paint.
     * <p>
     * In most cases, the renderer's paint table will be active and so this default value will
     * not be used.
     *
     * @param paint  the paint.
     */
    public void setBasePaint(Paint paint) {
        this.basePaint = paint;
    }

    // OUTLINE PAINT
    
    /**
     * Returns the paint used to outline data items as they are drawn.
     * <p>
     * The default implementation passes control to the getSeriesOutlinePaint method.  You can
     * override this method if you require different behaviour.
     *
     * @param row  the row (or series) index (zero-based).
     * @param column  the column (or category) index (zero-based).
     *
     * @return  The paint.
     */
    public Paint getItemOutlinePaint(int row, int column) {
        return getSeriesOutlinePaint(row);
    }

    /**
     * Returns the color used to outline an item drawn by the renderer.
     *
     * @param series  the series (zero-based index).
     *
     * @return  The paint.
     */
    public Paint getSeriesOutlinePaint(int series) {

        // return the override, if there is one...
        if (this.outlinePaint != null) {
            return this.outlinePaint;
        }

        // otherwise look up the paint table
        Paint paint = this.outlinePaintList.getPaint(0, series);
        if (paint == null) {
            DrawingSupplier supplier = getDrawingSupplier();
            if (supplier != null) {
                paint = supplier.getNextOutlinePaint();
                this.outlinePaintList.setPaint(0, series, paint);
            }
            else {
                paint = this.baseOutlinePaint;
            }
        }
        return paint;

    }

    /**
     * Sets the paint used for a series outline.
     *
     * @param series  the series index (zero-based).
     * @param paint  the paint.
     */
    public void setSeriesOutlinePaint(int series, Paint paint) {
        this.outlinePaintList.setPaint(0, series, paint);
    }

    /**
     * Returns the base outline paint.
     *
     * @return The base outline paint.
     */
    public Paint getBaseOutlinePaint() {
        return this.baseOutlinePaint;
    }

    /**
     * Sets the base outline paint.
     *
     * @param paint  the paint.
     */
    public void setBaseOutlinePaint(Paint paint) {
        this.baseOutlinePaint = paint;
    }

    // STROKE
    
    /**
     * Returns the stroke used to draw data items.
     * <p>

⌨️ 快捷键说明

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