1 42 43 package org.jfree.chart; 44 45 import java.awt.Paint ; 46 import java.io.IOException ; 47 import java.io.ObjectInputStream ; 48 import java.io.ObjectOutputStream ; 49 import java.io.Serializable ; 50 import java.util.Iterator ; 51 import java.util.Map ; 52 import java.util.Set ; 53 import java.util.TreeMap ; 54 55 import org.jfree.io.SerialUtilities; 56 import org.jfree.util.PaintUtilities; 57 58 68 public class PaintMap implements Cloneable , Serializable { 69 70 71 private transient Map store; 72 73 76 public PaintMap() { 77 this.store = new TreeMap (); 78 } 79 80 91 public Paint getPaint(Comparable key) { 92 if (key == null) { 93 throw new IllegalArgumentException ("Null 'key' argument."); 94 } 95 return (Paint ) this.store.get(key); 96 } 97 98 107 public boolean containsKey(Comparable key) { 108 return this.store.containsKey(key); 109 } 110 111 121 public void put(Comparable key, Paint paint) { 122 if (key == null) { 123 throw new IllegalArgumentException ("Null 'key' argument."); 124 } 125 this.store.put(key, paint); 126 } 127 128 131 public void clear() { 132 this.store.clear(); 133 } 134 135 142 public boolean equals(Object obj) { 143 if (obj == this) { 144 return true; 145 } 146 if (!(obj instanceof PaintMap)) { 147 return false; 148 } 149 PaintMap that = (PaintMap) obj; 150 if (this.store.size() != that.store.size()) { 151 return false; 152 } 153 Set keys = this.store.keySet(); 154 Iterator iterator = keys.iterator(); 155 while (iterator.hasNext()) { 156 Comparable key = (Comparable ) iterator.next(); 157 Paint p1 = getPaint(key); 158 Paint p2 = that.getPaint(key); 159 if (!PaintUtilities.equal(p1, p2)) { 160 return false; 161 } 162 } 163 return true; 164 } 165 166 173 public Object clone() throws CloneNotSupportedException { 174 return super.clone(); 177 } 178 179 186 private void writeObject(ObjectOutputStream stream) throws IOException { 187 stream.defaultWriteObject(); 188 stream.writeInt(this.store.size()); 189 Set keys = this.store.keySet(); 190 Iterator iterator = keys.iterator(); 191 while (iterator.hasNext()) { 192 Comparable key = (Comparable ) iterator.next(); 193 stream.writeObject(key); 194 Paint paint = getPaint(key); 195 SerialUtilities.writePaint(paint, stream); 196 } 197 } 198 199 207 private void readObject(ObjectInputStream stream) 208 throws IOException , ClassNotFoundException { 209 stream.defaultReadObject(); 210 this.store = new TreeMap (); 211 int keyCount = stream.readInt(); 212 for (int i = 0; i < keyCount; i++) { 213 Comparable key = (Comparable ) stream.readObject(); 214 Paint paint = SerialUtilities.readPaint(stream); 215 this.store.put(key, paint); 216 } 217 } 218 219 } 220 | Popular Tags |