KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > RefactoringPluginImages


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ltk.internal.ui.refactoring;
12
13 import java.net.URL JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16
17 import org.eclipse.core.runtime.FileLocator;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.Path;
20
21 import org.eclipse.swt.graphics.Image;
22
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.resource.ImageDescriptor;
25 import org.eclipse.jface.resource.ImageRegistry;
26
27 import org.osgi.framework.Bundle;
28
29 public class RefactoringPluginImages {
30
31     private static final String JavaDoc NAME_PREFIX= "org.eclipse.ltk.ui.refactoring"; //$NON-NLS-1$
32
private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length();
33     
34     private static final IPath ICONS_PATH= new Path("$nl$/icons/full"); //$NON-NLS-1$
35

36     private static ImageRegistry fgImageRegistry= null;
37     private static HashMap JavaDoc fgAvoidSWTErrorMap= null;
38
39     private static final String JavaDoc T_WIZBAN= "wizban"; //$NON-NLS-1$
40
private static final String JavaDoc T_OBJ= "obj16"; //$NON-NLS-1$
41
private static final String JavaDoc T_OVR= "ovr16"; //$NON-NLS-1$
42
private static final String JavaDoc T_ELCL= "elcl16"; //$NON-NLS-1$
43
private static final String JavaDoc T_DLCL= "dlcl16"; //$NON-NLS-1$
44

45     public static final ImageDescriptor DESC_WIZBAN_REFACTOR= createUnManaged(T_WIZBAN, "refactor_wiz.png"); //$NON-NLS-1$
46

47     /** @since 3.2 */
48     public static final ImageDescriptor DESC_WIZBAN_SHOW_HISTORY= createUnManaged(T_WIZBAN, "show_history_wiz.png"); //$NON-NLS-1$
49
/** @since 3.2 */
50     public static final ImageDescriptor DESC_WIZBAN_APPLY_SCRIPT= createUnManaged(T_WIZBAN, "apply_rescript_wiz.png"); //$NON-NLS-1$
51
/** @since 3.2 */
52     public static final ImageDescriptor DESC_WIZBAN_CREATE_SCRIPT= createUnManaged(T_WIZBAN, "create_rescript_wiz.png"); //$NON-NLS-1$
53

54     public static final String JavaDoc IMG_OBJS_REFACTORING_FATAL= NAME_PREFIX + "fatalerror_obj.gif"; //$NON-NLS-1$
55
public static final String JavaDoc IMG_OBJS_REFACTORING_ERROR= NAME_PREFIX + "error_obj.gif"; //$NON-NLS-1$
56
public static final String JavaDoc IMG_OBJS_REFACTORING_WARNING= NAME_PREFIX + "warning_obj.gif"; //$NON-NLS-1$
57
public static final String JavaDoc IMG_OBJS_REFACTORING_INFO= NAME_PREFIX + "info_obj.gif"; //$NON-NLS-1$
58

59     /** @since 3.2 */
60     public static final String JavaDoc IMG_OBJS_REFACTORING_DATE= NAME_PREFIX + "date_obj.gif"; //$NON-NLS-1$
61
/** @since 3.2 */
62     public static final String JavaDoc IMG_OBJS_REFACTORING_TIME= NAME_PREFIX + "time_obj.gif"; //$NON-NLS-1$
63

64     public static final ImageDescriptor DESC_ELCL_FILTER= createUnManaged(T_ELCL, "filter_ps.gif"); //$NON-NLS-1$
65
public static final ImageDescriptor DESC_DLCL_FILTER= createUnManaged(T_DLCL, "filter_ps.gif"); //$NON-NLS-1$
66

67     /** @since 3.2 */
68     public static final ImageDescriptor DESC_ELCL_SORT_PROJECT= createUnManaged(T_ELCL, "prj_mode.gif"); //$NON-NLS-1$
69
/** @since 3.2 */
70     public static final ImageDescriptor DESC_DLCL_SORT_PROJECT= createUnManaged(T_DLCL, "prj_mode.gif"); //$NON-NLS-1$
71
/** @since 3.2 */
72     public static final ImageDescriptor DESC_ELCL_SORT_DATE= createUnManaged(T_ELCL, "date_mode.gif"); //$NON-NLS-1$
73
/** @since 3.2 */
74     public static final ImageDescriptor DESC_DLCL_SORT_DATE= createUnManaged(T_DLCL, "date_mode.gif"); //$NON-NLS-1$
75

76     public static final ImageDescriptor DESC_OBJS_REFACTORING_FATAL= createManaged(T_OBJ, IMG_OBJS_REFACTORING_FATAL);
77     public static final ImageDescriptor DESC_OBJS_REFACTORING_ERROR= createManaged(T_OBJ, IMG_OBJS_REFACTORING_ERROR);
78     public static final ImageDescriptor DESC_OBJS_REFACTORING_WARNING= createManaged(T_OBJ, IMG_OBJS_REFACTORING_WARNING);
79     public static final ImageDescriptor DESC_OBJS_REFACTORING_INFO= createManaged(T_OBJ, IMG_OBJS_REFACTORING_INFO);
80
81     /** @since 3.2 */
82     public static final ImageDescriptor DESC_OBJS_REFACTORING_DATE= createUnManaged(T_OBJ, "date_obj.gif"); //$NON-NLS-1$
83
/** @since 3.2 */
84     public static final ImageDescriptor DESC_OBJS_REFACTORING_TIME= createUnManaged(T_OBJ, "time_obj.gif"); //$NON-NLS-1$
85
/** @since 3.2 */
86     public static final ImageDescriptor DESC_OBJS_REFACTORING= createUnManaged(T_OBJ, "refactoring_obj.gif"); //$NON-NLS-1$
87
/** @since 3.2 */
88     public static final ImageDescriptor DESC_OBJS_REFACTORING_COLL= createUnManaged(T_OBJ, "refactorings_obj.gif"); //$NON-NLS-1$
89
/** @since 3.2 */
90     public static final ImageDescriptor DESC_OVR_WORKSPACE= createUnManaged(T_OVR, "workspace_ovr.gif"); //$NON-NLS-1$
91

92     public static final ImageDescriptor DESC_OBJS_DEFAULT_CHANGE= createUnManaged(T_OBJ, "change.gif"); //$NON-NLS-1$
93
public static final ImageDescriptor DESC_OBJS_COMPOSITE_CHANGE= createUnManaged(T_OBJ, "composite_change.gif"); //$NON-NLS-1$
94
public static final ImageDescriptor DESC_OBJS_FILE_CHANGE= createUnManaged(T_OBJ, "file_change.gif"); //$NON-NLS-1$
95
public static final ImageDescriptor DESC_OBJS_TEXT_EDIT= createUnManaged(T_OBJ, "text_edit.gif"); //$NON-NLS-1$
96

97     /**
98      * Returns the image managed under the given key in this registry.
99      *
100      * @param key the image's key
101      * @return the image managed under the given key
102      */

103     public static Image get(String JavaDoc key) {
104         return getImageRegistry().get(key);
105     }
106     
107     /**
108      * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
109      * are retrieved from the *tool16 folders.
110      *
111      * @param action the action to set the icons to
112      * @param iconName the iconName
113      */

114     public static void setToolImageDescriptors(IAction action, String JavaDoc iconName) {
115         setImageDescriptors(action, "tool16", iconName); //$NON-NLS-1$
116
}
117     
118     /**
119      * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
120      * are retrieved from the *lcl16 folders.
121      *
122      * @param action the action to set the icons to
123      * @param iconName the iconName
124      */

125     public static void setLocalImageDescriptors(IAction action, String JavaDoc iconName) {
126         setImageDescriptors(action, "lcl16", iconName); //$NON-NLS-1$
127
}
128     
129     /*
130      * Helper method to access the image registry from the Refactoring Plugin class.
131      */

132     /* package */ static ImageRegistry getImageRegistry() {
133         if (fgImageRegistry == null) {
134             fgImageRegistry= new ImageRegistry();
135             for (Iterator JavaDoc iter= fgAvoidSWTErrorMap.keySet().iterator(); iter.hasNext();) {
136                 String JavaDoc key= (String JavaDoc) iter.next();
137                 fgImageRegistry.put(key, (ImageDescriptor) fgAvoidSWTErrorMap.get(key));
138             }
139             fgAvoidSWTErrorMap= null;
140         }
141         return fgImageRegistry;
142     }
143
144     //---- Helper methods to access icons on the file system --------------------------------------
145

146     private static void setImageDescriptors(IAction action, String JavaDoc type, String JavaDoc relPath) {
147         ImageDescriptor id= create("d" + type, relPath, false); //$NON-NLS-1$
148
if (id != null)
149             action.setDisabledImageDescriptor(id);
150     
151         ImageDescriptor descriptor= create("e" + type, relPath, true); //$NON-NLS-1$
152
action.setHoverImageDescriptor(descriptor);
153         action.setImageDescriptor(descriptor);
154     }
155     
156     private static ImageDescriptor createManaged(String JavaDoc prefix, String JavaDoc name) {
157         ImageDescriptor result= create(prefix, name.substring(NAME_PREFIX_LENGTH), true);
158         if (fgAvoidSWTErrorMap == null) {
159             fgAvoidSWTErrorMap= new HashMap JavaDoc();
160         }
161         fgAvoidSWTErrorMap.put(name, result);
162         if (fgImageRegistry != null) {
163             RefactoringUIPlugin.logErrorMessage("Image registry already defined"); //$NON-NLS-1$
164
}
165         return result;
166     }
167     
168     private static ImageDescriptor createUnManaged(String JavaDoc prefix, String JavaDoc name) {
169         return create(prefix, name, true);
170     }
171     
172     /*
173      * Creates an image descriptor for the given prefix and name in the Refactoring UI bundle. The path can
174      * contain variables like $NL$.
175      * If no image could be found, <code>useMissingImageDescriptor</code> decides if either
176      * the 'missing image descriptor' is returned or <code>null</code>.
177      * or <code>null</code>.
178      */

179     private static ImageDescriptor create(String JavaDoc prefix, String JavaDoc name, boolean useMissingImageDescriptor) {
180         IPath path= ICONS_PATH.append(prefix).append(name);
181         return createImageDescriptor(RefactoringUIPlugin.getDefault().getBundle(), path, useMissingImageDescriptor);
182     }
183     
184     /*
185      * Since 3.1.1. Load from icon paths with $NL$
186      */

187     private static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path, boolean useMissingImageDescriptor) {
188         URL JavaDoc url= FileLocator.find(bundle, path, null);
189         if (url != null) {
190             return ImageDescriptor.createFromURL(url);
191         }
192         if (useMissingImageDescriptor) {
193             return ImageDescriptor.getMissingImageDescriptor();
194         }
195         return null;
196     }
197 }
198
Popular Tags