?? meterlegend.java
字號(hào):
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ----------------
* MeterLegend.java
* ----------------
* (C) Copyright 2000-2003, by Hari and Contributors.
*
* Original Author: Hari (ourhari@hotmail.com);
* Contributor(s): David Gilbert (for Object Refinery Limited);
*
* $Id: MeterLegend.java,v 1.4 2003/08/28 16:23:40 mungady Exp $
*
* Changes
* -------
* 01-Apr-2002 : Version 1, contributed by Hari (DG);
* 25-Jun-2002 : Updated imports and Javadoc comments (DG);
* 18-Sep-2002 : Updated for changes to StandardLegend (DG);
* 01-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 14-Jan-2003 : Changed outer gap to a Spacer (DG);
* 11-Feb-2003 : Removed constructor in line with changes to StandardLegend class (DG);
*
*/
package org.jfree.chart;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.font.LineMetrics;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import org.jfree.chart.event.LegendChangeEvent;
import org.jfree.chart.plot.MeterPlot;
import org.jfree.chart.plot.Plot;
import org.jfree.data.MeterDataset;
import org.jfree.data.ValueDataset;
/**
* A legend for meter plots.
*
* @author Hari
*/
public class MeterLegend extends StandardLegend {
/** The legend text. */
private String legendText;
/** Show the normal range? */
private boolean showNormal = true;
/** Show the warning range? */
private boolean showWarning = true;
/** Show the critical range? */
private boolean showCritical = true;
/**
* Constructs a new legend.
*
* @param chart the chart.
* @param legendText the legend text.
*
*/
public MeterLegend(JFreeChart chart, String legendText) {
super(chart);
this.legendText = legendText;
}
/**
* Returns the legend text.
*
* @return the legend text.
*/
public String getLegendText() {
return this.legendText;
}
/**
* Sets the legend text.
*
* @param text the new legend text.
*/
public void setLegendText(String text) {
this.legendText = text;
notifyListeners(new LegendChangeEvent(this));
}
/**
* Draws the legend.
*
* @param g2 the graphics device.
* @param available the available area.
*
* @return the remaining available drawing area.
*/
public Rectangle2D draw(Graphics2D g2, Rectangle2D available) {
return draw(g2, available, (getAnchor() & HORIZONTAL) != 0, (getAnchor() & INVERTED) != 0);
}
/**
* Updates the legend information.
*
* @param plot the plot.
* @param data the dataset.
* @param type the type.
* @param index the index.
* @param legendItems the legend items.
* @param legendItemColors the colors.
*
* @return boolean.
*/
private boolean updateInformation(MeterPlot plot, ValueDataset data, int type, int index,
LegendItem[] legendItems, Paint[] legendItemColors) {
boolean ret = false;
String label = null;
double minValue = 0.0;
double maxValue = 0.0;
Paint paint = null;
switch(type) {
case MeterDataset.NORMAL_DATA:
minValue = plot.getNormalRange().getLowerBound();
maxValue = plot.getNormalRange().getUpperBound();
paint = plot.getNormalPaint();
label = MeterPlot.NORMAL_TEXT;
break;
case MeterDataset.WARNING_DATA:
minValue = plot.getWarningRange().getLowerBound();
maxValue = plot.getWarningRange().getUpperBound();
paint = plot.getWarningPaint();
label = MeterPlot.WARNING_TEXT;
break;
case MeterDataset.CRITICAL_DATA:
minValue = plot.getCriticalRange().getLowerBound();
maxValue = plot.getCriticalRange().getUpperBound();
paint = plot.getCriticalPaint();
label = MeterPlot.CRITICAL_TEXT;
break;
case MeterDataset.FULL_DATA:
minValue = plot.getRange().getLowerBound();
maxValue = plot.getRange().getUpperBound();
paint = MeterPlot.DEFAULT_BACKGROUND_PAINT;
label = "Meter Graph";
break;
default:
return false;
}
// if (minValue != null && maxValue != null) {
// if (data.getBorderType() == type) {
label += " Range: ";
// + data.getMinimumValue().toString() + " to "
// + minValue.toString()
// + " and "
// + maxValue.toString() + " to "
// + data.getMaximumValue().toString();
// }
// else {
// label += " Range: " + minValue.toString() + " to " + maxValue.toString();
// }
legendItems[index] = new LegendItem(label, label, null, null, null, null);
legendItemColors[index] = paint;
ret = true;
//}
return ret;
}
/**
* Draws the legend.
*
* @param g2 the graphics device.
* @param available the available drawing area.
* @param horizontal if <code>true</code> draw a horizontal legend.
* @param inverted ???
*
* @return the remaining available drawing area.
*
*/
protected Rectangle2D draw(Graphics2D g2, Rectangle2D available,
boolean horizontal, boolean inverted) {
int legendCount = 0;
Plot plot = getChart().getPlot();
if (!(plot instanceof MeterPlot)) {
throw new IllegalArgumentException("Plot must be MeterPlot");
}
MeterPlot meterPlot = (MeterPlot) plot;
ValueDataset data = meterPlot.getDataset();
legendCount = 1; // Name of the Chart.
legendCount++; // Display Full Range
if (showCritical) {
legendCount++;
}
if (showWarning) {
legendCount++;
}
if (showNormal) {
legendCount++;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -