KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > RenderingHints


1 /*
2  * @(#)RenderingHints.java 1.21 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt;
9
10 import java.util.Map JavaDoc;
11 import java.util.Set JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.Collections JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import sun.awt.SunHints;
17 import java.lang.ref.WeakReference JavaDoc;
18
19 /**
20  * The <code>RenderingHints</code> class contains rendering hints that can
21  * be used by the {@link java.awt.Graphics2D} class, and classes that
22  * implement {@link java.awt.image.BufferedImageOp} and
23  * {@link java.awt.image.Raster}.
24  */

25 public class RenderingHints
26     implements Map JavaDoc<Object JavaDoc,Object JavaDoc>, Cloneable JavaDoc
27 {
28     /**
29      * Defines the base type of all keys used to control various
30      * aspects of the rendering and imaging pipelines. Instances
31      * of this class are immutable and unique which means that
32      * tests for matches can be made using the == operator instead
33      * of the more expensive equals() method.
34      */

35     public abstract static class Key {
36     private static HashMap JavaDoc identitymap = new HashMap JavaDoc(17);
37
38     private String JavaDoc getIdentity() {
39         // Note that the identity string is dependent on 3 variables:
40
// - the name of the subclass of Key
41
// - the identityHashCode of the subclass of Key
42
// - the integer key of the Key
43
// It is theoretically possible for 2 distinct keys to collide
44
// along all 3 of those attributes in the context of multiple
45
// class loaders, but that occurence will be extremely rare and
46
// we account for that possibility below in the recordIdentity
47
// method by slightly relaxing our uniqueness guarantees if we
48
// end up in that situation.
49
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 JavaDoc identity = k.getIdentity();
56         Object JavaDoc otherref = identitymap.get(identity);
57         if (otherref != null) {
58         Key otherkey = (Key) ((WeakReference JavaDoc) otherref).get();
59         if (otherkey != null && otherkey.getClass() == k.getClass()) {
60             throw new IllegalArgumentException JavaDoc(identity+
61                                " already registered");
62         }
63         // Note that this system can fail in a mostly harmless
64
// way. If we end up generating the same identity
65
// String for 2 different classes (a very rare case)
66
// then we correctly avoid throwing the exception above,
67
// but we are about to drop through to a statement that
68
// will replace the entry for the old Key subclass with
69
// an entry for the new Key subclass. At that time the
70
// old subclass will be vulnerable to someone generating
71
// a duplicate Key instance for it. We could bail out
72
// of the method here and let the old identity keep its
73
// record in the map, but we are more likely to see a
74
// duplicate key go by for the new class than the old
75
// one since the new one is probably still in the
76
// initialization stage. In either case, the probability
77
// of loading 2 classes in the same VM with the same name
78
// and identityHashCode should be nearly impossible.
79
}
80         // Note: Use a weak reference to avoid holding on to extra
81
// objects and classes after they should be unloaded.
82
identitymap.put(identity, new WeakReference JavaDoc(k));
83     }
84
85     private int privatekey;
86
87     /**
88      * Construct a key using the indicated private key. Each
89      * subclass of Key maintains its own unique domain of integer
90      * keys. No two objects with the same integer key and of the
91      * same specific subclass can be constructed. An exception
92      * will be thrown if an attempt is made to construct another
93      * object of a given class with the same integer key as a
94      * pre-existing instance of that subclass of Key.
95      * @param privatekey the specified key
96      */

97     protected Key(int privatekey) {
98         this.privatekey = privatekey;
99         recordIdentity(this);
100     }
101
102     /**
103      * Returns true if the specified object is a valid value
104      * for this Key.
105      * @param val the <code>Object</code> to test for validity
106      * @return <code>true</code> if <code>val</code> is valid;
107      * <code>false</code> otherwise.
108      */

109     public abstract boolean isCompatibleValue(Object JavaDoc val);
110
111     /**
112      * Returns the private integer key that the subclass
113      * instantiated this Key with.
114      * @return the private integer key that the subclass
115          * instantiated this Key with.
116      */

117     protected final int intKey() {
118         return privatekey;
119     }
120
121     /**
122      * The hash code for all Key objects will be the same as the
123      * system identity code of the object as defined by the
124      * System.identityHashCode() method.
125      */

126     public final int hashCode() {
127         return System.identityHashCode(this);
128     }
129
130     /**
131      * The equals method for all Key objects will return the same
132      * result as the equality operator '=='.
133      */

134     public final boolean equals(Object JavaDoc o) {
135         return this == o;
136     }
137     }
138
139     HashMap JavaDoc hintmap = new HashMap JavaDoc(7);
140
141     /**
142      * Antialiasing hint key.
143      */

144     public static final Key KEY_ANTIALIASING =
145     SunHints.KEY_ANTIALIASING;
146
147     /**
148      * Antialiasing hint values -- rendering is done with antialiasing.
149      */

150     public static final Object JavaDoc VALUE_ANTIALIAS_ON =
151     SunHints.VALUE_ANTIALIAS_ON;
152
153     /**
154      * Antialiasing hint values -- rendering is done without antialiasing.
155      */

156     public static final Object JavaDoc VALUE_ANTIALIAS_OFF =
157     SunHints.VALUE_ANTIALIAS_OFF;
158
159     /**
160      * Antialiasing hint values -- rendering is done with the platform
161      * default antialiasing mode.
162      */

163     public static final Object JavaDoc VALUE_ANTIALIAS_DEFAULT =
164      SunHints.VALUE_ANTIALIAS_DEFAULT;
165
166     /**
167      * Rendering hint key.
168      */

169     public static final Key KEY_RENDERING =
170      SunHints.KEY_RENDERING;
171
172     /**
173      * Rendering hint values -- Appropriate rendering algorithms are chosen
174      * with a preference for output speed.
175      */

176     public static final Object JavaDoc VALUE_RENDER_SPEED =
177      SunHints.VALUE_RENDER_SPEED;
178
179     /**
180      * Rendering hint values -- Appropriate rendering algorithms are chosen
181      * with a preference for output quality.
182      */

183     public static final Object JavaDoc VALUE_RENDER_QUALITY =
184      SunHints.VALUE_RENDER_QUALITY;
185
186     /**
187      * Rendering hint values -- The platform default rendering algorithms
188      * are chosen.
189      */

190     public static final Object JavaDoc VALUE_RENDER_DEFAULT =
191      SunHints.VALUE_RENDER_DEFAULT;
192
193
194     /**
195      * Dithering hint key.
196      */

197     public static final Key KEY_DITHERING =
198      SunHints.KEY_DITHERING;
199
200     /**
201      * Dithering hint values -- do not dither when rendering.
202      */

203     public static final Object JavaDoc VALUE_DITHER_DISABLE =
204      SunHints.VALUE_DITHER_DISABLE;
205
206     /**
207      * Dithering hint values -- dither when rendering, if needed.
208      */

209     public static final Object JavaDoc VALUE_DITHER_ENABLE =
210      SunHints.VALUE_DITHER_ENABLE;
211
212     /**
213      * Dithering hint values -- use the platform default for dithering.
214      */

215     public static final Object JavaDoc VALUE_DITHER_DEFAULT =
216      SunHints.VALUE_DITHER_DEFAULT;
217
218     /**
219      * Text antialiasing hint key.
220      */

221     public static final Key KEY_TEXT_ANTIALIASING =
222      SunHints.KEY_TEXT_ANTIALIASING;
223
224     /**
225      * Text antialiasing hint value -- text rendering is done with
226      * antialiasing.
227      */

228     public static final Object JavaDoc VALUE_TEXT_ANTIALIAS_ON =
229      SunHints.VALUE_TEXT_ANTIALIAS_ON;
230
231     /**
232      * Text antialiasing hint value -- text rendering is done without
233      * antialiasing.
234      */

235     public static final Object JavaDoc VALUE_TEXT_ANTIALIAS_OFF =
236      SunHints.VALUE_TEXT_ANTIALIAS_OFF;
237
238     /**
239      * Text antialiasing hint value -- text rendering is done using the
240      * platform default text antialiasing mode.
241      */

242     public static final Object JavaDoc VALUE_TEXT_ANTIALIAS_DEFAULT =
243      SunHints.VALUE_TEXT_ANTIALIAS_DEFAULT;
244
245     /**
246      * Font fractional metrics hint key.
247      */

248     public static final Key KEY_FRACTIONALMETRICS =
249      SunHints.KEY_FRACTIONALMETRICS;
250
251     /**
252      * Font fractional metrics hint values -- fractional metrics disabled.
253      */

254     public static final Object JavaDoc VALUE_FRACTIONALMETRICS_OFF =
255      SunHints.VALUE_FRACTIONALMETRICS_OFF;
256
257     /**
258      * Font fractional metrics hint values -- fractional metrics enabled.
259      */

260     public static final Object JavaDoc VALUE_FRACTIONALMETRICS_ON =
261      SunHints.VALUE_FRACTIONALMETRICS_ON;
262
263     /**
264      * Font fractional metrics hint values -- use the platform default for
265      * fractional metrics.
266      */

267     public static final Object JavaDoc VALUE_FRACTIONALMETRICS_DEFAULT =
268      SunHints.VALUE_FRACTIONALMETRICS_DEFAULT;
269
270
271     /**
272      * Interpolation hint key.
273      */

274     public static final Key KEY_INTERPOLATION =
275      SunHints.KEY_INTERPOLATION;
276
277     /**
278      * Interpolation hint value -- INTERPOLATION_NEAREST_NEIGHBOR.
279      */

280     public static final Object JavaDoc VALUE_INTERPOLATION_NEAREST_NEIGHBOR =
281      SunHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
282
283     /**
284      * Interpolation hint value -- INTERPOLATION_BILINEAR.
285      */

286     public static final Object JavaDoc VALUE_INTERPOLATION_BILINEAR =
287      SunHints.VALUE_INTERPOLATION_BILINEAR;
288
289     /**
290      * Interpolation hint value -- INTERPOLATION_BICUBIC.
291      */

292     public static final Object JavaDoc VALUE_INTERPOLATION_BICUBIC =
293      SunHints.VALUE_INTERPOLATION_BICUBIC;
294
295     /**
296      * Alpha interpolation hint key.
297      */

298     public static final Key KEY_ALPHA_INTERPOLATION =
299      SunHints.KEY_ALPHA_INTERPOLATION;
300
301     /**
302      * Alpha interpolation hint value -- ALPHA_INTERPOLATION_SPEED.
303      */

304     public static final Object JavaDoc VALUE_ALPHA_INTERPOLATION_SPEED =
305      SunHints.VALUE_ALPHA_INTERPOLATION_SPEED;
306
307     /**
308      * Alpha interpolation hint value -- ALPHA_INTERPOLATION_QUALITY.
309      */

310     public static final Object JavaDoc VALUE_ALPHA_INTERPOLATION_QUALITY =
311      SunHints.VALUE_ALPHA_INTERPOLATION_QUALITY;
312
313     /**
314      * Alpha interpolation hint value -- ALPHA_INTERPOLATION_DEFAULT.
315      */

316     public static final Object JavaDoc VALUE_ALPHA_INTERPOLATION_DEFAULT =
317      SunHints.VALUE_ALPHA_INTERPOLATION_DEFAULT;
318
319     /**
320      * Color rendering hint key.
321      */

322     public static final Key KEY_COLOR_RENDERING =
323      SunHints.KEY_COLOR_RENDERING;
324
325     /**
326      * Color rendering hint value -- COLOR_RENDER_SPEED.
327      */

328     public static final Object JavaDoc VALUE_COLOR_RENDER_SPEED =
329      SunHints.VALUE_COLOR_RENDER_SPEED;
330
331     /**
332      * Color rendering hint value -- COLOR_RENDER_QUALITY.
333      */

334     public static final Object JavaDoc VALUE_COLOR_RENDER_QUALITY =
335      SunHints.VALUE_COLOR_RENDER_QUALITY;
336
337     /**
338      * Color rendering hint value -- COLOR_RENDER_DEFAULT.
339      */

340     public static final Object JavaDoc VALUE_COLOR_RENDER_DEFAULT =
341      SunHints.VALUE_COLOR_RENDER_DEFAULT;
342
343     /**
344      * Stroke normalization control hint key.
345      */

346     public static final Key KEY_STROKE_CONTROL =
347     SunHints.KEY_STROKE_CONTROL;
348
349     /**
350      * Stroke normalization control hint value -- STROKE_DEFAULT.
351      */

352     public static final Object JavaDoc VALUE_STROKE_DEFAULT =
353     SunHints.VALUE_STROKE_DEFAULT;
354
355     /**
356      * Stroke normalization control hint value -- STROKE_NORMALIZE.
357      */

358     public static final Object JavaDoc VALUE_STROKE_NORMALIZE =
359     SunHints.VALUE_STROKE_NORMALIZE;
360
361     /**
362      * Stroke normalization control hint value -- STROKE_PURE.
363      */

364     public static final Object JavaDoc VALUE_STROKE_PURE =
365     SunHints.VALUE_STROKE_PURE;
366
367     /**
368      * Constructs a new object with keys and values initialized
369      * from the specified Map object (which may be null).
370      * @param init a map of key/value pairs to initialize the hints
371      * or null if the object should be empty
372      */

373     public RenderingHints(Map JavaDoc<Key,?> init) {
374     if (init != null) {
375         hintmap.putAll(init);
376     }
377     }
378
379     /**
380      * Constructs a new object with the specified key/value pair.
381      * @param key the key of the particular hint property
382      * @param value the value of the hint property specified with
383      * <code>key</code>
384      */

385     public RenderingHints(Key key, Object JavaDoc value) {
386     hintmap.put(key, value);
387     }
388
389     /**
390      * Returns the number of key-value mappings in this
391      * <code>RenderingHints</code>.
392      *
393      * @return the number of key-value mappings in this
394      * <code>RenderingHints</code>.
395      */

396     public int size() {
397     return hintmap.size();
398     }
399
400     /**
401      * Returns <code>true</code> if this
402      * <code>RenderingHints</code> contains no key-value mappings.
403      *
404      * @return <code>true</code> if this
405      * <code>RenderingHints</code> contains no key-value mappings.
406      */

407     public boolean isEmpty() {
408     return hintmap.isEmpty();
409     }
410
411     /**
412      * Returns <code>true</code> if this <code>RenderingHints</code>
413      * contains a mapping for the specified key.
414      *
415      * @param key key whose presence in this
416      * <code>RenderingHints</code> is to be tested.
417      * @return <code>true</code> if this <code>RenderingHints</code>
418      * contains a mapping for the specified key.
419      * @exception <code>ClassCastException</code> key is not
420      * of type <code>RenderingHints.Key</code>
421      * @exception <code>NullPointerException</code>
422      * key is <code>null</code>
423      */

424     public boolean containsKey(Object JavaDoc key) {
425     return hintmap.containsKey((Key) key);
426     }
427
428     /**
429      * Returns true if this RenderingHints maps one or more keys to the
430      * specified value.
431      * More formally, returns <code>true</code> if and only
432      * if this <code>RenderingHints</code>
433      * contains at least one mapping to a value <code>v</code> such that
434      * <pre>
435      * (value==null ? v==null : value.equals(v))
436      * </pre>.
437      * This operation will probably require time linear in the
438      * <code>RenderingHints</code> size for most implementations
439      * of <code>RenderingHints</code>.
440      *
441      * @param value value whose presence in this
442      * <code>RenderingHints</code> is to be tested.
443      * @return <code>true</code> if this <code>RenderingHints</code>
444      * maps one or more keys to the specified value.
445      */

446     public boolean containsValue(Object JavaDoc value) {
447     return hintmap.containsValue(value);
448     }
449
450     /**
451      * Returns the value to which the specified key is mapped.
452      * @param key a rendering hint key
453      * @return the value to which the key is mapped in this object or
454      * <code>null</code> if the key is not mapped to any value in
455      * this object.
456      * @exception <code>ClassCastException</code> key is not of
457      * type <code>RenderingHints.Key</code>.
458      * @see #put(Object, Object)
459      */

460     public Object JavaDoc get(Object JavaDoc key) {
461     return hintmap.get((Key) key);
462     }
463
464     /**
465      * Maps the specified <code>key</code> to the specified
466      * <code>value</code> in this <code>RenderingHints</code> object.
467      * Neither the key nor the value can be <code>null</code>.
468      * The value can be retrieved by calling the <code>get</code> method
469      * with a key that is equal to the original key.
470      * @param key the rendering hint key.
471      * @param value the rendering hint value.
472      * @return the previous value of the specified key in this object
473      * or <code>null</code> if it did not have one.
474      * @exception <code>NullPointerException</code> if the key or value is
475      * <code>null</code>.
476      * @exception <code>ClassCastException</code> key is not of
477      * type <code>RenderingHints.Key</code>.
478      * @exception <code>IllegalArgumentException</code> value is not
479      * appropriate for the specified key.
480      * @see #get(Object)
481      */

482     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
483     if (!((Key) key).isCompatibleValue(value)) {
484         throw new IllegalArgumentException JavaDoc(value+
485                            " incompatible with "+
486                            key);
487     }
488         return hintmap.put((Key) key, value);
489     }
490
491     /**
492      * Adds all of the keys and corresponding values from the specified
493      * <code>RenderingHints</code> object to this
494      * <code>RenderingHints</code> object. Keys that are present in
495      * this <code>RenderingHints</code> object, but not in the specified
496      * <code>RenderingHints</code> object are not affected.
497      * @param hints the set of key/value pairs to be added to this
498      * <code>RenderingHints</code> object
499      */

