1 42 43 package org.jfree.chart; 44 45 import java.awt.Stroke ; 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.ObjectUtilities; 57 58 68 public class StrokeMap implements Cloneable , Serializable { 69 70 71 private transient Map store; 72 73 76 public StrokeMap() { 77 this.store = new TreeMap (); 78 } 79 80 91 public Stroke getStroke(Comparable key) { 92 if (key == null) { 93 throw new IllegalArgumentException ("Null 'key' argument."); 94 } 95 return (Stroke ) this.store.get(key); 96 } 97 98 107 public boolean containsKey(Comparable key) { 108 return this.store.containsKey(key); 109 } 110 111 118 public void put(Comparable key, Stroke stroke) { 119 if (key == null) { 120 throw new IllegalArgumentException ("Null 'key' argument."); 121 } 122 this.store.put(key, stroke); 123 } 124 125 128 public void clear() { 129 this.store.clear(); 130 } 131 132 139 public boolean equals(Object obj) { 140 if (obj == this) { 141 return true; 142 } 143 if (!(obj instanceof StrokeMap)) { 144 return false; 145 } 146 StrokeMap that = (StrokeMap) obj; 147 if (this.store.size() != that.store.size()) { 148 return false; 149 } 150 Set keys = this.store.keySet(); 151 Iterator iterator = keys.iterator(); 152 while (iterator.hasNext()) { 153 Comparable key = (Comparable ) iterator.next(); 154 Stroke s1 = getStroke(key); 155 Stroke s2 = that.getStroke(key); 156 if (!ObjectUtilities.equal(s1, s2)) { 157 return false; 158 } 159 } 160 return true; 161 } 162 163 170 public Object clone() throws CloneNotSupportedException { 171 return super.clone(); 174 } 175 176 183 private void writeObject(ObjectOutputStream stream) throws IOException { 184 stream.defaultWriteObject(); 185 stream.writeInt(this.store.size()); 186 Set keys = this.store.keySet(); 187 Iterator iterator = keys.iterator(); 188 while (iterator.hasNext()) { 189 Comparable key = (Comparable ) iterator.next(); 190 stream.writeObject(key); 191 Stroke stroke = getStroke(key); 192 SerialUtilities.writeStroke(stroke, stream); 193 } 194 } 195 196 204 private void readObject(ObjectInputStream stream) 205 throws IOException , ClassNotFoundException { 206 stream.defaultReadObject(); 207 this.store = new TreeMap (); 208 int keyCount = stream.readInt(); 209 for (int i = 0; i < keyCount; i++) { 210 Comparable key = (Comparable ) stream.readObject(); 211 Stroke stroke = SerialUtilities.readStroke(stream); 212 this.store.put(key, stroke); 213 } 214 } 215 216 } 217 | Popular Tags |