📄 abstractcategoryitemrenderer.java
字号:
PlotOrientation orientation,
CategoryDataset dataset,
int row, int column,
double x, double y,
boolean negative) {
CategoryItemLabelGenerator generator
= getItemLabelGenerator(row, column);
if (generator != null) {
Font labelFont = getItemLabelFont(row, column);
Paint paint = getItemLabelPaint(row, column);
g2.setFont(labelFont);
g2.setPaint(paint);
String label = generator.generateLabel(dataset, row, column);
ItemLabelPosition position = null;
if (!negative) {
position = getPositiveItemLabelPosition(row, column);
}
else {
position = getNegativeItemLabelPosition(row, column);
}
Point2D anchorPoint = calculateLabelAnchorPoint(
position.getItemLabelAnchor(), x, y, orientation);
TextUtilities.drawRotatedString(label, g2,
(float) anchorPoint.getX(), (float) anchorPoint.getY(),
position.getTextAnchor(),
position.getAngle(), position.getRotationAnchor());
}
}
/**
* Returns an independent copy of the renderer. The <code>plot</code>
* reference is shallow copied.
*
* @return A clone.
*
* @throws CloneNotSupportedException can be thrown if one of the objects
* belonging to the renderer does not support cloning (for example,
* an item label generator).
*/
public Object clone() throws CloneNotSupportedException {
AbstractCategoryItemRenderer clone
= (AbstractCategoryItemRenderer) super.clone();
if (this.itemLabelGenerator != null) {
if (this.itemLabelGenerator instanceof PublicCloneable) {
PublicCloneable pc = (PublicCloneable) this.itemLabelGenerator;
clone.itemLabelGenerator
= (CategoryItemLabelGenerator) pc.clone();
}
else {
throw new CloneNotSupportedException(
"ItemLabelGenerator not cloneable.");
}
}
if (this.itemLabelGeneratorList != null) {
clone.itemLabelGeneratorList
= (ObjectList) this.itemLabelGeneratorList.clone();
}
if (this.baseItemLabelGenerator != null) {
if (this.baseItemLabelGenerator instanceof PublicCloneable) {
PublicCloneable pc
= (PublicCloneable) this.baseItemLabelGenerator;
clone.baseItemLabelGenerator
= (CategoryItemLabelGenerator) pc.clone();
}
else {
throw new CloneNotSupportedException(
"ItemLabelGenerator not cloneable.");
}
}
if (this.toolTipGenerator != null) {
if (this.toolTipGenerator instanceof PublicCloneable) {
PublicCloneable pc = (PublicCloneable) this.toolTipGenerator;
clone.toolTipGenerator = (CategoryToolTipGenerator) pc.clone();
}
else {
throw new CloneNotSupportedException(
"Tool tip generator not cloneable.");
}
}
if (this.toolTipGeneratorList != null) {
clone.toolTipGeneratorList
= (ObjectList) this.toolTipGeneratorList.clone();
}
if (this.baseToolTipGenerator != null) {
if (this.baseToolTipGenerator instanceof PublicCloneable) {
PublicCloneable pc
= (PublicCloneable) this.baseToolTipGenerator;
clone.baseToolTipGenerator
= (CategoryToolTipGenerator) pc.clone();
}
else {
throw new CloneNotSupportedException(
"Base tool tip generator not cloneable.");
}
}
if (this.itemURLGenerator != null) {
if (this.itemURLGenerator instanceof PublicCloneable) {
PublicCloneable pc = (PublicCloneable) this.itemURLGenerator;
clone.itemURLGenerator = (CategoryURLGenerator) pc.clone();
}
else {
throw new CloneNotSupportedException(
"Item URL generator not cloneable.");
}
}
if (this.itemURLGeneratorList != null) {
clone.itemURLGeneratorList
= (ObjectList) this.itemURLGeneratorList.clone();
}
if (this.baseItemURLGenerator != null) {
if (this.baseItemURLGenerator instanceof PublicCloneable) {
PublicCloneable pc
= (PublicCloneable) this.baseItemURLGenerator;
clone.baseItemURLGenerator = (CategoryURLGenerator) pc.clone();
}
else {
throw new CloneNotSupportedException(
"Base item URL generator not cloneable.");
}
}
if (this.legendItemLabelGenerator instanceof PublicCloneable) {
clone.legendItemLabelGenerator = (CategorySeriesLabelGenerator)
ObjectUtilities.clone(this.legendItemLabelGenerator);
}
if (this.legendItemToolTipGenerator instanceof PublicCloneable) {
clone.legendItemToolTipGenerator = (CategorySeriesLabelGenerator)
ObjectUtilities.clone(this.legendItemToolTipGenerator);
}
if (this.legendItemURLGenerator instanceof PublicCloneable) {
clone.legendItemURLGenerator = (CategorySeriesLabelGenerator)
ObjectUtilities.clone(this.legendItemURLGenerator);
}
return clone;
}
/**
* Returns a domain axis for a plot.
*
* @param plot the plot.
* @param index the axis index.
*
* @return A domain axis.
*/
protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {
CategoryAxis result = plot.getDomainAxis(index);
if (result == null) {
result = plot.getDomainAxis();
}
return result;
}
/**
* Returns a range axis for a plot.
*
* @param plot the plot.
* @param index the axis index.
*
* @return A range axis.
*/
protected ValueAxis getRangeAxis(CategoryPlot plot, int index) {
ValueAxis result = plot.getRangeAxis(index);
if (result == null) {
result = plot.getRangeAxis();
}
return result;
}
/**
* Returns a (possibly empty) collection of legend items for the series
* that this renderer is responsible for drawing.
*
* @return The legend item collection (never <code>null</code>).
*
* @see #getLegendItem(int, int)
*/
public LegendItemCollection getLegendItems() {
if (this.plot == null) {
return new LegendItemCollection();
}
LegendItemCollection result = new LegendItemCollection();
int index = this.plot.getIndexOf(this);
CategoryDataset dataset = this.plot.getDataset(index);
if (dataset != null) {
int seriesCount = dataset.getRowCount();
for (int i = 0; i < seriesCount; i++) {
if (isSeriesVisibleInLegend(i)) {
LegendItem item = getLegendItem(index, i);
if (item != null) {
result.add(item);
}
}
}
}
return result;
}
/**
* Returns the legend item label generator.
*
* @return The label generator (never <code>null</code>).
*
* @see #setLegendItemLabelGenerator(CategorySeriesLabelGenerator)
*/
public CategorySeriesLabelGenerator getLegendItemLabelGenerator() {
return this.legendItemLabelGenerator;
}
/**
* Sets the legend item label generator and sends a
* {@link RendererChangeEvent} to all registered listeners.
*
* @param generator the generator (<code>null</code> not permitted).
*
* @see #getLegendItemLabelGenerator()
*/
public void setLegendItemLabelGenerator(
CategorySeriesLabelGenerator generator) {
if (generator == null) {
throw new IllegalArgumentException("Null 'generator' argument.");
}
this.legendItemLabelGenerator = generator;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the legend item tool tip generator.
*
* @return The tool tip generator (possibly <code>null</code>).
*
* @see #setLegendItemToolTipGenerator(CategorySeriesLabelGenerator)
*/
public CategorySeriesLabelGenerator getLegendItemToolTipGenerator() {
return this.legendItemToolTipGenerator;
}
/**
* Sets the legend item tool tip generator and sends a
* {@link RendererChangeEvent} to all registered listeners.
*
* @param generator the generator (<code>null</code> permitted).
*
* @see #setLegendItemToolTipGenerator(CategorySeriesLabelGenerator)
*/
public void setLegendItemToolTipGenerator(
CategorySeriesLabelGenerator generator) {
this.legendItemToolTipGenerator = generator;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the legend item URL generator.
*
* @return The URL generator (possibly <code>null</code>).
*
* @see #setLegendItemURLGenerator(CategorySeriesLabelGenerator)
*/
public CategorySeriesLabelGenerator getLegendItemURLGenerator() {
return this.legendItemURLGenerator;
}
/**
* Sets the legend item URL generator and sends a
* {@link RendererChangeEvent} to all registered listeners.
*
* @param generator the generator (<code>null</code> permitted).
*
* @see #getLegendItemURLGenerator()
*/
public void setLegendItemURLGenerator(
CategorySeriesLabelGenerator generator) {
this.legendItemURLGenerator = generator;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Adds an entity with the specified hotspot.
*
* @param entities the entity collection.
* @param dataset the dataset.
* @param row the row index.
* @param column the column index.
* @param hotspot the hotspot.
*/
protected void addItemEntity(EntityCollection entities,
CategoryDataset dataset, int row, int column,
Shape hotspot) {
String tip = null;
CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
if (tipster != null) {
tip = tipster.generateToolTip(dataset, row, column);
}
String url = null;
CategoryURLGenerator urlster = getItemURLGenerator(row, column);
if (urlster != null) {
url = urlster.generateURL(dataset, row, column);
}
CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url,
dataset, dataset.getRowKey(row), dataset.getColumnKey(column));
entities.add(entity);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -