Java源码示例:org.jfree.chart.plot.dial.DialValueIndicator
示例1
/**
* Two objects that are equal are required to return the same hashCode.
*/
public void testHashCode() {
DialValueIndicator i1 = new DialValueIndicator(0);
DialValueIndicator i2 = new DialValueIndicator(0);
assertTrue(i1.equals(i2));
int h1 = i1.hashCode();
int h2 = i2.hashCode();
assertEquals(h1, h2);
}
示例2
/**
* Two objects that are equal are required to return the same hashCode.
*/
public void testHashCode() {
DialValueIndicator i1 = new DialValueIndicator(0);
DialValueIndicator i2 = new DialValueIndicator(0);
assertTrue(i1.equals(i2));
int h1 = i1.hashCode();
int h2 = i2.hashCode();
assertEquals(h1, h2);
}
示例3
/**
* Creates a chart displaying a circular dial.
*
* @param chartTitle the chart title.
* @param dialLabel the dial label.
* @param dataset the dataset.
* @param lowerBound the lower bound.
* @param upperBound the upper bound.
* @return A chart that displays a value as a dial.
*/
private JFreeChart createStatusDialChart(
String chartTitle,
String dialLabel,
ValueDataset dataset,
double lowerBound,
double upperBound) {
DialPlot plot = new DialPlot();
plot.setDataset(dataset);
plot.setDialFrame(new StandardDialFrame());
DialTextAnnotation annotation1 = new DialTextAnnotation(dialLabel);
annotation1.setFont(new Font("Dialog", Font.BOLD, 14));
annotation1.setRadius(0.7);
plot.addLayer(annotation1);
DialValueIndicator dvi = new DialValueIndicator(0);
plot.addLayer(dvi);
StandardDialScale scale = new StandardDialScale(lowerBound, upperBound, -120, -300, 1, 4);
scale.setTickRadius(0.88);
scale.setTickLabelOffset(0.15);
scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 14));
plot.addScale(0, scale);
plot.addPointer(new DialPointer.Pin());
DialCap cap = new DialCap();
plot.setCap(cap);
JFreeChart chart = new JFreeChart(chartTitle, plot);
chart.setBackgroundPaint(Color.WHITE);
StandardDialRange range =
new StandardDialRange(UnitStatusInfo.DIAL_CHART_YELLOW, upperBound, Color.green);
range.setInnerRadius(0.52);
range.setOuterRadius(0.55);
plot.addLayer(range);
StandardDialRange range2 =
new StandardDialRange(
UnitStatusInfo.DIAL_CHART_RED, UnitStatusInfo.DIAL_CHART_YELLOW, Color.orange);
range2.setInnerRadius(0.52);
range2.setOuterRadius(0.55);
plot.addLayer(range2);
StandardDialRange range3 =
new StandardDialRange(lowerBound, UnitStatusInfo.DIAL_CHART_RED, Color.red);
range3.setInnerRadius(0.52);
range3.setOuterRadius(0.55);
plot.addLayer(range3);
GradientPaint gp =
new GradientPaint(
new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220));
DialBackground db = new DialBackground(gp);
db.setGradientPaintTransformer(
new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
plot.setBackground(db);
plot.removePointer(0);
DialPointer.Pointer p = new DialPointer.Pointer();
plot.addPointer(p);
return chart;
}
示例4
/**
* Creates a chart of type speedometer.
*
* @param chartTitle the chart title.
* @param dataset the dataset.
*
* @return A chart speedometer.
*/
public JFreeChart createChart(DatasetMap datasets) {
logger.debug("IN");
Dataset dataset=(Dataset)datasets.getDatasets().get("1");
DialPlot plot = new DialPlot();
plot.setDataset((ValueDataset)dataset);
plot.setDialFrame(new StandardDialFrame());
plot.setBackground(new DialBackground());
if(dialtextuse){
DialTextAnnotation annotation1 = new DialTextAnnotation(dialtext);
annotation1.setFont(styleTitle.getFont());
annotation1.setRadius(0.7);
plot.addLayer(annotation1);
}
DialValueIndicator dvi = new DialValueIndicator(0);
dvi.setFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));
dvi.setPaint(labelsValueStyle.getColor());
plot.addLayer(dvi);
StandardDialScale scale = new StandardDialScale(lower,
upper, -120, -300, 10.0, 4);
if (!( increment > 0)){
logger.warn("increment cannot be less than 0, put default to 0.1");
increment = 0.01;
}
scale.setMajorTickIncrement(increment);
// if (!( minorTickCount > 0)){
// logger.warn("minor tick count cannot be less than 0, put default to 1");
// minorTickCount = 1;
// }
scale.setMinorTickCount(minorTickCount);
scale.setTickRadius(0.88);
scale.setTickLabelOffset(0.15);
//set tick label style
Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
scale.setTickLabelFont(tickLabelsFont);
scale.setTickLabelPaint(labelsTickStyle.getColor());
plot.addScale(0, scale);
plot.addPointer(new DialPointer.Pin());
DialCap cap = new DialCap();
plot.setCap(cap);
// sets intervals
for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
KpiInterval interval = (KpiInterval) iterator.next();
StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(),
interval.getColor());
range.setInnerRadius(0.52);
range.setOuterRadius(0.55);
plot.addLayer(range);
}
GradientPaint gp = new GradientPaint(new Point(),
new Color(255, 255, 255), new Point(),
new Color(170, 170, 220));
DialBackground db = new DialBackground(gp);
db.setGradientPaintTransformer(new StandardGradientPaintTransformer(
GradientPaintTransformType.VERTICAL));
plot.setBackground(db);
plot.removePointer(0);
DialPointer.Pointer p = new DialPointer.Pointer();
p.setFillPaint(Color.yellow);
plot.addPointer(p);
logger.debug("OUT");
JFreeChart chart=new JFreeChart(name, plot);
TextTitle title = setStyleTitle(name, styleTitle);
chart.setTitle(title);
if(subName!= null && !subName.equals("")){
TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
chart.addSubtitle(subTitle);
}
chart.setBackgroundPaint(color);
return chart;
}
示例5
private void fillChart(String title, float value, int lowerBound, int upperBound) throws Exception {
DefaultValueDataset dataset = new DefaultValueDataset();
dataset.setValue(value);
DialPlot plot = new DialPlot();
plot.setView(0.0d, 0.0d, 1.0d, 1.0d);
plot.setDataset(0, dataset);
StandardDialFrame frame = new StandardDialFrame();
plot.setDialFrame(frame);
DialBackground dialBackground = new DialBackground();
dialBackground.setGradientPaintTransformer(
new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
plot.setBackground(dialBackground);
DialTextAnnotation textAnnotation = new DialTextAnnotation( title );
textAnnotation.setRadius(0.555555555555555555D);
plot.addLayer(textAnnotation);
DialValueIndicator valueIndicator = new DialValueIndicator(0);
plot.addLayer(valueIndicator);
StandardDialScale scale1 = new StandardDialScale();
scale1.setLowerBound( lowerBound );
scale1.setUpperBound( upperBound );
scale1.setStartAngle( -140 ); // -120
scale1.setExtent( -260D ); // -300D
scale1.setTickRadius(0.88D);
scale1.setTickLabelOffset(0.14999999999999999D);
scale1.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 14));
plot.addScale(0, scale1);
StandardDialRange standarddialrange0 = new StandardDialRange( lowerBound, (upperBound*0.6), Color.red);
standarddialrange0.setInnerRadius(0.52000000000000002D);
standarddialrange0.setOuterRadius(0.55000000000000004D);
plot.addLayer(standarddialrange0);
StandardDialRange standarddialrange1 = new StandardDialRange( (upperBound*0.6), (upperBound*0.8), Color.orange);
standarddialrange1.setInnerRadius(0.52000000000000002D);
standarddialrange1.setOuterRadius(0.55000000000000004D);
plot.addLayer(standarddialrange1);
StandardDialRange standarddialrange2 = new StandardDialRange( (upperBound*0.8), upperBound, Color.green);
standarddialrange2.setInnerRadius(0.52000000000000002D);
standarddialrange2.setOuterRadius(0.55000000000000004D);
plot.addLayer(standarddialrange2);
Pointer pointer = new Pointer(0);
pointer.setFillPaint(new Color(144, 196, 246));
plot.addPointer(pointer);
plot.mapDatasetToScale(0, 0);
DialCap dialcap = new DialCap();
dialcap.setRadius(0.0700000000000001D);
plot.setCap(dialcap);
this.chart = new JFreeChart(plot);
//this.chart.setBackgroundPaint(new Color(234, 244, 253));
this.chart.setBackgroundPaint( Color.white );
}
示例6
/**
* Confirm that the equals method can distinguish all the required fields.
*/
public void testEquals() {
DialValueIndicator i1 = new DialValueIndicator(0);
DialValueIndicator i2 = new DialValueIndicator(0);
assertTrue(i1.equals(i2));
// dataset index
i1.setDatasetIndex(99);
assertFalse(i1.equals(i2));
i2.setDatasetIndex(99);
assertTrue(i1.equals(i2));
// angle
i1.setAngle(43);
assertFalse(i1.equals(i2));
i2.setAngle(43);
assertTrue(i1.equals(i2));
// radius
i1.setRadius(0.77);
assertFalse(i1.equals(i2));
i2.setRadius(0.77);
assertTrue(i1.equals(i2));
// frameAnchor
i1.setFrameAnchor(RectangleAnchor.TOP_LEFT);
assertFalse(i1.equals(i2));
i2.setFrameAnchor(RectangleAnchor.TOP_LEFT);
assertTrue(i1.equals(i2));
// templateValue
i1.setTemplateValue(new Double(1.23));
assertFalse(i1.equals(i2));
i2.setTemplateValue(new Double(1.23));
assertTrue(i1.equals(i2));
// font
i1.setFont(new Font("Dialog", Font.PLAIN, 7));
assertFalse(i1.equals(i2));
i2.setFont(new Font("Dialog", Font.PLAIN, 7));
assertTrue(i1.equals(i2));
// paint
i1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertFalse(i1.equals(i2));
i2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertTrue(i1.equals(i2));
// backgroundPaint
i1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
4.0f, Color.green));
assertFalse(i1.equals(i2));
i2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
4.0f, Color.green));
assertTrue(i1.equals(i2));
// outlineStroke
i1.setOutlineStroke(new BasicStroke(1.1f));
assertFalse(i1.equals(i2));
i2.setOutlineStroke(new BasicStroke(1.1f));
assertTrue(i1.equals(i2));
// outlinePaint
i1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertFalse(i1.equals(i2));
i2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertTrue(i1.equals(i2));
// insets
i1.setInsets(new RectangleInsets(1, 2, 3, 4));
assertFalse(i1.equals(i2));
i2.setInsets(new RectangleInsets(1, 2, 3, 4));
assertTrue(i1.equals(i2));
// valueAnchor
i1.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
assertFalse(i1.equals(i2));
i2.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
assertTrue(i1.equals(i2));
// textAnchor
i1.setTextAnchor(TextAnchor.TOP_LEFT);
assertFalse(i1.equals(i2));
i2.setTextAnchor(TextAnchor.TOP_LEFT);
assertTrue(i1.equals(i2));
// check an inherited attribute
i1.setVisible(false);
assertFalse(i1.equals(i2));
i2.setVisible(false);
assertTrue(i1.equals(i2));
}
示例7
/**
* Confirm that the equals method can distinguish all the required fields.
*/
public void testEquals() {
DialValueIndicator i1 = new DialValueIndicator(0);
DialValueIndicator i2 = new DialValueIndicator(0);
assertTrue(i1.equals(i2));
// dataset index
i1.setDatasetIndex(99);
assertFalse(i1.equals(i2));
i2.setDatasetIndex(99);
assertTrue(i1.equals(i2));
// angle
i1.setAngle(43);
assertFalse(i1.equals(i2));
i2.setAngle(43);
assertTrue(i1.equals(i2));
// radius
i1.setRadius(0.77);
assertFalse(i1.equals(i2));
i2.setRadius(0.77);
assertTrue(i1.equals(i2));
// frameAnchor
i1.setFrameAnchor(RectangleAnchor.TOP_LEFT);
assertFalse(i1.equals(i2));
i2.setFrameAnchor(RectangleAnchor.TOP_LEFT);
assertTrue(i1.equals(i2));
// templateValue
i1.setTemplateValue(new Double(1.23));
assertFalse(i1.equals(i2));
i2.setTemplateValue(new Double(1.23));
assertTrue(i1.equals(i2));
// font
i1.setFont(new Font("Dialog", Font.PLAIN, 7));
assertFalse(i1.equals(i2));
i2.setFont(new Font("Dialog", Font.PLAIN, 7));
assertTrue(i1.equals(i2));
// paint
i1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertFalse(i1.equals(i2));
i2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertTrue(i1.equals(i2));
// backgroundPaint
i1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
4.0f, Color.green));
assertFalse(i1.equals(i2));
i2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
4.0f, Color.green));
assertTrue(i1.equals(i2));
// outlineStroke
i1.setOutlineStroke(new BasicStroke(1.1f));
assertFalse(i1.equals(i2));
i2.setOutlineStroke(new BasicStroke(1.1f));
assertTrue(i1.equals(i2));
// outlinePaint
i1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertFalse(i1.equals(i2));
i2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertTrue(i1.equals(i2));
// insets
i1.setInsets(new RectangleInsets(1, 2, 3, 4));
assertFalse(i1.equals(i2));
i2.setInsets(new RectangleInsets(1, 2, 3, 4));
assertTrue(i1.equals(i2));
// valueAnchor
i1.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
assertFalse(i1.equals(i2));
i2.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
assertTrue(i1.equals(i2));
// textAnchor
i1.setTextAnchor(TextAnchor.TOP_LEFT);
assertFalse(i1.equals(i2));
i2.setTextAnchor(TextAnchor.TOP_LEFT);
assertTrue(i1.equals(i2));
// check an inherited attribute
i1.setVisible(false);
assertFalse(i1.equals(i2));
i2.setVisible(false);
assertTrue(i1.equals(i2));
}