📄 valueaxis.java
字号:
notifyListeners(new AxisChangeEvent(this));
}
}
/**
* Sets the axis range and sends an {@link AxisChangeEvent} to all
* registered listeners. As a side-effect, the auto-range flag is set to
* <code>false</code>.
*
* @param lower the lower axis limit.
* @param upper the upper axis limit.
*
* @see #getRange()
* @see #setRange(Range)
*/
public void setRange(double lower, double upper) {
setRange(new Range(lower, upper));
}
/**
* Sets the range for the axis (after first adding the current margins to
* the specified range) and sends an {@link AxisChangeEvent} to all
* registered listeners.
*
* @param range the range (<code>null</code> not permitted).
*/
public void setRangeWithMargins(Range range) {
setRangeWithMargins(range, true, true);
}
/**
* Sets the range for the axis after first adding the current margins to
* the range and, if requested, sends an {@link AxisChangeEvent} to all
* registered listeners. As a side-effect, the auto-range flag is set to
* <code>false</code> (optional).
*
* @param range the range (excluding margins, <code>null</code> not
* permitted).
* @param turnOffAutoRange a flag that controls whether or not the auto
* range is turned off.
* @param notify a flag that controls whether or not listeners are
* notified.
*/
public void setRangeWithMargins(Range range, boolean turnOffAutoRange,
boolean notify) {
if (range == null) {
throw new IllegalArgumentException("Null 'range' argument.");
}
setRange(Range.expand(range, getLowerMargin(), getUpperMargin()),
turnOffAutoRange, notify);
}
/**
* Sets the axis range (after first adding the current margins to the
* range) and sends an {@link AxisChangeEvent} to all registered listeners.
* As a side-effect, the auto-range flag is set to <code>false</code>.
*
* @param lower the lower axis limit.
* @param upper the upper axis limit.
*/
public void setRangeWithMargins(double lower, double upper) {
setRangeWithMargins(new Range(lower, upper));
}
/**
* Sets the axis range, where the new range is 'size' in length, and
* centered on 'value'.
*
* @param value the central value.
* @param length the range length.
*/
public void setRangeAboutValue(double value, double length) {
setRange(new Range(value - length / 2, value + length / 2));
}
/**
* Returns a flag indicating whether or not the tick unit is automatically
* selected from a range of standard tick units.
*
* @return A flag indicating whether or not the tick unit is automatically
* selected.
*
* @see #setAutoTickUnitSelection(boolean)
*/
public boolean isAutoTickUnitSelection() {
return this.autoTickUnitSelection;
}
/**
* Sets a flag indicating whether or not the tick unit is automatically
* selected from a range of standard tick units. If the flag is changed,
* registered listeners are notified that the chart has changed.
*
* @param flag the new value of the flag.
*
* @see #isAutoTickUnitSelection()
*/
public void setAutoTickUnitSelection(boolean flag) {
setAutoTickUnitSelection(flag, true);
}
/**
* Sets a flag indicating whether or not the tick unit is automatically
* selected from a range of standard tick units.
*
* @param flag the new value of the flag.
* @param notify notify listeners?
*
* @see #isAutoTickUnitSelection()
*/
public void setAutoTickUnitSelection(boolean flag, boolean notify) {
if (this.autoTickUnitSelection != flag) {
this.autoTickUnitSelection = flag;
if (notify) {
notifyListeners(new AxisChangeEvent(this));
}
}
}
/**
* Returns the source for obtaining standard tick units for the axis.
*
* @return The source (possibly <code>null</code>).
*
* @see #setStandardTickUnits(TickUnitSource)
*/
public TickUnitSource getStandardTickUnits() {
return this.standardTickUnits;
}
/**
* Sets the source for obtaining standard tick units for the axis and sends
* an {@link AxisChangeEvent} to all registered listeners. The axis will
* try to select the smallest tick unit from the source that does not cause
* the tick labels to overlap (see also the
* {@link #setAutoTickUnitSelection(boolean)} method.
*
* @param source the source for standard tick units (<code>null</code>
* permitted).
*
* @see #getStandardTickUnits()
*/
public void setStandardTickUnits(TickUnitSource source) {
this.standardTickUnits = source;
notifyListeners(new AxisChangeEvent(this));
}
/**
* Converts a data value to a coordinate in Java2D space, assuming that the
* axis runs along one edge of the specified dataArea.
* <p>
* Note that it is possible for the coordinate to fall outside the area.
*
* @param value the data value.
* @param area the area for plotting the data.
* @param edge the edge along which the axis lies.
*
* @return The Java2D coordinate.
*
* @see #java2DToValue(double, Rectangle2D, RectangleEdge)
*/
public abstract double valueToJava2D(double value, Rectangle2D area,
RectangleEdge edge);
/**
* Converts a length in data coordinates into the corresponding length in
* Java2D coordinates.
*
* @param length the length.
* @param area the plot area.
* @param edge the edge along which the axis lies.
*
* @return The length in Java2D coordinates.
*/
public double lengthToJava2D(double length, Rectangle2D area,
RectangleEdge edge) {
double zero = valueToJava2D(0.0, area, edge);
double l = valueToJava2D(length, area, edge);
return Math.abs(l - zero);
}
/**
* Converts a coordinate in Java2D space to the corresponding data value,
* assuming that the axis runs along one edge of the specified dataArea.
*
* @param java2DValue the coordinate in Java2D space.
* @param area the area in which the data is plotted.
* @param edge the edge along which the axis lies.
*
* @return The data value.
*
* @see #valueToJava2D(double, Rectangle2D, RectangleEdge)
*/
public abstract double java2DToValue(double java2DValue,
Rectangle2D area,
RectangleEdge edge);
/**
* Automatically sets the axis range to fit the range of values in the
* dataset. Sometimes this can depend on the renderer used as well (for
* example, the renderer may "stack" values, requiring an axis range
* greater than otherwise necessary).
*/
protected abstract void autoAdjustRange();
/**
* Centers the axis range about the specified value and sends an
* {@link AxisChangeEvent} to all registered listeners.
*
* @param value the center value.
*/
public void centerRange(double value) {
double central = this.range.getCentralValue();
Range adjusted = new Range(this.range.getLowerBound() + value - central,
this.range.getUpperBound() + value - central);
setRange(adjusted);
}
/**
* Increases or decreases the axis range by the specified percentage about
* the central value and sends an {@link AxisChangeEvent} to all registered
* listeners.
* <P>
* To double the length of the axis range, use 200% (2.0).
* To halve the length of the axis range, use 50% (0.5).
*
* @param percent the resize factor.
*
* @see #resizeRange(double, double)
*/
public void resizeRange(double percent) {
resizeRange(percent, this.range.getCentralValue());
}
/**
* Increases or decreases the axis range by the specified percentage about
* the specified anchor value and sends an {@link AxisChangeEvent} to all
* registered listeners.
* <P>
* To double the length of the axis range, use 200% (2.0).
* To halve the length of the axis range, use 50% (0.5).
*
* @param percent the resize factor.
* @param anchorValue the new central value after the resize.
*
* @see #resizeRange(double)
*/
public void resizeRange(double percent, double anchorValue) {
if (percent > 0.0) {
double halfLength = this.range.getLength() * percent / 2;
Range adjusted = new Range(anchorValue - halfLength,
anchorValue + halfLength);
setRange(adjusted);
}
else {
setAutoRange(true);
}
}
/**
* Zooms in on the current range.
*
* @param lowerPercent the new lower bound.
* @param upperPercent the new upper bound.
*/
public void zoomRange(double lowerPercent, double upperPercent) {
double start = this.range.getLowerBound();
double length = this.range.getLength();
Range adjusted = null;
if (isInverted()) {
adjusted = new Range(start + (length * (1 - upperPercent)),
start + (length * (1 - lowerPercent)));
}
else {
adjusted = new Range(start + length * lowerPercent,
start + length * upperPercent);
}
setRange(adjusted);
}
/**
* Returns the auto tick index.
*
* @return The auto tick index.
*
* @see #setAutoTickIndex(int)
*/
protected int getAutoTickIndex() {
return this.autoTickIndex;
}
/**
* Sets the auto tick index.
*
* @param index the new value.
*
* @see #getAutoTickIndex()
*/
protected void setAutoTickIndex(int index) {
this.autoTickIndex = index;
}
/**
* Tests the axis 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 ValueAxis)) {
return false;
}
ValueAxis that = (ValueAxis) obj;
if (this.positiveArrowVisible != that.positiveArrowVisible) {
return false;
}
if (this.negativeArrowVisible != that.negativeArrowVisible) {
return false;
}
if (this.inverted != that.inverted) {
return false;
}
if (!ObjectUtilities.equal(this.range, that.range)) {
return false;
}
if (this.autoRange != that.autoRange) {
return false;
}
if (this.autoRangeMinimumSize != that.autoRangeMinimumSize) {
return false;
}
if (!this.defaultAutoRange.equals(that.defaultAutoRange)) {
return false;
}
if (this.upperMargin != that.upperMargin) {
return false;
}
if (this.lowerMargin != that.lowerMargin) {
return false;
}
if (this.fixedAutoRange != that.fixedAutoRange) {
return false;
}
if (this.autoTickUnitSelection != that.autoTickUnitSelection) {
return false;
}
if (!ObjectUtilities.equal(this.standardTickUnits,
that.standardTickUnits)) {
return false;
}
if (this.verticalTickLabels != that.verticalTickLabels) {
return false;
}
return super.equals(obj);
}
/**
* Returns a clone of the object.
*
* @return A clone.
*
* @throws CloneNotSupportedException if some component of the axis does
* not support cloning.
*/
public Object clone() throws CloneNotSupportedException {
ValueAxis clone = (ValueAxis) super.clone();
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.writeShape(this.upArrow, stream);
SerialUtilities.writeShape(this.downArrow, stream);
SerialUtilities.writeShape(this.leftArrow, stream);
SerialUtilities.writeShape(this.rightArrow, 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.upArrow = SerialUtilities.readShape(stream);
this.downArrow = SerialUtilities.readShape(stream);
this.leftArrow = SerialUtilities.readShape(stream);
this.rightArrow = SerialUtilities.readShape(stream);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -