📄 abstractcategoryitemrenderer.java
字号:
IntervalMarker im = (IntervalMarker) marker;
double start = im.getStartValue();
double end = im.getEndValue();
Range range = axis.getRange();
if (!(range.intersects(start, end))) {
return;
}
// don't draw beyond the axis range...
start = range.constrain(start);
end = range.constrain(end);
double v0 = axis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge());
double v1 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
PlotOrientation orientation = plot.getOrientation();
Rectangle2D rect = null;
if (orientation == PlotOrientation.HORIZONTAL) {
rect = new Rectangle2D.Double(
v0, dataArea.getMinY(), v1 - v0, dataArea.getHeight()
);
}
else if (orientation == PlotOrientation.VERTICAL) {
rect = new Rectangle2D.Double(
dataArea.getMinX(), Math.min(v0, v1), dataArea.getWidth(), Math.abs(v1 - v0)
);
}
Paint p = marker.getPaint();
if (p instanceof GradientPaint) {
GradientPaint gp = (GradientPaint) p;
GradientPaintTransformer t = im.getGradientPaintTransformer();
if (t != null) {
gp = t.transform(gp, rect);
}
g2.setPaint(gp);
}
else {
g2.setPaint(p);
}
g2.fill(rect);
String label = marker.getLabel();
RectangleAnchor anchor = marker.getLabelAnchor();
if (label != null) {
Font labelFont = marker.getLabelFont();
g2.setFont(labelFont);
g2.setPaint(marker.getLabelPaint());
double[] coordinates = calculateRangeMarkerTextAnchorPoint(
g2, orientation, dataArea, rect, marker.getLabelOffset(), anchor
);
TextUtilities.drawAlignedString(
label, g2, (float) coordinates[0], (float) coordinates[1],
marker.getLabelTextAnchor()
);
}
}
}
/**
* Calculates the (x, y) coordinates for drawing a marker label.
*
* @param g2 the graphics device.
* @param orientation the plot orientation.
* @param dataArea the data area.
* @param markerArea the rectangle surrounding the marker.
* @param markerOffset the marker offset.
* @param anchor the label anchor.
*
* @return the coordinates for drawing the marker label.
*/
private double[] calculateRangeMarkerTextAnchorPoint(Graphics2D g2,
PlotOrientation orientation,
Rectangle2D dataArea,
Rectangle2D markerArea,
RectangleInsets markerOffset,
RectangleAnchor anchor) {
double[] result = null;
if (orientation == PlotOrientation.HORIZONTAL) {
Rectangle2D anchorRect = markerOffset.createOutsetRectangle(markerArea, true, false);
result = RectangleAnchor.coordinates(anchorRect, anchor);
}
else if (orientation == PlotOrientation.VERTICAL) {
Rectangle2D anchorRect = markerOffset.createOutsetRectangle(markerArea, false, true);
result = RectangleAnchor.coordinates(anchorRect, anchor);
}
return result;
}
/**
* Returns a legend item for a series.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return the legend item.
*/
public LegendItem getLegendItem(int datasetIndex, int series) {
CategoryPlot cp = getPlot();
if (cp == null) {
return null;
}
CategoryDataset dataset;
dataset = cp.getDataset(datasetIndex);
String label = dataset.getRowKey(series).toString();
String description = label;
Shape shape = getSeriesShape(series);
Paint paint = getSeriesPaint(series);
Paint outlinePaint = getSeriesOutlinePaint(series);
Stroke stroke = getSeriesStroke(series);
return new LegendItem(
label, description, shape, true, paint, stroke, outlinePaint, stroke
);
}
/**
* Tests this renderer for equality with another object.
*
* @param obj the object.
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
boolean result = super.equals(obj);
if (obj instanceof AbstractCategoryItemRenderer) {
AbstractCategoryItemRenderer r = (AbstractCategoryItemRenderer) obj;
boolean b0 = ObjectUtils.equal(this.labelGenerator, r.labelGenerator);
boolean b1 = ObjectUtils.equal(this.labelGeneratorList, r.labelGeneratorList);
boolean b2 = ObjectUtils.equal(this.baseLabelGenerator, r.baseLabelGenerator);
boolean b3 = ObjectUtils.equal(this.toolTipGenerator, r.toolTipGenerator);
boolean b4 = ObjectUtils.equal(this.toolTipGeneratorList, r.toolTipGeneratorList);
boolean b5 = ObjectUtils.equal(this.baseToolTipGenerator, r.baseToolTipGenerator);
boolean b6 = ObjectUtils.equal(this.itemURLGenerator, r.itemURLGenerator);
boolean b7 = ObjectUtils.equal(this.itemURLGeneratorList, r.itemURLGeneratorList);
boolean b8 = ObjectUtils.equal(this.baseItemURLGenerator, r.baseItemURLGenerator);
result = b0 && b1 && b2 && b3 && b4 && b5 && b6 && b7 && b8;
}
return result;
}
/**
* Returns a hash code for the renderer.
*
* @return The hash code.
*/
public int hashCode() {
int result = super.hashCode();
return result;
}
/**
* Returns the drawing supplier from the plot.
*
* @return The drawing supplier (possibly <code>null</code>).
*/
public DrawingSupplier getDrawingSupplier() {
DrawingSupplier result = null;
CategoryPlot cp = getPlot();
if (cp != null) {
result = cp.getDrawingSupplier();
}
return result;
}
/**
* Draws an item label.
*
* @param g2 the graphics device.
* @param orientation the orientation.
* @param dataset the dataset.
* @param row the row.
* @param column the column.
* @param x the x coordinate (in Java2D space).
* @param y the y coordinate (in Java2D space).
* @param negative indicates a negative value (which affects the item label position).
*/
protected void drawItemLabel(Graphics2D g2,
PlotOrientation orientation,
CategoryDataset dataset,
int row, int column,
double x, double y,
boolean negative) {
CategoryLabelGenerator generator = getLabelGenerator(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
);
RefineryUtilities.drawRotatedString(
label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
position.getTextAnchor(), position.getRotationAnchor(), position.getAngle()
);
}
}
/**
* Returns an independent copy of the renderer.
* <p>
* 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.labelGenerator != null) {
if (this.labelGenerator instanceof PublicCloneable) {
PublicCloneable pc = (PublicCloneable) this.labelGenerator;
clone.labelGenerator = (CategoryLabelGenerator) pc.clone();
}
else {
throw new CloneNotSupportedException("ItemLabelGenerator not cloneable.");
}
}
if (this.labelGeneratorList != null) {
clone.labelGeneratorList = (ObjectList) this.labelGeneratorList.clone();
}
if (this.baseLabelGenerator != null) {
if (this.baseLabelGenerator instanceof PublicCloneable) {
PublicCloneable pc = (PublicCloneable) this.baseLabelGenerator;
clone.baseLabelGenerator = (CategoryLabelGenerator) 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.");
}
}
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 (<code>null</code> for the primary axis).
*
* @return A range axis.
*/
protected ValueAxis getRangeAxis(CategoryPlot plot, int index) {
ValueAxis result = plot.getRangeAxis(index);
if (result == null) {
result = plot.getRangeAxis();
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -