| Method from org.jfree.chart.plot.ThermometerPlot Detail: |
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;
}
Returns a clone of the plot. |
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);
}
Checks to see if a new value means the axis range needs adjusting. |
public void draw(Graphics2D g2,
Rectangle2D area,
Point2D anchor,
PlotState parentState,
PlotRenderingInfo info) {
RoundRectangle2D outerStem = new RoundRectangle2D.Double();
RoundRectangle2D innerStem = new RoundRectangle2D.Double();
RoundRectangle2D mercuryStem = new RoundRectangle2D.Double();
Ellipse2D outerBulb = new Ellipse2D.Double();
Ellipse2D innerBulb = new Ellipse2D.Double();
String temp = null;
FontMetrics metrics = null;
if (info != null) {
info.setPlotArea(area);
}
// adjust for insets...
RectangleInsets insets = getInsets();
insets.trim(area);
drawBackground(g2, area);
// adjust for padding...
Rectangle2D interior = (Rectangle2D) area.clone();
this.padding.trim(interior);
int midX = (int) (interior.getX() + (interior.getWidth() / 2));
int midY = (int) (interior.getY() + (interior.getHeight() / 2));
int stemTop = (int) (interior.getMinY() + getBulbRadius());
int stemBottom = (int) (interior.getMaxY() - getBulbDiameter());
Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(),
stemTop, getColumnRadius(), stemBottom - stemTop);
outerBulb.setFrame(midX - getBulbRadius(), stemBottom,
getBulbDiameter(), getBulbDiameter());
outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(),
getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop,
getColumnDiameter(), getColumnDiameter());
Area outerThermometer = new Area(outerBulb);
Area tempArea = new Area(outerStem);
outerThermometer.add(tempArea);
innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom
+ getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter()
- getGap() * 2);
innerStem.setRoundRect(midX - getColumnRadius() + getGap(),
interior.getMinY() + getGap(), getColumnDiameter()
- getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2
- stemTop, getColumnDiameter() - getGap() * 2,
getColumnDiameter() - getGap() * 2);
Area innerThermometer = new Area(innerBulb);
tempArea = new Area(innerStem);
innerThermometer.add(tempArea);
if ((this.dataset != null) && (this.dataset.getValue() != null)) {
double current = this.dataset.getValue().doubleValue();
double ds = this.rangeAxis.valueToJava2D(current, dataArea,
RectangleEdge.LEFT);
int i = getColumnDiameter() - getGap() * 2; // already calculated
int j = getColumnRadius() - getGap(); // already calculated
int l = (i / 2);
int k = (int) Math.round(ds);
if (k < (getGap() + interior.getMinY())) {
k = (int) (getGap() + interior.getMinY());
l = getBulbRadius();
}
Area mercury = new Area(innerBulb);
if (k < (stemBottom + getBulbRadius())) {
mercuryStem.setRoundRect(midX - j, k, i,
(stemBottom + getBulbRadius()) - k, l, l);
tempArea = new Area(mercuryStem);
mercury.add(tempArea);
}
g2.setPaint(getCurrentPaint());
g2.fill(mercury);
// draw range indicators...
if (this.subrangeIndicatorsVisible) {
g2.setStroke(this.subrangeIndicatorStroke);
Range range = this.rangeAxis.getRange();
// draw start of normal range
double value = this.subrangeInfo[NORMAL][RANGE_LOW];
if (range.contains(value)) {
double x = midX + getColumnRadius() + 2;
double y = this.rangeAxis.valueToJava2D(value, dataArea,
RectangleEdge.LEFT);
Line2D line = new Line2D.Double(x, y, x + 10, y);
g2.setPaint(this.subrangePaint[NORMAL]);
g2.draw(line);
}
// draw start of warning range
value = this.subrangeInfo[WARNING][RANGE_LOW];
if (range.contains(value)) {
double x = midX + getColumnRadius() + 2;
double y = this.rangeAxis.valueToJava2D(value, dataArea,
RectangleEdge.LEFT);
Line2D line = new Line2D.Double(x, y, x + 10, y);
g2.setPaint(this.subrangePaint[WARNING]);
g2.draw(line);
}
// draw start of critical range
value = this.subrangeInfo[CRITICAL][RANGE_LOW];
if (range.contains(value)) {
double x = midX + getColumnRadius() + 2;
double y = this.rangeAxis.valueToJava2D(value, dataArea,
RectangleEdge.LEFT);
Line2D line = new Line2D.Double(x, y, x + 10, y);
g2.setPaint(this.subrangePaint[CRITICAL]);
g2.draw(line);
}
}
// draw the axis...
if ((this.rangeAxis != null) && (this.axisLocation != NONE)) {
int drawWidth = AXIS_GAP;
if (this.showValueLines) {
drawWidth += getColumnDiameter();
}
Rectangle2D drawArea;
double cursor = 0;
switch (this.axisLocation) {
case RIGHT:
cursor = midX + getColumnRadius();
drawArea = new Rectangle2D.Double(cursor,
stemTop, drawWidth, (stemBottom - stemTop + 1));
this.rangeAxis.draw(g2, cursor, area, drawArea,
RectangleEdge.RIGHT, null);
break;
case LEFT:
default:
//cursor = midX - COLUMN_RADIUS - AXIS_GAP;
cursor = midX - getColumnRadius();
drawArea = new Rectangle2D.Double(cursor, stemTop,
drawWidth, (stemBottom - stemTop + 1));
this.rangeAxis.draw(g2, cursor, area, drawArea,
RectangleEdge.LEFT, null);
break;
}
}
// draw text value on screen
g2.setFont(this.valueFont);
g2.setPaint(this.valuePaint);
metrics = g2.getFontMetrics();
switch (this.valueLocation) {
case RIGHT:
g2.drawString(this.valueFormat.format(current),
midX + getColumnRadius() + getGap(), midY);
break;
case LEFT:
String valueString = this.valueFormat.format(current);
int stringWidth = metrics.stringWidth(valueString);
g2.drawString(valueString, midX - getColumnRadius()
- getGap() - stringWidth, midY);
break;
case BULB:
temp = this.valueFormat.format(current);
i = metrics.stringWidth(temp) / 2;
g2.drawString(temp, midX - i,
stemBottom + getBulbRadius() + getGap());
break;
default:
}
/***/
}
g2.setPaint(this.thermometerPaint);
g2.setFont(this.valueFont);
// draw units indicator
metrics = g2.getFontMetrics();
int tickX1 = midX - getColumnRadius() - getGap() * 2
- metrics.stringWidth(UNITS[this.units]);
if (tickX1 > area.getMinX()) {
g2.drawString(UNITS[this.units], tickX1,
(int) (area.getMinY() + 20));
}
// draw thermometer outline
g2.setStroke(this.thermometerStroke);
g2.draw(outerThermometer);
g2.draw(innerThermometer);
drawOutline(g2, area);
}
Draws the plot on a Java 2D graphics device (such as the screen or a
printer). |
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;
}
if (this.bulbRadius != that.bulbRadius) {
return false;
}
if (this.columnRadius != that.columnRadius) {
return false;
}
if (this.gap != that.gap) {
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 this plot for equality with another object. The plot's dataset
is not considered in the test. |
public int getAxisLocation() {
return this.axisLocation;
}
Returns the axis location. |
public int getBulbDiameter() {
return getBulbRadius() * 2;
}
Returns the bulb diameter, which is always twice the value returned
by #getBulbRadius() . |
public int getBulbRadius() {
return this.bulbRadius;
}
Returns the bulb radius, in Java2D units. |
public int getColumnDiameter() {
return getColumnRadius() * 2;
}
Returns the column diameter, which is always twice the value returned
by #getColumnRadius() . |
public int getColumnRadius() {
return this.columnRadius;
}
Returns the column radius, in Java2D units. |
public Range getDataRange(ValueAxis axis) {
return new Range(this.lowerBound, this.upperBound);
}
|
public ValueDataset getDataset() {
return this.dataset;
}
Returns the dataset for the plot. |
public boolean getFollowDataInSubranges() {
return this.followDataInSubranges;
}
Returns a flag that controls whether or not the thermometer axis zooms
to display the subrange within which the data value falls. |
public int getGap() {
return this.gap;
}
Returns the gap, in Java2D units, between the two outlines that
represent the thermometer. |
public LegendItemCollection getLegendItems() {
return null;
}
Returns the legend items for the plot. |
public double getLowerBound() {
return this.lowerBound;
}
Returns the lower bound for the thermometer. The data value can be set
lower than this, but it will not be shown in the thermometer. |
public Number getMaximumVerticalDataValue() {
return new Double(this.upperBound);
} Deprecated! This - method is not used. Officially deprecated in version
1.0.6.
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. |
public Paint getMercuryPaint() {
return this.mercuryPaint;
}
Returns the default mercury paint. |
public Number getMinimumVerticalDataValue() {
return new Double(this.lowerBound);
} Deprecated! This - method is not used. Officially deprecated in version
1.0.6.
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. |
public PlotOrientation getOrientation() {
return PlotOrientation.VERTICAL;
}
Returns the orientation of the plot. |
public RectangleInsets getPadding() {
return this.padding;
}
Returns the padding for the thermometer. This is the space inside the
plot area. |
public String getPlotType() {
return localizationResources.getString("Thermometer_Plot");
}
Returns a short string describing the type of plot. |
public ValueAxis getRangeAxis() {
return this.rangeAxis;
}
|
public boolean getShowValueLines() {
return this.showValueLines;
} Deprecated! This - flag doesn't do anything useful/visible. Deprecated
as of version 1.0.6.
Returns the flag that controls whether not value lines are displayed. |
public Paint getSubrangePaint(int range) {
if ((range >= 0) && (range < this.subrangePaint.length)) {
return this.subrangePaint[range];
}
else {
return this.mercuryPaint;
}
}
Gets the paint used for a particular subrange. |
public Paint getThermometerPaint() {
return this.thermometerPaint;
}
Returns the paint used to draw the thermometer outline. |
public Stroke getThermometerStroke() {
return this.thermometerStroke;
}
Returns the stroke used to draw the thermometer outline. |
public int getUnits() {
return this.units;
}
|
public double getUpperBound() {
return this.upperBound;
}
Returns the upper bound for the thermometer. The data value can be set
higher than this, but it will not be shown in the thermometer. |
public boolean getUseSubrangePaint() {
return this.useSubrangePaint;
}
Returns a flag that controls whether or not the mercury color changes
for each subrange. |
public Font getValueFont() {
return this.valueFont;
}
Gets the font used to display the current value. |
public int getValueLocation() {
return this.valueLocation;
}
Returns a code indicating the location at which the value label is
displayed. |
public Paint getValuePaint() {
return this.valuePaint;
}
Gets the paint used to display the current value. |
public boolean isDomainZoomable() {
return false;
}
|
public boolean isRangeZoomable() {
return true;
}
|
protected static boolean isValidNumber(double d) {
return (!(Double.isNaN(d) || Double.isInfinite(d)));
}
Determine whether a number is valid and finite. |
public void setAxisLocation(int location) {
if ((location >= 0) && (location < 3)) {
this.axisLocation = location;
fireChangeEvent();
}
else {
throw new IllegalArgumentException("Location not recognised.");
}
}
Sets the location at which the axis is displayed relative to the
thermometer, and sends a PlotChangeEvent to all registered
listeners. |
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);
}
}
Sets the axis range to the current values in the rangeInfo array. |
public void setBulbRadius(int r) {
this.bulbRadius = r;
fireChangeEvent();
}
Sets the bulb radius (in Java2D units) and sends a
PlotChangeEvent to all registered listeners. |
public void setColumnRadius(int r) {
this.columnRadius = r;
fireChangeEvent();
}
Sets the column radius (in Java2D units) and sends a
PlotChangeEvent to all registered listeners. |
public void setDataset(ValueDataset dataset) {
// if there is an existing dataset, remove the plot from the list
// of change listeners...
ValueDataset existing = this.dataset;
if (existing != null) {
existing.removeChangeListener(this);
}
// set the new dataset, and register the chart as a change listener...
this.dataset = dataset;
if (dataset != null) {
setDatasetGroup(dataset.getGroup());
dataset.addChangeListener(this);
}
// send a dataset change event to self...
DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);
datasetChanged(event);
}
Sets the dataset for the plot, replacing the existing dataset if there
is one, and sends a PlotChangeEvent to all registered listeners. |
public void setDisplayRange(int range,
double low,
double high) {
if ((range >= 0) && (range < this.subrangeInfo.length)
&& isValidNumber(high) && isValidNumber(low)) {
if (high > low) {
this.subrangeInfo[range][DISPLAY_HIGH] = high;
this.subrangeInfo[range][DISPLAY_LOW] = low;
}
else {
this.subrangeInfo[range][DISPLAY_HIGH] = low;
this.subrangeInfo[range][DISPLAY_LOW] = high;
}
}
}
Sets the displayed bounds for a sub range. |
public void setFollowDataInSubranges(boolean flag) {
this.followDataInSubranges = flag;
fireChangeEvent();
}
Sets the flag that controls whether or not the thermometer axis zooms
to display the subrange within which the data value falls. |
public void setGap(int gap) {
this.gap = gap;
fireChangeEvent();
}
Sets the gap (in Java2D units) between the two outlines that represent
the thermometer, and sends a PlotChangeEvent to all registered
listeners. |
public void setLowerBound(double lower) {
this.lowerBound = lower;
setAxisRange();
}
Sets the lower bound for the thermometer. |
public void setMercuryPaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.mercuryPaint = paint;
fireChangeEvent();
}
Sets the default mercury paint and sends a PlotChangeEvent to
all registered listeners. |
public void setPadding(RectangleInsets padding) {
if (padding == null) {
throw new IllegalArgumentException("Null 'padding' argument.");
}
this.padding = padding;
fireChangeEvent();
}
Sets the padding for the thermometer and sends a PlotChangeEvent
to all registered listeners. |
public void setRange(double lower,
double upper) {
this.lowerBound = lower;
this.upperBound = upper;
setAxisRange();
}
Sets the lower and upper bounds for the thermometer. |
public void setRangeAxis(ValueAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("Null 'axis' argument.");
}
// plot is registered as a listener with the existing axis...
this.rangeAxis.removeChangeListener(this);
axis.setPlot(this);
axis.addChangeListener(this);
this.rangeAxis = axis;
fireChangeEvent();
}
Sets the range axis for the plot and sends a PlotChangeEvent to
all registered listeners. |
public void setShowValueLines(boolean b) {
this.showValueLines = b;
fireChangeEvent();
} Deprecated! This - flag doesn't do anything useful/visible. Deprecated
as of version 1.0.6.
Sets the display as to whether to show value lines in the output. |
public void setSubrange(int range,
double low,
double high) {
if ((range >= 0) && (range < 3)) {
this.subrangeInfo[range][RANGE_HIGH] = high;
this.subrangeInfo[range][RANGE_LOW] = low;
}
}
Sets the bounds for a subrange. |
public void setSubrangeInfo(int range,
double low,
double hi) {
setSubrangeInfo(range, low, hi, low, hi);
}
Sets information for a particular range. |
public void setSubrangeInfo(int range,
double rangeLow,
double rangeHigh,
double displayLow,
double displayHigh) {
if ((range >= 0) && (range < 3)) {
setSubrange(range, rangeLow, rangeHigh);
setDisplayRange(range, displayLow, displayHigh);
setAxisRange();
fireChangeEvent();
}
}
Sets the subrangeInfo attribute of the ThermometerPlot object |
public void setSubrangePaint(int range,
Paint paint) {
if ((range >= 0)
&& (range < this.subrangePaint.length) && (paint != null)) {
this.subrangePaint[range] = paint;
fireChangeEvent();
}
}
Sets the paint to be used for a subrange and sends a
PlotChangeEvent to all registered listeners. |
public void setThermometerPaint(Paint paint) {
if (paint != null) {
this.thermometerPaint = paint;
fireChangeEvent();
}
}
Sets the paint used to draw the thermometer outline and sends a
PlotChangeEvent to all registered listeners. |
public void setThermometerStroke(Stroke s) {
if (s != null) {
this.thermometerStroke = s;
fireChangeEvent();
}
}
Sets the stroke used to draw the thermometer outline and sends a
PlotChangeEvent to all registered listeners. |
public void setUnits(int u) {
if ((u >= 0) && (u < UNITS.length)) {
if (this.units != u) {
this.units = u;
fireChangeEvent();
}
}
}
Sets the units to be displayed in the thermometer. Use one of the
following constants:
- UNITS_NONE : no units displayed.
- UNITS_FAHRENHEIT : units displayed in Fahrenheit.
- UNITS_CELCIUS : units displayed in Celcius.
- UNITS_KELVIN : units displayed in Kelvin.
|
public void setUnits(String u) {
if (u == null) {
return;
}
u = u.toUpperCase().trim();
for (int i = 0; i < UNITS.length; ++i) {
if (u.equals(UNITS[i].toUpperCase().trim())) {
setUnits(i);
i = UNITS.length;
}
}
} Deprecated! Use - setUnits(int) instead. Deprecated as of version 1.0.6,
because this method is a little obscure and redundant anyway.
|
public void setUpperBound(double upper) {
this.upperBound = upper;
setAxisRange();
}
Sets the upper bound for the thermometer. |
public void setUseSubrangePaint(boolean flag) {
this.useSubrangePaint = flag;
fireChangeEvent();
}
Sets the range colour change option. |
public void setValueFont(Font f) {
if (f == null) {
throw new IllegalArgumentException("Null 'font' argument.");
}
if (!this.valueFont.equals(f)) {
this.valueFont = f;
fireChangeEvent();
}
}
Sets the font used to display the current value. |
public void setValueFormat(NumberFormat formatter) {
if (formatter == null) {
throw new IllegalArgumentException("Null 'formatter' argument.");
}
this.valueFormat = formatter;
fireChangeEvent();
}
Sets the formatter for the value label and sends a
PlotChangeEvent to all registered listeners. |
public void setValueLocation(int location) {
if ((location >= 0) && (location < 4)) {
this.valueLocation = location;
fireChangeEvent();
}
else {
throw new IllegalArgumentException("Location not recognised.");
}
}
Sets the location at which the current value is displayed and sends a
PlotChangeEvent to all registered listeners.
The location can be one of the constants:
NONE,
RIGHT
LEFT and
BULB. |
public void setValuePaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
if (!this.valuePaint.equals(paint)) {
this.valuePaint = paint;
fireChangeEvent();
}
}
Sets the paint used to display the current value and sends a
PlotChangeEvent to all registered listeners. |
public void zoom(double percent) {
// intentionally blank
}
A zoom method that does nothing. Plots are required to support the
zoom operation. In the case of a thermometer chart, it doesn't make
sense to zoom in or out, so the method is empty. |
public void zoomDomainAxes(double factor,
PlotRenderingInfo state,
Point2D source) {
// no domain axis to zoom
}
Multiplies the range on the domain axis/axes by the specified factor. |
public void zoomDomainAxes(double factor,
PlotRenderingInfo state,
Point2D source,
boolean useAnchor) {
// no domain axis to zoom
}
Multiplies the range on the domain axis/axes by the specified factor. |
public void zoomDomainAxes(double lowerPercent,
double upperPercent,
PlotRenderingInfo state,
Point2D source) {
// no domain axis to zoom
}
This method does nothing. |
public void zoomRangeAxes(double factor,
PlotRenderingInfo state,
Point2D source) {
this.rangeAxis.resizeRange(factor);
}
Multiplies the range on the range axis/axes by the specified factor. |
public void zoomRangeAxes(double factor,
PlotRenderingInfo state,
Point2D source,
boolean useAnchor) {
double anchorY = this.getRangeAxis().java2DToValue(source.getY(),
state.getDataArea(), RectangleEdge.LEFT);
this.rangeAxis.resizeRange(factor, anchorY);
}
Multiplies the range on the range axis/axes by the specified factor. |
public void zoomRangeAxes(double lowerPercent,
double upperPercent,
PlotRenderingInfo state,
Point2D source) {
this.rangeAxis.zoomRange(lowerPercent, upperPercent);
}
|