📄 polarplot.java
字号:
*/
public void zoom(double percent) {
if (percent > 0.0) {
double radius = getMaxRadius();
double scaledRadius = radius * percent;
this.axis.setUpperBound(scaledRadius);
getAxis().setAutoRange(false);
}
else {
getAxis().setAutoRange(true);
}
}
/**
* Returns the range for the specified axis.
*
* @param axis the axis.
*
* @return The range.
*/
public Range getDataRange(ValueAxis axis) {
Range result = null;
if (this.dataset != null) {
result = Range.combine(result,
DatasetUtilities.findRangeBounds(this.dataset));
}
return result;
}
/**
* Receives notification of a change to the plot's m_Dataset.
* <P>
* The axis ranges are updated if necessary.
*
* @param event information about the event (not used here).
*/
public void datasetChanged(DatasetChangeEvent event) {
if (this.axis != null) {
this.axis.configure();
}
if (getParent() != null) {
getParent().datasetChanged(event);
}
else {
super.datasetChanged(event);
}
}
/**
* Notifies all registered listeners of a property change.
* <P>
* One source of property change events is the plot's m_Renderer.
*
* @param event information about the property change.
*/
public void rendererChanged(RendererChangeEvent event) {
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the number of series in the dataset for this plot. If the
* dataset is <code>null</code>, the method returns 0.
*
* @return The series count.
*/
public int getSeriesCount() {
int result = 0;
if (this.dataset != null) {
result = this.dataset.getSeriesCount();
}
return result;
}
/**
* Returns the legend items for the plot. Each legend item is generated by
* the plot's m_Renderer, since the m_Renderer is responsible for the visual
* representation of the data.
*
* @return The legend items.
*/
public LegendItemCollection getLegendItems() {
LegendItemCollection result = new LegendItemCollection();
// get the legend items for the main m_Dataset...
if (this.dataset != null) {
if (this.renderer != null) {
int seriesCount = this.dataset.getSeriesCount();
for (int i = 0; i < seriesCount; i++) {
LegendItem item = this.renderer.getLegendItem(i);
result.add(item);
}
}
}
return result;
}
/**
* Tests this plot for equality with another 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 PolarPlot)) {
return false;
}
PolarPlot that = (PolarPlot) obj;
if (!ObjectUtilities.equal(this.axis, that.axis)) {
return false;
}
if (!ObjectUtilities.equal(this.renderer, that.renderer)) {
return false;
}
if (this.angleGridlinesVisible != that.angleGridlinesVisible) {
return false;
}
if (this.angleLabelsVisible != that.angleLabelsVisible) {
return false;
}
if (!this.angleLabelFont.equals(that.angleLabelFont)) {
return false;
}
if (!PaintUtilities.equal(this.angleLabelPaint, that.angleLabelPaint)) {
return false;
}
if (!ObjectUtilities.equal(this.angleGridlineStroke,
that.angleGridlineStroke)) {
return false;
}
if (!PaintUtilities.equal(
this.angleGridlinePaint, that.angleGridlinePaint
)) {
return false;
}
if (this.radiusGridlinesVisible != that.radiusGridlinesVisible) {
return false;
}
if (!ObjectUtilities.equal(this.radiusGridlineStroke,
that.radiusGridlineStroke)) {
return false;
}
if (!PaintUtilities.equal(this.radiusGridlinePaint,
that.radiusGridlinePaint)) {
return false;
}
if (!this.cornerTextItems.equals(that.cornerTextItems)) {
return false;
}
return super.equals(obj);
}
/**
* Returns a clone of the plot.
*
* @return A clone.
*
* @throws CloneNotSupportedException this can occur if some component of
* the plot cannot be cloned.
*/
public Object clone() throws CloneNotSupportedException {
PolarPlot clone = (PolarPlot) super.clone();
if (this.axis != null) {
clone.axis = (ValueAxis) ObjectUtilities.clone(this.axis);
clone.axis.setPlot(clone);
clone.axis.addChangeListener(clone);
}
if (clone.dataset != null) {
clone.dataset.addChangeListener(clone);
}
if (this.renderer != null) {
clone.renderer
= (PolarItemRenderer) ObjectUtilities.clone(this.renderer);
}
clone.cornerTextItems = new ArrayList(this.cornerTextItems);
return 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.writeStroke(this.angleGridlineStroke, stream);
SerialUtilities.writePaint(this.angleGridlinePaint, stream);
SerialUtilities.writeStroke(this.radiusGridlineStroke, stream);
SerialUtilities.writePaint(this.radiusGridlinePaint, stream);
SerialUtilities.writePaint(this.angleLabelPaint, 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.angleGridlineStroke = SerialUtilities.readStroke(stream);
this.angleGridlinePaint = SerialUtilities.readPaint(stream);
this.radiusGridlineStroke = SerialUtilities.readStroke(stream);
this.radiusGridlinePaint = SerialUtilities.readPaint(stream);
this.angleLabelPaint = SerialUtilities.readPaint(stream);
if (this.axis != null) {
this.axis.setPlot(this);
this.axis.addChangeListener(this);
}
if (this.dataset != null) {
this.dataset.addChangeListener(this);
}
}
/**
* This method is required by the {@link Zoomable} interface, but since
* the plot does not have any domain axes, it does nothing.
*
* @param factor the zoom factor.
* @param state the plot state.
* @param source the source point (in Java2D coordinates).
*/
public void zoomDomainAxes(double factor, PlotRenderingInfo state,
Point2D source) {
// do nothing
}
/**
* This method is required by the {@link Zoomable} interface, but since
* the plot does not have any domain axes, it does nothing.
*
* @param factor the zoom factor.
* @param state the plot state.
* @param source the source point (in Java2D coordinates).
* @param useAnchor use source point as zoom anchor?
*
* @since 1.0.7
*/
public void zoomDomainAxes(double factor, PlotRenderingInfo state,
Point2D source, boolean useAnchor) {
// do nothing
}
/**
* This method is required by the {@link Zoomable} interface, but since
* the plot does not have any domain axes, it does nothing.
*
* @param lowerPercent the new lower bound.
* @param upperPercent the new upper bound.
* @param state the plot state.
* @param source the source point (in Java2D coordinates).
*/
public void zoomDomainAxes(double lowerPercent, double upperPercent,
PlotRenderingInfo state, Point2D source) {
// do nothing
}
/**
* Multiplies the range on the range axis/axes by the specified factor.
*
* @param factor the zoom factor.
* @param state the plot state.
* @param source the source point (in Java2D coordinates).
*/
public void zoomRangeAxes(double factor, PlotRenderingInfo state,
Point2D source) {
zoom(factor);
}
/**
* Multiplies the range on the range axis by the specified factor.
*
* @param factor the zoom factor.
* @param info the plot rendering info.
* @param source the source point (in Java2D space).
* @param useAnchor use source point as zoom anchor?
*
* @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)
*
* @since 1.0.7
*/
public void zoomRangeAxes(double factor, PlotRenderingInfo info,
Point2D source, boolean useAnchor) {
if (useAnchor) {
// get the source coordinate - this plot has always a VERTICAL
// orientation
double sourceX = source.getX();
double anchorX = this.axis.java2DToValue(sourceX,
info.getDataArea(), RectangleEdge.BOTTOM);
this.axis.resizeRange(factor, anchorX);
}
else {
this.axis.resizeRange(factor);
}
}
/**
* Zooms in on the range axes.
*
* @param lowerPercent the new lower bound.
* @param upperPercent the new upper bound.
* @param state the plot state.
* @param source the source point (in Java2D coordinates).
*/
public void zoomRangeAxes(double lowerPercent, double upperPercent,
PlotRenderingInfo state, Point2D source) {
zoom((upperPercent + lowerPercent) / 2.0);
}
/**
* Returns <code>false</code> always.
*
* @return <code>false</code> always.
*/
public boolean isDomainZoomable() {
return false;
}
/**
* Returns <code>true</code> to indicate that the range axis is zoomable.
*
* @return <code>true</code>.
*/
public boolean isRangeZoomable() {
return true;
}
/**
* Returns the orientation of the plot.
*
* @return The orientation.
*/
public PlotOrientation getOrientation() {
return PlotOrientation.HORIZONTAL;
}
/**
* Returns the upper bound of the radius axis.
*
* @return The upper bound.
*/
public double getMaxRadius() {
return this.axis.getUpperBound();
}
/**
* Translates a (theta, radius) pair into Java2D coordinates. If
* <code>radius</code> is less than the lower bound of the axis, then
* this method returns the centre point.
*
* @param angleDegrees the angle in degrees.
* @param radius the radius.
* @param dataArea the data area.
*
* @return A point in Java2D space.
*/
public Point translateValueThetaRadiusToJava2D(double angleDegrees,
double radius,
Rectangle2D dataArea) {
double radians = Math.toRadians(angleDegrees - 90.0);
double minx = dataArea.getMinX() + MARGIN;
double maxx = dataArea.getMaxX() - MARGIN;
double miny = dataArea.getMinY() + MARGIN;
double maxy = dataArea.getMaxY() - MARGIN;
double lengthX = maxx - minx;
double lengthY = maxy - miny;
double length = Math.min(lengthX, lengthY);
double midX = minx + lengthX / 2.0;
double midY = miny + lengthY / 2.0;
double axisMin = this.axis.getLowerBound();
double axisMax = getMaxRadius();
double adjustedRadius = Math.max(radius, axisMin);
double xv = length / 2.0 * Math.cos(radians);
double yv = length / 2.0 * Math.sin(radians);
float x = (float) (midX + (xv * (adjustedRadius - axisMin)
/ (axisMax - axisMin)));
float y = (float) (midY + (yv * (adjustedRadius - axisMin)
/ (axisMax - axisMin)));
int ix = Math.round(x);
int iy = Math.round(y);
Point p = new Point(ix, iy);
return p;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -