1 7 8 package java.awt; 9 10 import java.util.Map ; 11 import java.util.Set ; 12 import java.util.Collection ; 13 import java.util.Collections ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import sun.awt.SunHints; 17 import java.lang.ref.WeakReference ; 18 19 25 public class RenderingHints 26 implements Map <Object ,Object >, Cloneable 27 { 28 35 public abstract static class Key { 36 private static HashMap identitymap = new HashMap (17); 37 38 private String getIdentity() { 39 return getClass().getName()+"@"+ 50 Integer.toHexString(System.identityHashCode(getClass()))+":"+ 51 Integer.toHexString(privatekey); 52 } 53 54 private synchronized static void recordIdentity(Key k) { 55 Object identity = k.getIdentity(); 56 Object otherref = identitymap.get(identity); 57 if (otherref != null) { 58 Key otherkey = (Key) ((WeakReference ) otherref).get(); 59 if (otherkey != null && otherkey.getClass() == k.getClass()) { 60 throw new IllegalArgumentException (identity+ 61 " already registered"); 62 } 63 } 80 identitymap.put(identity, new WeakReference (k)); 83 } 84 85 private int privatekey; 86 87 97 protected Key(int privatekey) { 98 this.privatekey = privatekey; 99 recordIdentity(this); 100 } 101 102 109 public abstract boolean isCompatibleValue(Object val); 110 111 117 protected final int intKey() { 118 return privatekey; 119 } 120 121 126 public final int hashCode() { 127 return System.identityHashCode(this); 128 } 129 130 134 public final boolean equals(Object o) { 135 return this == o; 136 } 137 } 138 139 HashMap hintmap = new HashMap (7); 140 141 144 public static final Key KEY_ANTIALIASING = 145 SunHints.KEY_ANTIALIASING; 146 147 150 public static final Object VALUE_ANTIALIAS_ON = 151 SunHints.VALUE_ANTIALIAS_ON; 152 153 156 public static final Object VALUE_ANTIALIAS_OFF = 157 SunHints.VALUE_ANTIALIAS_OFF; 158 159 163 public static final Object VALUE_ANTIALIAS_DEFAULT = 164 SunHints.VALUE_ANTIALIAS_DEFAULT; 165 166 169 public static final Key KEY_RENDERING = 170 SunHints.KEY_RENDERING; 171 172 176 public static final Object VALUE_RENDER_SPEED = 177 SunHints.VALUE_RENDER_SPEED; 178 179 183 public static final Object VALUE_RENDER_QUALITY = 184 SunHints.VALUE_RENDER_QUALITY; 185 186 190 public static final Object VALUE_RENDER_DEFAULT = 191 SunHints.VALUE_RENDER_DEFAULT; 192 193 194 197 public static final Key KEY_DITHERING = 198 SunHints.KEY_DITHERING; 199 200 203 public static final Object VALUE_DITHER_DISABLE = 204 SunHints.VALUE_DITHER_DISABLE; 205 206 209 public static final Object VALUE_DITHER_ENABLE = 210 SunHints.VALUE_DITHER_ENABLE; 211 212 215 public static final Object VALUE_DITHER_DEFAULT = 216 SunHints.VALUE_DITHER_DEFAULT; 217 218 221 public static final Key KEY_TEXT_ANTIALIASING = 222 SunHints.KEY_TEXT_ANTIALIASING; 223 224 228 public static final Object VALUE_TEXT_ANTIALIAS_ON = 229 SunHints.VALUE_TEXT_ANTIALIAS_ON; 230 231 235 public static final Object VALUE_TEXT_ANTIALIAS_OFF = 236 SunHints.VALUE_TEXT_ANTIALIAS_OFF; 237 238 242 public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT = 243 SunHints.VALUE_TEXT_ANTIALIAS_DEFAULT; 244 245 248 public static final Key KEY_FRACTIONALMETRICS = 249 SunHints.KEY_FRACTIONALMETRICS; 250 251 254 public static final Object VALUE_FRACTIONALMETRICS_OFF = 255 SunHints.VALUE_FRACTIONALMETRICS_OFF; 256 257 260 public static final Object VALUE_FRACTIONALMETRICS_ON = 261 SunHints.VALUE_FRACTIONALMETRICS_ON; 262 263 267 public static final Object VALUE_FRACTIONALMETRICS_DEFAULT = 268 SunHints.VALUE_FRACTIONALMETRICS_DEFAULT; 269 270 271 274 public static final Key KEY_INTERPOLATION = 275 SunHints.KEY_INTERPOLATION; 276 277 280 public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR = 281 SunHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; 282 283 286 public static final Object VALUE_INTERPOLATION_BILINEAR = 287 SunHints.VALUE_INTERPOLATION_BILINEAR; 288 289 292 public static final Object VALUE_INTERPOLATION_BICUBIC = 293 SunHints.VALUE_INTERPOLATION_BICUBIC; 294 295 298 public static final Key KEY_ALPHA_INTERPOLATION = 299 SunHints.KEY_ALPHA_INTERPOLATION; 300 301 304 public static final Object VALUE_ALPHA_INTERPOLATION_SPEED = 305 SunHints.VALUE_ALPHA_INTERPOLATION_SPEED; 306 307 310 public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY = 311 SunHints.VALUE_ALPHA_INTERPOLATION_QUALITY; 312 313 316 public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT = 317 SunHints.VALUE_ALPHA_INTERPOLATION_DEFAULT; 318 319 322 public static final Key KEY_COLOR_RENDERING = 323 SunHints.KEY_COLOR_RENDERING; 324 325 328 public static final Object VALUE_COLOR_RENDER_SPEED = 329 SunHints.VALUE_COLOR_RENDER_SPEED; 330 331 334 public static final Object VALUE_COLOR_RENDER_QUALITY = 335 SunHints.VALUE_COLOR_RENDER_QUALITY; 336 337 340 public static final Object VALUE_COLOR_RENDER_DEFAULT = 341 SunHints.VALUE_COLOR_RENDER_DEFAULT; 342 343 346 public static final Key KEY_STROKE_CONTROL = 347 SunHints.KEY_STROKE_CONTROL; 348 349 352 public static final Object VALUE_STROKE_DEFAULT = 353 SunHints.VALUE_STROKE_DEFAULT; 354 355 358 public static final Object VALUE_STROKE_NORMALIZE = 359 SunHints.VALUE_STROKE_NORMALIZE; 360 361 364 public static final Object VALUE_STROKE_PURE = 365 SunHints.VALUE_STROKE_PURE; 366 367 373 public RenderingHints(Map <Key,?> init) { 374 if (init != null) { 375 hintmap.putAll(init); 376 } 377 } 378 379 385 public RenderingHints(Key key, Object value) { 386 hintmap.put(key, value); 387 } 388 389 396 public int size() { 397 return hintmap.size(); 398 } 399 400 407 public boolean isEmpty() { 408 return hintmap.isEmpty(); 409 } 410 411 424 public boolean containsKey(Object key) { 425 return hintmap.containsKey((Key) key); 426 } 427 428 446 public boolean containsValue(Object value) { 447 return hintmap.containsValue(value); 448 } 449 450 460 public Object get(Object key) { 461 return hintmap.get((Key) key); 462 } 463 464 482 public Object put(Object key, Object value) { 483 if (!((Key) key).isCompatibleValue(value)) { 484 throw new IllegalArgumentException (value+ 485 " incompatible with "+ 486 key); 487 } 488 return hintmap.put((Key) key, value); 489 } 490 491 500 public void add(RenderingHints hints) { 501 hintmap.putAll(hints.hintmap); 502 } 503 504 508 public void clear() { 509 hintmap.clear(); 510 } 511 512 523 public Object remove(Object key) { 524 return hintmap.remove((Key) key); 525 } 526 527 541 public void putAll(Map <?,?> m) { 542 if (RenderingHints .class.isInstance(m)) { 545 for (Map.Entry <?,?> entry : m.entrySet()) 547 hintmap.put(entry.getKey(), entry.getValue()); 548 } else { 549 for (Map.Entry <?,?> entry : m.entrySet()) 551 put(entry.getKey(), entry.getValue()); 552 } 553 } 554 555 573 public Set <Object > keySet() { 574 return hintmap.keySet(); 575 } 576 577 599 public Collection <Object > values() { 600 return hintmap.values(); 601 } 602 603 620 public Set <Map.Entry <Object ,Object >> entrySet() { 621 return Collections.unmodifiableMap(hintmap).entrySet(); 622 } 623 624 644 public boolean equals(Object o) { 645 if (o instanceof RenderingHints ) { 646 return hintmap.equals(((RenderingHints ) o).hintmap); 647 } else if (o instanceof Map ) { 648 return hintmap.equals(o); 649 } 650 return false; 651 } 652 653 669 public int hashCode() { 670 return hintmap.hashCode(); 671 } 672 673 679 public Object clone() { 680 RenderingHints rh; 681 try { 682 rh = (RenderingHints ) super.clone(); 683 if (hintmap != null) { 684 rh.hintmap = (HashMap ) hintmap.clone(); 685 } 686 } catch (CloneNotSupportedException e) { 687 throw new InternalError (); 689 } 690 691 return rh; 692 } 693 694 700 public String toString() { 701 if (hintmap == null) { 702 return getClass().getName() + "@" + 703 Integer.toHexString(hashCode()) + 704 " (0 hints)"; 705 } 706 707 return hintmap.toString(); 708 } 709 } 710 | Popular Tags |