📄 standarddialscale.java
字号:
/* ===========================================================
* 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.]
*
* ----------------------
* StandardDialScale.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-Nov-2006 : Added flags for tick label visibility (DG);
* 24-Oct-2007 : Added tick label formatter (DG);
* 19-Nov-2007 : Added some missing accessor methods (DG);
*
*/
package org.jfree.chart.plot.dial;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Stroke;
import java.awt.geom.Arc2D;
import java.awt.geom.Line2D;
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.io.SerialUtilities;
import org.jfree.text.TextUtilities;
import org.jfree.ui.TextAnchor;
import org.jfree.util.PaintUtilities;
import org.jfree.util.PublicCloneable;
/**
* A scale for a {@link DialPlot}.
*
* @since 1.0.7
*/
public class StandardDialScale extends AbstractDialLayer implements DialScale,
Cloneable, PublicCloneable, Serializable {
/** For serialization. */
static final long serialVersionUID = 3715644629665918516L;
/** The minimum data value for the scale. */
private double lowerBound;
/** The maximum data value for the scale. */
private double upperBound;
/**
* The start angle for the scale display, in degrees (using the same
* encoding as Arc2D).
*/
private double startAngle;
/** The extent of the scale display. */
private double extent;
/**
* The factor (in the range 0.0 to 1.0) that determines the outside limit
* of the tick marks.
*/
private double tickRadius;
/**
* The increment (in data units) between major tick marks.
*/
private double majorTickIncrement;
/**
* The factor that is subtracted from the tickRadius to determine the
* inner point of the major ticks.
*/
private double majorTickLength;
/**
* The paint to use for major tick marks. This field is transient because
* it requires special handling for serialization.
*/
private transient Paint majorTickPaint;
/**
* The stroke to use for major tick marks. This field is transient because
* it requires special handling for serialization.
*/
private transient Stroke majorTickStroke;
/**
* The number of minor ticks between each major tick.
*/
private int minorTickCount;
/**
* The factor that is subtracted from the tickRadius to determine the
* inner point of the minor ticks.
*/
private double minorTickLength;
/**
* The paint to use for minor tick marks. This field is transient because
* it requires special handling for serialization.
*/
private transient Paint minorTickPaint;
/**
* The stroke to use for minor tick marks. This field is transient because
* it requires special handling for serialization.
*/
private transient Stroke minorTickStroke;
/**
* The tick label offset.
*/
private double tickLabelOffset;
/**
* The tick label font.
*/
private Font tickLabelFont;
/**
* A flag that controls whether or not the tick labels are
* displayed.
*/
private boolean tickLabelsVisible;
/**
* The number formatter for the tick labels.
*/
private NumberFormat tickLabelFormatter;
/**
* A flag that controls whether or not the first tick label is
* displayed.
*/
private boolean firstTickLabelVisible;
/**
* The tick label paint. This field is transient because it requires
* special handling for serialization.
*/
private transient Paint tickLabelPaint;
/**
* Creates a new instance of DialScale.
*/
public StandardDialScale() {
this(0.0, 100.0, 175, -170, 10.0, 4);
}
/**
* Creates a new instance.
*
* @param lowerBound the lower bound of the scale.
* @param upperBound the upper bound of the scale.
* @param startAngle the start angle (in degrees, using the same
* orientation as Java's <code>Arc2D</code> class).
* @param extent the extent (in degrees, counter-clockwise).
* @param majorTickIncrement the interval between major tick marks
* @param minorTickCount the number of minor ticks between major tick
* marks.
*/
public StandardDialScale(double lowerBound, double upperBound,
double startAngle, double extent, double majorTickIncrement,
int minorTickCount) {
this.startAngle = startAngle;
this.extent = extent;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.tickRadius = 0.70;
this.tickLabelsVisible = true;
this.tickLabelFormatter = new DecimalFormat("0.0");
this.firstTickLabelVisible = true;
this.tickLabelFont = new Font("Dialog", Font.BOLD, 16);
this.tickLabelPaint = Color.blue;
this.tickLabelOffset = 0.10;
this.majorTickIncrement = majorTickIncrement;
this.majorTickLength = 0.04;
this.majorTickPaint = Color.black;
this.majorTickStroke = new BasicStroke(3.0f);
this.minorTickCount = minorTickCount;
this.minorTickLength = 0.02;
this.minorTickPaint = Color.black;
this.minorTickStroke = new BasicStroke(1.0f);
}
/**
* Returns the lower bound for the scale.
*
* @return The lower bound for the scale.
*
* @see #setLowerBound(double)
*
* @since 1.0.8
*/
public double getLowerBound() {
return this.lowerBound;
}
/**
* Sets the lower bound for the scale and sends a
* {@link DialLayerChangeEvent} to all registered listeners.
*
* @param lower the lower bound.
*
* @see #getLowerBound()
*
* @since 1.0.8
*/
public void setLowerBound(double lower) {
this.lowerBound = lower;
notifyListeners(new DialLayerChangeEvent(this));
}
/**
* Returns the upper bound for the scale.
*
* @return The upper bound for the scale.
*
* @see #setUpperBound(double)
*
* @since 1.0.8
*/
public double getUpperBound() {
return this.upperBound;
}
/**
* Sets the upper bound for the scale and sends a
* {@link DialLayerChangeEvent} to all registered listeners.
*
* @param upper the upper bound.
*
* @see #getUpperBound()
*
* @since 1.0.8
*/
public void setUpperBound(double upper) {
this.upperBound = upper;
notifyListeners(new DialLayerChangeEvent(this));
}
/**
* Returns the start angle for the scale (in degrees using the same
* orientation as Java's <code>Arc2D</code> class).
*
* @return The start angle.
*
* @see #setStartAngle(double)
*/
public double getStartAngle() {
return this.startAngle;
}
/**
* Sets the start angle for the scale and sends a
* {@link DialLayerChangeEvent} to all registered listeners.
*
* @param angle the angle (in degrees).
*
* @see #getStartAngle()
*/
public void setStartAngle(double angle) {
this.startAngle = angle;
notifyListeners(new DialLayerChangeEvent(this));
}
/**
* Returns the extent.
*
* @return The extent.
*
* @see #setExtent(double)
*/
public double getExtent() {
return this.extent;
}
/**
* Sets the extent and sends a {@link DialLayerChangeEvent} to all
* registered listeners.
*
* @param extent the extent.
*
* @see #getExtent()
*/
public void setExtent(double extent) {
this.extent = extent;
notifyListeners(new DialLayerChangeEvent(this));
}
/**
* Returns the radius (as a percentage of the maximum space available) of
* the outer limit of the tick marks.
*
* @return The tick radius.
*
* @see #setTickRadius(double)
*/
public double getTickRadius() {
return this.tickRadius;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -