1 46 47 package org.jfree.chart.needle; 48 49 import java.awt.Graphics2D ; 50 import java.awt.geom.Area ; 51 import java.awt.geom.Ellipse2D ; 52 import java.awt.geom.GeneralPath ; 53 import java.awt.geom.Point2D ; 54 import java.awt.geom.Rectangle2D ; 55 import java.io.Serializable ; 56 57 60 public class MiddlePinNeedle extends MeterNeedle 61 implements Cloneable , Serializable { 62 63 64 private static final long serialVersionUID = 6237073996403125310L; 65 66 74 protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 75 Point2D rotate, double angle) { 76 77 Area shape; 78 GeneralPath pointer = new GeneralPath (); 79 80 int minY = (int) (plotArea.getMinY()); 81 int maxY = (int) (plotArea.getMaxY()); 83 int midY = ((maxY - minY) / 2) + minY; 84 85 int midX = (int) (plotArea.getMinX() + (plotArea.getWidth() / 2)); 86 int lenX = (int) (plotArea.getWidth() / 10); 88 if (lenX < 2) { 89 lenX = 2; 90 } 91 92 pointer.moveTo(midX - lenX, midY - lenX); 93 pointer.lineTo(midX + lenX, midY - lenX); 94 pointer.lineTo(midX, minY); 95 pointer.closePath(); 96 97 lenX = 4 * lenX; 98 Ellipse2D circle = new Ellipse2D.Double (midX - lenX / 2, 99 midY - lenX, lenX, lenX); 100 101 shape = new Area (circle); 102 shape.add(new Area (pointer)); 103 if ((rotate != null) && (angle != 0)) { 104 getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); 106 shape.transform(getTransform()); 107 } 108 109 defaultDisplay(g2, shape); 110 111 } 112 113 120 public boolean equals(Object object) { 121 if (object == null) { 122 return false; 123 } 124 if (object == this) { 125 return true; 126 } 127 if (super.equals(object) && object instanceof MiddlePinNeedle) { 128 return true; 129 } 130 return false; 131 } 132 133 141 public Object clone() throws CloneNotSupportedException { 142 return super.clone(); 143 } 144 145 } 146 | Popular Tags |