500     public void add(RenderingHints JavaDoc hints) {
501     hintmap.putAll(hints.hintmap);
502     }
503
504     /**
505      * Clears this <code>RenderingHints</code> object of all key/value
506      * pairs.
507      */

508     public void clear() {
509     hintmap.clear();
510     }
511
512     /**
513      * Removes the key and its corresponding value from this
514      * <code>RenderingHints</code> object. This method does nothing if the
515      * key is not in this <code>RenderingHints</code> object.
516      * @param key the rendering hints key that needs to be removed
517      * @exception <code>ClassCastException</code> key is not of
518      * type <code>RenderingHints.Key</code>.
519      * @return the value to which the key had previously been mapped in this
520      * <code>RenderingHints</code> object, or <code>null</code>
521      * if the key did not have a mapping.
522      */

523     public Object JavaDoc remove(Object JavaDoc key) {
524     return hintmap.remove((Key) key);
525     }
526
527     /**
528      * Copies all of the mappings from the specified <code>Map</code>
529      * to this <code>RenderingHints</code>. These mappings replace
530      * any mappings that this <code>RenderingHints</code> had for any
531      * of the keys currently in the specified <code>Map</code>.
532      * @param m the specified <code>Map</code>
533      * @exception <code>ClassCastException</code> class of a key or value
534      * in the specified <code>Map</code> prevents it from being
535      * stored in this <code>RenderingHints</code>.
536      * @exception <code>IllegalArgumentException</code> some aspect
537      * of a key or value in the specified <code>Map</code>
538      * prevents it from being stored in
539      * this <code>RenderingHints</code>.
540      */

541     public void putAll(Map JavaDoc<?,?> m) {
542     // ## javac bug?
543
//if (m instanceof RenderingHints) {
544
if (RenderingHints JavaDoc.class.isInstance(m)) {
545         //hintmap.putAll(((RenderingHints) m).hintmap);
546
for (Map.Entry JavaDoc<?,?> entry : m.entrySet())
547         hintmap.put(entry.getKey(), entry.getValue());
548     } else {
549         // Funnel each key/value pair through our protected put method
550
for (Map.Entry JavaDoc<?,?> entry : m.entrySet())
551         put(entry.getKey(), entry.getValue());
552     }
553     }
554
555     /**
556      * Returns a <code>Set</code> view of the Keys contained in this
557      * <code>RenderingHints</code>. The Set is backed by the
558      * <code>RenderingHints</code>, so changes to the
559      * <code>RenderingHints</code> are reflected in the <code>Set</code>,
560      * and vice-versa. If the <code>RenderingHints</code> is modified
561      * while an iteration over the <code>Set</code> is in progress,
562      * the results of the iteration are undefined. The <code>Set</code>
563      * supports element removal, which removes the corresponding
564      * mapping from the <code>RenderingHints</code>, via the
565      * <code>Iterator.remove</code>, <code>Set.remove</code>,
566      * <code>removeAll</code> <code>retainAll</code>, and
567      * <code>clear</code> operations. It does not support
568      * the <code>add</code> or <code>addAll</code> operations.
569      *
570      * @return a <code>Set</code> view of the keys contained
571      * in this <code>RenderingHints</code>.
572      */

573     public Set JavaDoc<Object JavaDoc> keySet() {
574     return hintmap.keySet();
575     }
576
577     /**
578      * Returns a <code>Collection</code> view of the values
579      * contained in this <code>RenderinHints</code>.
580      * The <code>Collection</code> is backed by the
581      * <code>RenderingHints</code>, so changes to
582      * the <code>RenderingHints</code> are reflected in
583      * the <code>Collection</code>, and vice-versa.
584      * If the <code>RenderingHints</code> is modified while
585      * an iteration over the <code>Collection</code> is
586      * in progress, the results of the iteration are undefined.
587      * The <code>Collection</code> supports element removal,
588      * which removes the corresponding mapping from the
589      * <code>RenderingHints</code>, via the
590      * <code>Iterator.remove</code>,
591      * <code>Collection.remove</code>, <code>removeAll</code>,
592      * <code>retainAll</code> and <code>clear</code> operations.
593      * It does not support the <code>add</code> or
594      * <code>addAll</code> operations.
595      *
596      * @return a <code>Collection</code> view of the values
597      * contained in this <code>RenderingHints</code>.
598      */

599     public Collection JavaDoc<Object JavaDoc> values() {
600     return hintmap.values();
601     }
602
603     /**
604      * Returns a <code>Set</code> view of the mappings contained
605      * in this <code>RenderingHints</code>. Each element in the
606      * returned <code>Set</code> is a <code>Map.Entry</code>.
607      * The <code>Set</code> is backed by the <code>RenderingHints</code>,
608      * so changes to the <code>RenderingHints</code> are reflected
609      * in the <code>Set</code>, and vice-versa. If the
610      * <code>RenderingHints</code> is modified while
611      * while an iteration over the <code>Set</code> is in progress,
612      * the results of the iteration are undefined.
613      * <p>
614      * The entrySet returned from a <code>RenderingHints</code> object
615      * is not modifiable.
616      *
617      * @return a <code>Set</code> view of the mappings contained in
618      * this <code>RenderingHints</code>.
619      */

