KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > gif > GIFImageMetadataFormat


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

7
8 package com.sun.imageio.plugins.gif;
9
10 import java.util.Arrays JavaDoc;
11 import javax.imageio.ImageTypeSpecifier JavaDoc;
12 import javax.imageio.metadata.IIOMetadataFormat JavaDoc;
13 import javax.imageio.metadata.IIOMetadataFormatImpl JavaDoc;
14
15 public class GIFImageMetadataFormat extends IIOMetadataFormatImpl JavaDoc {
16
17     private static IIOMetadataFormat JavaDoc instance = null;
18
19     private GIFImageMetadataFormat() {
20         super(GIFImageMetadata.nativeMetadataFormatName,
21               CHILD_POLICY_SOME);
22
23         // root -> ImageDescriptor
24
addElement("ImageDescriptor",
25                    GIFImageMetadata.nativeMetadataFormatName,
26                    CHILD_POLICY_EMPTY);
27         addAttribute("ImageDescriptor", "imageLeftPosition",
28                      DATATYPE_INTEGER, true, null,
29                      "0", "65535", true, true);
30         addAttribute("ImageDescriptor", "imageTopPosition",
31                      DATATYPE_INTEGER, true, null,
32                      "0", "65535", true, true);
33         addAttribute("ImageDescriptor", "imageWidth",
34                      DATATYPE_INTEGER, true, null,
35                      "1", "65535", true, true);
36         addAttribute("ImageDescriptor", "imageHeight",
37                      DATATYPE_INTEGER, true, null,
38                      "1", "65535", true, true);
39         addBooleanAttribute("ImageDescriptor", "interlaceFlag",
40                             false, false);
41
42         // root -> LocalColorTable
43
addElement("LocalColorTable",
44                    GIFImageMetadata.nativeMetadataFormatName,
45                    2, 256);
46         addAttribute("LocalColorTable", "sizeOfLocalColorTable",
47                      DATATYPE_INTEGER, true, null,
48                      Arrays.asList(GIFStreamMetadata.colorTableSizes));
49         addBooleanAttribute("LocalColorTable", "sortFlag",
50                             false, false);
51
52         // root -> LocalColorTable -> ColorTableEntry
53
addElement("ColorTableEntry", "LocalColorTable",
54                    CHILD_POLICY_EMPTY);
55         addAttribute("ColorTableEntry", "index",
56                      DATATYPE_INTEGER, true, null,
57                      "0", "255", true, true);
58         addAttribute("ColorTableEntry", "red",
59                      DATATYPE_INTEGER, true, null,
60                      "0", "255", true, true);
61         addAttribute("ColorTableEntry", "green",
62                      DATATYPE_INTEGER, true, null,
63                      "0", "255", true, true);
64         addAttribute("ColorTableEntry", "blue",
65                      DATATYPE_INTEGER, true, null,
66                      "0", "255", true, true);
67
68         // root -> GraphicControlExtension
69
addElement("GraphicControlExtension",
70                    GIFImageMetadata.nativeMetadataFormatName,
71                    CHILD_POLICY_EMPTY);
72         addAttribute("GraphicControlExtension", "disposalMethod",
73                      DATATYPE_STRING, true, null,
74                      Arrays.asList(GIFImageMetadata.disposalMethodNames));
75         addBooleanAttribute("GraphicControlExtension", "userInputFlag",
76                             false, false);
77         addBooleanAttribute("GraphicControlExtension", "transparentColorFlag",
78                             false, false);
79         addAttribute("GraphicControlExtension", "delayTime",
80                      DATATYPE_INTEGER, true, null,
81                      "0", "65535", true, true);
82         addAttribute("GraphicControlExtension", "transparentColorIndex",
83                      DATATYPE_INTEGER, true, null,
84                      "0", "255", true, true);
85
86         // root -> PlainTextExtension
87
addElement("PlainTextExtension",
88                    GIFImageMetadata.nativeMetadataFormatName,
89                    CHILD_POLICY_EMPTY);
90         addAttribute("PlainTextExtension", "textGridLeft",
91                      DATATYPE_INTEGER, true, null,
92                      "0", "65535", true, true);
93         addAttribute("PlainTextExtension", "textGridTop",
94                      DATATYPE_INTEGER, true, null,
95                      "0", "65535", true, true);
96         addAttribute("PlainTextExtension", "textGridWidth",
97                      DATATYPE_INTEGER, true, null,
98                      "1", "65535", true, true);
99         addAttribute("PlainTextExtension", "textGridHeight",
100                      DATATYPE_INTEGER, true, null,
101                      "1", "65535", true, true);
102         addAttribute("PlainTextExtension", "characterCellWidth",
103                      DATATYPE_INTEGER, true, null,
104                      "1", "65535", true, true);
105         addAttribute("PlainTextExtension", "characterCellHeight",
106                      DATATYPE_INTEGER, true, null,
107                      "1", "65535", true, true);
108         addAttribute("PlainTextExtension", "textForegroundColor",
109                      DATATYPE_INTEGER, true, null,
110                      "0", "255", true, true);
111         addAttribute("PlainTextExtension", "textBackgroundColor",
112                      DATATYPE_INTEGER, true, null,
113                      "0", "255", true, true);
114         
115         // root -> ApplicationExtensions
116
addElement("ApplicationExtensions",
117                    GIFImageMetadata.nativeMetadataFormatName,
118                    1, Integer.MAX_VALUE);
119
120         // root -> ApplicationExtensions -> ApplicationExtension
121
addElement("ApplicationExtension", "ApplicationExtensions",
122                    CHILD_POLICY_EMPTY);
123         addAttribute("ApplicationExtension", "applicationID",
124                      DATATYPE_STRING, true, null);
125         addAttribute("ApplicationExtension", "authenticationCode",
126                      DATATYPE_STRING, true, null);
127         addObjectValue("ApplicationExtension", byte.class,
128                        0, Integer.MAX_VALUE);
129
130         // root -> CommentExtensions
131
addElement("CommentExtensions",
132                    GIFImageMetadata.nativeMetadataFormatName,
133                    1, Integer.MAX_VALUE);
134
135         // root -> CommentExtensions -> CommentExtension
136
addElement("CommentExtension", "CommentExtensions",
137                    CHILD_POLICY_EMPTY);
138         addAttribute("CommentExtension", "value",
139                      DATATYPE_STRING, true, null);
140     }
141
142     public boolean canNodeAppear(String JavaDoc elementName,
143                                  ImageTypeSpecifier JavaDoc imageType) {
144         return true;
145     }
146
147     public static synchronized IIOMetadataFormat JavaDoc getInstance() {
148         if (instance == null) {
149             instance = new GIFImageMetadataFormat();
150         }
151         return instance;
152     }
153 }
154
Popular Tags