?? compassplot.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.
*
* ----------------
* CompassPlot.java
* ----------------
* (C) Copyright 2002, 2003, by the Australian Antarctic Division and Contributors.
*
* Original Author: Bryan Scott (for the Australian Antarctic Division);
* Contributor(s): David Gilbert (for Object Refinery Limited);
* Arnaud Lelievre;
*
* $Id: CompassPlot.java,v 1.10 2003/09/11 08:11:18 mungady Exp $
*
* Changes:
* --------
* 25-Sep-2002 : Version 1, contributed by Bryan Scott (DG);
* 23-Jan-2003 : Removed one constructor (DG);
* 26-Mar-2003 : Implemented Serializable (DG);
* 27-Mar-2003 : Changed MeterDataset to ValueDataset (DG);
* 21-Aug-2003 : Implemented Cloneable (DG);
* 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL);
* 09-Sep-2003 : Changed Color --> Paint (DG);
*/
package org.jfree.chart.plot;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.Polygon;
import java.awt.Stroke;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.Arrays;
import java.util.ResourceBundle;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.needle.ArrowNeedle;
import org.jfree.chart.needle.LineNeedle;
import org.jfree.chart.needle.LongNeedle;
import org.jfree.chart.needle.MeterNeedle;
import org.jfree.chart.needle.PinNeedle;
import org.jfree.chart.needle.PlumNeedle;
import org.jfree.chart.needle.PointerNeedle;
import org.jfree.chart.needle.ShipNeedle;
import org.jfree.chart.needle.WindNeedle;
import org.jfree.data.DefaultValueDataset;
import org.jfree.data.ValueDataset;
import org.jfree.util.ObjectUtils;
/**
* A specialised plot that draws a compass to indicate a direction based on the value from a
* {@link ValueDataset}.
*
* @author Bryan Scott
*/
public class CompassPlot extends Plot implements Cloneable, Serializable {
/** The default label font. */
public static final Font DEFAULT_LABEL_FONT = new Font("SansSerif", Font.BOLD, 10);
/** A constant for the label type. */
public static final int NO_LABELS = 0;
/** A constant for the label type. */
public static final int VALUE_LABELS = 1;
/** The label type (NO_LABELS, VALUE_LABELS). */
private int labelType;
/** The label font. */
private Font labelFont;
/** A flag that controls whether or not a border is drawn. */
private boolean drawBorder = false;
/** The rose highlight paint. */
private Paint roseHighlightPaint = Color.black;
/** The rose paint. */
private Paint rosePaint = Color.yellow;
/** The rose center paint. */
private Paint roseCenterPaint = Color.white;
/** The compass font. */
private Font compassFont = new Font("Arial", Font.PLAIN, 10);
/** A working shape. */
private transient Ellipse2D circle1;
/** A working shape. */
private transient Ellipse2D circle2;
/** A working area. */
private transient Area a1;
/** A working area. */
private transient Area a2;
/** A working shape. */
private transient Rectangle2D rect1;
/** An array of value datasets. */
private ValueDataset[] datasets = new ValueDataset[1];
/** An array of needles. */
private MeterNeedle[] seriesNeedle = new MeterNeedle[1];
/** The resourceBundle for the localization. */
static protected ResourceBundle localizationResources =
ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");
/**
* Default constructor.
*/
public CompassPlot() {
this(new DefaultValueDataset());
}
/**
* Constructs a new compass plot.
*
* @param dataset the dataset for the plot.
*/
public CompassPlot(ValueDataset dataset) {
super();
if (dataset != null) {
datasets[0] = dataset;
dataset.addChangeListener(this);
}
circle1 = new Ellipse2D.Double();
circle2 = new Ellipse2D.Double();
rect1 = new Rectangle2D.Double();
setSeriesNeedle(0);
}
/**
* Returns the label type. Defined by the constants: NO_LABELS, VALUE_LABELS.
*
* @return The label type.
*/
public int getLabelType() {
return this.labelType;
}
/**
* Sets the label type.
* <P>
* Valid types are defined by the following constants: NO_LABELS, VALUE_LABELS.
*
* @param type the type.
*/
public void setLabelType(int type) {
// check the argument...
if ((type != NO_LABELS) && (type != VALUE_LABELS)) {
throw new IllegalArgumentException("MeterPlot.setLabelType(int): unrecognised type.");
}
// make the change...
if (labelType != type) {
this.labelType = type;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the label font.
*
* @return the label font.
*/
public Font getLabelFont() {
return this.labelFont;
}
/**
* Sets the label font.
* <P>
* Notifies registered listeners that the plot has been changed.
*
* @param font the new label font.
*/
public void setLabelFont(Font font) {
// check arguments...
if (font == null) {
throw new IllegalArgumentException("MeterPlot.setLabelFont(...): "
+ "null font not allowed.");
}
// make the change...
if (!this.labelFont.equals(font)) {
this.labelFont = font;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns a flag that controls whether or not a border is drawn.
*
* @return the flag.
*/
public boolean getDrawBorder() {
return drawBorder;
}
/**
* Sets a flag that controls whether or not a border is drawn.
*
* @param status the flag status.
*/
public void setDrawBorder(boolean status) {
drawBorder = status;
}
/**
* Sets the series paint.
*
* @param series the series index.
* @param paint the paint.
*/
public void setSeriesPaint(int series, Paint paint) {
// super.setSeriesPaint(series, paint);
if ((series >= 0) && (series < seriesNeedle.length)) {
seriesNeedle[series].setFillPaint(paint);
}
}
/**
* Sets the series outline paint.
*
* @param series the series index.
* @param p the paint.
*/
public void setSeriesOutlinePaint(int series, Paint p) {
if ((series >= 0) && (series < seriesNeedle.length)) {
seriesNeedle[series].setOutlinePaint(p);
}
}
/**
* Sets the series outline stroke.
*
* @param series the series index.
* @param stroke the stroke.
*/
public void setSeriesOutlineStroke(int series, Stroke stroke) {
if ((series >= 0) && (series < seriesNeedle.length)) {
seriesNeedle[series].setOutlineStroke(stroke);
}
}
/**
* Sets the needle type.
*
* @param type the type.
*/
public void setSeriesNeedle(int type) {
setSeriesNeedle(0, type);
}
/**
* Sets the needle for a series.
*
* @param index the series index.
* @param type the needle type.
*/
public void setSeriesNeedle(int index, int type) {
switch (type) {
case 0:
setSeriesNeedle(index, new ArrowNeedle(true));
setSeriesPaint(index, Color.red);
seriesNeedle[index].setHighlightPaint(Color.white);
break;
case 1:
setSeriesNeedle(index, new LineNeedle());
break;
case 2:
setSeriesNeedle(index, new LongNeedle());
break;
case 3:
setSeriesNeedle(index, new PinNeedle());
break;
case 4:
setSeriesNeedle(index, new PlumNeedle());
break;
case 5:
setSeriesNeedle(index, new PointerNeedle());
break;
case 6:
setSeriesPaint(index, null);
setSeriesOutlineStroke(index, new BasicStroke(3));
setSeriesNeedle(index, new ShipNeedle());
break;
case 7:
setSeriesPaint(index, Color.blue);
setSeriesNeedle(index, new WindNeedle());
break;
case 8:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -