📄 xylineandshaperenderer.java
字号:
/**
* Returns the flag used to control whether or not the shape for an item is filled.
* <p>
* 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) {
Boolean flag = this.shapesFilled;
if (flag == null) {
flag = getSeriesShapesFilled(series);
}
if (flag != null) {
return flag.booleanValue();
}
else {
return this.defaultShapesVisible;
}
}
/**
* Sets the 'shapes filled' for ALL series and sends a {@link RendererChangeEvent}
* to all registered listeners.
*
* @param filled the flag.
*/
public void setShapesFilled(boolean filled) {
setShapesFilled(BooleanUtils.valueOf(filled));
}
/**
* Sets the 'shapes filled' for ALL series and sends a {@link RendererChangeEvent}
* to all registered listeners.
*
* @param filled the flag (<code>null</code> permitted).
*/
public void setShapesFilled(Boolean filled) {
this.shapesFilled = filled;
notifyListeners(new RendererChangeEvent(this));
}
/**
* 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 this.seriesShapesFilled.getBoolean(series);
}
/**
* Sets the 'shapes filled' flag for a series.
*
* @param series the series index (zero-based).
* @param flag the flag.
*/
public void setSeriesShapesFilled(int series, boolean flag) {
setSeriesShapesFilled(series, BooleanUtils.valueOf(flag));
}
/**
* Sets the 'shapes filled' flag for a series.
*
* @param series the series index (zero-based).
* @param flag the flag.
*/
public void setSeriesShapesFilled(int series, Boolean flag) {
this.seriesShapesFilled.setBoolean(series, flag);
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the default 'shape filled' attribute.
*
* @return The default flag.
*/
public boolean getDefaultShapesFilled() {
return this.defaultShapesFilled;
}
/**
* Sets the default 'shapes filled' flag.
*
* @param flag the flag.
*/
public void setDefaultShapesFilled(boolean flag) {
this.defaultShapesFilled = flag;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns <code>true</code> if outlines should be drawn for filled shapes, and
* <code>false</code> otherwise.
*
* @return A boolean.
*/
public boolean getDrawOutlines() {
return this.drawOutlines;
}
/**
* Sets the flag that controls whether outlines are drawn for filled 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 <code>true</code> if the renderer should use the outline paint setting to draw
* shape outlines, and <code>false</code> if it should just use the regular paint.
*
* @return A boolean.
*/
public boolean getUseOutlinePaint() {
return this.useOutlinePaint;
}
/**
* Sets the flag that controls whether the outline paint is used to draw shape outlines, and
* sends a {@link RendererChangeEvent} to all registered listeners.
*
* @param flag the flag.
*/
public void setUseOutlinePaint(boolean flag) {
this.useOutlinePaint = flag;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Initialises the renderer.
* <P>
* This method will be called before the first item is rendered, giving the
* renderer an opportunity to initialise any state information it wants to maintain.
* The renderer can do nothing if it chooses.
*
* @param g2 the graphics device.
* @param dataArea the area inside the axes.
* @param plot the plot.
* @param data the data.
* @param info an optional info collection object to return data back to the caller.
*
* @return The renderer state.
*/
public XYItemRendererState initialise(Graphics2D g2,
Rectangle2D dataArea,
XYPlot plot,
XYDataset data,
PlotRenderingInfo info) {
XYItemRendererState state = new XYItemRendererState(info);
return state;
}
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the data is being drawn.
* @param info collects information about the drawing.
* @param plot the plot (can be used to obtain standard color information etc).
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState crosshair information for the plot (<code>null</code> permitted).
* @param pass the pass index.
*/
public void drawItem(Graphics2D g2,
XYItemRendererState state,
Rectangle2D dataArea,
PlotRenderingInfo info,
XYPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYDataset dataset,
int series,
int item,
CrosshairState crosshairState,
int pass) {
if (!getItemVisible(series, item)) {
return;
}
// get the data point...
Number x1n = dataset.getX(series, item);
Number y1n = dataset.getY(series, item);
if (y1n == null || x1n == null) {
return;
}
// setup for collecting optional entity info...
Shape entityArea = null;
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
double x1 = x1n.doubleValue();
double y1 = y1n.doubleValue();
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
if (pass == 0) {
if (getItemLineVisible(series, item) && item > 0) {
// get the previous data point...
Number x0n = dataset.getX(series, item - 1);
Number y0n = dataset.getY(series, item - 1);
if (y0n != null && x0n != null) {
double x0 = x0n.doubleValue();
double y0 = y0n.doubleValue();
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
// only draw if we have good values
if (Double.isNaN(transX0) || Double.isNaN(transY0)
|| Double.isNaN(transX1) || Double.isNaN(transY1)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
state.workingLine.setLine(transY0, transX0, transY1, transX1);
}
else if (orientation == PlotOrientation.VERTICAL) {
state.workingLine.setLine(transX0, transY0, transX1, transY1);
}
if (state.workingLine.intersects(dataArea)) {
g2.setStroke(getItemStroke(series, item));
g2.setPaint(getItemPaint(series, item));
g2.draw(state.workingLine);
}
}
}
}
else if (pass == 1) {
if (getItemShapeVisible(series, item)) {
Shape shape = getItemShape(series, item);
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
shape = createTransformedShape(shape, transY1, transX1);
}
else if (orientation == PlotOrientation.VERTICAL) {
shape = createTransformedShape(shape, transX1, transY1);
}
entityArea = shape;
if (shape.intersects(dataArea)) {
if (getItemShapeFilled(series, item)) {
g2.setPaint(getItemPaint(series, item));
g2.fill(shape);
if (getDrawOutlines()) {
if (getUseOutlinePaint()) {
g2.setPaint(getItemOutlinePaint(series, item));
}
else {
g2.setPaint(getItemPaint(series, item));
}
g2.draw(shape);
}
}
else {
if (getUseOutlinePaint()) {
g2.setPaint(getItemOutlinePaint(series, item));
}
else {
g2.setPaint(getItemPaint(series, item));
}
g2.draw(shape);
}
}
}
// add an entity for the item...
if (entities != null) {
addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
}
}
}
/**
* Returns a clone of the renderer.
*
* @return A clone.
*
* @throws CloneNotSupportedException if the clone cannot be created.
*/
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
/**
* 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) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) obj;
if (super.equals(obj)) {
boolean b0 = ObjectUtils.equal(this.linesVisible, r.linesVisible);
boolean b1 = ObjectUtils.equal(this.seriesLinesVisible, r.seriesLinesVisible);
boolean b2 = (this.defaultLinesVisible == r.defaultLinesVisible);
boolean b3 = ObjectUtils.equal(this.shapesVisible, r.shapesVisible);
boolean b4 = ObjectUtils.equal(this.seriesShapesVisible, r.seriesShapesVisible);
boolean b5 = (this.defaultShapesVisible == r.defaultShapesVisible);
boolean b6 = ObjectUtils.equal(this.shapesFilled, r.shapesFilled);
boolean b7 = ObjectUtils.equal(this.seriesShapesFilled, r.seriesShapesFilled);
boolean b8 = (this.defaultShapesFilled == r.defaultShapesFilled);
boolean b9 = (this.drawOutlines == r.drawOutlines);
boolean b10 = (this.useOutlinePaint == r.useOutlinePaint);
return b0 && b1 && b2 && b3 && b4 && b5 && b6 && b7 && b8 && b9 && b10;
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -