1 42 43 package org.jfree.experimental.chart.plot.dial; 44 45 import java.awt.Color ; 46 import java.awt.GradientPaint ; 47 import java.awt.Graphics2D ; 48 import java.awt.Paint ; 49 import java.awt.geom.Rectangle2D ; 50 import java.io.IOException ; 51 import java.io.ObjectInputStream ; 52 import java.io.ObjectOutputStream ; 53 import java.io.Serializable ; 54 55 import org.jfree.chart.HashUtilities; 56 import org.jfree.io.SerialUtilities; 57 import org.jfree.ui.GradientPaintTransformer; 58 import org.jfree.ui.StandardGradientPaintTransformer; 59 import org.jfree.util.PaintUtilities; 60 import org.jfree.util.PublicCloneable; 61 62 65 public class DialBackground extends AbstractDialLayer implements DialLayer, 66 Cloneable , PublicCloneable, Serializable { 67 68 72 private transient Paint paint; 73 74 78 private GradientPaintTransformer gradientPaintTransformer; 79 80 84 public DialBackground() { 85 this(Color.white); 86 } 87 88 96 public DialBackground(Paint paint) { 97 if (paint == null) { 98 throw new IllegalArgumentException ("Null 'paint' argument."); 99 } 100 this.paint = paint; 101 this.gradientPaintTransformer = new StandardGradientPaintTransformer(); 102 } 103 104 111 public Paint getPaint() { 112 return this.paint; 113 } 114 115 122 public void setPaint(Paint paint) { 123 if (paint == null) { 124 throw new IllegalArgumentException ("Null 'paint' argument."); 125 } 126 this.paint = paint; 127 notifyListeners(new DialLayerChangeEvent(this)); 128 } 129 130 138 public GradientPaintTransformer getGradientPaintTransformer() { 139 return this.gradientPaintTransformer; 140 } 141 142 150 public void setGradientPaintTransformer(GradientPaintTransformer t) { 151 if (t == null) { 152 throw new IllegalArgumentException ("Null 't' argument."); 153 } 154 this.gradientPaintTransformer = t; 155 notifyListeners(new DialLayerChangeEvent(this)); 156 } 157 158 164 public boolean isClippedToWindow() { 165 return true; 166 } 167 168 178 public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 179 Rectangle2D view) { 180 181 Paint p = this.paint; 182 if (p instanceof GradientPaint ) { 183 p = this.gradientPaintTransformer.transform((GradientPaint ) p, view); 184 } 185 g2.setPaint(p); 186 g2.fill(view); 187 } 188 189 196 public boolean equals(Object obj) { 197 if (obj == this) { 198 return true; 199 } 200 if (!(obj instanceof DialBackground)) { 201 return false; 202 } 203 DialBackground that = (DialBackground) obj; 204 if (!PaintUtilities.equal(this.paint, that.paint)) { 205 return false; 206 } 207 if (!this.gradientPaintTransformer.equals( 208 that.gradientPaintTransformer)) { 209 return false; 210 } 211 return true; 212 } 213 214 219 public int hashCode() { 220 int result = 193; 221 result = 37 * result + HashUtilities.hashCodeForPaint(paint); 222 result = 37 * result + this.gradientPaintTransformer.hashCode(); 223 return result; 224 } 225 226 234 public Object clone() throws CloneNotSupportedException { 235 return super.clone(); 236 } 237 238 245 private void writeObject(ObjectOutputStream stream) throws IOException { 246 stream.defaultWriteObject(); 247 SerialUtilities.writePaint(this.paint, stream); 248 } 249 250 258 private void readObject(ObjectInputStream stream) 259 throws IOException , ClassNotFoundException { 260 stream.defaultReadObject(); 261 this.paint = SerialUtilities.readPaint(stream); 262 } 263 264 } 265 | Popular Tags |