1 48 49 package org.jfree.chart.annotations; 50 51 import java.awt.Color ; 52 import java.awt.Font ; 53 import java.awt.Paint ; 54 import java.io.IOException ; 55 import java.io.ObjectInputStream ; 56 import java.io.ObjectOutputStream ; 57 import java.io.Serializable ; 58 59 import org.jfree.io.SerialUtilities; 60 import org.jfree.ui.TextAnchor; 61 import org.jfree.util.ObjectUtilities; 62 63 67 public class TextAnnotation implements Serializable { 68 69 70 private static final long serialVersionUID = 7008912287533127432L; 71 72 73 public static final Font DEFAULT_FONT 74 = new Font ("SansSerif", Font.PLAIN, 10); 75 76 77 public static final Paint DEFAULT_PAINT = Color.black; 78 79 80 public static final TextAnchor DEFAULT_TEXT_ANCHOR = TextAnchor.CENTER; 81 82 83 public static final TextAnchor DEFAULT_ROTATION_ANCHOR = TextAnchor.CENTER; 84 85 86 public static final double DEFAULT_ROTATION_ANGLE = 0.0; 87 88 89 private String text; 90 91 92 private Font font; 93 94 95 private transient Paint paint; 96 97 98 private TextAnchor textAnchor; 99 100 101 private TextAnchor rotationAnchor; 102 103 104 private double rotationAngle; 105 106 111 protected TextAnnotation(String text) { 112 if (text == null) { 113 throw new IllegalArgumentException ("Null 'text' argument."); 114 } 115 this.text = text; 116 this.font = DEFAULT_FONT; 117 this.paint = DEFAULT_PAINT; 118 this.textAnchor = DEFAULT_TEXT_ANCHOR; 119 this.rotationAnchor = DEFAULT_ROTATION_ANCHOR; 120 this.rotationAngle = DEFAULT_ROTATION_ANGLE; 121 } 122 123 128 public String getText() { 129 return this.text; 130 } 131 132 137 public void setText(String text) { 138 this.text = text; 139 } 140 141 146 public Font getFont() { 147 return this.font; 148 } 149 150 155 public void setFont(Font font) { 156 this.font = font; 157 } 158 159 164 public Paint getPaint() { 165 return this.paint; 166 } 167 168 173 public void setPaint(Paint paint) { 174 this.paint = paint; 175 } 176 177 182 public TextAnchor getTextAnchor() { 183 return this.textAnchor; 184 } 185 186 192 public void setTextAnchor(TextAnchor anchor) { 193 this.textAnchor = anchor; 194 } 195 196 201 public TextAnchor getRotationAnchor() { 202 return this.rotationAnchor; 203 } 204 205 210 public void setRotationAnchor(TextAnchor anchor) { 211 this.rotationAnchor = anchor; 212 } 213 214 219 public double getRotationAngle() { 220 return this.rotationAngle; 221 } 222 223 230 public void setRotationAngle(double angle) { 231 this.rotationAngle = angle; 232 } 233 234 241 public boolean equals(Object obj) { 242 243 if (obj == this) { 244 return true; 245 } 246 247 if (!(obj instanceof TextAnnotation)) { 249 return false; 250 } 251 TextAnnotation that = (TextAnnotation) obj; 252 if (!ObjectUtilities.equal(this.text, that.getText())) { 253 return false; 254 } 255 if (!ObjectUtilities.equal(this.font, that.getFont())) { 256 return false; 257 } 258 if (!ObjectUtilities.equal(this.paint, that.getPaint())) { 259 return false; 260 } 261 if (!ObjectUtilities.equal(this.textAnchor, that.getTextAnchor())) { 262 return false; 263 } 264 if (!ObjectUtilities.equal( 265 this.rotationAnchor, that.getRotationAnchor() 266 )) { 267 return false; 268 } 269 if (this.rotationAngle != that.getRotationAngle()) { 270 return false; 271 } 272 273 return true; 275 276 } 277 278 283 public int hashCode() { 284 return this.text.hashCode(); 286 } 287 288 295 private void writeObject(ObjectOutputStream stream) throws IOException { 296 stream.defaultWriteObject(); 297 SerialUtilities.writePaint(this.paint, stream); 298 } 299 300 308 private void readObject(ObjectInputStream stream) 309 throws IOException , ClassNotFoundException { 310 stream.defaultReadObject(); 311 this.paint = SerialUtilities.readPaint(stream); 312 } 313 314 } 315 | Popular Tags |