?? pieplot.java
字號:
/**
* Initialisation shared by constructors.
*/
private void initialise() {
this.interiorGap = DEFAULT_INTERIOR_GAP;
this.circular = true;
this.radius = DEFAULT_RADIUS;
this.startAngle = DEFAULT_START_ANGLE;
this.direction = Rotation.CLOCKWISE;
this.sectionLabelType = DEFAULT_SECTION_LABEL_TYPE;
this.sectionLabelFont = DEFAULT_SECTION_LABEL_FONT;
this.sectionLabelPaint = DEFAULT_SECTION_LABEL_PAINT;
this.sectionLabelGap = DEFAULT_SECTION_LABEL_GAP;
this.valueFormatter = DEFAULT_VALUE_FORMATTER;
this.percentFormatter = DEFAULT_PERCENT_FORMATTER;
this.itemLabelGenerator = null;
this.urlGenerator = null;
this.sectionPaint = null;
this.sectionPaintList = new PaintList();
this.sectionPaintListAutoFill = true;
this.sectionOutlinePaint = Color.lightGray;
this.sectionOutlinePaintList = new PaintList();
this.sectionOutlinePaintListAutoFill = true;
this.sectionOutlineStroke = new BasicStroke(1.0f);
this.sectionOutlineStrokeList = new StrokeList();
this.sectionOutlineStrokeListAutoFill = true;
this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;
}
/**
* Returns the dataset.
*
* @return The dataset.
*/
public PieDataset getDataset() {
return this.dataset;
}
/**
* Sets the dataset. A {@link DatasetChangeEvent} is sent to all registered listeners.
*
* @param dataset the dataset.
*/
public void setDataset(PieDataset dataset) {
// if there is an existing dataset, remove the plot from the list of change listeners...
PieDataset existing = this.dataset;
if (existing != null) {
existing.removeChangeListener(this);
}
// set the new dataset, and register the chart as a change listener...
this.dataset = dataset;
if (dataset != null) {
setDatasetGroup(dataset.getGroup());
dataset.addChangeListener(this);
}
// send a dataset change event to self...
DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
datasetChanged(event);
}
/**
* Returns the dataset for multiple pies.
*
* @return The dataset.
*/
public CategoryDataset getMultiDataset() {
return this.multiDataset;
}
/**
* Sets the dataset for multiplie pies. A {@link DatasetChangeEvent} is sent to all
* registered listeners.
*
* @param dataset the dataset.
*/
public void setMultiDataset(CategoryDataset dataset) {
// if there is an existing dataset, remove the plot from the list of change listeners...
CategoryDataset existing = this.multiDataset;
if (existing != null) {
existing.removeChangeListener(this);
}
// set the new dataset, and register the chart as a change listener...
this.multiDataset = dataset;
if (dataset != null) {
setDatasetGroup(dataset.getGroup());
dataset.addChangeListener(this);
}
// send a dataset change event to self...
DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
datasetChanged(event);
}
/**
* Returns the start angle for the first pie section.
* <P>
* This is measured in degrees starting from 3 o'clock and measuring anti-clockwise.
*
* @return the start angle.
*/
public double getStartAngle() {
return this.startAngle;
}
/**
* Sets the starting angle.
* <P>
* The initial default value is 90 degrees, which corresponds to 12 o'clock. A value of zero
* corresponds to 3 o'clock... this is the encoding used by Java's Arc2D class.
*
* @param angle the angle (in degrees).
*/
public void setStartAngle(double angle) {
this.startAngle = angle;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the direction in which the pie sections are drawn (clockwise or anti-clockwise).
*
* @return The direction.
*/
public Rotation getDirection() {
return this.direction;
}
/**
* Sets the direction (use the constants CLOCKWISE or ANTICLOCKWISE).
*
* @param direction the new direction (<code>null</code> not permitted).
*/
public void setDirection(Rotation direction) {
// check argument...
if (direction == null) {
throw new IllegalArgumentException("PiePlot.setDirection(...): null not allowed.");
}
// make the change...
this.direction = direction;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the interior gap, measured as a percentage of the available drawing space.
*
* @return The gap percentage.
*/
public double getInteriorGap() {
return this.interiorGap;
}
/**
* Sets the interior gap.
*
* @param percent The gap.
*/
public void setInteriorGap(double percent) {
// check arguments...
if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) {
throw new IllegalArgumentException(
"PiePlot.setInteriorGapPercent(double): percentage outside valid range.");
}
// make the change...
if (this.interiorGap != percent) {
this.interiorGap = percent;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns a flag indicating whether the pie chart is circular, or
* stretched into an elliptical shape.
*
* @return a flag indicating whether the pie chart is circular.
*/
public boolean isCircular() {
return circular;
}
/**
* A flag indicating whether the pie chart is circular, or stretched into
* an elliptical shape.
*
* @param flag the new value.
*/
public void setCircular(boolean flag) {
// no argument checking required...
// make the change...
if (circular != flag) {
circular = flag;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Sets the circular attribute, with no side effects.
*
* @param circular the new value of the flag.
*/
protected void setCircularAttribute(boolean circular) {
this.circular = circular;
}
/**
* Returns the radius (a percentage of the available space).
*
* @return The radius percentage.
*/
public double getRadius() {
return this.radius;
}
/**
* Sets the radius.
*
* @param percent the new value.
*/
public void setRadius(double percent) {
// check arguments...
if ((percent <= 0.0) || (percent > MAX_RADIUS)) {
throw new IllegalArgumentException(
"PiePlot.setRadiusPercent(double): percentage outside valid range.");
}
// make the change (if necessary)...
if (this.radius != percent) {
this.radius = percent;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the amount that a section should be 'exploded'.
*
* @param section the section number.
*
* @return the amount that a section should be 'exploded'.
*/
public double getExplodePercent(int section) {
// check argument...
if (section < 0) {
throw new IllegalArgumentException(
"PiePlot.getExplodePercent(int): section outside valid range.");
}
// fetch the result...
double result = 0.0;
if (this.explodePercentages != null) {
Number percent = (Number) this.explodePercentages.get(section);
if (percent != null) {
result = percent.doubleValue();
}
}
return result;
}
/**
* Sets the amount that a pie section should be exploded.
* <p>
* If you want to display a pie chart with one or more exploded sections, you first need
* to set the pie chart radius to something less than 100%. Then, consider a circle that
* represents a pie chart with the maximum radius (100%) and a smaller circle that is the
* actual pie chart (with radius x%). Now, the explode percent determines how far out
* towards the outer circle the pie section is shifted (exploded).
*
* @param section the section index.
* @param percent the amount to explode the section as a percentage.
*/
public void setExplodePercent(int section, double percent) {
// check argument...
int keyCount = 0;
Collection keys = getKeys();
if (keys != null) {
keyCount = keys.size();
}
if ((section < 0) || (section >= keyCount)) {
throw new IllegalArgumentException(
"PiePlot.setExplodePercent(int, double): section outside valid range.");
}
// store the value...
if (this.explodePercentages == null) {
this.explodePercentages = new ObjectList();
}
this.explodePercentages.set(section, new Double(percent));
}
/**
* Returns the section label type. Defined by the constants: NO_LABELS,
* NAME_LABELS, PERCENT_LABELS and NAME_AND_PERCENT_LABELS.
*
* @return the section label type.
*/
public int getSectionLabelType() {
return this.sectionLabelType;
}
/**
* Sets the section label type.
* <P>
* Valid types are defined by the following constants: NO_LABELS,
* NAME_LABELS, VALUE_LABELS, PERCENT_LABELS, NAME_AND_VALUE_LABELS,
* NAME_AND_PERCENT_LABELS, VALUE_AND_PERCENT_LABELS.
*
* @param type the type.
*/
public void setSectionLabelType(int type) {
// check the argument...
if ((type != NO_LABELS)
&& (type != NAME_LABELS)
&& (type != VALUE_LABELS)
&& (type != PERCENT_LABELS)
&& (type != NAME_AND_VALUE_LABELS)
&& (type != NAME_AND_PERCENT_LABELS)
&& (type != VALUE_AND_PERCENT_LABELS)) {
throw new IllegalArgumentException(
"PiePlot.setSectionLabelType(int): unrecognised type.");
}
// make the change...
if (sectionLabelType != type) {
this.sectionLabelType = type;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the section label font.
*
* @return the section label font.
*/
public Font getSectionLabelFont() {
return this.sectionLabelFont;
}
/**
* Sets the section label font.
* <P>
* Notifies registered listeners that the plot has been changed.
*
* @param font the new section label font.
*/
public void setSectionLabelFont(Font font) {
// check arguments...
if (font == null) {
throw new IllegalArgumentException(
"PiePlot.setSectionLabelFont(...): null font not allowed.");
}
// make the change...
if (!this.sectionLabelFont.equals(font)) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -