📄 abstractxyitemrenderer.java
字号:
*
* @param generator the generator (<code>null</code> permitted).
*
* @see #getLegendItemToolTipGenerator()
*/
public void setLegendItemToolTipGenerator(
XYSeriesLabelGenerator generator) {
this.legendItemToolTipGenerator = generator;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the legend item URL generator.
*
* @return The URL generator (possibly <code>null</code>).
*
* @see #setLegendItemURLGenerator(XYSeriesLabelGenerator)
*/
public XYSeriesLabelGenerator 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(XYSeriesLabelGenerator generator) {
this.legendItemURLGenerator = generator;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the lower and upper bounds (range) of the x-values in the
* specified dataset.
*
* @param dataset the dataset (<code>null</code> permitted).
*
* @return The range (<code>null</code> if the dataset is <code>null</code>
* or empty).
*/
public Range findDomainBounds(XYDataset dataset) {
if (dataset != null) {
return DatasetUtilities.findDomainBounds(dataset, false);
}
else {
return null;
}
}
/**
* Returns the range of values the renderer requires to display all the
* items from the specified dataset.
*
* @param dataset the dataset (<code>null</code> permitted).
*
* @return The range (<code>null</code> if the dataset is <code>null</code>
* or empty).
*/
public Range findRangeBounds(XYDataset dataset) {
if (dataset != null) {
return DatasetUtilities.findRangeBounds(dataset, false);
}
else {
return null;
}
}
/**
* 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>).
*/
public LegendItemCollection getLegendItems() {
if (this.plot == null) {
return new LegendItemCollection();
}
LegendItemCollection result = new LegendItemCollection();
int index = this.plot.getIndexOf(this);
XYDataset dataset = this.plot.getDataset(index);
if (dataset != null) {
int seriesCount = dataset.getSeriesCount();
for (int i = 0; i < seriesCount; i++) {
if (isSeriesVisibleInLegend(i)) {
LegendItem item = getLegendItem(index, i);
if (item != null) {
result.add(item);
}
}
}
}
return result;
}
/**
* Returns a default legend item for the specified series. Subclasses
* should override this method to generate customised items.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return A legend item for the series.
*/
public LegendItem getLegendItem(int datasetIndex, int series) {
LegendItem result = null;
XYPlot xyplot = getPlot();
if (xyplot != null) {
XYDataset dataset = xyplot.getDataset(datasetIndex);
if (dataset != null) {
String label = this.legendItemLabelGenerator.generateLabel(
dataset, series);
String description = label;
String toolTipText = null;
if (getLegendItemToolTipGenerator() != null) {
toolTipText = getLegendItemToolTipGenerator().generateLabel(
dataset, series);
}
String urlText = null;
if (getLegendItemURLGenerator() != null) {
urlText = getLegendItemURLGenerator().generateLabel(
dataset, series);
}
Shape shape = lookupSeriesShape(series);
Paint paint = lookupSeriesPaint(series);
Paint outlinePaint = lookupSeriesOutlinePaint(series);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
result = new LegendItem(label, description, toolTipText,
urlText, shape, paint, outlineStroke, outlinePaint);
result.setSeriesKey(dataset.getSeriesKey(series));
result.setSeriesIndex(series);
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
}
}
return result;
}
/**
* Fills a band between two values on the axis. This can be used to color
* bands between the grid lines.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the domain axis.
* @param dataArea the data area.
* @param start the start value.
* @param end the end value.
*/
public void fillDomainGridBand(Graphics2D g2,
XYPlot plot,
ValueAxis axis,
Rectangle2D dataArea,
double start, double end) {
double x1 = axis.valueToJava2D(start, dataArea,
plot.getDomainAxisEdge());
double x2 = axis.valueToJava2D(end, dataArea,
plot.getDomainAxisEdge());
// TODO: need to change the next line to take account of plot
// orientation...
Rectangle2D band = new Rectangle2D.Double(x1, dataArea.getMinY(),
x2 - x1, dataArea.getMaxY() - dataArea.getMinY());
Paint paint = plot.getDomainTickBandPaint();
if (paint != null) {
g2.setPaint(paint);
g2.fill(band);
}
}
/**
* Fills a band between two values on the range axis. This can be used to
* color bands between the grid lines.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the range axis.
* @param dataArea the data area.
* @param start the start value.
* @param end the end value.
*/
public void fillRangeGridBand(Graphics2D g2,
XYPlot plot,
ValueAxis axis,
Rectangle2D dataArea,
double start, double end) {
double y1 = axis.valueToJava2D(start, dataArea,
plot.getRangeAxisEdge());
double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
// TODO: need to change the next line to take account of the plot
// orientation
Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2,
dataArea.getWidth(), y1 - y2);
Paint paint = plot.getRangeTickBandPaint();
if (paint != null) {
g2.setPaint(paint);
g2.fill(band);
}
}
/**
* Draws a grid line against the range axis.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param dataArea the area for plotting data (not yet adjusted for any
* 3D effect).
* @param value the value at which the grid line should be drawn.
*/
public void drawDomainGridLine(Graphics2D g2,
XYPlot plot,
ValueAxis axis,
Rectangle2D dataArea,
double value) {
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
double v = axis.valueToJava2D(value, dataArea,
plot.getDomainAxisEdge());
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(dataArea.getMinX(), v,
dataArea.getMaxX(), v);
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(v, dataArea.getMinY(), v,
dataArea.getMaxY());
}
Paint paint = plot.getDomainGridlinePaint();
Stroke stroke = plot.getDomainGridlineStroke();
g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
g2.draw(line);
}
/**
* Draws a line perpendicular to the domain axis.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param dataArea the area for plotting data (not yet adjusted for any 3D
* effect).
* @param value the value at which the grid line should be drawn.
* @param paint the paint.
* @param stroke the stroke.
*
* @since 1.0.5
*/
public void drawDomainLine(Graphics2D g2, XYPlot plot, ValueAxis axis,
Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
Line2D line = null;
double v = axis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge());
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(),
v);
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(v, dataArea.getMinY(), v,
dataArea.getMaxY());
}
g2.setPaint(paint);
g2.setStroke(stroke);
g2.draw(line);
}
/**
* Draws a line perpendicular to the range axis.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param dataArea the area for plotting data (not yet adjusted for any 3D
* effect).
* @param value the value at which the grid line should be drawn.
* @param paint the paint.
* @param stroke the stroke.
*/
public void drawRangeLine(Graphics2D g2,
XYPlot plot,
ValueAxis axis,
Rectangle2D dataArea,
double value,
Paint paint,
Stroke stroke) {
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
Line2D line = null;
double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(v, dataArea.getMinY(), v,
dataArea.getMaxY());
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(dataArea.getMinX(), v,
dataArea.getMaxX(), v);
}
g2.setPaint(paint);
g2.setStroke(stroke);
g2.draw(line);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -