📄 pieplot.java
字号:
this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;
this.sectionPaint = null;
this.sectionPaintList = new PaintList();
this.baseSectionPaint = null;
this.sectionOutlinePaint = null;
this.sectionOutlinePaintList = new PaintList();
this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
this.sectionOutlineStroke = null;
this.sectionOutlineStrokeList = new StrokeList();
this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
this.explodePercentages = new ObjectList();
this.labelGenerator = new StandardPieItemLabelGenerator();
this.labelFont = DEFAULT_LABEL_FONT;
this.labelPaint = DEFAULT_LABEL_PAINT;
this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
this.toolTipGenerator = null;
this.urlGenerator = null;
}
/**
* Returns the dataset.
*
* @return The dataset (possibly <code>null</code>).
*/
public PieDataset getDataset() {
return this.dataset;
}
/**
* Sets the dataset and sends a {@link DatasetChangeEvent} to 'this'.
*
* @param dataset the dataset (<code>null</code> permitted).
*/
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 pie index (this is used by the {@link MultiplePiePlot} class to track
* subplots).
*
* @return the pie index.
*/
public int getPieIndex() {
return this.pieIndex;
}
/**
* Sets the pie index (this is used by the {@link MultiplePiePlot} class to track
* subplots).
*
* @param index the index.
*/
public void setPieIndex(int index) {
this.pieIndex = index;
}
/**
* 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 and sends a {@link PlotChangeEvent} to all registered listeners.
* <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 (never <code>null</code>).
*/
public Rotation getDirection() {
return this.direction;
}
/**
* Sets the direction in which the pie sections are drawn and sends a {@link PlotChangeEvent}
* to all registered listeners.
*
* @param direction the direction (<code>null</code> not permitted).
*/
public void setDirection(Rotation direction) {
if (direction == null) {
throw new IllegalArgumentException("Null 'direction' argument.");
}
this.direction = direction;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the interior gap, measured as a percentage of the available drawing space.
*
* @return the gap (as a percentage of the available drawing space).
*/
public double getInteriorGap() {
return this.interiorGap;
}
/**
* Sets the interior gap and sends a {@link PlotChangeEvent} to all registered listeners. This
* controls the space between the edges of the pie plot and the plot area itself (the region
* where the section labels appear).
*
* @param percent the gap (as a percentage of the available drawing space).
*/
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 this.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) {
setCircular(flag, true);
}
/**
* Sets the circular attribute and, if requested, sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param circular the new value of the flag.
* @param notify notify listeners?
*/
public void setCircular(boolean circular, boolean notify) {
this.circular = circular;
if (notify) {
notifyListeners(new PlotChangeEvent(this));
}
}
//// SECTION PAINT ////////////////////////////////////////////////////////////////////////////
/**
* Returns the paint for ALL sections in the plot.
*
* @return the paint (possibly <code>null</code>).
*/
public Paint getSectionPaint() {
return this.sectionPaint;
}
/**
* Sets the paint for ALL sections in the plot. If this is set to
* </code>null</code>, then a list of paints is used instead (to allow
* different colors to be used for each section).
*
* @param paint the paint (<code>null</code> permitted).
*/
public void setSectionPaint(Paint paint) {
this.sectionPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the paint for the specified section.
*
* @param section the section index (zero-based).
*
* @return the paint (never <code>null</code>).
*/
public Paint getSectionPaint(int section) {
// return the override, if there is one...
if (this.sectionPaint != null) {
return this.sectionPaint;
}
// otherwise look up the paint list
Paint result = this.sectionPaintList.getPaint(section);
if (result == null) {
DrawingSupplier supplier = getDrawingSupplier();
if (supplier != null) {
Paint p = supplier.getNextPaint();
this.sectionPaintList.setPaint(section, p);
result = p;
}
else {
result = this.baseSectionPaint;
}
}
return result;
}
/**
* Sets the paint used to fill a section of the pie and sends a {@link PlotChangeEvent} to
* all registered listeners.
*
* @param section the section index (zero-based).
* @param paint the paint (<code>null</code> permitted).
*/
public void setSectionPaint(int section, Paint paint) {
this.sectionPaintList.setPaint(section, paint);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the base section paint. This is used when no other paint is available.
*
* @return the paint (never <code>null</code>).
*/
public Paint getBaseSectionPaint() {
return this.baseSectionPaint;
}
/**
* Sets the base section paint.
*
* @param paint the paint (<code>null</code> not permitted).
*/
public void setBaseSectionPaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.baseSectionPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
//// SECTION OUTLINE PAINT ////////////////////////////////////////////////////////////////////
/**
* Returns the outline paint for ALL sections in the plot.
*
* @return the paint (possibly <code>null</code>).
*/
public Paint getSectionOutlinePaint() {
return this.sectionOutlinePaint;
}
/**
* Sets the outline paint for ALL sections in the plot. If this is set to
* </code>null</code>, then a list of paints is used instead (to allow
* different colors to be used for each section).
*
* @param paint the paint (<code>null</code> permitted).
*/
public void setSectionOutlinePaint(Paint paint) {
this.sectionOutlinePaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the paint for the specified section.
*
* @param section the section index (zero-based).
*
* @return the paint (never <code>null</code>).
*/
public Paint getSectionOutlinePaint(int section) {
// return the override, if there is one...
if (this.sectionOutlinePaint != null) {
return this.sectionOutlinePaint;
}
// otherwise look up the paint list
Paint result = this.sectionOutlinePaintList.getPaint(section);
if (result == null) {
result = this.baseSectionOutlinePaint;
}
return result;
}
/**
* Sets the paint used to fill a section of the pie and sends a {@link PlotChangeEvent} to
* all registered listeners.
*
* @param section the section index (zero-based).
* @param paint the paint (<code>null</code> permitted).
*/
public void setSectionOutlinePaint(int section, Paint paint) {
this.sectionOutlinePaintList.setPaint(section, paint);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the base section paint. This is used when no other paint is available.
*
* @return the paint (never <code>null</code>).
*/
public Paint getBaseSectionOutlinePaint() {
return this.baseSectionOutlinePaint;
}
/**
* Sets the base section paint.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -