1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.BasicStroke ; 41 import java.awt.Color ; 42 import java.awt.Graphics2D ; 43 import java.awt.Paint ; 44 import java.awt.Stroke ; 45 import java.awt.geom.Ellipse2D ; 46 import java.awt.geom.Line2D ; 47 import java.awt.geom.Rectangle2D ; 48 49 import org.jfree.ui.Drawable; 50 51 57 public class CircleDrawer implements Drawable { 58 59 60 private Paint outlinePaint; 61 62 63 private Stroke outlineStroke; 64 65 66 private Paint fillPaint; 67 68 75 public CircleDrawer(Paint outlinePaint, Stroke outlineStroke, Paint fillPaint) { 76 this.outlinePaint = outlinePaint; 77 this.outlineStroke = outlineStroke; 78 this.fillPaint = fillPaint; 79 } 80 81 87 public void draw(Graphics2D g2, Rectangle2D area) { 88 Ellipse2D ellipse = new Ellipse2D.Double (area.getX(), area.getY(), 89 area.getWidth(), area.getHeight()); 90 if (this.fillPaint != null) { 91 g2.setPaint(this.fillPaint); 92 g2.fill(ellipse); 93 } 94 if (this.outlinePaint != null && this.outlineStroke != null) { 95 g2.setPaint(this.outlinePaint); 96 g2.setStroke(this.outlineStroke); 97 g2.draw(ellipse); 98 } 99 100 g2.setPaint(Color.black); 101 g2.setStroke(new BasicStroke (1.0f)); 102 Line2D line1 = new Line2D.Double (area.getCenterX(), area.getMinY(), 103 area.getCenterX(), area.getMaxY()); 104 Line2D line2 = new Line2D.Double (area.getMinX(), area.getCenterY(), 105 area.getMaxX(), area.getCenterY()); 106 g2.draw(line1); 107 g2.draw(line2); 108 } 109 } 110 | Popular Tags |