📄 valueaxis.java
字号:
* Sets the upper and lower bounds for the axis. Registered listeners are
* notified of the change.
* <P>
* As a side-effect, the auto-range flag is set to <code>false</code>.
*
* @param range the new range.
* @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 setRange(Range range, boolean turnOffAutoRange, boolean notify) {
// check arguments...
if (range == null) {
throw new IllegalArgumentException("ValueAxis.setRange(...): null not permitted.");
}
if (turnOffAutoRange) {
this.autoRange = false;
}
this.range = range;
if (notify) {
notifyListeners(new AxisChangeEvent(this));
}
}
/**
* Sets the range attribute.
*
* @param range the range.
*/
public void setRange(Range range) {
setRange(range, true, true);
}
/**
* Sets the axis range.
*
* @param lower the lower axis limit.
* @param upper the upper axis limit.
*/
public void setRange(double lower, double upper) {
setRange(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.
*/
public boolean isAutoTickUnitSelection() {
return 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.
*/
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?
*/
public void setAutoTickUnitSelection(boolean flag, boolean notify) {
if (this.autoTickUnitSelection != flag) {
this.autoTickUnitSelection = flag;
if (notify) {
notifyListeners(new AxisChangeEvent(this));
}
}
}
/**
* Returns the standard tick units for the axis.
* <P>
* If autoTickUnitSelection is on, the tick unit for the axis will be
* automatically selected from this collection.
*
* @return the standard tick units.
*/
public TickUnits getStandardTickUnits() {
return this.standardTickUnits;
}
/**
* Sets the collection of tick units for the axis, and notifies registered
* listeners that the axis has changed.
* <P>
* If the autoTickUnitSelection flag is true, a tick unit will be selected
* from this collection automatically (to ensure that labels do not
* overlap).
*
* @param collection the tick unit collection.
*/
public void setStandardTickUnits(TickUnits collection) {
this.standardTickUnits = collection;
notifyListeners(new AxisChangeEvent(this));
}
// /**
// * Returns <code>true</code> if the axis hides this value, and <code>false</code>
// * otherwise.
// *
// * @param dataValue the data value.
// *
// * @return <code>false</code>.
// */
// public boolean isHiddenValue(double dataValue) {
// return false;
// }
/**
* 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 plotArea.
*
* @param dataValue the data value.
* @param dataArea the area for plotting the data.
* @param edge the edge along which the axis lies.
*
* @return the Java2D coordinate.
*/
public abstract double translateValueToJava2D(double dataValue,
Rectangle2D dataArea,
RectangleEdge edge);
/**
* 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 dataArea the area in which the data is plotted.
* @param edge the edge along which the axis lies.
*
* @return the data value.
*/
public abstract double translateJava2DtoValue(float java2DValue,
Rectangle2D dataArea,
RectangleEdge edge);
/**
* Automatically determines the maximum and minimum values on the axis to 'fit' the data.
*/
protected abstract void autoAdjustRange();
/**
* Centers the axis range about the specified value.
*
* @param value the center value.
*/
public void centerRange(double value) {
double central = range.getCentralValue();
Range adjusted = new Range(range.getLowerBound() + value - central,
range.getUpperBound() + value - central);
setRange(adjusted);
}
/**
* Increases or decreases the axis range by the specified percentage, about the
* central value.
* <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.
*/
public void resizeRange(double percent) {
resizeRange(percent, range.getCentralValue());
}
/**
* Increases or decreases the axis range by the specified percentage, about the
* specified anchor value.
* <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.
*/
public void resizeRange(double percent, double anchorValue) {
if (percent > 0.0) {
double halfLength = 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 = range.getLowerBound();
double length = 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.
*/
protected int getAutoTickIndex() {
return this.autoTickIndex;
}
/**
* Sets the auto tick index.
*
* @param index the new value.
*/
protected void setAutoTickIndex(int index) {
this.autoTickIndex = index;
}
/**
* Tests this axis 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 ValueAxis) {
ValueAxis axis = (ValueAxis) obj;
if (super.equals(obj)) {
boolean b0 = (this.axisLineVisible == axis.axisLineVisible);
boolean b1 = (this.positiveArrowVisible == axis.positiveArrowVisible);
boolean b2 = (this.negativeArrowVisible == axis.negativeArrowVisible);
// boolean b3 = ObjectUtils.equalOrBothNull(this.upArrow, axis.upArrow);
// boolean b4 = ObjectUtils.equalOrBothNull(this.downArrow, axis.downArrow);
// boolean b5 = ObjectUtils.equalOrBothNull(this.leftArrow, axis.leftArrow);
// boolean b6 = ObjectUtils.equalOrBothNull(this.rightArrow, axis.rightArrow);
boolean b7 = (this.axisLinePaint.equals(axis.axisLinePaint));
boolean b8 = (this.axisLineStroke.equals(axis.axisLineStroke));
boolean b9 = (this.inverted == axis.inverted);
boolean b10 = ObjectUtils.equal(this.range, axis.range);
boolean b11 = (this.autoRange == axis.autoRange);
boolean b12 = (Math.abs(this.autoRangeMinimumSize - axis.autoRangeMinimumSize)
< 0.000001);
boolean b13 = (Math.abs(this.upperMargin - axis.upperMargin) < 0.000001);
boolean b14 = (Math.abs(this.lowerMargin - axis.lowerMargin) < 0.000001);
boolean b15 = (Math.abs(this.fixedAutoRange - axis.fixedAutoRange) < 0.000001);
boolean b16 = (this.autoTickUnitSelection == axis.autoTickUnitSelection);
boolean b17 = ObjectUtils.equal(this.standardTickUnits, axis.standardTickUnits);
boolean b18 = (this.verticalTickLabels == axis.verticalTickLabels);
//private int autoTickIndex;
//protected double reservedForTickLabels;
//protected double reservedForAxisLabel;
return b0
&& b1
&& b2
// && b3
// && b4
// && b5
// && b6
&& b7
&& b8
&& b9
&& b10 && b11 && b12 && b13 && b14 && b15 && b16 && b17 && b18;
}
else {
return false;
}
}
return false;
}
/**
* 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.writePaint(this.axisLinePaint, stream);
SerialUtilities.writeStroke(this.axisLineStroke, stream);
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.axisLinePaint = SerialUtilities.readPaint(stream);
this.axisLineStroke = SerialUtilities.readStroke(stream);
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 + -