1 7 8 package com.sun.imageio.plugins.wbmp; 9 10 import java.io.UnsupportedEncodingException ; 11 import java.util.ArrayList ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 import javax.imageio.ImageTypeSpecifier ; 15 import javax.imageio.metadata.IIOMetadata ; 16 import javax.imageio.metadata.IIOMetadataNode ; 17 import javax.imageio.metadata.IIOMetadataFormat ; 18 import javax.imageio.metadata.IIOMetadataFormatImpl ; 19 import org.w3c.dom.Node ; 20 import com.sun.imageio.plugins.common.I18N; 21 22 import com.sun.imageio.plugins.common.ImageUtil; 23 24 public class WBMPMetadata extends IIOMetadata { 25 26 static final String 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 getAsTree(String 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 (I18N.getString("WBMPMetadata0")); 53 } 54 } 55 56 private Node getNativeTree() { 57 IIOMetadataNode root = 58 new IIOMetadataNode (nativeMetadataFormatName); 59 60 addChildNode(root, "WBMPType", new Integer (wbmpType)); 61 addChildNode(root, "Width", new Integer (width)); 62 addChildNode(root, "Height", new Integer (height)); 63 64 return root; 65 } 66 67 public void setFromTree(String formatName, Node root) { 68 throw new IllegalStateException (I18N.getString("WBMPMetadata1")); 69 } 70 71 public void mergeTree(String formatName, Node root) { 72 throw new IllegalStateException (I18N.getString("WBMPMetadata1")); 73 } 74 75 public void reset() { 76 throw new IllegalStateException (I18N.getString("WBMPMetadata1")); 77 } 78 79 private IIOMetadataNode addChildNode(IIOMetadataNode root, 80 String name, 81 Object object) { 82 IIOMetadataNode child = new IIOMetadataNode (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 getStandardChromaNode() { 93 94 IIOMetadataNode node = new IIOMetadataNode ("Chroma"); 95 IIOMetadataNode subNode = new IIOMetadataNode ("BlackIsZero"); 96 subNode.setAttribute("value", "TRUE"); 97 98 node.appendChild(subNode); 99 return node; 100 } 101 102 103 protected IIOMetadataNode getStandardDimensionNode() { 104 IIOMetadataNode dimension_node = new IIOMetadataNode ("Dimension"); 105 IIOMetadataNode node = null; 107 109 node = new IIOMetadataNode ("ImageOrientation"); 110 node.setAttribute("value", "Normal"); 111 dimension_node.appendChild(node); 112 113 return dimension_node; 114 } 115 116 } 117 | Popular Tags |