Source Code Cross Referenced for XIconInfo.java in  » 6.0-JDK-Platform » solaris » sun » awt » X11 » 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 Platform » solaris » sun.awt.X11 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-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:        package sun.awt.X11;
026:
027:        import java.awt.*;
028:        import java.awt.color.*;
029:        import java.awt.image.*;
030:        import sun.awt.image.ToolkitImage;
031:        import sun.awt.image.ImageRepresentation;
032:        import java.util.Arrays;
033:
034:        class XIconInfo {
035:            /**
036:             * Representation of image as an int array
037:             * It's being used for _NET_WM_ICON hint
038:             * with 32-bit X data model
039:             */
040:            private int[] intIconData;
041:            /**
042:             * Representation of image as an int array
043:             * It's being used for _NET_WM_ICON hint
044:             * with 64-bit X data model
045:             */
046:            private long[] longIconData;
047:            /**
048:             * Icon image.
049:             */
050:            private Image image;
051:            /** 
052:             * Width of icon image. Being set in constructor.
053:             */
054:            private final int width;
055:            /** 
056:             * Height of icon image. Being set in constructor.
057:             */
058:            private final int height;
059:            /**
060:             * Width of scaled icon image. Can be set in setScaledDimension.
061:             */
062:            private int scaledWidth;
063:            /**
064:             * Height of scaled icon image. Can be set in setScaledDimension.
065:             */
066:            private int scaledHeight;
067:            /**
068:             * Length of raw data. Being set in constructor / setScaledDimension.
069:             */
070:            private int rawLength;
071:
072:            XIconInfo(int[] intIconData) {
073:                this .intIconData = (null == intIconData) ? null : Arrays
074:                        .copyOf(intIconData, intIconData.length);
075:                this .width = intIconData[0];
076:                this .height = intIconData[1];
077:                this .scaledWidth = width;
078:                this .scaledHeight = height;
079:                this .rawLength = width * height + 2;
080:            }
081:
082:            XIconInfo(long[] longIconData) {
083:                this .longIconData = (null == longIconData) ? null : Arrays
084:                        .copyOf(longIconData, longIconData.length);
085:                this .width = (int) longIconData[0];
086:                this .height = (int) longIconData[1];
087:                this .scaledWidth = width;
088:                this .scaledHeight = height;
089:                this .rawLength = width * height + 2;
090:            }
091:
092:            XIconInfo(Image image) {
093:                this .image = image;
094:                if (image instanceof  ToolkitImage) {
095:                    ImageRepresentation ir = ((ToolkitImage) image)
096:                            .getImageRep();
097:                    ir.reconstruct(ImageObserver.ALLBITS);
098:                    this .width = ir.getWidth();
099:                    this .height = ir.getHeight();
100:                } else {
101:                    this .width = image.getWidth(null);
102:                    this .height = image.getHeight(null);
103:                }
104:                this .scaledWidth = width;
105:                this .scaledHeight = height;
106:                this .rawLength = width * height + 2;
107:            }
108:
109:            /*
110:             * It sets size of scaled icon.
111:             */
112:            void setScaledSize(int width, int height) {
113:                this .scaledWidth = width;
114:                this .scaledHeight = height;
115:                this .rawLength = width * height + 2;
116:            }
117:
118:            boolean isValid() {
119:                return (width > 0 && height > 0);
120:            }
121:
122:            int getWidth() {
123:                return width;
124:            }
125:
126:            int getHeight() {
127:                return height;
128:            }
129:
130:            public String toString() {
131:                return "XIconInfo[w=" + width + ",h=" + height + ",sw="
132:                        + scaledWidth + ",sh=" + scaledHeight + "]";
133:            }
134:
135:            int getRawLength() {
136:                return rawLength;
137:            }
138:
139:            int[] getIntData() {
140:                if (this .intIconData == null) {
141:                    if (this .longIconData != null) {
142:                        this .intIconData = longArrayToIntArray(longIconData);
143:                    } else if (this .image != null) {
144:                        this .intIconData = imageToIntArray(this .image,
145:                                scaledWidth, scaledHeight);
146:                    }
147:                }
148:                return this .intIconData;
149:            }
150:
151:            long[] getLongData() {
152:                if (this .longIconData == null) {
153:                    if (this .intIconData != null) {
154:                        this .longIconData = intArrayToLongArray(this .intIconData);
155:                    } else if (this .image != null) {
156:                        int[] intIconData = imageToIntArray(this .image,
157:                                scaledWidth, scaledHeight);
158:                        this .longIconData = intArrayToLongArray(intIconData);
159:                    }
160:                }
161:                return this .longIconData;
162:            }
163:
164:            Image getImage() {
165:                if (this .image == null) {
166:                    if (this .intIconData != null) {
167:                        this .image = intArrayToImage(this .intIconData);
168:                    } else if (this .longIconData != null) {
169:                        int[] intIconData = longArrayToIntArray(this .longIconData);
170:                        this .image = intArrayToImage(intIconData);
171:                    }
172:                }
173:                return this .image;
174:            }
175:
176:            private static int[] longArrayToIntArray(long[] longData) {
177:                int[] intData = new int[longData.length];
178:                for (int i = 0; i < longData.length; i++) {
179:                    // Such a conversion is valid since the
180:                    // original data (see
181:                    // make/sun/xawt/ToBin.java) were ints
182:                    intData[i] = (int) longData[i];
183:                }
184:                return intData;
185:            }
186:
187:            private static long[] intArrayToLongArray(int[] intData) {
188:                long[] longData = new long[intData.length];
189:                for (int i = 0; i < intData.length; i++) {
190:                    longData[i] = (int) intData[i];
191:                }
192:                return longData;
193:            }
194:
195:            static Image intArrayToImage(int[] raw) {
196:                ColorModel cm = new DirectColorModel(ColorSpace
197:                        .getInstance(ColorSpace.CS_sRGB), 32, 0x00ff0000,
198:                        0x0000ff00, 0x000000ff, 0xff000000, false,
199:                        DataBuffer.TYPE_INT);
200:                DataBuffer buffer = new DataBufferInt(raw, raw.length - 2, 2);
201:                WritableRaster raster = Raster.createPackedRaster(buffer,
202:                        raw[0], raw[1], raw[0], new int[] { 0x00ff0000,
203:                                0x0000ff00, 0x000000ff, 0xff000000 }, null);
204:                BufferedImage im = new BufferedImage(cm, raster, false, null);
205:                return im;
206:            }
207:
208:            /*
209:             * Returns array of integers which holds data for the image.
210:             * It scales the image if necessary.
211:             */
212:            static int[] imageToIntArray(Image image, int width, int height) {
213:                if (width <= 0 || height <= 0) {
214:                    return null;
215:                }
216:                ColorModel cm = new DirectColorModel(ColorSpace
217:                        .getInstance(ColorSpace.CS_sRGB), 32, 0x00ff0000,
218:                        0x0000ff00, 0x000000ff, 0xff000000, false,
219:                        DataBuffer.TYPE_INT);
220:                DataBufferInt buffer = new DataBufferInt(width * height);
221:                WritableRaster raster = Raster.createPackedRaster(buffer,
222:                        width, height, width, new int[] { 0x00ff0000,
223:                                0x0000ff00, 0x000000ff, 0xff000000 }, null);
224:                BufferedImage im = new BufferedImage(cm, raster, false, null);
225:                Graphics g = im.getGraphics();
226:                g.drawImage(image, 0, 0, width, height, null);
227:                g.dispose();
228:                int[] data = buffer.getData();
229:                int[] raw = new int[width * height + 2];
230:                raw[0] = width;
231:                raw[1] = height;
232:                System.arraycopy(data, 0, raw, 2, width * height);
233:                return raw;
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.