📄 pieplot.java
字号:
/**
* Returns the paint for the specified section. This is equivalent to
* <code>lookupSectionPaint(section, false)</code>.
*
* @param key the section key.
*
* @return The paint for the specified section.
*
* @since 1.0.3
*
* @see #lookupSectionPaint(Comparable, boolean)
*/
protected Paint lookupSectionPaint(Comparable key) {
return lookupSectionPaint(key, false);
}
/**
* Returns the paint for the specified section. The lookup involves these
* steps:
* <ul>
* <li>if {@link #getSectionPaint()} is non-<code>null</code>, return
* it;</li>
* <li>if {@link #getSectionPaint(int)} is non-<code>null</code> return
* it;</li>
* <li>if {@link #getSectionPaint(int)} is <code>null</code> but
* <code>autoPopulate</code> is <code>true</code>, attempt to fetch
* a new paint from the drawing supplier
* ({@link #getDrawingSupplier()});
* <li>if all else fails, return {@link #getBaseSectionPaint()}.
* </ul>
*
* @param key the section key.
* @param autoPopulate a flag that controls whether the drawing supplier
* is used to auto-populate the section paint settings.
*
* @return The paint.
*
* @since 1.0.3
*/
protected Paint lookupSectionPaint(Comparable key, boolean autoPopulate) {
// is there an override?
Paint result = getSectionPaint();
if (result != null) {
return result;
}
// if not, check if there is a paint defined for the specified key
result = this.sectionPaintMap.getPaint(key);
if (result != null) {
return result;
}
// nothing defined - do we autoPopulate?
if (autoPopulate) {
DrawingSupplier ds = getDrawingSupplier();
if (ds != null) {
result = ds.getNextPaint();
this.sectionPaintMap.put(key, result);
}
else {
result = this.baseSectionPaint;
}
}
else {
result = this.baseSectionPaint;
}
return result;
}
/**
* Returns the paint for ALL sections in the plot.
*
* @return The paint (possibly <code>null</code>).
*
* @see #setSectionPaint(Paint)
*
* @deprecated Use {@link #getSectionPaint(Comparable)} and
* {@link #getBaseSectionPaint()}. Deprecated as of version 1.0.6.
*/
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).
*
* @see #getSectionPaint()
*
* @deprecated Use {@link #setSectionPaint(Comparable, Paint)} and
* {@link #setBaseSectionPaint(Paint)}. Deprecated as of version 1.0.6.
*/
public void setSectionPaint(Paint paint) {
this.sectionPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns a key for the specified section. If there is no such section
* in the dataset, we generate a key. This is to provide some backward
* compatibility for the (now deprecated) methods that get/set attributes
* based on section indices. The preferred way of doing this now is to
* link the attributes directly to the section key (there are new methods
* for this, starting from version 1.0.3).
*
* @param section the section index.
*
* @return The key.
*
* @since 1.0.3
*/
protected Comparable getSectionKey(int section) {
Comparable key = null;
if (this.dataset != null) {
if (section >= 0 && section < this.dataset.getItemCount()) {
key = this.dataset.getKey(section);
}
}
if (key == null) {
key = new Integer(section);
}
return key;
}
/**
* Returns the paint associated with the specified key, or
* <code>null</code> if there is no paint associated with the key.
*
* @param key the key (<code>null</code> not permitted).
*
* @return The paint associated with the specified key, or
* <code>null</code>.
*
* @throws IllegalArgumentException if <code>key</code> is
* <code>null</code>.
*
* @see #setSectionPaint(Comparable, Paint)
*
* @since 1.0.3
*/
public Paint getSectionPaint(Comparable key) {
// null argument check delegated...
return this.sectionPaintMap.getPaint(key);
}
/**
* Sets the paint associated with the specified key, and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param key the key (<code>null</code> not permitted).
* @param paint the paint.
*
* @throws IllegalArgumentException if <code>key</code> is
* <code>null</code>.
*
* @see #getSectionPaint(Comparable)
*
* @since 1.0.3
*/
public void setSectionPaint(Comparable key, Paint paint) {
// null argument check delegated...
this.sectionPaintMap.put(key, paint);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the base section paint. This is used when no other paint is
* defined, which is rare. The default value is <code>Color.gray</code>.
*
* @return The paint (never <code>null</code>).
*
* @see #setBaseSectionPaint(Paint)
*/
public Paint getBaseSectionPaint() {
return this.baseSectionPaint;
}
/**
* Sets the base section paint and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param paint the paint (<code>null</code> not permitted).
*
* @see #getBaseSectionPaint()
*/
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 flag that controls whether or not the outline is drawn for
* each pie section.
*
* @return The flag that controls whether or not the outline is drawn for
* each pie section.
*
* @see #setSectionOutlinesVisible(boolean)
*/
public boolean getSectionOutlinesVisible() {
return this.sectionOutlinesVisible;
}
/**
* Sets the flag that controls whether or not the outline is drawn for
* each pie section, and sends a {@link PlotChangeEvent} to all registered
* listeners.
*
* @param visible the flag.
*
* @see #getSectionOutlinesVisible()
*/
public void setSectionOutlinesVisible(boolean visible) {
this.sectionOutlinesVisible = visible;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the outline paint for the specified section. This is equivalent
* to <code>lookupSectionPaint(section, false)</code>.
*
* @param key the section key.
*
* @return The paint for the specified section.
*
* @since 1.0.3
*
* @see #lookupSectionOutlinePaint(Comparable, boolean)
*/
protected Paint lookupSectionOutlinePaint(Comparable key) {
return lookupSectionOutlinePaint(key, false);
}
/**
* Returns the outline paint for the specified section. The lookup
* involves these steps:
* <ul>
* <li>if {@link #getSectionOutlinePaint()} is non-<code>null</code>,
* return it;</li>
* <li>otherwise, if {@link #getSectionOutlinePaint(int)} is
* non-<code>null</code> return it;</li>
* <li>if {@link #getSectionOutlinePaint(int)} is <code>null</code> but
* <code>autoPopulate</code> is <code>true</code>, attempt to fetch
* a new outline paint from the drawing supplier
* ({@link #getDrawingSupplier()});
* <li>if all else fails, return {@link #getBaseSectionOutlinePaint()}.
* </ul>
*
* @param key the section key.
* @param autoPopulate a flag that controls whether the drawing supplier
* is used to auto-populate the section outline paint settings.
*
* @return The paint.
*
* @since 1.0.3
*/
protected Paint lookupSectionOutlinePaint(Comparable key,
boolean autoPopulate) {
// is there an override?
Paint result = getSectionOutlinePaint();
if (result != null) {
return result;
}
// if not, check if there is a paint defined for the specified key
result = this.sectionOutlinePaintMap.getPaint(key);
if (result != null) {
return result;
}
// nothing defined - do we autoPopulate?
if (autoPopulate) {
DrawingSupplier ds = getDrawingSupplier();
if (ds != null) {
result = ds.getNextOutlinePaint();
this.sectionOutlinePaintMap.put(key, result);
}
else {
result = this.baseSectionOutlinePaint;
}
}
else {
result = this.baseSectionOutlinePaint;
}
return result;
}
/**
* Returns the outline paint for ALL sections in the plot.
*
* @return The paint (possibly <code>null</code>).
*
* @see #setSectionOutlinePaint(Paint)
*
* @deprecated Use {@link #getSectionOutlinePaint(Comparable)} and
* {@link #getBaseSectionOutlinePaint()}. Deprecated as of version
* 1.0.6.
*/
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).
*
* @see #getSectionOutlinePaint()
*
* @deprecated Use {@link #setSectionOutlinePaint(Comparable, Paint)} and
* {@link #setBaseSectionOutlinePaint(Paint)}. Deprecated as of
* version 1.0.6.
*/
public void setSectionOutlinePaint(Paint paint) {
this.sectionOutlinePaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the outline paint associated with the specified key, or
* <code>null</code> if there is no paint associated with the key.
*
* @param key the key (<code>null</code> not permitted).
*
* @return The paint associated with the specified key, or
* <code>null</code>.
*
* @throws IllegalArgumentException if <code>key</code> is
* <code>null</code>.
*
* @see #setSectionOutlinePaint(Comparable, Paint)
*
* @since 1.0.3
*/
public Paint getSectionOutlinePaint(Comparable key) {
// null argument check delegated...
return this.sectionOutlinePaintMap.getPaint(key);
}
/**
* Sets the outline paint associated with the specified key, and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param key the key (<code>null</code> not permitted).
* @param paint the paint.
*
* @throws IllegalArgumentException if <code>key</code> is
* <code>null</code>.
*
* @see #getSectionOutlinePaint(Comparable)
*
* @since 1.0.3
*/
public void setSectionOutlinePaint(Comparable key, Paint paint) {
// null argument check delegated...
this.sectionOutlinePaintMap.put(key, 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>).
*
* @see #setBaseSectionOutlinePaint(Paint)
*/
public Paint getBaseSectionOutlinePaint() {
return this.baseSectionOutlinePaint;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -