📄 thermometerplot.java
字号:
/**
* Returns the stroke used to draw the thermometer outline.
*
* @return the stroke.
*/
public Stroke getThermometerStroke() {
return this.thermometerStroke;
}
/**
* Sets the stroke used to draw the thermometer outline.
*
* @param s the new stroke (null ignored).
*/
public void setThermometerStroke(Stroke s) {
if (s != null) {
this.thermometerStroke = s;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the paint used to draw the thermometer outline.
*
* @return the paint.
*/
public Paint getThermometerPaint() {
return this.thermometerPaint;
}
/**
* Sets the paint used to draw the thermometer outline.
*
* @param paint the new paint (null ignored).
*/
public void setThermometerPaint(Paint paint) {
if (paint != null) {
this.thermometerPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the unit display type (none/Fahrenheit/Celcius/Kelvin).
*
* @return the units type.
*/
public int getUnits() {
return this.units;
}
/**
* Sets the units to be displayed in the thermometer.
* <p>
* Use one of the following constants:
*
* <ul>
* <li>UNITS_NONE : no units displayed.</li>
* <li>UNITS_FAHRENHEIT : units displayed in Fahrenheit.</li>
* <li>UNITS_CELCIUS : units displayed in Celcius.</li>
* <li>UNITS_KELVIN : units displayed in Kelvin.</li>
* </ul>
*
* @param u the new unit type.
*/
public void setUnits(int u) {
if ((u >= 0) && (u < UNITS.length)) {
if (this.units != u) {
this.units = u;
notifyListeners(new PlotChangeEvent(this));
}
}
}
/**
* Sets the unit type.
*
* @param u the unit type (null ignored).
*/
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;
}
}
}
/**
* Returns the value location.
*
* @return the location.
*/
public int getValueLocation() {
return this.valueLocation;
}
/**
* Sets the location at which the current value is displayed.
* <P>
* The location can be one of the constants:
* <code>NONE</code>,
* <code>RIGHT</code>
* <code>LEFT</code> and
* <code>BULB</code>.
*
* @param location the location.
*/
public void setValueLocation(int location) {
if ((location >= 0) && (location < 4)) {
this.valueLocation = location;
notifyListeners(new PlotChangeEvent(this));
}
else {
throw new IllegalArgumentException(
"ThermometerPlot.setDisplayLocation: location not recognised.");
}
}
/**
* Sets the location at which the axis is displayed with reference to the
* bulb.
* <P>
* The location can be one of the constants:
* <code>NONE</code>,
* <code>RIGHT</code> and
* <code>LEFT</code>.
*
* @param location the location.
*/
public void setAxisLocation(int location) {
if ((location >= 0) && (location < 3)) {
this.axisLocation = location;
notifyListeners(new PlotChangeEvent(this));
}
else {
throw new IllegalArgumentException(
"ThermometerPlot.setAxisLocation: location not recognised.");
}
}
/**
* Returns the axis location.
*
* @return the location.
*/
public int getAxisocation() {
return this.axisLocation;
}
/**
* Gets the font used to display the current value.
*
* @return The font.
*/
public Font getValueFont() {
return this.valueFont;
}
/**
* Sets the font used to display the current value.
*
* @param f the new font.
*/
public void setValueFont(Font f) {
if ((f != null) && (!this.valueFont.equals(f))) {
this.valueFont = f;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Gets the paint used to display the current value.
*
* @return the paint.
*/
public Paint getValuePaint() {
return this.valuePaint;
}
/**
* Sets the paint used to display the current value.
*
* @param p the new paint.
*/
public void setValuePaint(Paint p) {
if ((p != null) && (!this.valuePaint.equals(p))) {
this.valuePaint = p;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Sets the formatter for the value label.
*
* @param formatter the new formatter.
*/
public void setValueFormat(NumberFormat formatter) {
if (formatter != null) {
this.valueFormat = formatter;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the default mercury paint.
*
* @return the paint.
*/
public Paint getMercuryPaint() {
return this.mercuryPaint;
}
/**
* Sets the default mercury paint.
*
* @param paint the new paint.
*/
public void setMercuryPaint(Paint paint) {
this.mercuryPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the flag that controls whether not value lines are displayed.
*
* @return the flag.
*/
public boolean getShowValueLines() {
return this.showValueLines;
}
/**
* Sets the display as to whether to show value lines in the output.
*
* @param b Whether to show value lines in the thermometer
*/
public void setShowValueLines(boolean b) {
this.showValueLines = b;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Sets information for a particular range.
*
* @param range the range to specify information about.
* @param low the low value for the range
* @param hi the high value for the range
*/
public void setSubrangeInfo(int range, double low, double hi) {
setSubrangeInfo(range, low, hi, low, hi);
}
/**
* Sets the subrangeInfo attribute of the ThermometerPlot object
*
* @param range the new rangeInfo value.
* @param rangeLow the new rangeInfo value
* @param rangeHigh the new rangeInfo value
* @param displayLow the new rangeInfo value
* @param displayHigh the new rangeInfo value
*/
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();
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Sets the range.
*
* @param range the range type.
* @param low the low value.
* @param high the high value.
*/
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 display range.
*
* @param range the range type.
* @param low the low value.
* @param high the high value.
*/
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] = high;
this.subrangeInfo[range][DISPLAY_LOW] = low;
}
}
}
/**
* Gets the paint used for a particular subrange.
*
* @param range the range.
*
* @return the paint.
*/
public Paint getSubrangePaint(int range) {
if ((range >= 0) && (range < this.subrangePaint.length)) {
return this.subrangePaint[range];
}
else {
return this.mercuryPaint;
}
}
/**
* Sets the paint to be used for a range.
*
* @param range the range.
* @param paint the paint to be applied.
*/
public void setSubrangePaint(int range, Paint paint) {
if ((range >= 0) && (range < this.subrangePaint.length) && (paint != null)) {
this.subrangePaint[range] = paint;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns a flag that controls whether or not the thermometer axis zooms to display the
* subrange within which the data value falls.
*
* @return the flag.
*/
public boolean getFollowDataInSubranges() {
return this.followDataInSubranges;
}
/**
* Sets the flag that controls whether or not the thermometer axis zooms to display the
* subrange within which the data value falls.
*
* @param flag the flag.
*/
public void setFollowDataInSubranges(boolean flag) {
this.followDataInSubranges = flag;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns a flag that controls whether or not the mercury color changes for each
* subrange.
*
* @return the flag.
*/
public boolean getUseSubrangePaint() {
return this.useSubrangePaint;
}
/**
* Sets the range colour change option.
*
* @param flag The new range colour change option
*/
public void setUseSubrangePaint(boolean flag) {
this.useSubrangePaint = flag;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a printer).
*
* @param g2 the graphics device.
* @param plotArea the area within which the plot should be drawn.
* @param parentState the state from the parent plot, if there is one.
* @param info collects info about the drawing.
*/
public void draw(Graphics2D g2, Rectangle2D plotArea, 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(plotArea);
}
// adjust for insets...
Insets insets = getInsets();
if (insets != null) {
plotArea.setRect(plotArea.getX() + insets.left,
plotArea.getY() + insets.top,
plotArea.getWidth() - insets.left - insets.right,
plotArea.getHeight() - insets.top - insets.bottom);
}
drawBackground(g2, plotArea);
// adjust for padding...
//this.padding.trim(plotArea);
int midX = (int) (plotArea.getX() + (plotArea.getWidth() / 2));
int midY = (int) (plotArea.getY() + (plotArea.getHeight() / 2));
int stemTop = (int) (plotArea.getMinY() + BULB_RADIUS);
int stemBottom = (int) (plotArea.getMaxY() - BULB_DIAMETER);
Rectangle2D dataArea = new Rectangle2D.Double(midX - COLUMN_RADIUS,
stemTop,
COLUMN_RADIUS,
stemBottom - stemTop);
outerBulb.setFrame(midX - BULB_RADIUS,
stemBottom,
BULB_DIAMETER,
BULB_DIAMETER);
outerStem.setRoundRect(midX - COLUMN_RADIUS,
plotArea.getMinY(),
COLUMN_DIAMETER,
stemBottom + BULB_DIAMETER - stemTop,
COLUMN_DIAMETER,
COLUMN_DIAMETER);
Area outerThermometer = new Area(outerBulb);
Area tempArea = new Area(outerStem);
outerThermometer.add(tempArea);
innerBulb.setFrame(midX - BULB_RADIUS + GAP_RADIUS,
stemBottom + GAP_RADIUS,
BULB_DIAMETER - GAP_DIAMETER,
BULB_DIAMETER - GAP_DIAMETER);
innerStem.setRoundRect(midX - COLUMN_RADIUS + GAP_RADIUS,
plotArea.getMinY() + GAP_RADIUS,
COLUMN_DIAMETER - GAP_DIAMETER,
stemBottom + BULB_DIAMETER - GAP_DIAMETER - stemTop,
COLUMN_DIAMETER - GAP_DIAMETER,
COLUMN_DIAMETER - GAP_DIAMETER);
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 = COLUMN_DIAMETER - GAP_DIAMETER; // already calculated
int j = COLUMN_RADIUS - GAP_RADIUS; // already calculated
int l = (i / 2);
int k = (int) Math.round(ds);
if (k < (GAP_RADIUS + plotArea.getMinY())) {
k = (int) (GAP_RADIUS + plotArea.getMinY());
l = BULB_RADIUS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -