1 | /* RenderingHints.java --
|
---|
2 | Copyright (C) 2000, 2001, 2002 Free Software Foundation
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
6 | GNU Classpath is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | GNU Classpath is distributed in the hope that it will be useful, but
|
---|
12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
---|
18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA.
|
---|
20 |
|
---|
21 | Linking this library statically or dynamically with other modules is
|
---|
22 | making a combined work based on this library. Thus, the terms and
|
---|
23 | conditions of the GNU General Public License cover the whole
|
---|
24 | combination.
|
---|
25 |
|
---|
26 | As a special exception, the copyright holders of this library give you
|
---|
27 | permission to link this library with independent modules to produce an
|
---|
28 | executable, regardless of the license terms of these independent
|
---|
29 | modules, and to copy and distribute the resulting executable under
|
---|
30 | terms of your choice, provided that you also meet, for each linked
|
---|
31 | independent module, the terms and conditions of the license of that
|
---|
32 | module. An independent module is a module which is not derived from
|
---|
33 | or based on this library. If you modify this library, you may extend
|
---|
34 | this exception to your version of the library, but you are not
|
---|
35 | obligated to do so. If you do not wish to do so, delete this
|
---|
36 | exception statement from your version. */
|
---|
37 |
|
---|
38 |
|
---|
39 | package java.awt;
|
---|
40 |
|
---|
41 | import java.util.Collection;
|
---|
42 | import java.util.Collections;
|
---|
43 | import java.util.HashMap;
|
---|
44 | import java.util.Map;
|
---|
45 | import java.util.Set;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * NEEDS DOCUMENTATION
|
---|
49 | *
|
---|
50 | * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
|
---|
51 | * @author Eric Blake <ebb9@email.byu.edu>
|
---|
52 | */
|
---|
53 | public class RenderingHints implements Map, Cloneable
|
---|
54 | {
|
---|
55 | public abstract static class Key
|
---|
56 | {
|
---|
57 | private final int key;
|
---|
58 |
|
---|
59 | protected Key(int privateKey)
|
---|
60 | {
|
---|
61 | key = privateKey;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public abstract boolean isCompatibleValue(Object value);
|
---|
65 |
|
---|
66 | protected final int intKey()
|
---|
67 | {
|
---|
68 | return key;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public final int hashCode()
|
---|
72 | {
|
---|
73 | return System.identityHashCode(this);
|
---|
74 | }
|
---|
75 |
|
---|
76 | public final boolean equals(Object other)
|
---|
77 | {
|
---|
78 | return this == other;
|
---|
79 | }
|
---|
80 | } // class Key
|
---|
81 |
|
---|
82 | private static final class KeyImpl extends Key
|
---|
83 | {
|
---|
84 | final String description;
|
---|
85 | final Object v1;
|
---|
86 | final Object v2;
|
---|
87 | final Object v3;
|
---|
88 |
|
---|
89 | KeyImpl(int privateKey, String description,
|
---|
90 | Object v1, Object v2, Object v3)
|
---|
91 | {
|
---|
92 | super(privateKey);
|
---|
93 | this.description = description;
|
---|
94 | this.v1 = v1;
|
---|
95 | this.v2 = v2;
|
---|
96 | this.v3 = v3;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public boolean isCompatibleValue(Object value)
|
---|
100 | {
|
---|
101 | return value == v1 || value == v2 || value == v3;
|
---|
102 | }
|
---|
103 |
|
---|
104 | public String toString()
|
---|
105 | {
|
---|
106 | return description;
|
---|
107 | }
|
---|
108 | } // class KeyImpl
|
---|
109 |
|
---|
110 | private HashMap hintMap = new HashMap();
|
---|
111 |
|
---|
112 | public static final Key KEY_ANTIALIASING;
|
---|
113 |
|
---|
114 | public static final Object VALUE_ANTIALIAS_ON
|
---|
115 | = "Antialiased rendering mode";
|
---|
116 |
|
---|
117 | public static final Object VALUE_ANTIALIAS_OFF
|
---|
118 | = "Nonantialiased rendering mode";
|
---|
119 |
|
---|
120 | public static final Object VALUE_ANTIALIAS_DEFAULT
|
---|
121 | = "Default antialiasing rendering mode";
|
---|
122 |
|
---|
123 | public static final Key KEY_RENDERING;
|
---|
124 |
|
---|
125 | public static final Object VALUE_RENDER_SPEED
|
---|
126 | = "Fastest rendering methods";
|
---|
127 |
|
---|
128 | public static final Object VALUE_RENDER_QUALITY
|
---|
129 | = "Highest quality rendering methods";
|
---|
130 |
|
---|
131 | public static final Object VALUE_RENDER_DEFAULT
|
---|
132 | = "Default rendering methods";
|
---|
133 |
|
---|
134 | public static final Key KEY_DITHERING;
|
---|
135 |
|
---|
136 | public static final Object VALUE_DITHER_DISABLE
|
---|
137 | = "Nondithered rendering mode";
|
---|
138 |
|
---|
139 | public static final Object VALUE_DITHER_ENABLE
|
---|
140 | = "Dithered rendering mode";
|
---|
141 |
|
---|
142 | public static final Object VALUE_DITHER_DEFAULT
|
---|
143 | = "Default dithering mode";
|
---|
144 |
|
---|
145 | public static final Key KEY_TEXT_ANTIALIASING;
|
---|
146 |
|
---|
147 | public static final Object VALUE_TEXT_ANTIALIAS_ON
|
---|
148 | = "Antialiased text mode";
|
---|
149 |
|
---|
150 | public static final Object VALUE_TEXT_ANTIALIAS_OFF
|
---|
151 | = "Nonantialiased text mode";
|
---|
152 |
|
---|
153 | public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT
|
---|
154 | = "Default antialiasing text mode";
|
---|
155 |
|
---|
156 | public static final Key KEY_FRACTIONALMETRICS;
|
---|
157 |
|
---|
158 | public static final Object VALUE_FRACTIONALMETRICS_OFF
|
---|
159 | = "Integer text metrics mode";
|
---|
160 |
|
---|
161 | public static final Object VALUE_FRACTIONALMETRICS_ON
|
---|
162 | = "Fractional text metrics mode";
|
---|
163 |
|
---|
164 | public static final Object VALUE_FRACTIONALMETRICS_DEFAULT
|
---|
165 | = "Default fractional text metrics mode";
|
---|
166 |
|
---|
167 | public static final Key KEY_INTERPOLATION;
|
---|
168 |
|
---|
169 | public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR
|
---|
170 | = "Nearest Neighbor image interpolation mode";
|
---|
171 |
|
---|
172 | public static final Object VALUE_INTERPOLATION_BILINEAR
|
---|
173 | = "Bilinear image interpolation mode";
|
---|
174 |
|
---|
175 | public static final Object VALUE_INTERPOLATION_BICUBIC
|
---|
176 | = "Bicubic image interpolation mode";
|
---|
177 |
|
---|
178 | public static final Key KEY_ALPHA_INTERPOLATION;
|
---|
179 |
|
---|
180 | public static final Object VALUE_ALPHA_INTERPOLATION_SPEED
|
---|
181 | = "Fastest alpha blending methods";
|
---|
182 |
|
---|
183 | public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY
|
---|
184 | = "Highest quality alpha blending methods";
|
---|
185 |
|
---|
186 | public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT
|
---|
187 | = "Default alpha blending methods";
|
---|
188 |
|
---|
189 | public static final Key KEY_COLOR_RENDERING;
|
---|
190 |
|
---|
191 | public static final Object VALUE_COLOR_RENDER_SPEED
|
---|
192 | = "Fastest color rendering mode";
|
---|
193 |
|
---|
194 | public static final Object VALUE_COLOR_RENDER_QUALITY
|
---|
195 | = "Highest quality color rendering mode";
|
---|
196 |
|
---|
197 | public static final Object VALUE_COLOR_RENDER_DEFAULT
|
---|
198 | = "Default color rendering mode";
|
---|
199 |
|
---|
200 | public static final Key KEY_STROKE_CONTROL;
|
---|
201 |
|
---|
202 | public static final Object VALUE_STROKE_DEFAULT
|
---|
203 | = "Default stroke normalization";
|
---|
204 |
|
---|
205 | public static final Object VALUE_STROKE_NORMALIZE
|
---|
206 | = "Normalize strokes for consistent rendering";
|
---|
207 |
|
---|
208 | public static final Object VALUE_STROKE_PURE
|
---|
209 | = "Pure stroke conversion for accurate paths";
|
---|
210 |
|
---|
211 | static
|
---|
212 | {
|
---|
213 | KEY_ANTIALIASING = new KeyImpl(1, "Global antialiasing enable key",
|
---|
214 | VALUE_ANTIALIAS_ON,
|
---|
215 | VALUE_ANTIALIAS_OFF,
|
---|
216 | VALUE_ANTIALIAS_DEFAULT);
|
---|
217 | KEY_RENDERING = new KeyImpl(2, "Global rendering quality key",
|
---|
218 | VALUE_RENDER_SPEED,
|
---|
219 | VALUE_RENDER_QUALITY,
|
---|
220 | VALUE_RENDER_DEFAULT);
|
---|
221 | KEY_DITHERING = new KeyImpl(3, "Dithering quality key",
|
---|
222 | VALUE_DITHER_DISABLE,
|
---|
223 | VALUE_DITHER_ENABLE,
|
---|
224 | VALUE_DITHER_DEFAULT);
|
---|
225 | KEY_TEXT_ANTIALIASING
|
---|
226 | = new KeyImpl(4, "Text-specific antialiasing enable key",
|
---|
227 | VALUE_TEXT_ANTIALIAS_ON,
|
---|
228 | VALUE_TEXT_ANTIALIAS_OFF,
|
---|
229 | VALUE_TEXT_ANTIALIAS_DEFAULT);
|
---|
230 | KEY_FRACTIONALMETRICS = new KeyImpl(5, "Fractional metrics enable key",
|
---|
231 | VALUE_FRACTIONALMETRICS_OFF,
|
---|
232 | VALUE_FRACTIONALMETRICS_ON,
|
---|
233 | VALUE_FRACTIONALMETRICS_DEFAULT);
|
---|
234 | KEY_INTERPOLATION = new KeyImpl(6, "Image interpolation method key",
|
---|
235 | VALUE_INTERPOLATION_NEAREST_NEIGHBOR,
|
---|
236 | VALUE_INTERPOLATION_BILINEAR,
|
---|
237 | VALUE_INTERPOLATION_BICUBIC);
|
---|
238 | KEY_ALPHA_INTERPOLATION
|
---|
239 | = new KeyImpl(7, "Alpha blending interpolation method key",
|
---|
240 | VALUE_ALPHA_INTERPOLATION_SPEED,
|
---|
241 | VALUE_ALPHA_INTERPOLATION_QUALITY,
|
---|
242 | VALUE_ALPHA_INTERPOLATION_DEFAULT);
|
---|
243 | KEY_COLOR_RENDERING = new KeyImpl(8, "Color rendering quality key",
|
---|
244 | VALUE_COLOR_RENDER_SPEED,
|
---|
245 | VALUE_COLOR_RENDER_QUALITY,
|
---|
246 | VALUE_COLOR_RENDER_DEFAULT);
|
---|
247 | KEY_STROKE_CONTROL = new KeyImpl(9, "Stroke normalization control key",
|
---|
248 | VALUE_STROKE_DEFAULT,
|
---|
249 | VALUE_STROKE_NORMALIZE,
|
---|
250 | VALUE_STROKE_PURE);
|
---|
251 | }
|
---|
252 |
|
---|
253 | public RenderingHints(Map init)
|
---|
254 | {
|
---|
255 | putAll(init);
|
---|
256 | }
|
---|
257 |
|
---|
258 | public RenderingHints(Key key, Object value)
|
---|
259 | {
|
---|
260 | put(key, value);
|
---|
261 | }
|
---|
262 |
|
---|
263 | public int size()
|
---|
264 | {
|
---|
265 | return hintMap.size();
|
---|
266 | }
|
---|
267 |
|
---|
268 | public boolean isEmpty()
|
---|
269 | {
|
---|
270 | return hintMap.isEmpty();
|
---|
271 | }
|
---|
272 |
|
---|
273 | public boolean containsKey(Object key)
|
---|
274 | {
|
---|
275 | if (key == null)
|
---|
276 | throw new NullPointerException();
|
---|
277 | return hintMap.containsKey((Key) key);
|
---|
278 | }
|
---|
279 |
|
---|
280 | public boolean containsValue(Object value)
|
---|
281 | {
|
---|
282 | return hintMap.containsValue(value);
|
---|
283 | }
|
---|
284 |
|
---|
285 | public Object get(Object key)
|
---|
286 | {
|
---|
287 | return hintMap.get((Key) key);
|
---|
288 | }
|
---|
289 |
|
---|
290 | public Object put(Object key, Object value)
|
---|
291 | {
|
---|
292 | if (key == null || value == null)
|
---|
293 | throw new NullPointerException();
|
---|
294 | if (! ((Key) key).isCompatibleValue(value))
|
---|
295 | throw new IllegalArgumentException();
|
---|
296 | return hintMap.put(key, value);
|
---|
297 | }
|
---|
298 |
|
---|
299 | public void add(RenderingHints hints)
|
---|
300 | {
|
---|
301 | hintMap.putAll(hints);
|
---|
302 | }
|
---|
303 |
|
---|
304 | public void clear()
|
---|
305 | {
|
---|
306 | hintMap.clear();
|
---|
307 | }
|
---|
308 |
|
---|
309 | public Object remove(Object key)
|
---|
310 | {
|
---|
311 | return remove((Key) key);
|
---|
312 | }
|
---|
313 |
|
---|
314 | public void putAll(Map m)
|
---|
315 | {
|
---|
316 | hintMap.putAll(m);
|
---|
317 | }
|
---|
318 |
|
---|
319 | public Set keySet()
|
---|
320 | {
|
---|
321 | return hintMap.keySet();
|
---|
322 | }
|
---|
323 |
|
---|
324 | public Collection values()
|
---|
325 | {
|
---|
326 | return hintMap.values();
|
---|
327 | }
|
---|
328 |
|
---|
329 | public Set entrySet()
|
---|
330 | {
|
---|
331 | return Collections.unmodifiableSet(hintMap.entrySet());
|
---|
332 | }
|
---|
333 |
|
---|
334 | public boolean equals(Object o)
|
---|
335 | {
|
---|
336 | return hintMap.equals(o);
|
---|
337 | }
|
---|
338 |
|
---|
339 | public int hashCode()
|
---|
340 | {
|
---|
341 | return hintMap.hashCode();
|
---|
342 | }
|
---|
343 |
|
---|
344 | public Object clone()
|
---|
345 | {
|
---|
346 | try
|
---|
347 | {
|
---|
348 | RenderingHints copy = (RenderingHints) super.clone();
|
---|
349 | copy.hintMap = (HashMap) hintMap.clone();
|
---|
350 | return copy;
|
---|
351 | }
|
---|
352 | catch (CloneNotSupportedException e)
|
---|
353 | {
|
---|
354 | throw (Error) new InternalError().initCause(e); // Impossible
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | public String toString()
|
---|
359 | {
|
---|
360 | return hintMap.toString();
|
---|
361 | }
|
---|
362 | } // class RenderingHints
|
---|