001: /*
002: * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt;
027:
028: import java.awt.RenderingHints;
029:
030: /**
031: * This class contains rendering hints that can be used by the
032: * {@link java.awt.Graphics2D} class, and classes that implement
033: * {@link java.awt.image.BufferedImageOp} and
034: * {@link java.awt.image.Raster}.
035: */
036: public class SunHints {
037: /**
038: * Defines the type of all keys used to control various
039: * aspects of the rendering and imaging pipelines. Instances
040: * of this class are immutable and unique which means that
041: * tests for matches can be made using the == operator instead
042: * of the more expensive equals() method.
043: */
044: public static class Key extends RenderingHints.Key {
045: String description;
046:
047: /**
048: * Construct a key using the indicated private key. Each
049: * subclass of Key maintains its own unique domain of integer
050: * keys. No two objects with the same integer key and of the
051: * same specific subclass can be constructed. An exception
052: * will be thrown if an attempt is made to construct another
053: * object of a given class with the same integer key as a
054: * pre-existing instance of that subclass of Key.
055: */
056: public Key(int privatekey, String description) {
057: super (privatekey);
058: this .description = description;
059: }
060:
061: /**
062: * Returns the numeric index associated with this Key. This
063: * is useful for use in switch statements and quick lookups
064: * of the setting of a particular key.
065: */
066: public final int getIndex() {
067: return intKey();
068: }
069:
070: /**
071: * Returns a string representation of the Key.
072: */
073: public final String toString() {
074: return description;
075: }
076:
077: /**
078: * Returns true if the specified object is a valid value
079: * for this Key.
080: */
081: public boolean isCompatibleValue(Object val) {
082: if (val instanceof Value) {
083: return ((Value) val).isCompatibleKey(this );
084: }
085: return false;
086: }
087: }
088:
089: /**
090: * Defines the type of all "enumerative" values used to control
091: * various aspects of the rendering and imaging pipelines. Instances
092: * of this class are immutable and unique which means that
093: * tests for matches can be made using the == operator instead
094: * of the more expensive equals() method.
095: */
096: public static class Value {
097: private SunHints.Key myKey;
098: private int index;
099: private String description;
100:
101: private static Value[][] ValueObjects = new Value[NUM_KEYS][VALS_PER_KEY];
102:
103: private synchronized static void register(SunHints.Key key,
104: Value value) {
105: int kindex = key.getIndex();
106: int vindex = value.getIndex();
107: if (ValueObjects[kindex][vindex] != null) {
108: throw new InternalError("duplicate index: " + vindex);
109: }
110: ValueObjects[kindex][vindex] = value;
111: }
112:
113: public static Value get(int keyindex, int valueindex) {
114: return ValueObjects[keyindex][valueindex];
115: }
116:
117: /**
118: * Construct a value using the indicated private index. Each
119: * subclass of Value maintains its own unique domain of integer
120: * indices. Enforcing the uniqueness of the integer indices
121: * is left to the subclass.
122: */
123: public Value(SunHints.Key key, int index, String description) {
124: this .myKey = key;
125: this .index = index;
126: this .description = description;
127:
128: register(key, this );
129: }
130:
131: /**
132: * Returns the numeric index associated with this Key. This
133: * is useful for use in switch statements and quick lookups
134: * of the setting of a particular key.
135: */
136: public final int getIndex() {
137: return index;
138: }
139:
140: /**
141: * Returns a string representation of this Value.
142: */
143: public final String toString() {
144: return description;
145: }
146:
147: /**
148: * Returns true if the specified object is a valid Key
149: * for this Value.
150: */
151: public final boolean isCompatibleKey(Key k) {
152: return myKey == k;
153: }
154:
155: /**
156: * The hash code for all SunHints.Value objects will be the same
157: * as the system identity code of the object as defined by the
158: * System.identityHashCode() method.
159: */
160: public final int hashCode() {
161: return System.identityHashCode(this );
162: }
163:
164: /**
165: * The equals method for all SunHints.Value objects will return
166: * the same result as the equality operator '=='.
167: */
168: public final boolean equals(Object o) {
169: return this == o;
170: }
171: }
172:
173: private static final int NUM_KEYS = 9;
174: private static final int VALS_PER_KEY = 8;
175:
176: /**
177: * Rendering hint key and values
178: */
179: public static final int INTKEY_RENDERING = 0;
180: public static final int INTVAL_RENDER_DEFAULT = 0;
181: public static final int INTVAL_RENDER_SPEED = 1;
182: public static final int INTVAL_RENDER_QUALITY = 2;
183:
184: /**
185: * Antialiasing hint key and values
186: */
187: public static final int INTKEY_ANTIALIASING = 1;
188: public static final int INTVAL_ANTIALIAS_DEFAULT = 0;
189: public static final int INTVAL_ANTIALIAS_OFF = 1;
190: public static final int INTVAL_ANTIALIAS_ON = 2;
191:
192: /**
193: * Text antialiasing hint key and values
194: */
195: public static final int INTKEY_TEXT_ANTIALIASING = 2;
196: public static final int INTVAL_TEXT_ANTIALIAS_DEFAULT = 0;
197: public static final int INTVAL_TEXT_ANTIALIAS_OFF = 1;
198: public static final int INTVAL_TEXT_ANTIALIAS_ON = 2;
199: public static final int INTVAL_TEXT_ANTIALIAS_GASP = 3;
200: public static final int INTVAL_TEXT_ANTIALIAS_LCD_HRGB = 4;
201: public static final int INTVAL_TEXT_ANTIALIAS_LCD_HBGR = 5;
202: public static final int INTVAL_TEXT_ANTIALIAS_LCD_VRGB = 6;
203: public static final int INTVAL_TEXT_ANTIALIAS_LCD_VBGR = 7;
204:
205: /**
206: * Font fractional metrics hint key and values
207: */
208: public static final int INTKEY_FRACTIONALMETRICS = 3;
209: public static final int INTVAL_FRACTIONALMETRICS_DEFAULT = 0;
210: public static final int INTVAL_FRACTIONALMETRICS_OFF = 1;
211: public static final int INTVAL_FRACTIONALMETRICS_ON = 2;
212:
213: /**
214: * Dithering hint key and values
215: */
216: public static final int INTKEY_DITHERING = 4;
217: public static final int INTVAL_DITHER_DEFAULT = 0;
218: public static final int INTVAL_DITHER_DISABLE = 1;
219: public static final int INTVAL_DITHER_ENABLE = 2;
220:
221: /**
222: * Interpolation hint key and values
223: */
224: public static final int INTKEY_INTERPOLATION = 5;
225: public static final int INTVAL_INTERPOLATION_NEAREST_NEIGHBOR = 0;
226: public static final int INTVAL_INTERPOLATION_BILINEAR = 1;
227: public static final int INTVAL_INTERPOLATION_BICUBIC = 2;
228:
229: /**
230: * Alpha interpolation hint key and values
231: */
232: public static final int INTKEY_ALPHA_INTERPOLATION = 6;
233: public static final int INTVAL_ALPHA_INTERPOLATION_DEFAULT = 0;
234: public static final int INTVAL_ALPHA_INTERPOLATION_SPEED = 1;
235: public static final int INTVAL_ALPHA_INTERPOLATION_QUALITY = 2;
236:
237: /**
238: * Color rendering hint key and values
239: */
240: public static final int INTKEY_COLOR_RENDERING = 7;
241: public static final int INTVAL_COLOR_RENDER_DEFAULT = 0;
242: public static final int INTVAL_COLOR_RENDER_SPEED = 1;
243: public static final int INTVAL_COLOR_RENDER_QUALITY = 2;
244:
245: /**
246: * Stroke normalization control hint key and values
247: */
248: public static final int INTKEY_STROKE_CONTROL = 8;
249: public static final int INTVAL_STROKE_DEFAULT = 0;
250: public static final int INTVAL_STROKE_NORMALIZE = 1;
251: public static final int INTVAL_STROKE_PURE = 2;
252:
253: /**
254: * LCD text contrast control hint key.
255: * Value is "100" to make discontiguous with the others which
256: * are all enumerative and are of a different class.
257: */
258: public static final int INTKEY_AATEXT_LCD_CONTRAST = 100;
259:
260: /**
261: * Rendering hint key and value objects
262: */
263: public static final Key KEY_RENDERING = new SunHints.Key(
264: SunHints.INTKEY_RENDERING, "Global rendering quality key");
265: public static final Object VALUE_RENDER_SPEED = new SunHints.Value(
266: KEY_RENDERING, SunHints.INTVAL_RENDER_SPEED,
267: "Fastest rendering methods");
268: public static final Object VALUE_RENDER_QUALITY = new SunHints.Value(
269: KEY_RENDERING, SunHints.INTVAL_RENDER_QUALITY,
270: "Highest quality rendering methods");
271: public static final Object VALUE_RENDER_DEFAULT = new SunHints.Value(
272: KEY_RENDERING, SunHints.INTVAL_RENDER_DEFAULT,
273: "Default rendering methods");
274:
275: /**
276: * Antialiasing hint key and value objects
277: */
278: public static final Key KEY_ANTIALIASING = new SunHints.Key(
279: SunHints.INTKEY_ANTIALIASING,
280: "Global antialiasing enable key");
281: public static final Object VALUE_ANTIALIAS_ON = new SunHints.Value(
282: KEY_ANTIALIASING, SunHints.INTVAL_ANTIALIAS_ON,
283: "Antialiased rendering mode");
284: public static final Object VALUE_ANTIALIAS_OFF = new SunHints.Value(
285: KEY_ANTIALIASING, SunHints.INTVAL_ANTIALIAS_OFF,
286: "Nonantialiased rendering mode");
287: public static final Object VALUE_ANTIALIAS_DEFAULT = new SunHints.Value(
288: KEY_ANTIALIASING, SunHints.INTVAL_ANTIALIAS_DEFAULT,
289: "Default antialiasing rendering mode");
290:
291: /**
292: * Text antialiasing hint key and value objects
293: */
294: public static final Key KEY_TEXT_ANTIALIASING = new SunHints.Key(
295: SunHints.INTKEY_TEXT_ANTIALIASING,
296: "Text-specific antialiasing enable key");
297: public static final Object VALUE_TEXT_ANTIALIAS_ON = new SunHints.Value(
298: KEY_TEXT_ANTIALIASING, SunHints.INTVAL_TEXT_ANTIALIAS_ON,
299: "Antialiased text mode");
300: public static final Object VALUE_TEXT_ANTIALIAS_OFF = new SunHints.Value(
301: KEY_TEXT_ANTIALIASING, SunHints.INTVAL_TEXT_ANTIALIAS_OFF,
302: "Nonantialiased text mode");
303: public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT = new SunHints.Value(
304: KEY_TEXT_ANTIALIASING,
305: SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT,
306: "Default antialiasing text mode");
307: public static final Object VALUE_TEXT_ANTIALIAS_GASP = new SunHints.Value(
308: KEY_TEXT_ANTIALIASING, SunHints.INTVAL_TEXT_ANTIALIAS_GASP,
309: "gasp antialiasing text mode");
310: public static final Object VALUE_TEXT_ANTIALIAS_LCD_HRGB = new SunHints.Value(
311: KEY_TEXT_ANTIALIASING,
312: SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB,
313: "LCD HRGB antialiasing text mode");
314: public static final Object VALUE_TEXT_ANTIALIAS_LCD_HBGR = new SunHints.Value(
315: KEY_TEXT_ANTIALIASING,
316: SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HBGR,
317: "LCD HBGR antialiasing text mode");
318: public static final Object VALUE_TEXT_ANTIALIAS_LCD_VRGB = new SunHints.Value(
319: KEY_TEXT_ANTIALIASING,
320: SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB,
321: "LCD VRGB antialiasing text mode");
322: public static final Object VALUE_TEXT_ANTIALIAS_LCD_VBGR = new SunHints.Value(
323: KEY_TEXT_ANTIALIASING,
324: SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VBGR,
325: "LCD VBGR antialiasing text mode");
326:
327: /**
328: * Font fractional metrics hint key and value objects
329: */
330: public static final Key KEY_FRACTIONALMETRICS = new SunHints.Key(
331: SunHints.INTKEY_FRACTIONALMETRICS,
332: "Fractional metrics enable key");
333: public static final Object VALUE_FRACTIONALMETRICS_ON = new SunHints.Value(
334: KEY_FRACTIONALMETRICS,
335: SunHints.INTVAL_FRACTIONALMETRICS_ON,
336: "Fractional text metrics mode");
337: public static final Object VALUE_FRACTIONALMETRICS_OFF = new SunHints.Value(
338: KEY_FRACTIONALMETRICS,
339: SunHints.INTVAL_FRACTIONALMETRICS_OFF,
340: "Integer text metrics mode");
341: public static final Object VALUE_FRACTIONALMETRICS_DEFAULT = new SunHints.Value(
342: KEY_FRACTIONALMETRICS,
343: SunHints.INTVAL_FRACTIONALMETRICS_DEFAULT,
344: "Default fractional text metrics mode");
345:
346: /**
347: * Dithering hint key and value objects
348: */
349: public static final Key KEY_DITHERING = new SunHints.Key(
350: SunHints.INTKEY_DITHERING, "Dithering quality key");
351: public static final Object VALUE_DITHER_ENABLE = new SunHints.Value(
352: KEY_DITHERING, SunHints.INTVAL_DITHER_ENABLE,
353: "Dithered rendering mode");
354: public static final Object VALUE_DITHER_DISABLE = new SunHints.Value(
355: KEY_DITHERING, SunHints.INTVAL_DITHER_DISABLE,
356: "Nondithered rendering mode");
357: public static final Object VALUE_DITHER_DEFAULT = new SunHints.Value(
358: KEY_DITHERING, SunHints.INTVAL_DITHER_DEFAULT,
359: "Default dithering mode");
360:
361: /**
362: * Interpolation hint key and value objects
363: */
364: public static final Key KEY_INTERPOLATION = new SunHints.Key(
365: SunHints.INTKEY_INTERPOLATION,
366: "Image interpolation method key");
367: public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR = new SunHints.Value(
368: KEY_INTERPOLATION,
369: SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR,
370: "Nearest Neighbor image interpolation mode");
371: public static final Object VALUE_INTERPOLATION_BILINEAR = new SunHints.Value(
372: KEY_INTERPOLATION, SunHints.INTVAL_INTERPOLATION_BILINEAR,
373: "Bilinear image interpolation mode");
374: public static final Object VALUE_INTERPOLATION_BICUBIC = new SunHints.Value(
375: KEY_INTERPOLATION, SunHints.INTVAL_INTERPOLATION_BICUBIC,
376: "Bicubic image interpolation mode");
377:
378: /**
379: * Alpha interpolation hint key and value objects
380: */
381: public static final Key KEY_ALPHA_INTERPOLATION = new SunHints.Key(
382: SunHints.INTKEY_ALPHA_INTERPOLATION,
383: "Alpha blending interpolation method key");
384: public static final Object VALUE_ALPHA_INTERPOLATION_SPEED = new SunHints.Value(
385: KEY_ALPHA_INTERPOLATION,
386: SunHints.INTVAL_ALPHA_INTERPOLATION_SPEED,
387: "Fastest alpha blending methods");
388: public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY = new SunHints.Value(
389: KEY_ALPHA_INTERPOLATION,
390: SunHints.INTVAL_ALPHA_INTERPOLATION_QUALITY,
391: "Highest quality alpha blending methods");
392: public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT = new SunHints.Value(
393: KEY_ALPHA_INTERPOLATION,
394: SunHints.INTVAL_ALPHA_INTERPOLATION_DEFAULT,
395: "Default alpha blending methods");
396:
397: /**
398: * Color rendering hint key and value objects
399: */
400: public static final Key KEY_COLOR_RENDERING = new SunHints.Key(
401: SunHints.INTKEY_COLOR_RENDERING,
402: "Color rendering quality key");
403: public static final Object VALUE_COLOR_RENDER_SPEED = new SunHints.Value(
404: KEY_COLOR_RENDERING, SunHints.INTVAL_COLOR_RENDER_SPEED,
405: "Fastest color rendering mode");
406: public static final Object VALUE_COLOR_RENDER_QUALITY = new SunHints.Value(
407: KEY_COLOR_RENDERING, SunHints.INTVAL_COLOR_RENDER_QUALITY,
408: "Highest quality color rendering mode");
409: public static final Object VALUE_COLOR_RENDER_DEFAULT = new SunHints.Value(
410: KEY_COLOR_RENDERING, SunHints.INTVAL_COLOR_RENDER_DEFAULT,
411: "Default color rendering mode");
412:
413: /**
414: * Stroke normalization control hint key and value objects
415: */
416: public static final Key KEY_STROKE_CONTROL = new SunHints.Key(
417: SunHints.INTKEY_STROKE_CONTROL,
418: "Stroke normalization control key");
419: public static final Object VALUE_STROKE_DEFAULT = new SunHints.Value(
420: KEY_STROKE_CONTROL, SunHints.INTVAL_STROKE_DEFAULT,
421: "Default stroke normalization");
422: public static final Object VALUE_STROKE_NORMALIZE = new SunHints.Value(
423: KEY_STROKE_CONTROL, SunHints.INTVAL_STROKE_NORMALIZE,
424: "Normalize strokes for consistent rendering");
425: public static final Object VALUE_STROKE_PURE = new SunHints.Value(
426: KEY_STROKE_CONTROL, SunHints.INTVAL_STROKE_PURE,
427: "Pure stroke conversion for accurate paths");
428:
429: public static class LCDContrastKey extends Key {
430:
431: public LCDContrastKey(int privatekey, String description) {
432: super (privatekey, description);
433: }
434:
435: /**
436: * Returns true if the specified object is a valid value
437: * for this Key. The allowable range is 100 to 250.
438: */
439: public final boolean isCompatibleValue(Object val) {
440: if (val instanceof Integer) {
441: int ival = ((Integer) val).intValue();
442: return ival >= 100 && ival <= 250;
443: }
444: return false;
445: }
446:
447: }
448:
449: /**
450: * LCD text contrast hint key
451: */
452: public static final RenderingHints.Key KEY_TEXT_ANTIALIAS_LCD_CONTRAST = new LCDContrastKey(
453: SunHints.INTKEY_AATEXT_LCD_CONTRAST,
454: "Text-specific LCD contrast key");
455: }
|