Source Code Cross Referenced for ImageIcon.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » 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 » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package javax.swing;
019:
020:        import java.awt.Component;
021:        import java.awt.Graphics;
022:        import java.awt.IllegalComponentStateException;
023:        import java.awt.Image;
024:        import java.awt.MediaTracker;
025:        import java.awt.Panel;
026:        import java.awt.Toolkit;
027:        import java.awt.image.ImageObserver;
028:        import java.io.Serializable;
029:        import java.net.URL;
030:        import java.util.Locale;
031:        import javax.accessibility.Accessible;
032:        import javax.accessibility.AccessibleContext;
033:        import javax.accessibility.AccessibleIcon;
034:        import javax.accessibility.AccessibleRole;
035:        import javax.accessibility.AccessibleStateSet;
036:        import org.apache.harmony.luni.util.NotImplementedException;
037:
038:        /**
039:         * <p>
040:         * <i>ImageIcon</i>
041:         * </p>
042:         * <h3>Implementation Notes:</h3>
043:         * <ul>
044:         * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
045:         * optimization, not as a guarantee of serialization compatibility.</li>
046:         * </ul>
047:         */
048:        public class ImageIcon implements  Icon, Serializable, Accessible {
049:            private static final long serialVersionUID = -6101950798829449111L;
050:
051:            protected class AccessibleImageIcon extends AccessibleContext
052:                    implements  AccessibleIcon, Serializable {
053:                private static final long serialVersionUID = -860693743697825660L;
054:
055:                protected AccessibleImageIcon() {
056:                }
057:
058:                @Override
059:                public Accessible getAccessibleChild(int i) {
060:                    return null;
061:                }
062:
063:                @Override
064:                public int getAccessibleChildrenCount() {
065:                    return 0;
066:                }
067:
068:                @Override
069:                public Accessible getAccessibleParent() {
070:                    return null;
071:                }
072:
073:                @Override
074:                public int getAccessibleIndexInParent() {
075:                    return -1;
076:                }
077:
078:                @Override
079:                public AccessibleRole getAccessibleRole() {
080:                    return AccessibleRole.ICON;
081:                }
082:
083:                @Override
084:                public AccessibleStateSet getAccessibleStateSet() {
085:                    return null;
086:                }
087:
088:                @Override
089:                public Locale getLocale() throws IllegalComponentStateException {
090:                    return null;
091:                }
092:
093:                public void setAccessibleIconDescription(String description) {
094:                    setDescription(description);
095:                }
096:
097:                public String getAccessibleIconDescription() {
098:                    return getDescription();
099:                }
100:
101:                public int getAccessibleIconWidth() {
102:                    return getIconWidth();
103:                }
104:
105:                public int getAccessibleIconHeight() {
106:                    return getIconHeight();
107:                }
108:            }
109:
110:            protected static final Component component;
111:
112:            protected static final MediaTracker tracker;
113:
114:            private ImageObserver observer;
115:
116:            private AccessibleContext accessibleContext;
117:
118:            private Image image;
119:
120:            private String description;
121:
122:            /**
123:             * Unique id is to enable image loading tracking via MediaTracker
124:             */
125:            private final int id = getUniqueID();
126:
127:            /**
128:             * The last unique ID assigned.
129:             */
130:            private static int lastAssignedID;
131:            static {
132:                component = new Panel();
133:                tracker = new MediaTracker(component);
134:                lastAssignedID = 0;
135:            }
136:
137:            /**
138:             * 'generates' unique ids for icons
139:             */
140:            private final static int getUniqueID() {
141:                return lastAssignedID++;
142:            }
143:
144:            public ImageIcon(URL url, String description) {
145:                this (url);
146:                this .description = description;
147:            }
148:
149:            public ImageIcon(String fileName, String description) {
150:                this (fileName);
151:                this .description = description;
152:            }
153:
154:            public ImageIcon(Image image, String description) {
155:                this (image);
156:                this .description = description;
157:            }
158:
159:            public ImageIcon(byte[] imageData, String description) {
160:                this (imageData);
161:                this .description = description;
162:            }
163:
164:            public ImageIcon(URL url) {
165:                image = Toolkit.getDefaultToolkit().createImage(url);
166:                loadImage(image);
167:                description = url.toString();
168:            }
169:
170:            public ImageIcon(String fileName) {
171:                image = Toolkit.getDefaultToolkit().createImage(fileName);
172:                loadImage(image);
173:                description = fileName;
174:            }
175:
176:            public ImageIcon(Image image) {
177:                this .image = image;
178:                loadImage(image);
179:                Object comment = image.getProperty("comment", observer);
180:                if (comment instanceof  String) {
181:                    description = (String) comment;
182:                }
183:            }
184:
185:            public ImageIcon(byte[] imageData) {
186:                image = Toolkit.getDefaultToolkit().createImage(imageData);
187:                loadImage(image);
188:                Object comment = image.getProperty("comment", observer);
189:                if (comment instanceof  String) {
190:                    description = (String) comment;
191:                }
192:            }
193:
194:            public ImageIcon() {
195:            }
196:
197:            public synchronized void paintIcon(Component c, Graphics g, int x,
198:                    int y) {
199:                g.drawImage(image, x, y, (observer != null) ? observer : c);
200:            }
201:
202:            public AccessibleContext getAccessibleContext() {
203:                return (accessibleContext == null) ? (accessibleContext = new AccessibleImageIcon())
204:                        : accessibleContext;
205:            }
206:
207:            public void setDescription(String description) {
208:                this .description = description;
209:            }
210:
211:            @Override
212:            public String toString() {
213:                return description != null ? description : super .toString();
214:            }
215:
216:            public String getDescription() {
217:                return description;
218:            }
219:
220:            public void setImageObserver(ImageObserver observer) {
221:                this .observer = observer;
222:            }
223:
224:            public ImageObserver getImageObserver() {
225:                return observer;
226:            }
227:
228:            public void setImage(Image newImage) {
229:                tracker.removeImage(image);
230:                image = newImage;
231:                tracker.addImage(image, id);
232:            }
233:
234:            protected void loadImage(Image image) {
235:                tracker.addImage(image, id);
236:                try {
237:                    tracker.waitForID(id);
238:                } catch (InterruptedException e) {
239:                    // reset the interrupt state for the current thread
240:                    Thread.currentThread().interrupt();
241:                }
242:            }
243:
244:            public Image getImage() {
245:                return image;
246:            }
247:
248:            public int getImageLoadStatus() {
249:                return tracker.statusID(id, false);
250:            }
251:
252:            public int getIconWidth() {
253:                return (image != null) ? image.getWidth(observer) : -1;
254:            }
255:
256:            public int getIconHeight() {
257:                return (image != null) ? image.getHeight(observer) : -1;
258:            }
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.