Source Code Cross Referenced for PCXMetadata.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » com » sun » media » imageioimpl » plugins » pcx » 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 » Java Advanced Imaging » com.sun.media.imageioimpl.plugins.pcx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: PCXMetadata.java,v $
003:         *
004:         * 
005:         * Copyright (c) 2007 Sun Microsystems, Inc. All  Rights Reserved.
006:         * 
007:         * Redistribution and use in source and binary forms, with or without
008:         * modification, are permitted provided that the following conditions
009:         * are met: 
010:         * 
011:         * - Redistribution of source code must retain the above copyright 
012:         *   notice, this  list of conditions and the following disclaimer.
013:         * 
014:         * - Redistribution in binary form must reproduce the above copyright
015:         *   notice, this list of conditions and the following disclaimer in 
016:         *   the documentation and/or other materials provided with the
017:         *   distribution.
018:         * 
019:         * Neither the name of Sun Microsystems, Inc. or the names of 
020:         * contributors may be used to endorse or promote products derived 
021:         * from this software without specific prior written permission.
022:         * 
023:         * This software is provided "AS IS," without a warranty of any 
024:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 
025:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 
026:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
027:         * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 
028:         * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 
029:         * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
030:         * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 
031:         * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
032:         * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
033:         * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
034:         * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
035:         * POSSIBILITY OF SUCH DAMAGES. 
036:         * 
037:         * You acknowledge that this software is not designed or intended for 
038:         * use in the design, construction, operation or maintenance of any 
039:         * nuclear facility. 
040:         *
041:         * $Revision: 1.2 $
042:         * $Date: 2007/09/07 19:12:25 $
043:         * $State: Exp $
044:         */
045:        package com.sun.media.imageioimpl.plugins.pcx;
046:
047:        import javax.imageio.metadata.IIOInvalidTreeException;
048:        import javax.imageio.metadata.IIOMetadata;
049:        import javax.imageio.metadata.IIOMetadataFormatImpl;
050:        import javax.imageio.metadata.IIOMetadataNode;
051:
052:        import org.w3c.dom.NamedNodeMap;
053:        import org.w3c.dom.Node;
054:
055:        import com.sun.media.imageioimpl.common.ImageUtil;
056:
057:        public class PCXMetadata extends IIOMetadata implements  Cloneable,
058:                PCXConstants {
059:
060:            short version;
061:            byte bitsPerPixel;
062:            boolean gotxmin, gotymin;
063:            short xmin, ymin;
064:            int vdpi, hdpi;
065:            int hsize, vsize;
066:
067:            PCXMetadata() {
068:                super (true, null, null, null, null);
069:                reset();
070:            }
071:
072:            public Node getAsTree(String formatName) {
073:                if (formatName
074:                        .equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
075:                    return getStandardTree();
076:                } else {
077:                    throw new IllegalArgumentException(
078:                            "Not a recognized format!");
079:                }
080:            }
081:
082:            public boolean isReadOnly() {
083:                return false;
084:            }
085:
086:            public void mergeTree(String formatName, Node root)
087:                    throws IIOInvalidTreeException {
088:                if (formatName
089:                        .equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
090:                    if (root == null) {
091:                        throw new IllegalArgumentException("root == null!");
092:                    }
093:                    mergeStandardTree(root);
094:                } else {
095:                    throw new IllegalArgumentException(
096:                            "Not a recognized format!");
097:                }
098:            }
099:
100:            public void reset() {
101:                version = VERSION_3_0;
102:                bitsPerPixel = 0;
103:                gotxmin = false;
104:                gotymin = false;
105:                xmin = 0;
106:                ymin = 0;
107:                vdpi = 72;
108:                hdpi = 72;
109:                hsize = 0;
110:                vsize = 0;
111:            }
112:
113:            public IIOMetadataNode getStandardDocumentNode() {
114:                String versionString;
115:                switch (version) {
116:                case VERSION_2_5:
117:                    versionString = "2.5";
118:                    break;
119:                case VERSION_2_8_W_PALETTE:
120:                    versionString = "2.8 with palette";
121:                    break;
122:                case VERSION_2_8_WO_PALETTE:
123:                    versionString = "2.8 without palette";
124:                    break;
125:                case VERSION_PC_WINDOWS:
126:                    versionString = "PC Paintbrush for Windows";
127:                    break;
128:                case VERSION_3_0:
129:                    versionString = "3.0";
130:                    break;
131:                default:
132:                    // unknown
133:                    versionString = null;
134:                }
135:
136:                IIOMetadataNode documentNode = null;
137:                if (versionString != null) {
138:                    documentNode = new IIOMetadataNode("Document");
139:                    IIOMetadataNode node = new IIOMetadataNode("FormatVersion");
140:                    node.setAttribute("value", versionString);
141:                    documentNode.appendChild(node);
142:                }
143:
144:                return documentNode;
145:            }
146:
147:            public IIOMetadataNode getStandardDimensionNode() {
148:                IIOMetadataNode dimensionNode = new IIOMetadataNode("Dimension");
149:                IIOMetadataNode node = null; // scratch node
150:
151:                node = new IIOMetadataNode("HorizontalPixelOffset");
152:                node.setAttribute("value", String.valueOf(xmin));
153:                dimensionNode.appendChild(node);
154:
155:                node = new IIOMetadataNode("VerticalPixelOffset");
156:                node.setAttribute("value", String.valueOf(ymin));
157:                dimensionNode.appendChild(node);
158:
159:                node = new IIOMetadataNode("HorizontalPixelSize");
160:                node.setAttribute("value", String.valueOf(254.0 / hdpi));
161:                dimensionNode.appendChild(node);
162:
163:                node = new IIOMetadataNode("VerticalPixelSize");
164:                node.setAttribute("value", String.valueOf(254.0 / vdpi));
165:                dimensionNode.appendChild(node);
166:
167:                if (hsize != 0) {
168:                    node = new IIOMetadataNode("HorizontalScreenSize");
169:                    node.setAttribute("value", String.valueOf(hsize));
170:                    dimensionNode.appendChild(node);
171:                }
172:
173:                if (vsize != 0) {
174:                    node = new IIOMetadataNode("VerticalScreenSize");
175:                    node.setAttribute("value", String.valueOf(vsize));
176:                    dimensionNode.appendChild(node);
177:                }
178:
179:                return dimensionNode;
180:            }
181:
182:            private void mergeStandardTree(Node root)
183:                    throws IIOInvalidTreeException {
184:                Node node = root;
185:                if (!node.getNodeName().equals(
186:                        IIOMetadataFormatImpl.standardMetadataFormatName))
187:                    throw new IIOInvalidTreeException("Root must be "
188:                            + IIOMetadataFormatImpl.standardMetadataFormatName,
189:                            node);
190:
191:                node = node.getFirstChild();
192:                while (node != null) {
193:                    String name = node.getNodeName();
194:
195:                    if (name.equals("Dimension")) {
196:                        Node child = node.getFirstChild();
197:
198:                        while (child != null) {
199:                            String childName = child.getNodeName();
200:                            if (childName.equals("HorizontalPixelOffset")) {
201:                                String hpo = getAttribute(child, "value");
202:                                xmin = Short.valueOf(hpo).shortValue();
203:                                gotxmin = true;
204:                            } else if (childName.equals("VerticalPixelOffset")) {
205:                                String vpo = getAttribute(child, "value");
206:                                ymin = Short.valueOf(vpo).shortValue();
207:                                gotymin = true;
208:                            } else if (childName.equals("HorizontalPixelSize")) {
209:                                String hps = getAttribute(child, "value");
210:                                hdpi = (int) (254.0F / Float.parseFloat(hps) + 0.5F);
211:                            } else if (childName.equals("VerticalPixelSize")) {
212:                                String vps = getAttribute(child, "value");
213:                                vdpi = (int) (254.0F / Float.parseFloat(vps) + 0.5F);
214:                            } else if (childName.equals("HorizontalScreenSize")) {
215:                                String hss = getAttribute(child, "value");
216:                                hsize = Integer.valueOf(hss).intValue();
217:                            } else if (childName.equals("VerticalScreenSize")) {
218:                                String vss = getAttribute(child, "value");
219:                                vsize = Integer.valueOf(vss).intValue();
220:                            }
221:
222:                            child = child.getNextSibling();
223:                        }
224:                    }
225:
226:                    node = node.getNextSibling();
227:                }
228:            }
229:
230:            private static String getAttribute(Node node, String attrName) {
231:                NamedNodeMap attrs = node.getAttributes();
232:                Node attr = attrs.getNamedItem(attrName);
233:                return attr != null ? attr.getNodeValue() : null;
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.