Source Code Cross Referenced for ImageUtil.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » intro » universal » util » 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 » IDE Eclipse » ui » org.eclipse.ui.internal.intro.universal.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.intro.universal.util;
011:
012:        import java.net.URL;
013:
014:        import org.eclipse.core.runtime.FileLocator;
015:        import org.eclipse.core.runtime.IPath;
016:        import org.eclipse.core.runtime.Path;
017:        import org.eclipse.core.runtime.Platform;
018:        import org.eclipse.jface.resource.ImageDescriptor;
019:        import org.eclipse.jface.resource.ImageRegistry;
020:        import org.eclipse.swt.graphics.Image;
021:        import org.eclipse.swt.widgets.Display;
022:        import org.eclipse.ui.PlatformUI;
023:        import org.eclipse.ui.internal.intro.universal.IUniversalIntroConstants;
024:        import org.eclipse.ui.internal.intro.universal.UniversalIntroPlugin;
025:        import org.osgi.framework.Bundle;
026:
027:        /**
028:         * Convenience class for Images.
029:         */
030:        public final class ImageUtil {
031:
032:            /**
033:             * Image keys, to be used by plugin (intro) registry.
034:             */
035:            // Default images
036:            public static final String DEFAULT_ROOT_LINK = "rootLink"; //$NON-NLS-1$
037:
038:            public static final String DEFAULT_SMALL_ROOT_LINK = "rootLinkSmall"; //$NON-NLS-1$
039:
040:            public static final String DEFAULT_FORM_BG = "formBg"; //$NON-NLS-1$
041:
042:            public static final String DEFAULT_LINK = "link"; //$NON-NLS-1$
043:
044:            // Standby images
045:            public static final String BACK = "back"; //$NON-NLS-1$
046:
047:            public static final String HELP_TOPIC = "helpTopic"; //$NON-NLS-1$
048:
049:            // Launch bar image
050:            public static final String RESTORE_WELCOME = "restoreWelcome"; //$NON-NLS-1$
051:
052:            // Viewer images
053:            public static final String INTRO_MODEL_LEAF = "leaf"; //$NON-NLS-1$
054:
055:            public static final String INTRO_MODEL_CONTAINER = "container"; //$NON-NLS-1$
056:
057:            public static final String OPEN_ITNRO_VIEW = "introView"; //$NON-NLS-1$
058:
059:            public static final String CONFIG_EXTENSION = "configExtension";//$NON-NLS-1$
060:
061:            // Image location
062:            public static final String ICONS_PATH = "$nl$/icons/"; //$NON-NLS-1$
063:
064:            /**
065:             * Convenience method to create an image descriptor from the Intro plugin.
066:             * 
067:             * Method assumes that images are under the "icons" directory, so don't
068:             * append that directory name for "imageName".
069:             */
070:            public static ImageDescriptor createImageDescriptor(String imageName) {
071:                return createImageDescriptor(Platform
072:                        .getBundle(IUniversalIntroConstants.PLUGIN_ID),
073:                        ICONS_PATH + imageName);
074:            }
075:
076:            /**
077:             * Convenience method to create an image descriptor.
078:             * 
079:             */
080:            public static ImageDescriptor createImageDescriptor(Bundle bundle,
081:                    String imageName) {
082:                try {
083:                    URL imageUrl = FileLocator.find(bundle,
084:                            new Path(imageName), null);
085:                    if (imageUrl != null) {
086:                        ImageDescriptor desc = ImageDescriptor
087:                                .createFromURL(imageUrl);
088:                        return desc;
089:                    }
090:                } catch (Exception e) {
091:                    // Should never be here.
092:                    Log.error("could not create Image Descriptor", e); //$NON-NLS-1$
093:                }
094:                Log
095:                        .warning("could not create Image Descriptor for: " + imageName //$NON-NLS-1$
096:                                + " in bundle: " + bundle.getSymbolicName()); //$NON-NLS-1$
097:                return ImageDescriptor.getMissingImageDescriptor();
098:            }
099:
100:            /**
101:             * Convenience method to create an image descriptor.
102:             * 
103:             */
104:            public static ImageDescriptor createImageDescriptor(IPath base,
105:                    String imageName) {
106:                try {
107:                    URL imageUrl = new URL(base.append(imageName).toOSString());
108:                    if (imageUrl != null) {
109:                        ImageDescriptor desc = ImageDescriptor
110:                                .createFromURL(imageUrl);
111:                        return desc;
112:                    }
113:                } catch (Exception e) {
114:                    // Should never be here.
115:                    Log.error("could not create Image Descriptor", e); //$NON-NLS-1$
116:                }
117:                Log
118:                        .warning("could not create Image Descriptor for: " + imageName); //$NON-NLS-1$
119:                return ImageDescriptor.getMissingImageDescriptor();
120:            }
121:
122:            /**
123:             * Convenience method to create an image from the Intro plugin.
124:             * 
125:             * Method assumes that images are under the "icons" directory, so don't
126:             * append that directory name for "imageName".
127:             */
128:            public static Image createImage(String imageName) {
129:                try {
130:                    ImageDescriptor imageDsc = createImageDescriptor(imageName);
131:                    return imageDsc.createImage();
132:                } catch (Exception e) {
133:                    // Should never be here.
134:                    Log.error("could not create Image", e); //$NON-NLS-1$
135:                    return ImageDescriptor.getMissingImageDescriptor()
136:                            .createImage();
137:                }
138:            }
139:
140:            /**
141:             * Util method for image re-use in Intro Plugin.
142:             * 
143:             * @param key
144:             * @return
145:             */
146:            public static Image getImage(String key) {
147:                // INTRO: Image registry should not have the same life span
148:                // as the intro plug-in. It should be disposed when
149:                // presentation is disposed, otherwise images will
150:                // stay around once Inro has been loaded.
151:                return UniversalIntroPlugin.getDefault()
152:                        .getVolatileImageRegistry().get(key);
153:            }
154:
155:            public static boolean hasImage(String key) {
156:                ImageRegistry registry = UniversalIntroPlugin.getDefault()
157:                        .getVolatileImageRegistry();
158:                return (registry.getDescriptor(key) != null);
159:            }
160:
161:            /**
162:             * Register an image descriptor in the Intro Plugin image registry. Has no
163:             * effect if the key has already been registered.
164:             * 
165:             * @param key
166:             * @param imageName
167:             */
168:            public static void registerImage(String key, String imageName) {
169:                ImageRegistry registry = UniversalIntroPlugin.getDefault()
170:                        .getVolatileImageRegistry();
171:                if (registry.getDescriptor(key) != null)
172:                    // key has already been registered. do nothing.
173:                    return;
174:                registry.put(key, createImageDescriptor(imageName));
175:            }
176:
177:            public static void registerImage(String key, Bundle bundle,
178:                    String imageName) {
179:
180:                ImageRegistry registry = UniversalIntroPlugin.getDefault()
181:                        .getVolatileImageRegistry();
182:                if (registry.getDescriptor(key) != null)
183:                    // key has already been registered. do nothing.
184:                    return;
185:                registry.put(key, createImageDescriptor(bundle, imageName));
186:            }
187:
188:            public static void registerImage(String key, IPath base,
189:                    String imageName) {
190:                ImageRegistry registry = UniversalIntroPlugin.getDefault()
191:                        .getVolatileImageRegistry();
192:                if (registry.getDescriptor(key) != null)
193:                    // key has already been registered. do nothing.
194:                    return;
195:                registry.put(key, createImageDescriptor(base, imageName));
196:            }
197:
198:            /**
199:             * Tests for high contrast mode. Returns false if not called from a
200:             * UI thread (causes deadlocks during junit tests).
201:             * 
202:             * @return whether or not the display is in high contrast mode
203:             */
204:            public static boolean isHighContrast() {
205:                if (PlatformUI.isWorkbenchRunning()) {
206:                    Display display = PlatformUI.getWorkbench().getDisplay();
207:                    if (Display.getCurrent() == display) {
208:                        return display.getHighContrast();
209:                    }
210:                }
211:                return false;
212:            }
213:        }
w__w__w__.ja__v___a___2___s_.__co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.