620     public Set JavaDoc<Map.Entry JavaDoc<Object JavaDoc,Object JavaDoc>> entrySet() {
621     return Collections.unmodifiableMap(hintmap).entrySet();
622     }
623
624     /**
625      * Compares the specified <code>Object</code> with this
626      * <code>RenderingHints</code> for equality.
627      * Returns <code>true</code> if the specified object is also a
628      * <code>Map</code> and the two <code>Map</code> objects represent
629      * the same mappings. More formally, two <code>Map</code> objects
630      * <code>t1</code> and <code>t2</code> represent the same mappings
631      * if <code>t1.keySet().equals(t2.keySet())</code> and for every
632      * key <code>k</code> in <code>t1.keySet()</code>,
633      * <pre>
634      * (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k)))
635      * </pre>.
636      * This ensures that the <code>equals</code> method works properly across
637      * different implementations of the <code>Map</code> interface.
638      *
639      * @param o <code>Object</code> to be compared for equality with
640      * this <code>RenderingHints</code>.
641      * @return <code>true</code> if the specified <code>Object</code>
642      * is equal to this <code>RenderingHints</code>.
643      */

644     public boolean equals(Object JavaDoc o) {
645     if (o instanceof RenderingHints JavaDoc) {
646         return hintmap.equals(((RenderingHints JavaDoc) o).hintmap);
647     } else if (o instanceof Map JavaDoc) {
648         return hintmap.equals(o);
649     }
650     return false;
651     }
652
653     /**
654      * Returns the hash code value for this <code>RenderingHints</code>.
655      * The hash code of a <code>RenderingHints</code> is defined to be
656      * the sum of the hashCodes of each <code>Entry</code> in the
657      * <code>RenderingHints</code> object's entrySet view. This ensures that
658      * <code>t1.equals(t2)</code> implies that
659      * <code>t1.hashCode()==t2.hashCode()</code> for any two <code>Map</code>
660      * objects <code>t1</code> and <code>t2</code>, as required by the general
661      * contract of <code>Object.hashCode</code>.
662      *
663      * @return the hash code value for this <code>RenderingHints</code>.
664      * @see java.util.Map.Entry#hashCode()
665      * @see Object#hashCode()
666      * @see Object#equals(Object)
667      * @see #equals(Object)
668      */

669     public int hashCode() {
670     return hintmap.hashCode();
671     }
672
673     /**
674      * Creates a clone of this <code>RenderingHints</code> object
675      * that has the same contents as this <code>RenderingHints</code>
676      * object.
677      * @return a clone of this instance.
678      */

679     public Object JavaDoc clone() {
680         RenderingHints JavaDoc rh;
681         try {
682             rh = (RenderingHints JavaDoc) super.clone();
683         if (hintmap != null) {
684         rh.hintmap = (HashMap JavaDoc) hintmap.clone();
685         }
686         } catch (CloneNotSupportedException JavaDoc e) {
687         // this shouldn't happen, since we are Cloneable
688
throw new InternalError JavaDoc();
689     }
690
691         return rh;
692     }
693
694     /**
695      * Returns a rather long string representation of the hashmap
696      * which contains the mappings of keys to values for this
697      * <code>RenderingHints</code> object.
698      * @return a string representation of this object.
699      */

700     public String JavaDoc 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