1 44 45 package org.jfree.chart.needle; 46 47 import java.awt.Graphics2D ; 48 import java.awt.Shape ; 49 import java.awt.geom.GeneralPath ; 50 import java.awt.geom.Line2D ; 51 import java.awt.geom.Point2D ; 52 import java.awt.geom.Rectangle2D ; 53 import java.io.Serializable ; 54 55 60 public class ArrowNeedle extends MeterNeedle implements Serializable { 61 62 63 private static final long serialVersionUID = -5334056511213782357L; 64 65 69 private boolean isArrowAtTop = true; 70 71 77 public ArrowNeedle(boolean isArrowAtTop) { 78 this.isArrowAtTop = isArrowAtTop; 79 } 80 81 89 protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 90 Point2D rotate, double angle) { 91 92 Line2D shape = new Line2D.Float (); 93 Shape d = null; 94 95 float x = (float) (plotArea.getMinX() + (plotArea.getWidth() / 2)); 96 float minY = (float) plotArea.getMinY(); 97 float maxY = (float) plotArea.getMaxY(); 98 shape.setLine(x, minY, x, maxY); 99 100 GeneralPath shape1 = new GeneralPath (); 101 if (this.isArrowAtTop) { 102 shape1.moveTo(x, minY); 103 minY += 4 * getSize(); 104 } 105 else { 106 shape1.moveTo(x, maxY); 107 minY = maxY - 4 * getSize(); 108 } 109 shape1.lineTo(x + getSize(), minY); 110 shape1.lineTo(x - getSize(), minY); 111 shape1.closePath(); 112 113 if ((rotate != null) && (angle != 0)) { 114 getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); 115 d = getTransform().createTransformedShape(shape); 116 } 117 else { 118 d = shape; 119 } 120 defaultDisplay(g2, d); 121 122 if ((rotate != null) && (angle != 0)) { 123 d = getTransform().createTransformedShape(shape1); 124 } 125 else { 126 d = shape1; 127 } 128 defaultDisplay(g2, d); 129 130 } 131 132 139 public boolean equals(Object object) { 140 if (object == null) { 141 return false; 142 } 143 if (object == this) { 144 return true; 145 } 146 if (super.equals(object) && object instanceof ArrowNeedle) { 147 ArrowNeedle an = (ArrowNeedle) object; 148 return this.isArrowAtTop == an.isArrowAtTop; 149 } 150 return false; 151 } 152 153 } 154 | Popular Tags |