Package org.jfree.chart.labels
Class StandardPieSectionLabelGenerator
- java.lang.Object
-
- org.jfree.chart.labels.AbstractPieItemLabelGenerator
-
- org.jfree.chart.labels.StandardPieSectionLabelGenerator
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,PieSectionLabelGenerator
,PublicCloneable
public class StandardPieSectionLabelGenerator extends AbstractPieItemLabelGenerator implements PieSectionLabelGenerator, java.lang.Cloneable, PublicCloneable, java.io.Serializable
A standard item label generator for plots that use data from aPieDataset
.For the label format, use {0} where the pie section key should be inserted, {1} for the absolute section value and {2} for the percent amount of the pie section, e.g.
"{0} = {1} ({2})"
will display asapple = 120 (5%)
.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map
attributedLabels
An optional map between item indices (Integer) and attributed labels (instances of AttributedString).static java.lang.String
DEFAULT_SECTION_LABEL_FORMAT
The default section label format.private static long
serialVersionUID
For serialization.
-
Constructor Summary
Constructors Constructor Description StandardPieSectionLabelGenerator()
Creates a new section label generator usingDEFAULT_SECTION_LABEL_FORMAT
as the label format string, and platform default number and percentage formatters.StandardPieSectionLabelGenerator(java.lang.String labelFormat)
Creates a new section label generator using the specified label format string, and platform default number and percentage formatters.StandardPieSectionLabelGenerator(java.lang.String labelFormat, java.text.NumberFormat numberFormat, java.text.NumberFormat percentFormat)
Creates an item label generator using the specified number formatters.StandardPieSectionLabelGenerator(java.lang.String labelFormat, java.util.Locale locale)
Creates a new instance for the specified locale.StandardPieSectionLabelGenerator(java.util.Locale locale)
Creates a new instance for the specified locale.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Returns an independent copy of the generator.boolean
equals(java.lang.Object obj)
Tests the generator for equality with an arbitrary object.java.text.AttributedString
generateAttributedSectionLabel(PieDataset dataset, java.lang.Comparable key)
Generates an attributed label for the specified series, ornull
if no attributed label is available (in which case, the string returned bygenerateSectionLabel(PieDataset, Comparable)
will provide the fallback).java.lang.String
generateSectionLabel(PieDataset dataset, java.lang.Comparable key)
Generates a label for a pie section.java.text.AttributedString
getAttributedLabel(int section)
Returns the attributed label for a section, ornull
if none is defined.void
setAttributedLabel(int section, java.text.AttributedString label)
Sets the attributed label for a section.-
Methods inherited from class org.jfree.chart.labels.AbstractPieItemLabelGenerator
createItemArray, getLabelFormat, getNumberFormat, getPercentFormat, hashCode
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
DEFAULT_SECTION_LABEL_FORMAT
public static final java.lang.String DEFAULT_SECTION_LABEL_FORMAT
The default section label format.- See Also:
- Constant Field Values
-
attributedLabels
private java.util.Map attributedLabels
An optional map between item indices (Integer) and attributed labels (instances of AttributedString).
-
-
Constructor Detail
-
StandardPieSectionLabelGenerator
public StandardPieSectionLabelGenerator()
Creates a new section label generator usingDEFAULT_SECTION_LABEL_FORMAT
as the label format string, and platform default number and percentage formatters.
-
StandardPieSectionLabelGenerator
public StandardPieSectionLabelGenerator(java.util.Locale locale)
Creates a new instance for the specified locale.- Parameters:
locale
- the local (null
not permitted).
-
StandardPieSectionLabelGenerator
public StandardPieSectionLabelGenerator(java.lang.String labelFormat)
Creates a new section label generator using the specified label format string, and platform default number and percentage formatters.- Parameters:
labelFormat
- the label format (null
not permitted).
-
StandardPieSectionLabelGenerator
public StandardPieSectionLabelGenerator(java.lang.String labelFormat, java.util.Locale locale)
Creates a new instance for the specified locale.- Parameters:
labelFormat
- the label format (null
not permitted).locale
- the local (null
not permitted).
-
StandardPieSectionLabelGenerator
public StandardPieSectionLabelGenerator(java.lang.String labelFormat, java.text.NumberFormat numberFormat, java.text.NumberFormat percentFormat)
Creates an item label generator using the specified number formatters.- Parameters:
labelFormat
- the label format string (null
not permitted).numberFormat
- the format object for the values (null
not permitted).percentFormat
- the format object for the percentages (null
not permitted).
-
-
Method Detail
-
getAttributedLabel
public java.text.AttributedString getAttributedLabel(int section)
Returns the attributed label for a section, ornull
if none is defined.- Parameters:
section
- the section index.- Returns:
- The attributed label.
-
setAttributedLabel
public void setAttributedLabel(int section, java.text.AttributedString label)
Sets the attributed label for a section.- Parameters:
section
- the section index.label
- the label (null
permitted).
-
generateSectionLabel
public java.lang.String generateSectionLabel(PieDataset dataset, java.lang.Comparable key)
Generates a label for a pie section.- Specified by:
generateSectionLabel
in interfacePieSectionLabelGenerator
- Overrides:
generateSectionLabel
in classAbstractPieItemLabelGenerator
- Parameters:
dataset
- the dataset (null
not permitted).key
- the section key (null
not permitted).- Returns:
- The label (possibly
null
).
-
generateAttributedSectionLabel
public java.text.AttributedString generateAttributedSectionLabel(PieDataset dataset, java.lang.Comparable key)
Generates an attributed label for the specified series, ornull
if no attributed label is available (in which case, the string returned bygenerateSectionLabel(PieDataset, Comparable)
will provide the fallback). Only certain attributes are recognised by the code that ultimately displays the labels:TextAttribute.FONT
: will set the font;TextAttribute.POSTURE
: a value ofTextAttribute.POSTURE_OBLIQUE
will addFont.ITALIC
to the current font;TextAttribute.WEIGHT
: a value ofTextAttribute.WEIGHT_BOLD
will addFont.BOLD
to the current font;TextAttribute.FOREGROUND
: this will set thePaint
for the currentTextAttribute.SUPERSCRIPT
: the valuesTextAttribute.SUPERSCRIPT_SUB
andTextAttribute.SUPERSCRIPT_SUPER
are recognised.
- Specified by:
generateAttributedSectionLabel
in interfacePieSectionLabelGenerator
- Parameters:
dataset
- the dataset (null
not permitted).key
- the key.- Returns:
- An attributed label (possibly
null
).
-
equals
public boolean equals(java.lang.Object obj)
Tests the generator for equality with an arbitrary object.- Overrides:
equals
in classAbstractPieItemLabelGenerator
- Parameters:
obj
- the object to test against (null
permitted).- Returns:
- A boolean.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns an independent copy of the generator.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classAbstractPieItemLabelGenerator
- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException
- should not happen.
-
-