?? meterplot.java
字號:
/* ======================================
* 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;
* Arnaud Lelievre;
* Nicolas Brodu;
*
* $Id: MeterPlot.java,v 1.10 2003/09/11 08:13:09 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);
* 20-Aug-2003 : Changed dataset from MeterDataset --> ValueDataset, added equals(...) method,
* 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL);
* implemented Cloneable, and various other changes (DG);
* 08-Sep-2003 : Added serialization methods (NB);
*
*/
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.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.List;
import java.util.ResourceBundle;
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;
import org.jfree.data.Range;
import org.jfree.data.ValueDataset;
import org.jfree.io.SerialUtilities;
import org.jfree.util.ObjectUtils;
/**
* 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 {
/** 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 dataset. */
private ValueDataset dataset;
/** The units displayed on the dial. */
private String units;
/** The overall range. */
private Range range;
/** The normal range. */
private Range normalRange;
/** The warning range. */
private Range warningRange;
/** The critical range. */
private Range criticalRange;
/** The outline paint. */
private Paint dialOutlinePaint;
/** 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 dial shape (background shape). */
/** 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;
/** A flag that controls whether or not the border is drawn. */
private boolean drawBorder;
/** ??? */
private int meterCalcAngle = -1;
/** ??? */
private double meterRange = -1;
/** The resourceBundle for the localization. */
static protected ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/** 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(ValueDataset dataset) {
super();
this.dataset = dataset;
this.units = "Units";
this.range = new Range(0.0, 100.0);
this.normalRange = new Range(0.0, 60.0);
this.warningRange = new Range(60.0, 90.0);
this.criticalRange = new Range(90.0, 100.0);
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 units for the dial.
*
* @return The units.
*/
public String getUnits() {
return this.units;
}
/**
* Sets the units for the dial.
*
* @param units the units.
public void setUnits(String units) {
this.units = units;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the overall range for the dial.
*
* @return The overall range.
*/
public Range getRange() {
return this.range;
}
/**
* Sets the overall range for the dial.
*
* @param range the range.
*/
public void setRange(Range range) {
this.range = range;
}
/**
* Returns the normal range for the dial.
*
* @return The normal range.
*/
public Range getNormalRange() {
return this.normalRange;
}
/**
* Sets the normal range for the dial.
*
* @param range the range.
*/
public void setNormalRange(Range range) {
this.normalRange = range;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the warning range for the dial.
*
* @return The warning range.
*/
public Range getWarningRange() {
return this.warningRange;
}
/**
* Sets the warning range for the dial.
*
* @param range the range.
*/
public void setWarningRange(Range range) {
this.warningRange = range;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the critical range for the dial.
*
* @return The critical range.
*/
public Range getCriticalRange() {
return this.criticalRange;
}
/**
* Sets the critical range for the dial.
*
* @param range the range.
*/
public void setCriticalRange(Range range) {
this.criticalRange = range;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the dial shape.
*
* @return The dial shape.
*/
public DialShape getDialShape() {
return this.shape;
}
/**
* Sets the dial shape.
*
* @param shape the shape.
*/
public void setDialShape(DialShape shape) {
this.shape = shape;
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;
}
/**
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -