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

📄 dialvalueindicator.java

📁 提供JFreechart图表功能, 提供JFreechart图表功能,提供JFreechart图表功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2007, 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.]
 *
 * -----------------------
 * DialValueIndicator.java
 * -----------------------
 * (C) Copyright 2006-2007, by Object Refinery Limited.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * Changes
 * -------
 * 03-Nov-2006 : Version 1 (DG);
 * 17-Oct-2007 : Updated equals() (DG);
 * 24-Oct-2007 : Added default constructor and missing event notification (DG);
 * 
 */

package org.jfree.chart.plot.dial;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Stroke;
import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.jfree.chart.HashUtilities;
import org.jfree.io.SerialUtilities;
import org.jfree.text.TextUtilities;
import org.jfree.ui.RectangleAnchor;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.Size2D;
import org.jfree.ui.TextAnchor;
import org.jfree.util.PaintUtilities;
import org.jfree.util.PublicCloneable;

/**
 * A value indicator for a {@link DialPlot}.
 * 
 * @since 1.0.7
 */
public class DialValueIndicator extends AbstractDialLayer implements DialLayer, 
        Cloneable, PublicCloneable, Serializable {
    
    /** For serialization. */
    static final long serialVersionUID = 803094354130942585L;

    /** The dataset index. */
    private int datasetIndex;
    
    /** The angle that defines the anchor point. */
    private double angle;
    
    /** The radius that defines the anchor point. */
    private double radius;
    
    /** The frame anchor. */
    private RectangleAnchor frameAnchor;
    
    /** The template value. */
    private Number templateValue;
    
    /** The formatter. */
    private NumberFormat formatter;

    /** The font. */
    private Font font;
    
    /** The paint. */
    private transient Paint paint;
    
    /** The background paint. */
    private transient Paint backgroundPaint;
    
    /** The outline stroke. */
    private transient Stroke outlineStroke;
    
    /** The outline paint. */
    private transient Paint outlinePaint;
    
    /** The insets. */
    private RectangleInsets insets;
    
    /** The value anchor. */
    private RectangleAnchor valueAnchor;
    
    /** The text anchor for displaying the value. */
    private TextAnchor textAnchor;
    
    /**
     * Creates a new instance of <code>DialValueIndicator</code>.
     */
    public DialValueIndicator() {
        this(0);
    }
    
    /** 
     * Creates a new instance of <code>DialValueIndicator</code>.
     * 
     * @param datasetIndex  the dataset index.
     */
    public DialValueIndicator(int datasetIndex) {
        this.datasetIndex = datasetIndex;
        this.angle = -90.0;
        this.radius = 0.3;
        this.frameAnchor = RectangleAnchor.CENTER;
        this.templateValue = new Double(100.0);
        this.formatter = new DecimalFormat("0.0");
        this.font = new Font("Dialog", Font.BOLD, 14);
        this.paint = Color.black;
        this.backgroundPaint = Color.white;
        this.outlineStroke = new BasicStroke(1.0f);
        this.outlinePaint = Color.blue;
        this.insets = new RectangleInsets(4, 4, 4, 4);
        this.valueAnchor = RectangleAnchor.RIGHT;
        this.textAnchor = TextAnchor.CENTER_RIGHT;
    }
    
    /**
     * Returns the index of the dataset from which this indicator fetches its 
     * current value.
     * 
     * @return The dataset index.
     * 
     * @see #setDatasetIndex(int)
     */
    public int getDatasetIndex() {
        return this.datasetIndex;
    }
    
    /**
     * Sets the dataset index and sends a {@link DialLayerChangeEvent} to all 
     * registered listeners.
     * 
     * @param index  the index.
     * 
     * @see #getDatasetIndex()
     */
    public void setDatasetIndex(int index) {
        this.datasetIndex = index;
        notifyListeners(new DialLayerChangeEvent(this));
    }
    
    /**
     * Returns the angle for the anchor point.  The angle is specified in 
     * degrees using the same orientation as Java's <code>Arc2D</code> class.
     * 
     * @return The angle (in degrees).
     * 
     * @see #setAngle(double)
     */
    public double getAngle() {
        return this.angle;
    }
    
    /**
     * Sets the angle for the anchor point and sends a 
     * {@link DialLayerChangeEvent} to all registered listeners.
     * 
     * @param angle  the angle (in degrees).
     * 
     * @see #getAngle()
     */
    public void setAngle(double angle) {
        this.angle = angle;
        notifyListeners(new DialLayerChangeEvent(this));
    }
    
    /**
     * Returns the radius.
     * 
     * @return The radius.
     * 
     * @see #setRadius(double)
     */
    public double getRadius() {
        return this.radius;
    }
    
    /**
     * Sets the radius and sends a {@link DialLayerChangeEvent} to all 
     * registered listeners.
     * 
     * @param radius  the radius.
     * 
     * @see #getRadius()
     */
    public void setRadius(double radius) {
        this.radius = radius;
        notifyListeners(new DialLayerChangeEvent(this));
    }
    
    /**
     * Returns the frame anchor.
     * 
     * @return The frame anchor.
     * 
     * @see #setFrameAnchor(RectangleAnchor)
     */
    public RectangleAnchor getFrameAnchor() {
        return this.frameAnchor;
    }
    
    /**
     * Sets the frame anchor and sends a {@link DialLayerChangeEvent} to all
     * registered listeners.
     * 
     * @param anchor  the anchor (<code>null</code> not permitted).
     * 
     * @see #getFrameAnchor()
     */
    public void setFrameAnchor(RectangleAnchor anchor) {
        if (anchor == null) {
            throw new IllegalArgumentException("Null 'anchor' argument.");
        }
        this.frameAnchor = anchor;
        notifyListeners(new DialLayerChangeEvent(this));
    }
    
    /**
     * Returns the template value.
     * 
     * @return The template value (never <code>null</code>).
     * 
     * @see #setTemplateValue(Number)
     */
    public Number getTemplateValue() {
        return this.templateValue;
    }
    
    /**
     * Sets the template value and sends a {@link DialLayerChangeEvent} to
     * all registered listeners.
     * 
     * @param value  the value (<code>null</code> not permitted).
     * 
     * @see #setTemplateValue(Number)
     */
    public void setTemplateValue(Number value) {
        if (value == null) {
            throw new IllegalArgumentException("Null 'value' argument.");
        }
        this.templateValue = value;
        notifyListeners(new DialLayerChangeEvent(this));
    }
    
    /**
     * Returns the formatter used to format the value.
     * 
     * @return The formatter (never <code>null</code>).
     * 
     * @see #setNumberFormat(NumberFormat)
     */
    public NumberFormat getNumberFormat() {
        return this.formatter;
    }
    
    /**
     * Sets the formatter used to format the value and sends a 
     * {@link DialLayerChangeEvent} to all registered listeners.
     * 
     * @param formatter  the formatter (<code>null</code> not permitted).
     * 
     * @see #getNumberFormat()
     */
    public void setNumberFormat(NumberFormat formatter) {
        if (formatter == null) {
            throw new IllegalArgumentException("Null 'formatter' argument.");
        }
        this.formatter = formatter;
        notifyListeners(new DialLayerChangeEvent(this));
    }
    
    /**
     * Returns the font.
     * 
     * @return The font (never <code>null</code>).
     * 
     * @see #getFont()
     */
    public Font getFont() {
        return this.font;
    }
    
    /**
     * Sets the font and sends a {@link DialLayerChangeEvent} to all registered
     * listeners.
     * 
     * @param font  the font (<code>null</code> not permitted).
     */
    public void setFont(Font font) {
        if (font == null) {
            throw new IllegalArgumentException("Null 'font' argument.");
        }
        this.font = font;
        notifyListeners(new DialLayerChangeEvent(this));
    }
    
    /**
     * Returns the paint.
     * 
     * @return The paint (never <code>null</code>).
     * 
     * @see #setPaint(Paint)
     */
    public Paint getPaint() {
        return this.paint;
    }
    
    /**
     * Sets the paint and sends a {@link DialLayerChangeEvent} to all 
     * registered listeners.
     * 
     * @param paint  the paint (<code>null</code> not permitted).
     * 
     * @see #getPaint()
     */
    public void setPaint(Paint paint) {

⌨️ 快捷键说明

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