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

📄 meterplot.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.
 *
 * --------------
 * MeterPlot.java
 * --------------
 * (C) Copyright 2000-2003, by Hari and Contributors.
 *
 * Original Author:  Hari (ourhari@hotmail.com);
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *                   Bob Orchard;
 *
 * $Id: MeterPlot.java,v 1.4 2003/07/23 15:23:38 mungady Exp $
 *
 * Changes
 * -------
 * 01-Apr-2002 : Version 1, contributed by Hari (DG);
 * 23-Apr-2002 : Moved dataset from JFreeChart to Plot (DG);
 * 22-Aug-2002 : Added changes suggest by Bob Orchard, changed Color to Paint for consistency,
 *               plus added Javadoc comments (DG);
 * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG);
 * 23-Jan-2003 : Removed one constructor (DG);
 * 26-Mar-2003 : Implemented Serializable (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.Polygon;
import java.awt.Shape;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.List;

import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.data.DatasetChangeEvent;
import org.jfree.data.MeterDataset;

/**
 * A plot that displays a single value in the context of several ranges ('normal', 'warning'
 * and 'critical').
 *
 * @author Hari
 */
public class MeterPlot extends Plot implements Serializable {

    /** Constant for meter type 'pie'. */
    public static final int DIALTYPE_PIE = 0;

    /** Constant for meter type 'circle'. */
    public static final int DIALTYPE_CIRCLE = 1;

    /** Constant for meter type 'chord'. */
    public static final int DIALTYPE_CHORD = 2;

    /** The default text for the normal level. */
    public static final String NORMAL_TEXT = "Normal";

    /** The default text for the warning level. */
    public static final String WARNING_TEXT = "Warning";

    /** The default text for the critical level. */
    public static final String CRITICAL_TEXT = "Critical";

    /** The default 'normal' level color. */
    static final Paint DEFAULT_NORMAL_PAINT = Color.green;

    /** The default 'warning' level color. */
    static final Paint DEFAULT_WARNING_PAINT = Color.yellow;

    /** The default 'critical' level color. */
    static final Paint DEFAULT_CRITICAL_PAINT = Color.red;

    /** The default background paint. */
    static final Paint DEFAULT_DIAL_BACKGROUND_PAINT = Color.black;

    /** The default needle paint. */
    static final Paint DEFAULT_NEEDLE_PAINT = Color.green;

    /** The default value font. */
    static final Font DEFAULT_VALUE_FONT = new Font("SansSerif", Font.BOLD, 12);

    /** The default value paint. */
    static final Paint DEFAULT_VALUE_PAINT = Color.yellow;

    /** The default meter angle. */
    public static final int DEFAULT_METER_ANGLE = 270;

    /** The default border size. */
    public static final float DEFAULT_BORDER_SIZE = 3f;

    /** The default circle size. */
    public static final float DEFAULT_CIRCLE_SIZE = 10f;

    /** The default background color. */
    public static final Paint DEFAULT_BACKGROUND_PAINT = Color.lightGray;

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

    /** Constant for the label type. */
    public static final int NO_LABELS = 0;

    /** Constant for the label type. */
    public static final int VALUE_LABELS = 1;

    /** The dial type (background shape). */
    private int dialType = DIALTYPE_CIRCLE;

    /** The paint for the dial background. */
    private transient Paint dialBackgroundPaint;

    /** The paint for the needle. */
    private transient Paint needlePaint;

    /** The font for the value displayed in the center of the dial. */
    private Font valueFont;

    /** The paint for the value displayed in the center of the dial. */
    private transient Paint valuePaint;

    /** The tick label type (NO_LABELS, VALUE_LABELS). */
    private int tickLabelType;

    /** The tick label font. */
    private Font tickLabelFont;

    /** The 'normal' level color. */
    private transient Paint normalPaint = DEFAULT_NORMAL_PAINT;

    /** The 'warning' level color. */
    private transient Paint warningPaint = DEFAULT_WARNING_PAINT;

    /** The 'critical' level color. */
    private transient Paint criticalPaint = DEFAULT_CRITICAL_PAINT;

    /** The dataset. */
    private MeterDataset dataset;
    
    /** The color of the border around the dial. */
    private Color dialBorderColor;

    /** A flag that controls whether or not the border is drawn. */
    private boolean drawBorder;

    /** ??? */
    private int meterCalcAngle = -1;

    /** ??? */
    private double meterRange = -1;

    /** The dial extent. */
    private int meterAngle = DEFAULT_METER_ANGLE;

    /** The minimum meter value. */
    private double minMeterValue = 0.0;

    /**
     * Default constructor.
     *
     * @param dataset  The dataset.
     */
    public MeterPlot(MeterDataset dataset) {

        super();

        this.dataset = dataset;
        this.tickLabelType = MeterPlot.VALUE_LABELS;
        this.tickLabelFont = MeterPlot.DEFAULT_LABEL_FONT;

        this.dialBackgroundPaint = MeterPlot.DEFAULT_DIAL_BACKGROUND_PAINT;
        this.needlePaint = MeterPlot.DEFAULT_NEEDLE_PAINT;
        this.valueFont = MeterPlot.DEFAULT_VALUE_FONT;
        this.valuePaint = MeterPlot.DEFAULT_VALUE_PAINT;

    }

    /**
     * Returns the type of dial (DIALTYPE_PIE, DIALTYPE_CIRCLE, DIALTYPE_CHORD).
     *
     * @return The dial type.
     */
    public int getDialType() {
        return this.dialType;
    }

    /**
     * Sets the dial type (background shape).
     * <P>
     * This controls the shape of the dial background.  Use one of the constants:
     * DIALTYPE_PIE, DIALTYPE_CIRCLE, or DIALTYPE_CHORD.
     *
     * @param type The dial type.
     */
    public void setDialType(int type) {
        this.dialType = type;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the paint for the dial background.
     *
     * @return The paint.
     */
    public Paint getDialBackgroundPaint() {
        return this.dialBackgroundPaint;
    }

    /**
     * Sets the paint used to fill the dial background.
     * <P>
     * If you set this to null, it will revert to the default color.
     *
     * @param paint The paint.
     */
    public void setDialBackgroundPaint(Paint paint) {
        this.dialBackgroundPaint = paint == null ? DEFAULT_DIAL_BACKGROUND_PAINT : paint;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the paint for the needle.
     *
     * @return The paint.
     */
    public Paint getNeedlePaint() {
        return this.needlePaint;
    }

    /**
     * Sets the paint used to display the needle.
     * <P>
     * If you set this to null, it will revert to the default color.
     *
     * @param paint The paint.
     */
    public void setNeedlePaint(Paint paint) {
        this.needlePaint = paint == null ? DEFAULT_NEEDLE_PAINT : paint;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the font for the value label.
     *
     * @return The font.
     */
    public Font getValueFont() {
        return this.valueFont;
    }

    /**
     * Sets the font used to display the value label.
     * <P>
     * If you set this to null, it will revert to the default font.
     *
     * @param font The font.
     */
    public void setValueFont(Font font) {
        this.valueFont = (font == null) ? DEFAULT_VALUE_FONT : font;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the paint for the value label.
     *
     * @return The paint.
     */
    public Paint getValuePaint() {
        return this.valuePaint;
    }

    /**
     * Sets the paint used to display the value label.
     * <P>
     * If you set this to null, it will revert to the default paint.
     *
     * @param paint The paint.
     */
    public void setValuePaint(Paint paint) {
        this.valuePaint = paint == null ? DEFAULT_VALUE_PAINT : paint;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the paint for the 'normal' level.
     *
     * @return The paint.
     */
    public Paint getNormalPaint() {
        return this.normalPaint;
    }

    /**
     * Sets the paint used to display the 'normal' range.
     * <P>
     * If you set this to null, it will revert to the default color.
     *
     * @param paint The paint.
     */
    public void setNormalPaint(Paint paint) {
        this.normalPaint = (paint == null) ? DEFAULT_NORMAL_PAINT : paint;
        notifyListeners(new PlotChangeEvent(this));
    }

    /**
     * Returns the paint used to display the 'warning' range.

⌨️ 快捷键说明

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