📄 categorypointerannotation.java
字号:
*
* @see #getArrowLength()
*/
public void setArrowLength(double length) {
this.arrowLength = length;
}
/**
* Returns the arrow width.
*
* @return The arrow width (in Java2D units).
*
* @see #setArrowWidth(double)
*/
public double getArrowWidth() {
return this.arrowWidth;
}
/**
* Sets the arrow width.
*
* @param width the width (in Java2D units).
*
* @see #getArrowWidth()
*/
public void setArrowWidth(double width) {
this.arrowWidth = width;
}
/**
* Returns the stroke used to draw the arrow line.
*
* @return The arrow stroke (never <code>null</code>).
*
* @see #setArrowStroke(Stroke)
*/
public Stroke getArrowStroke() {
return this.arrowStroke;
}
/**
* Sets the stroke used to draw the arrow line.
*
* @param stroke the stroke (<code>null</code> not permitted).
*
* @see #getArrowStroke()
*/
public void setArrowStroke(Stroke stroke) {
if (stroke == null) {
throw new IllegalArgumentException("Null 'stroke' not permitted.");
}
this.arrowStroke = stroke;
}
/**
* Returns the paint used for the arrow.
*
* @return The arrow paint (never <code>null</code>).
*
* @see #setArrowPaint(Paint)
*/
public Paint getArrowPaint() {
return this.arrowPaint;
}
/**
* Sets the paint used for the arrow.
*
* @param paint the arrow paint (<code>null</code> not permitted).
*
* @see #getArrowPaint()
*/
public void setArrowPaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.arrowPaint = paint;
}
/**
* Draws the annotation.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the data area.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
*/
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
CategoryAxis domainAxis, ValueAxis rangeAxis) {
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
plot.getDomainAxisLocation(), orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
plot.getRangeAxisLocation(), orientation);
CategoryDataset dataset = plot.getDataset();
int catIndex = dataset.getColumnIndex(getCategory());
int catCount = dataset.getColumnCount();
double j2DX = domainAxis.getCategoryMiddle(catIndex, catCount,
dataArea, domainEdge);
double j2DY = rangeAxis.valueToJava2D(getValue(), dataArea, rangeEdge);
if (orientation == PlotOrientation.HORIZONTAL) {
double temp = j2DX;
j2DX = j2DY;
j2DY = temp;
}
double startX = j2DX + Math.cos(this.angle) * this.baseRadius;
double startY = j2DY + Math.sin(this.angle) * this.baseRadius;
double endX = j2DX + Math.cos(this.angle) * this.tipRadius;
double endY = j2DY + Math.sin(this.angle) * this.tipRadius;
double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength;
double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength;
double arrowLeftX = arrowBaseX
+ Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
double arrowLeftY = arrowBaseY
+ Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;
double arrowRightX = arrowBaseX
- Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
double arrowRightY = arrowBaseY
- Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;
GeneralPath arrow = new GeneralPath();
arrow.moveTo((float) endX, (float) endY);
arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
arrow.lineTo((float) arrowRightX, (float) arrowRightY);
arrow.closePath();
g2.setStroke(this.arrowStroke);
g2.setPaint(this.arrowPaint);
Line2D line = new Line2D.Double(startX, startY, endX, endY);
g2.draw(line);
g2.fill(arrow);
// draw the label
g2.setFont(getFont());
g2.setPaint(getPaint());
double labelX = j2DX
+ Math.cos(this.angle) * (this.baseRadius + this.labelOffset);
double labelY = j2DY
+ Math.sin(this.angle) * (this.baseRadius + this.labelOffset);
/* Rectangle2D hotspot = */ TextUtilities.drawAlignedString(getText(),
g2, (float) labelX, (float) labelY, getTextAnchor());
// TODO: implement the entity for the annotation
}
/**
* Tests this annotation for equality with an arbitrary object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CategoryPointerAnnotation)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
CategoryPointerAnnotation that = (CategoryPointerAnnotation) obj;
if (this.angle != that.angle) {
return false;
}
if (this.tipRadius != that.tipRadius) {
return false;
}
if (this.baseRadius != that.baseRadius) {
return false;
}
if (this.arrowLength != that.arrowLength) {
return false;
}
if (this.arrowWidth != that.arrowWidth) {
return false;
}
if (!this.arrowPaint.equals(that.arrowPaint)) {
return false;
}
if (!ObjectUtilities.equal(this.arrowStroke, that.arrowStroke)) {
return false;
}
if (this.labelOffset != that.labelOffset) {
return false;
}
return true;
}
/**
* Returns a hash code for this instance.
*
* @return A hash code.
*/
public int hashCode() {
int result = 193;
long temp = Double.doubleToLongBits(this.angle);
result = 37 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(this.tipRadius);
result = 37 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(this.baseRadius);
result = 37 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(this.arrowLength);
result = 37 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(this.arrowWidth);
result = 37 * result + (int) (temp ^ (temp >>> 32));
result = 37 * result + HashUtilities.hashCodeForPaint(this.arrowPaint);
result = 37 * result + this.arrowStroke.hashCode();
temp = Double.doubleToLongBits(this.labelOffset);
result = 37 * result + (int) (temp ^ (temp >>> 32));
return result;
}
/**
* Returns a clone of the annotation.
*
* @return A clone.
*
* @throws CloneNotSupportedException if the annotation can't be cloned.
*/
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
/**
* 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.arrowPaint, stream);
SerialUtilities.writeStroke(this.arrowStroke, stream);
}
/**
* 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.arrowPaint = SerialUtilities.readPaint(stream);
this.arrowStroke = SerialUtilities.readStroke(stream);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -