KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > wbmp > WBMPMetadata


1 /*
2  * @(#)WBMPMetadata.java 1.3 04/03/19 12:28:42
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.wbmp;
9
10 import java.io.UnsupportedEncodingException JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.List JavaDoc;
14 import javax.imageio.ImageTypeSpecifier JavaDoc;
15 import javax.imageio.metadata.IIOMetadata JavaDoc;
16 import javax.imageio.metadata.IIOMetadataNode JavaDoc;
17 import javax.imageio.metadata.IIOMetadataFormat JavaDoc;
18 import javax.imageio.metadata.IIOMetadataFormatImpl JavaDoc;
19 import org.w3c.dom.Node JavaDoc;
20 import com.sun.imageio.plugins.common.I18N;
21
22 import com.sun.imageio.plugins.common.ImageUtil;
23
24 public class WBMPMetadata extends IIOMetadata JavaDoc {
25
26     static final String JavaDoc nativeMetadataFormatName =
27         "javax_imageio_wbmp_1.0";
28
29     public int wbmpType;
30     
31     public int width;
32     public int height;
33
34     public WBMPMetadata() {
35         super(true,
36               nativeMetadataFormatName,
37               "com.sun.imageio.plugins.wbmp.WBMPMetadataFormat",
38               null, null);
39     }
40
41     public boolean isReadOnly() {
42         return true;
43     }
44     
45     public Node JavaDoc getAsTree(String JavaDoc formatName) {
46         if (formatName.equals(nativeMetadataFormatName)) {
47             return getNativeTree();
48         } else if (formatName.equals
49                    (IIOMetadataFormatImpl.standardMetadataFormatName)) {
50             return getStandardTree();
51         } else {
52             throw new IllegalArgumentException JavaDoc(I18N.getString("WBMPMetadata0"));
53         }
54     }
55
56     private Node JavaDoc getNativeTree() {
57         IIOMetadataNode JavaDoc root =
58             new IIOMetadataNode JavaDoc(nativeMetadataFormatName);
59
60         addChildNode(root, "WBMPType", new Integer JavaDoc(wbmpType));
61         addChildNode(root, "Width", new Integer JavaDoc(width));
62         addChildNode(root, "Height", new Integer JavaDoc(height));
63         
64         return root;
65     }
66
67     public void setFromTree(String JavaDoc formatName, Node JavaDoc root) {
68         throw new IllegalStateException JavaDoc(I18N.getString("WBMPMetadata1"));
69     }
70
71     public void mergeTree(String JavaDoc formatName, Node JavaDoc root) {
72         throw new IllegalStateException JavaDoc(I18N.getString("WBMPMetadata1"));
73     }
74
75     public void reset() {
76         throw new IllegalStateException JavaDoc(I18N.getString("WBMPMetadata1"));
77     }
78
79     private IIOMetadataNode JavaDoc addChildNode(IIOMetadataNode JavaDoc root,
80                                          String JavaDoc name,
81                                          Object JavaDoc object) {
82         IIOMetadataNode JavaDoc child = new IIOMetadataNode JavaDoc(name);
83         if (object != null) {
84             child.setUserObject(object);
85             child.setNodeValue(ImageUtil.convertObjectToString(object));
86         }
87         root.appendChild(child);
88         return child;
89     }
90     
91     
92     protected IIOMetadataNode JavaDoc getStandardChromaNode() {
93
94         IIOMetadataNode JavaDoc node = new IIOMetadataNode JavaDoc("Chroma");
95         IIOMetadataNode JavaDoc subNode = new IIOMetadataNode JavaDoc("BlackIsZero");
96         subNode.setAttribute("value", "TRUE");
97         
98         node.appendChild(subNode);
99         return node;
100     }
101
102     
103     protected IIOMetadataNode JavaDoc getStandardDimensionNode() {
104         IIOMetadataNode JavaDoc dimension_node = new IIOMetadataNode JavaDoc("Dimension");
105         IIOMetadataNode JavaDoc node = null; // scratch node
106

107         // PixelAspectRatio not in image
108

109         node = new IIOMetadataNode JavaDoc("ImageOrientation");
110         node.setAttribute("value", "Normal");
111         dimension_node.appendChild(node);
112
113         return dimension_node;
114     }
115
116 }
117
Popular Tags