📄 thermometerplot.java
字号:
public void datasetChanged(DatasetChangeEvent event) {
if (this.dataset != null) {
Number vn = this.dataset.getValue();
if (vn != null) {
double value = vn.doubleValue();
if (inSubrange(NORMAL, value)) {
this.subrange = NORMAL;
}
else if (inSubrange(WARNING, value)) {
this.subrange = WARNING;
}
else if (inSubrange(CRITICAL, value)) {
this.subrange = CRITICAL;
}
else {
this.subrange = -1;
}
setAxisRange();
}
}
super.datasetChanged(event);
}
/**
* Returns the minimum value in either the domain or the range, whichever
* is displayed against the vertical axis for the particular type of plot
* implementing this interface.
*
* @return The minimum value in either the domain or the range.
*
* @deprecated This method is not used. Officially deprecated in version
* 1.0.6.
*/
public Number getMinimumVerticalDataValue() {
return new Double(this.lowerBound);
}
/**
* Returns the maximum value in either the domain or the range, whichever
* is displayed against the vertical axis for the particular type of plot
* implementing this interface.
*
* @return The maximum value in either the domain or the range
*
* @deprecated This method is not used. Officially deprecated in version
* 1.0.6.
*/
public Number getMaximumVerticalDataValue() {
return new Double(this.upperBound);
}
/**
* Returns the data range.
*
* @param axis the axis.
*
* @return The range of data displayed.
*/
public Range getDataRange(ValueAxis axis) {
return new Range(this.lowerBound, this.upperBound);
}
/**
* Sets the axis range to the current values in the rangeInfo array.
*/
protected void setAxisRange() {
if ((this.subrange >= 0) && (this.followDataInSubranges)) {
this.rangeAxis.setRange(
new Range(this.subrangeInfo[this.subrange][DISPLAY_LOW],
this.subrangeInfo[this.subrange][DISPLAY_HIGH]));
}
else {
this.rangeAxis.setRange(this.lowerBound, this.upperBound);
}
}
/**
* Returns the legend items for the plot.
*
* @return <code>null</code>.
*/
public LegendItemCollection getLegendItems() {
return null;
}
/**
* Returns the orientation of the plot.
*
* @return The orientation (always {@link PlotOrientation#VERTICAL}).
*/
public PlotOrientation getOrientation() {
return PlotOrientation.VERTICAL;
}
/**
* Determine whether a number is valid and finite.
*
* @param d the number to be tested.
*
* @return <code>true</code> if the number is valid and finite, and
* <code>false</code> otherwise.
*/
protected static boolean isValidNumber(double d) {
return (!(Double.isNaN(d) || Double.isInfinite(d)));
}
/**
* Returns true if the value is in the specified range, and false otherwise.
*
* @param subrange the subrange.
* @param value the value to check.
*
* @return A boolean.
*/
private boolean inSubrange(int subrange, double value) {
return (value > this.subrangeInfo[subrange][RANGE_LOW]
&& value <= this.subrangeInfo[subrange][RANGE_HIGH]);
}
/**
* Returns the mercury paint corresponding to the current data value.
* Called from the {@link #draw(Graphics2D, Rectangle2D, Point2D,
* PlotState, PlotRenderingInfo)} method.
*
* @return The paint (never <code>null</code>).
*/
private Paint getCurrentPaint() {
Paint result = this.mercuryPaint;
if (this.useSubrangePaint) {
double value = this.dataset.getValue().doubleValue();
if (inSubrange(NORMAL, value)) {
result = this.subrangePaint[NORMAL];
}
else if (inSubrange(WARNING, value)) {
result = this.subrangePaint[WARNING];
}
else if (inSubrange(CRITICAL, value)) {
result = this.subrangePaint[CRITICAL];
}
}
return result;
}
/**
* Tests this plot for equality with another object. The plot's dataset
* is not considered in the test.
*
* @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 ThermometerPlot)) {
return false;
}
ThermometerPlot that = (ThermometerPlot) obj;
if (!super.equals(obj)) {
return false;
}
if (!ObjectUtilities.equal(this.rangeAxis, that.rangeAxis)) {
return false;
}
if (this.axisLocation != that.axisLocation) {
return false;
}
if (this.lowerBound != that.lowerBound) {
return false;
}
if (this.upperBound != that.upperBound) {
return false;
}
if (!ObjectUtilities.equal(this.padding, that.padding)) {
return false;
}
if (!ObjectUtilities.equal(this.thermometerStroke,
that.thermometerStroke)) {
return false;
}
if (!PaintUtilities.equal(this.thermometerPaint,
that.thermometerPaint)) {
return false;
}
if (this.units != that.units) {
return false;
}
if (this.valueLocation != that.valueLocation) {
return false;
}
if (!ObjectUtilities.equal(this.valueFont, that.valueFont)) {
return false;
}
if (!PaintUtilities.equal(this.valuePaint, that.valuePaint)) {
return false;
}
if (!ObjectUtilities.equal(this.valueFormat, that.valueFormat)) {
return false;
}
if (!PaintUtilities.equal(this.mercuryPaint, that.mercuryPaint)) {
return false;
}
if (this.showValueLines != that.showValueLines) {
return false;
}
if (this.subrange != that.subrange) {
return false;
}
if (this.followDataInSubranges != that.followDataInSubranges) {
return false;
}
if (!equal(this.subrangeInfo, that.subrangeInfo)) {
return false;
}
if (this.useSubrangePaint != that.useSubrangePaint) {
return false;
}
for (int i = 0; i < this.subrangePaint.length; i++) {
if (!PaintUtilities.equal(this.subrangePaint[i],
that.subrangePaint[i])) {
return false;
}
}
return true;
}
/**
* Tests two double[][] arrays for equality.
*
* @param array1 the first array (<code>null</code> permitted).
* @param array2 the second arrray (<code>null</code> permitted).
*
* @return A boolean.
*/
private static boolean equal(double[][] array1, double[][] array2) {
if (array1 == null) {
return (array2 == null);
}
if (array2 == null) {
return false;
}
if (array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (!Arrays.equals(array1[i], array2[i])) {
return false;
}
}
return true;
}
/**
* Returns a clone of the plot.
*
* @return A clone.
*
* @throws CloneNotSupportedException if the plot cannot be cloned.
*/
public Object clone() throws CloneNotSupportedException {
ThermometerPlot clone = (ThermometerPlot) super.clone();
if (clone.dataset != null) {
clone.dataset.addChangeListener(clone);
}
clone.rangeAxis = (ValueAxis) ObjectUtilities.clone(this.rangeAxis);
if (clone.rangeAxis != null) {
clone.rangeAxis.setPlot(clone);
clone.rangeAxis.addChangeListener(clone);
}
clone.valueFormat = (NumberFormat) this.valueFormat.clone();
clone.subrangePaint = (Paint[]) this.subrangePaint.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.writeStroke(this.thermometerStroke, stream);
SerialUtilities.writePaint(this.thermometerPaint, stream);
SerialUtilities.writePaint(this.valuePaint, stream);
SerialUtilities.writePaint(this.mercuryPaint, stream);
SerialUtilities.writeStroke(this.subrangeIndicatorStroke, stream);
SerialUtilities.writeStroke(this.rangeIndicatorStroke, stream);
for (int i = 0; i < 3; i++) {
SerialUtilities.writePaint(this.subrangePaint[i], 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.thermometerStroke = SerialUtilities.readStroke(stream);
this.thermometerPaint = SerialUtilities.readPaint(stream);
this.valuePaint = SerialUtilities.readPaint(stream);
this.mercuryPaint = SerialUtilities.readPaint(stream);
this.subrangeIndicatorStroke = SerialUtilities.readStroke(stream);
this.rangeIndicatorStroke = SerialUtilities.readStroke(stream);
this.subrangePaint = new Paint[3];
for (int i = 0; i < 3; i++) {
this.subrangePaint[i] = SerialUtilities.readPaint(stream);
}
if (this.rangeAxis != null) {
this.rangeAxis.addChangeListener(this);
}
}
/**
* Multiplies the range on the domain axis/axes by the specified factor.
*
* @param factor the zoom factor.
* @param state the plot state.
* @param source the source point.
*/
public void zoomDomainAxes(double factor, PlotRenderingInfo state,
Point2D source) {
// no domain axis to zoom
}
/**
* 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.
*/
public void zoomRangeAxes(double factor, PlotRenderingInfo state,
Point2D source) {
this.rangeAxis.resizeRange(factor);
}
/**
* This method does nothing.
*
* @param lowerPercent the lower percent.
* @param upperPercent the upper percent.
* @param state the plot state.
* @param source the source point.
*/
public void zoomDomainAxes(double lowerPercent, double upperPercent,
PlotRenderingInfo state, Point2D source) {
// no domain axis to zoom
}
/**
* Zooms the range axes.
*
* @param lowerPercent the lower percent.
* @param upperPercent the upper percent.
* @param state the plot state.
* @param source the source point.
*/
public void zoomRangeAxes(double lowerPercent, double upperPercent,
PlotRenderingInfo state, Point2D source) {
this.rangeAxis.zoomRange(lowerPercent, upperPercent);
}
/**
* Returns <code>false</code>.
*
* @return A boolean.
*/
public boolean isDomainZoomable() {
return false;
}
/**
* Returns <code>true</code>.
*
* @return A boolean.
*/
public boolean isRangeZoomable() {
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -