📄 lineandshaperenderer.java
字号:
/**
* Sets the flag that controls whether outlines are drawn for
* shapes, and sends a {@link RendererChangeEvent} to all registered
* listeners.
* <P>
* In some cases, shapes look better if they do NOT have an outline, but
* this flag allows you to set your own preference.
*
* @param flag the flag.
*/
public void setDrawOutlines(boolean flag) {
this.drawOutlines = flag;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the flag that controls whether the outline paint is used for
* shape outlines. If not, the regular series paint is used.
*
* @return A boolean.
*/
public boolean getUseOutlinePaint() {
return this.useOutlinePaint;
}
/**
* Sets the flag that controls whether the outline paint is used for shape
* outlines.
*
* @param use the flag.
*/
public void setUseOutlinePaint(boolean use) {
this.useOutlinePaint = use;
}
// SHAPES FILLED
/**
* Returns the flag used to control whether or not the shape for an item
* is filled. The default implementation passes control to the
* <code>getSeriesShapesFilled</code> method. You can override this method
* if you require different behaviour.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return A boolean.
*/
public boolean getItemShapeFilled(int series, int item) {
return getSeriesShapesFilled(series);
}
/**
* Returns the flag used to control whether or not the shapes for a series
* are filled.
*
* @param series the series index (zero-based).
*
* @return A boolean.
*/
public boolean getSeriesShapesFilled(int series) {
// return the overall setting, if there is one...
if (this.shapesFilled != null) {
return this.shapesFilled.booleanValue();
}
// otherwise look up the paint table
Boolean flag = this.seriesShapesFilled.getBoolean(series);
if (flag != null) {
return flag.booleanValue();
}
else {
return this.baseShapesFilled;
}
}
/**
* Returns the flag that controls whether or not shapes are filled for
* ALL series.
*
* @return A Boolean.
*/
public Boolean getShapesFilled() {
return this.shapesFilled;
}
/**
* Sets the 'shapes filled' for ALL series.
*
* @param filled the flag.
*/
public void setShapesFilled(boolean filled) {
if (filled) {
setShapesFilled(Boolean.TRUE);
}
else {
setShapesFilled(Boolean.FALSE);
}
}
/**
* Sets the 'shapes filled' for ALL series.
*
* @param filled the flag (<code>null</code> permitted).
*/
public void setShapesFilled(Boolean filled) {
this.shapesFilled = filled;
}
/**
* Sets the 'shapes filled' flag for a series.
*
* @param series the series index (zero-based).
* @param filled the flag.
*/
public void setSeriesShapesFilled(int series, Boolean filled) {
this.seriesShapesFilled.setBoolean(series, filled);
}
/**
* Sets the 'shapes filled' flag for a series.
*
* @param series the series index (zero-based).
* @param filled the flag.
*/
public void setSeriesShapesFilled(int series, boolean filled) {
this.seriesShapesFilled.setBoolean(
series, BooleanUtilities.valueOf(filled)
);
}
/**
* Returns the base 'shape filled' attribute.
*
* @return The base flag.
*/
public boolean getBaseShapesFilled() {
return this.baseShapesFilled;
}
/**
* Sets the base 'shapes filled' flag.
*
* @param flag the flag.
*/
public void setBaseShapesFilled(boolean flag) {
this.baseShapesFilled = flag;
}
/**
* Returns <code>true</code> if the renderer should use the fill paint
* setting to fill shapes, and <code>false</code> if it should just
* use the regular paint.
*
* @return A boolean.
*/
public boolean getUseFillPaint() {
return this.useFillPaint;
}
/**
* Sets the flag that controls whether the fill paint is used to fill
* shapes, and sends a {@link RendererChangeEvent} to all
* registered listeners.
*
* @param flag the flag.
*/
public void setUseFillPaint(boolean flag) {
this.useFillPaint = flag;
notifyListeners(new RendererChangeEvent(this));
}
/**
* 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;
}
if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
CategoryDataset dataset = cp.getDataset(datasetIndex);
String label = getLegendItemLabelGenerator().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 fillPaint = (this.useFillPaint
? getItemFillPaint(series, 0) : paint);
boolean shapeOutlineVisible = this.drawOutlines;
Paint outlinePaint = (this.useOutlinePaint
? getItemOutlinePaint(series, 0) : paint);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
boolean lineVisible = getItemLineVisible(series, 0);
boolean shapeVisible = getItemShapeVisible(series, 0);
LegendItem result = new LegendItem(label, description, toolTipText,
urlText, shapeVisible, shape, getItemShapeFilled(series, 0),
fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke,
lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0),
getItemStroke(series, 0), getItemPaint(series, 0));
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
result.setSeriesKey(dataset.getRowKey(series));
result.setSeriesIndex(series);
return result;
}
return null;
}
/**
* This renderer uses two passes to draw the data.
*
* @return The pass count (<code>2</code> for this renderer).
*/
public int getPassCount() {
return 2;
}
/**
* Draw a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area in which the data is drawn.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
* @param pass the pass index.
*/
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
int pass) {
// do nothing if item is not visible
if (!getItemVisible(row, column)) {
return;
}
// do nothing if both the line and shape are not visible
if (!getItemLineVisible(row, column)
&& !getItemShapeVisible(row, column)) {
return;
}
// nothing is drawn for null...
Number v = dataset.getValue(row, column);
if (v == null) {
return;
}
PlotOrientation orientation = plot.getOrientation();
// current data point...
double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(),
dataArea, plot.getDomainAxisEdge());
double value = v.doubleValue();
double y1 = rangeAxis.valueToJava2D(value, dataArea,
plot.getRangeAxisEdge());
if (pass == 0 && getItemLineVisible(row, column)) {
if (column != 0) {
Number previousValue = dataset.getValue(row, column - 1);
if (previousValue != null) {
// previous data point...
double previous = previousValue.doubleValue();
double x0 = domainAxis.getCategoryMiddle(column - 1,
getColumnCount(), dataArea,
plot.getDomainAxisEdge());
double y0 = rangeAxis.valueToJava2D(previous, dataArea,
plot.getRangeAxisEdge());
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(y0, x0, y1, x1);
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(x0, y0, x1, y1);
}
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
g2.draw(line);
}
}
}
if (pass == 1) {
Shape shape = getItemShape(row, column);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
}
else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
}
if (getItemShapeVisible(row, column)) {
if (getItemShapeFilled(row, column)) {
if (this.useFillPaint) {
g2.setPaint(getItemFillPaint(row, column));
}
else {
g2.setPaint(getItemPaint(row, column));
}
g2.fill(shape);
}
if (this.drawOutlines) {
if (this.useOutlinePaint) {
g2.setPaint(getItemOutlinePaint(row, column));
}
else {
g2.setPaint(getItemPaint(row, column));
}
g2.setStroke(getItemOutlineStroke(row, column));
g2.draw(shape);
}
}
// draw the item label if there is one...
if (isItemLabelVisible(row, column)) {
if (orientation == PlotOrientation.HORIZONTAL) {
drawItemLabel(g2, orientation, dataset, row, column, y1,
x1, (value < 0.0));
}
else if (orientation == PlotOrientation.VERTICAL) {
drawItemLabel(g2, orientation, dataset, row, column, x1,
y1, (value < 0.0));
}
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, shape);
}
}
}
/**
* Tests this renderer for equality with an arbitrary object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof LineAndShapeRenderer)) {
return false;
}
LineAndShapeRenderer that = (LineAndShapeRenderer) obj;
if (this.baseLinesVisible != that.baseLinesVisible) {
return false;
}
if (!ObjectUtilities.equal(this.seriesLinesVisible,
that.seriesLinesVisible)) {
return false;
}
if (!ObjectUtilities.equal(this.linesVisible, that.linesVisible)) {
return false;
}
if (this.baseShapesVisible != that.baseShapesVisible) {
return false;
}
if (!ObjectUtilities.equal(this.seriesShapesVisible,
that.seriesShapesVisible)) {
return false;
}
if (!ObjectUtilities.equal(this.shapesVisible, that.shapesVisible)) {
return false;
}
if (!ObjectUtilities.equal(this.shapesFilled, that.shapesFilled)) {
return false;
}
if (!ObjectUtilities.equal(this.seriesShapesFilled,
that.seriesShapesFilled)) {
return false;
}
if (this.baseShapesFilled != that.baseShapesFilled) {
return false;
}
if (this.useOutlinePaint != that.useOutlinePaint) {
return false;
}
if (!super.equals(obj)) {
return false;
}
return true;
}
/**
* Returns an independent copy of the renderer.
*
* @return A clone.
*
* @throws CloneNotSupportedException should not happen.
*/
public Object clone() throws CloneNotSupportedException {
LineAndShapeRenderer clone = (LineAndShapeRenderer) super.clone();
clone.seriesLinesVisible
= (BooleanList) this.seriesLinesVisible.clone();
clone.seriesShapesVisible
= (BooleanList) this.seriesLinesVisible.clone();
clone.seriesShapesFilled
= (BooleanList) this.seriesShapesFilled.clone();
return clone;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -