Source Code Cross Referenced for SurfaceType.java in  » 6.0-JDK-Modules-sun » java2d » sun » java2d » loops » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules sun » java2d » sun.java2d.loops 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2007 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.java2d.loops;
027:
028:        import java.awt.image.BufferedImage;
029:        import java.awt.image.ColorModel;
030:        import sun.awt.image.PixelConverter;
031:        import java.util.HashMap;
032:
033:        /**
034:         * A SurfaceType object provides a chained description of a type of
035:         * drawing surface.  The object will provide a single String constant
036:         * descriptor which is one way of viewing or accessing a particular
037:         * drawing surface as well as a pointer to another SurfaceType which
038:         * describes the same drawing surface in a different (typically more
039:         * generalized) way.
040:         * <p>
041:         * A more specific description of a surface is considered a "subtype"
042:         * and a more general description is considered a "supertype".  Thus,
043:         * the deriveSubType method provides a way to create a new SurfaceType
044:         * that is related to but more specific than an existing SurfaceType and
045:         * the getSuperType method provides a way to ask a given SurfaceType
046:         * for a more general way to describe the same surface.
047:         * <p>
048:         * Note that you cannot construct a brand new root for a chain since
049:         * the constructor is private.  Every chain of types must at some point
050:         * derive from the Any node provided here using the deriveSubType()
051:         * method.  The presence of this common Any node on every chain
052:         * ensures that all chains end with the DESC_ANY descriptor so that
053:         * a suitable General GraphicsPrimitive object can be obtained for
054:         * the indicated surface if all of the more specific searches fail.
055:         */
056:        public final class SurfaceType {
057:
058:            private static int unusedUID = 1;
059:            private static HashMap surfaceUIDMap = new HashMap(100);
060:
061:            /*
062:             * CONSTANTS USED BY ALL PRIMITIVES TO DESCRIBE THE SURFACES
063:             * THEY CAN OPERATE ON
064:             */
065:
066:            /**
067:             * surface is unknown color model or sample model.
068:             */
069:            public static final String DESC_ANY = "Any Surface";
070:
071:            /**
072:             * common surface formats defined in BufferedImage
073:             */
074:            public static final String DESC_INT_RGB = "Integer RGB";
075:            public static final String DESC_INT_ARGB = "Integer ARGB";
076:            public static final String DESC_INT_ARGB_PRE = "Integer ARGB Premultiplied";
077:            public static final String DESC_INT_BGR = "Integer BGR";
078:            public static final String DESC_3BYTE_BGR = "3 Byte BGR";
079:            public static final String DESC_4BYTE_ABGR = "4 Byte ABGR";
080:            public static final String DESC_4BYTE_ABGR_PRE = "4 Byte ABGR Premultiplied";
081:            public static final String DESC_USHORT_565_RGB = "Short 565 RGB";
082:            public static final String DESC_USHORT_555_RGB = "Short 555 RGB";
083:            public static final String DESC_USHORT_555_RGBx = "Short 555 RGBx";
084:            public static final String DESC_USHORT_4444_ARGB = "Short 4444 ARGB";
085:            public static final String DESC_BYTE_GRAY = "8-bit Gray";
086:            public static final String DESC_USHORT_INDEXED = "16-bit Indexed";
087:            public static final String DESC_USHORT_GRAY = "16-bit Gray";
088:            public static final String DESC_BYTE_BINARY = "Packed Binary Bitmap";
089:            public static final String DESC_BYTE_INDEXED = "8-bit Indexed";
090:
091:            /**
092:             * wildcard format which indicates that the GraphicsPrimitive
093:             * is independent of the color model on an IntegerComponent
094:             * sample model surface
095:             */
096:            public static final String DESC_ANY_INT = "Any Discrete Integer";
097:
098:            /**
099:             * wildcard format which indicates that the GraphicsPrimitive
100:             * is independent of the color model on a ShortComponent
101:             * sample model surface
102:             */
103:            public static final String DESC_ANY_SHORT = "Any Discrete Short";
104:
105:            /**
106:             * wildcard format which indicates that the GraphicsPrimitive
107:             * is independent of the color model on a ByteComponent
108:             * sample model surface
109:             */
110:            public static final String DESC_ANY_BYTE = "Any Discrete Byte";
111:
112:            /**
113:             * wildcard format which indicates that the GraphicsPrimitive
114:             * operates on a surface with 3 component interleaved Raster and
115:             * sample model and a ComponentColorModel with an arbitrary ordering
116:             * of the RGB channels
117:             */
118:            public static final String DESC_ANY_3BYTE = "Any 3 Byte Component";
119:
120:            /**
121:             * wildcard format which indicates that the GraphicsPrimitive
122:             * operates on a surface with 4 component interleaved Raster and
123:             * sample model and a ComponentColorModel with an arbitrary ordering
124:             * of the ARGB channels
125:             */
126:            public static final String DESC_ANY_4BYTE = "Any 4 Byte Component";
127:
128:            /**
129:             * wildcard format which indicates that the GraphicsPrimitive
130:             * operates on a surface with a single component IntegerComponent
131:             * sample model and a DirectColorModel with an arbitrary ordering
132:             * of the RGB channels
133:             */
134:            public static final String DESC_ANY_INT_DCM = "Any Integer DCM";
135:
136:            /**
137:             * additional IntegerComponent types common on Windows
138:             */
139:            public static final String DESC_INT_RGBx = "Integer RGBx";
140:            public static final String DESC_INT_BGRx = "Integer BGRx";
141:
142:            /**
143:             * additional 3 byte format common on Windows
144:             */
145:            public static final String DESC_3BYTE_RGB = "3 Byte RGB";
146:
147:            /**
148:             * common formats for BITMASK transparency.
149:             */
150:            public static final String DESC_INT_ARGB_BM = "Int ARGB (Bitmask)";
151:            public static final String DESC_BYTE_INDEXED_BM = "8-bit Indexed (Bitmask)";
152:
153:            /**
154:             * Opaque 8-bit indexed images
155:             */
156:            public static final String DESC_BYTE_INDEXED_OPAQUE = "8-bit Indexed (Opaque)";
157:
158:            /**
159:             * Special Gray Scale types for rendering loops.  Really indexed
160:             * types, but colormap has all gray values.
161:             */
162:            public static final String DESC_INDEX8_GRAY = "8-bit Palettized Gray";
163:            public static final String DESC_INDEX12_GRAY = "12-bit Palettized Gray";
164:
165:            public static final String DESC_BYTE_BINARY_1BIT = "Packed Binary 1-bit Bitmap";
166:            public static final String DESC_BYTE_BINARY_2BIT = "Packed Binary 2-bit Bitmap";
167:            public static final String DESC_BYTE_BINARY_4BIT = "Packed Binary 4-bit Bitmap";
168:
169:            /**
170:             * Special type for describing the sources of loops that render the
171:             * current foreground color or paint instead of copying colors from
172:             * a source surface.
173:             */
174:            public static final String DESC_ANY_PAINT = "Paint Object";
175:            public static final String DESC_ANY_COLOR = "Single Color";
176:            public static final String DESC_OPAQUE_COLOR = "Opaque Color";
177:            public static final String DESC_GRADIENT_PAINT = "Gradient Paint";
178:            public static final String DESC_OPAQUE_GRADIENT_PAINT = "Opaque Gradient Paint";
179:            public static final String DESC_TEXTURE_PAINT = "Texture Paint";
180:            public static final String DESC_OPAQUE_TEXTURE_PAINT = "Opaque Texture Paint";
181:            public static final String DESC_LINEAR_GRADIENT_PAINT = "Linear Gradient Paint";
182:            public static final String DESC_OPAQUE_LINEAR_GRADIENT_PAINT = "Opaque Linear Gradient Paint";
183:            public static final String DESC_RADIAL_GRADIENT_PAINT = "Radial Gradient Paint";
184:            public static final String DESC_OPAQUE_RADIAL_GRADIENT_PAINT = "Opaque Radial Gradient Paint";
185:
186:            /*
187:             * END OF SURFACE TYPE CONSTANTS
188:             */
189:
190:            /**
191:             * The root SurfaceType object for all chains of surface descriptions.
192:             * The root uses the default PixelConverter object, which uses a given
193:             * ColorModel object to calculate its pixelFor() values when asked.  
194:             * Any SurfaceType objects that are not created with a specific
195:             * PixelConverter object will inherit this behavior from the root.
196:             */
197:            public static final SurfaceType Any = new SurfaceType(null,
198:                    DESC_ANY, PixelConverter.instance);
199:
200:            /*
201:             * START OF SurfaceType OBJECTS FOR THE VARIOUS CONSTANTS
202:             */
203:
204:            public static final SurfaceType AnyInt = Any
205:                    .deriveSubType(DESC_ANY_INT);
206:            public static final SurfaceType AnyShort = Any
207:                    .deriveSubType(DESC_ANY_SHORT);
208:            public static final SurfaceType AnyByte = Any
209:                    .deriveSubType(DESC_ANY_BYTE);
210:            public static final SurfaceType AnyByteBinary = Any
211:                    .deriveSubType(DESC_BYTE_BINARY);
212:            public static final SurfaceType Any3Byte = Any
213:                    .deriveSubType(DESC_ANY_3BYTE);
214:            public static final SurfaceType Any4Byte = Any
215:                    .deriveSubType(DESC_ANY_4BYTE);
216:            public static final SurfaceType AnyDcm = AnyInt
217:                    .deriveSubType(DESC_ANY_INT_DCM);
218:
219:            public static final SurfaceType Custom = Any;
220:            public static final SurfaceType IntRgb = AnyDcm.deriveSubType(
221:                    DESC_INT_RGB, PixelConverter.Xrgb.instance);
222:
223:            public static final SurfaceType IntArgb = AnyDcm.deriveSubType(
224:                    DESC_INT_ARGB, PixelConverter.Argb.instance);
225:
226:            public static final SurfaceType IntArgbPre = AnyDcm.deriveSubType(
227:                    DESC_INT_ARGB_PRE, PixelConverter.ArgbPre.instance);
228:
229:            public static final SurfaceType IntBgr = AnyDcm.deriveSubType(
230:                    DESC_INT_BGR, PixelConverter.Xbgr.instance);
231:
232:            public static final SurfaceType ThreeByteBgr = Any3Byte
233:                    .deriveSubType(DESC_3BYTE_BGR, PixelConverter.Xrgb.instance);
234:
235:            public static final SurfaceType FourByteAbgr = Any4Byte
236:                    .deriveSubType(DESC_4BYTE_ABGR,
237:                            PixelConverter.Rgba.instance);
238:
239:            public static final SurfaceType FourByteAbgrPre = Any4Byte
240:                    .deriveSubType(DESC_4BYTE_ABGR_PRE,
241:                            PixelConverter.RgbaPre.instance);
242:
243:            public static final SurfaceType Ushort565Rgb = AnyShort
244:                    .deriveSubType(DESC_USHORT_565_RGB,
245:                            PixelConverter.Ushort565Rgb.instance);
246:
247:            public static final SurfaceType Ushort555Rgb = AnyShort
248:                    .deriveSubType(DESC_USHORT_555_RGB,
249:                            PixelConverter.Ushort555Rgb.instance);
250:
251:            public static final SurfaceType Ushort555Rgbx = AnyShort
252:                    .deriveSubType(DESC_USHORT_555_RGBx,
253:                            PixelConverter.Ushort555Rgbx.instance);
254:
255:            public static final SurfaceType Ushort4444Argb = AnyShort
256:                    .deriveSubType(DESC_USHORT_4444_ARGB,
257:                            PixelConverter.Ushort4444Argb.instance);
258:
259:            public static final SurfaceType UshortIndexed = AnyShort
260:                    .deriveSubType(DESC_USHORT_INDEXED);
261:
262:            public static final SurfaceType ByteGray = AnyByte.deriveSubType(
263:                    DESC_BYTE_GRAY, PixelConverter.ByteGray.instance);
264:
265:            public static final SurfaceType UshortGray = AnyShort
266:                    .deriveSubType(DESC_USHORT_GRAY,
267:                            PixelConverter.UshortGray.instance);
268:
269:            public static final SurfaceType ByteBinary1Bit = AnyByteBinary
270:                    .deriveSubType(DESC_BYTE_BINARY_1BIT);
271:            public static final SurfaceType ByteBinary2Bit = AnyByteBinary
272:                    .deriveSubType(DESC_BYTE_BINARY_2BIT);
273:            public static final SurfaceType ByteBinary4Bit = AnyByteBinary
274:                    .deriveSubType(DESC_BYTE_BINARY_4BIT);
275:
276:            public static final SurfaceType ByteIndexed = AnyByte
277:                    .deriveSubType(DESC_BYTE_INDEXED);
278:
279:            public static final SurfaceType IntRgbx = AnyDcm.deriveSubType(
280:                    DESC_INT_RGBx, PixelConverter.Rgbx.instance);
281:
282:            public static final SurfaceType IntBgrx = AnyDcm.deriveSubType(
283:                    DESC_INT_BGRx, PixelConverter.Bgrx.instance);
284:
285:            public static final SurfaceType ThreeByteRgb = Any3Byte
286:                    .deriveSubType(DESC_3BYTE_RGB, PixelConverter.Xbgr.instance);
287:
288:            public static final SurfaceType IntArgbBm = AnyDcm.deriveSubType(
289:                    DESC_INT_ARGB_BM, PixelConverter.ArgbBm.instance);
290:
291:            public static final SurfaceType ByteIndexedBm = ByteIndexed
292:                    .deriveSubType(DESC_BYTE_INDEXED_BM);
293:
294:            public static final SurfaceType ByteIndexedOpaque = ByteIndexedBm
295:                    .deriveSubType(DESC_BYTE_INDEXED_OPAQUE);
296:
297:            public static final SurfaceType Index8Gray = ByteIndexedOpaque
298:                    .deriveSubType(DESC_INDEX8_GRAY);
299:
300:            public static final SurfaceType Index12Gray = Any
301:                    .deriveSubType(DESC_INDEX12_GRAY);
302:
303:            public static final SurfaceType AnyPaint = Any
304:                    .deriveSubType(DESC_ANY_PAINT);
305:
306:            public static final SurfaceType AnyColor = AnyPaint
307:                    .deriveSubType(DESC_ANY_COLOR);
308:
309:            public static final SurfaceType OpaqueColor = AnyColor
310:                    .deriveSubType(DESC_OPAQUE_COLOR);
311:
312:            public static final SurfaceType GradientPaint = AnyPaint
313:                    .deriveSubType(DESC_GRADIENT_PAINT);
314:            public static final SurfaceType OpaqueGradientPaint = GradientPaint
315:                    .deriveSubType(DESC_OPAQUE_GRADIENT_PAINT);
316:
317:            public static final SurfaceType LinearGradientPaint = AnyPaint
318:                    .deriveSubType(DESC_LINEAR_GRADIENT_PAINT);
319:            public static final SurfaceType OpaqueLinearGradientPaint = LinearGradientPaint
320:                    .deriveSubType(DESC_OPAQUE_LINEAR_GRADIENT_PAINT);
321:
322:            public static final SurfaceType RadialGradientPaint = AnyPaint
323:                    .deriveSubType(DESC_RADIAL_GRADIENT_PAINT);
324:            public static final SurfaceType OpaqueRadialGradientPaint = RadialGradientPaint
325:                    .deriveSubType(DESC_OPAQUE_RADIAL_GRADIENT_PAINT);
326:
327:            public static final SurfaceType TexturePaint = AnyPaint
328:                    .deriveSubType(DESC_TEXTURE_PAINT);
329:            public static final SurfaceType OpaqueTexturePaint = TexturePaint
330:                    .deriveSubType(DESC_OPAQUE_TEXTURE_PAINT);
331:
332:            /*
333:             * END OF SurfaceType OBJECTS FOR THE VARIOUS CONSTANTS
334:             */
335:
336:            /**
337:             * Return a new SurfaceType object which uses this object as its
338:             * more general "supertype" descriptor.  If no operation can be
339:             * found that manipulates the type of surface described more exactly
340:             * by desc, then this object will define the more relaxed specification
341:             * of the surface that can be used to find a more general operator.
342:             */
343:            public SurfaceType deriveSubType(String desc) {
344:                return new SurfaceType(this , desc);
345:            }
346:
347:            public SurfaceType deriveSubType(String desc,
348:                    PixelConverter pixelConverter) {
349:                return new SurfaceType(this , desc, pixelConverter);
350:            }
351:
352:            private int uniqueID;
353:            private String desc;
354:            private SurfaceType next;
355:            protected PixelConverter pixelConverter;
356:
357:            private SurfaceType(SurfaceType parent, String desc,
358:                    PixelConverter pixelConverter) {
359:                next = parent;
360:                this .desc = desc;
361:                this .uniqueID = makeUniqueID(desc);
362:                this .pixelConverter = pixelConverter;
363:            }
364:
365:            private SurfaceType(SurfaceType parent, String desc) {
366:                next = parent;
367:                this .desc = desc;
368:                this .uniqueID = makeUniqueID(desc);
369:                this .pixelConverter = parent.pixelConverter;
370:            }
371:
372:            public synchronized static final int makeUniqueID(String desc) {
373:                Integer i = (Integer) surfaceUIDMap.get((Object) desc);
374:
375:                if (i == null) {
376:                    if (unusedUID > 255) {
377:                        throw new InternalError("surface type id overflow");
378:                    }
379:                    i = new Integer(unusedUID++);
380:                    surfaceUIDMap.put(desc, i);
381:                }
382:                return i.intValue();
383:            }
384:
385:            public int getUniqueID() {
386:                return uniqueID;
387:            }
388:
389:            public String getDescriptor() {
390:                return desc;
391:            }
392:
393:            public SurfaceType getSuperType() {
394:                return next;
395:            }
396:
397:            public PixelConverter getPixelConverter() {
398:                return pixelConverter;
399:            }
400:
401:            public int pixelFor(int rgb, ColorModel cm) {
402:                return pixelConverter.rgbToPixel(rgb, cm);
403:            }
404:
405:            public int rgbFor(int pixel, ColorModel cm) {
406:                return pixelConverter.pixelToRgb(pixel, cm);
407:            }
408:
409:            public int getAlphaMask() {
410:                return pixelConverter.getAlphaMask();
411:            }
412:
413:            public int hashCode() {
414:                return desc.hashCode();
415:            }
416:
417:            public boolean equals(Object o) {
418:                if (o instanceof  SurfaceType) {
419:                    return (((SurfaceType) o).uniqueID == this .uniqueID);
420:                }
421:                return false;
422:            }
423:
424:            public String toString() {
425:                return desc;
426:            }
427:
428:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.