1 44 45 package org.jfree.chart.needle; 46 47 import java.awt.Graphics2D ; 48 import java.awt.geom.GeneralPath ; 49 import java.awt.geom.Point2D ; 50 import java.awt.geom.Rectangle2D ; 51 import java.awt.Shape ; 52 import java.io.Serializable ; 53 54 59 public class LongNeedle extends MeterNeedle implements Serializable { 60 61 62 private static final long serialVersionUID = -4319985779783688159L; 63 64 67 public LongNeedle() { 68 super(); 69 setRotateY(0.8); 70 } 71 72 80 protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 81 Point2D rotate, double angle) { 82 83 GeneralPath shape1 = new GeneralPath (); 84 GeneralPath shape2 = new GeneralPath (); 85 GeneralPath shape3 = new GeneralPath (); 86 87 float minX = (float) plotArea.getMinX(); 88 float minY = (float) plotArea.getMinY(); 89 float maxX = (float) plotArea.getMaxX(); 90 float maxY = (float) plotArea.getMaxY(); 91 float midX = (float) (minX + (plotArea.getWidth() * 0.5)); 94 float midY = (float) (minY + (plotArea.getHeight() * 0.8)); 95 float y = maxY - (2 * (maxY - midY)); 96 if (y < minY) { 97 y = minY; 98 } 99 shape1.moveTo(minX, midY); 100 shape1.lineTo(midX, minY); 101 shape1.lineTo(midX, y); 102 shape1.closePath(); 103 104 shape2.moveTo(maxX, midY); 105 shape2.lineTo(midX, minY); 106 shape2.lineTo(midX, y); 107 shape2.closePath(); 108 109 shape3.moveTo(minX, midY); 110 shape3.lineTo(midX, maxY); 111 shape3.lineTo(maxX, midY); 112 shape3.lineTo(midX, y); 113 shape3.closePath(); 114 115 Shape s1 = shape1; 116 Shape s2 = shape2; 117 Shape s3 = shape3; 118 119 if ((rotate != null) && (angle != 0)) { 120 getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); 122 s1 = shape1.createTransformedShape(transform); 123 s2 = shape2.createTransformedShape(transform); 124 s3 = shape3.createTransformedShape(transform); 125 } 126 127 128 if (getHighlightPaint() != null) { 129 g2.setPaint(getHighlightPaint()); 130 g2.fill(s3); 131 } 132 133 if (getFillPaint() != null) { 134 g2.setPaint(getFillPaint()); 135 g2.fill(s1); 136 g2.fill(s2); 137 } 138 139 140 if (getOutlinePaint() != null) { 141 g2.setStroke(getOutlineStroke()); 142 g2.setPaint(getOutlinePaint()); 143 g2.draw(s1); 144 g2.draw(s2); 145 g2.draw(s3); 146 } 147 } 148 149 156 public boolean equals(Object object) { 157 if (object == null) { 158 return false; 159 } 160 if (object == this) { 161 return true; 162 } 163 if (super.equals(object) && object instanceof LongNeedle) { 164 return true; 165 } 166 return false; 167 } 168 169 } 170 | Popular Tags |