📄 xyshaperenderer.java
字号:
public void setGuideLinePaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.guideLinePaint = paint;
fireChangeEvent();
}
/**
* Returns the stroke used to draw the guide lines.
*
* @return The stroke.
*
* @see #setGuideLineStroke(Stroke)
*/
public Stroke getGuideLineStroke() {
return this.guideLineStroke;
}
/**
* Sets the stroke used to draw the guide lines and sends a
* {@link RendererChangeEvent} to all registered listeners.
*
* @param stroke the stroke (<code>null</code> not permitted).
*
* @see #getGuideLineStroke()
*/
public void setGuideLineStroke(Stroke stroke) {
if (stroke == null) {
throw new IllegalArgumentException("Null 'stroke' argument.");
}
this.guideLineStroke = stroke;
fireChangeEvent();
}
/**
* 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) {
Range r = DatasetUtilities.findDomainBounds(dataset, false);
double offset = 0; // TODO getSeriesShape(n).getBounds().width / 2;
return new Range(r.getLowerBound() + offset,
r.getUpperBound() + offset);
}
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) {
Range r = DatasetUtilities.findRangeBounds(dataset, false);
double offset = 0; // TODO getSeriesShape(n).getBounds().height / 2;
return new Range(r.getLowerBound() + offset, r.getUpperBound()
+ offset);
}
else {
return null;
}
}
/**
* Returns the number of passes required by this renderer.
*
* @return <code>2</code>.
*/
public int getPassCount() {
return 2;
}
/**
* Draws the block representing the specified item.
*
* @param g2 the graphics device.
* @param state the state.
* @param dataArea the data area.
* @param info the plot rendering info.
* @param plot the plot.
* @param domainAxis the x-axis.
* @param rangeAxis the y-axis.
* @param dataset the dataset.
* @param series the series index.
* @param item the item index.
* @param crosshairState the crosshair state.
* @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) {
Shape hotspot = null;
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
if (Double.isNaN(x) || Double.isNaN(y)) {
// can't draw anything
return;
}
double transX = domainAxis.valueToJava2D(x, dataArea,
plot.getDomainAxisEdge());
double transY = rangeAxis.valueToJava2D(y, dataArea,
plot.getRangeAxisEdge());
PlotOrientation orientation = plot.getOrientation();
// draw optional guide lines
if ((pass == 0) && this.guideLinesVisible) {
g2.setStroke(this.guideLineStroke);
g2.setPaint(this.guideLinePaint);
if (orientation == PlotOrientation.HORIZONTAL) {
g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY,
dataArea.getMaxY()));
g2.draw(new Line2D.Double(dataArea.getMinX(), transX,
dataArea.getMaxX(), transX));
}
else {
g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX,
dataArea.getMaxY()));
g2.draw(new Line2D.Double(dataArea.getMinX(), transY,
dataArea.getMaxX(), transY));
}
}
else if (pass == 1) {
Shape shape = getItemShape(series, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY,
transX);
}
else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX,
transY);
}
hotspot = shape;
if (shape.intersects(dataArea)) {
//if (getItemShapeFilled(series, item)) {
g2.setPaint(getPaint(dataset, series, item));
g2.fill(shape);
//}
if (this.drawOutlines) {
if (getUseOutlinePaint()) {
g2.setPaint(getItemOutlinePaint(series, item));
}
else {
g2.setPaint(getItemPaint(series, item));
}
g2.setStroke(getItemOutlineStroke(series, item));
g2.draw(shape);
}
}
// add an entity for the item...
if (entities != null) {
addEntity(entities, hotspot, dataset, series, item, transX,
transY);
}
}
}
/**
* Get the paint for a given series and item from a dataset.
*
* @param dataset the dataset..
* @param series the series index.
* @param item the item index.
*
* @return The paint.
*/
protected Paint getPaint(XYDataset dataset, int series, int item) {
Paint p = null;
if (dataset instanceof XYZDataset) {
double z = ((XYZDataset) dataset).getZValue(series, item);
p = this.paintScale.getPaint(z);
}
else {
if (this.useFillPaint) {
p = getItemFillPaint(series, item);
}
else {
p = getItemPaint(series, item);
}
}
return p;
}
/**
* Tests this instance for equality with an arbitrary object. This method
* returns <code>true</code> if and only if:
* <ul>
* <li><code>obj</code> is an instance of <code>XYShapeRenderer</code> (not
* <code>null</code>);</li>
* <li><code>obj</code> has the same field values as this
* <code>XYShapeRenderer</code>;</li>
* </ul>
*
* @param obj the object (<code>null</code> permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof XYShapeRenderer)) {
return false;
}
XYShapeRenderer that = (XYShapeRenderer) obj;
if ((this.paintScale == null && that.paintScale != null)
|| (!this.paintScale.equals(that.paintScale))) {
return false;
}
if (this.drawOutlines != that.drawOutlines) {
return false;
}
if (this.useOutlinePaint != that.useOutlinePaint) {
return false;
}
if (this.useFillPaint != that.useFillPaint) {
return false;
}
if (this.guideLinesVisible != that.guideLinesVisible) {
return false;
}
if ((this.guideLinePaint == null && that.guideLinePaint != null)
|| (!this.guideLinePaint.equals(that.guideLinePaint)))
return false;
if ((this.guideLineStroke == null && that.guideLineStroke != null)
|| (!this.guideLineStroke.equals(that.guideLineStroke)))
return false;
return super.equals(obj);
}
/**
* Returns a clone of this renderer.
*
* @return A clone of this renderer.
*
* @throws CloneNotSupportedException if there is a problem creating the
* clone.
*/
public Object clone() throws CloneNotSupportedException {
XYShapeRenderer clone = (XYShapeRenderer) super.clone();
if (this.paintScale instanceof PublicCloneable) {
PublicCloneable pc = (PublicCloneable) this.paintScale;
clone.paintScale = (PaintScale) pc.clone();
}
return clone;
}
/**
* Provides serialization support.
*
* @param stream the input stream.
*
* @throws IOException if there is an I/O error.
* @throws ClassNotFoundException if there is a classpath problem.
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.guideLinePaint = SerialUtilities.readPaint(stream);
this.guideLineStroke = SerialUtilities.readStroke(stream);
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
SerialUtilities.writePaint(this.guideLinePaint, stream);
SerialUtilities.writeStroke(this.guideLineStroke, stream);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -