Remove timeout in serverSocket, it not required and fix compatibility with Jsun...
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / internal / model / ExternalToolsImages.java
1 package net.sourceforge.phpdt.externaltools.internal.model;
2
3 /**********************************************************************
4  Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5  This file is made available under the terms of the Common Public License v1.0
6  which accompanies this distribution, and is available at
7  http://www.eclipse.org/legal/cpl-v10.html
8  �
9  Contributors:
10  **********************************************************************/
11
12 import java.net.MalformedURLException;
13 import java.net.URL;
14 import java.util.HashMap;
15
16 import net.sourceforge.phpdt.externaltools.internal.ui.IExternalToolsUIConstants;
17 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
18
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
23
24 /**
25  * The images provided by the external tools plugin.
26  */
27 public class ExternalToolsImages {
28
29         /**
30          * The image registry containing <code>Image</code>s.
31          */
32         private static ImageRegistry imageRegistry;
33
34         /**
35          * A table of all the <code>ImageDescriptor</code>s.
36          */
37         private static HashMap imageDescriptors;
38
39         private static final String ATTR_LAUNCH_CONFIG_TYPE_ICON = "icon"; //$NON-NLS-1$
40
41         private static final String ATTR_LAUNCH_CONFIG_TYPE_ID = "configTypeID"; //$NON-NLS-1$
42
43         /* Declare Common paths */
44         private static URL ICON_BASE_URL = null;
45
46         // static {
47         // String pathSuffix = "icons/externaltools/full/"; //$NON-NLS-1$
48         //                      
49         // try {
50         // ICON_BASE_URL= new
51         // URL(PHPeclipsePlugin.getDefault().getDescriptor().getInstallURL(),
52         // pathSuffix);
53         // } catch (MalformedURLException e) {
54         // // do nothing
55         // }
56         // }
57         static {
58                 String pathSuffix = "icons/full/"; //$NON-NLS-1$        
59                 ICON_BASE_URL = ExternalToolsPlugin.getDefault().getBundle().getEntry(
60                                 pathSuffix);
61         }
62
63         // Use IPath and toOSString to build the names to ensure they have the
64         // slashes correct
65         private final static String CTOOL = "ctool16/"; // basic colors - size 16x16
66                                                                                                         // //$NON-NLS-1$
67
68         private final static String LOCALTOOL = "clcl16/"; // basic colors - size
69                                                                                                                 // 16x16 //$NON-NLS-1$
70
71         private final static String DLCL = "dlcl16/"; // disabled - size 16x16
72                                                                                                         // //$NON-NLS-1$
73
74         private final static String ELCL = "elcl16/"; // enabled - size 16x16
75                                                                                                         // //$NON-NLS-1$
76
77         private final static String OBJECT = "obj16/"; // basic colors - size 16x16
78                                                                                                         // //$NON-NLS-1$
79
80         private final static String WIZBAN = "wizban/"; // basic colors - size 16x16
81                                                                                                         // //$NON-NLS-1$
82
83         private final static String OVR = "ovr16/"; // basic colors - size 7x8
84                                                                                                 // //$NON-NLS-1$
85
86         private final static String VIEW = "cview16/"; // views //$NON-NLS-1$
87
88         /**
89          * Declare all images
90          */
91         private static void declareImages() {
92                 // Ant View Actions
93                 declareRegistryImage(IExternalToolsUIConstants.IMG_REMOVE, LOCALTOOL
94                                 + "remove_co.gif"); //$NON-NLS-1$
95                 declareRegistryImage(IExternalToolsUIConstants.IMG_REMOVE_ALL,
96                                 LOCALTOOL + "removeAll_co.gif"); //$NON-NLS-1$
97                 declareRegistryImage(IExternalToolsUIConstants.IMG_ADD, LOCALTOOL
98                                 + "add_co.gif"); //$NON-NLS-1$
99                 declareRegistryImage(IExternalToolsUIConstants.IMG_RUN, LOCALTOOL
100                                 + "run_tool.gif"); //$NON-NLS-1$
101                 declareRegistryImage(IExternalToolsUIConstants.IMG_SEARCH, LOCALTOOL
102                                 + "search.gif"); //$NON-NLS-1$
103                 declareRegistryImage(IExternalToolsUIConstants.IMG_MOVE_UP, LOCALTOOL
104                                 + "moveUp.gif"); //$NON-NLS-1$
105                 declareRegistryImage(IExternalToolsUIConstants.IMG_MOVE_DOWN, LOCALTOOL
106                                 + "moveDown.gif"); //$NON-NLS-1$
107                 declareRegistryImage(IExternalToolsUIConstants.IMG_ACTIVATE, LOCALTOOL
108                                 + "activate.gif"); //$NON-NLS-1$
109                 declareRegistryImage(IExternalToolsUIConstants.IMG_DEACTIVATE,
110                                 LOCALTOOL + "deactivate.gif"); //$NON-NLS-1$
111                 declareRegistryImage(IExternalToolsUIConstants.IMG_GO_TO_FILE,
112                                 LOCALTOOL + "gotoobj_tsk.gif"); //$NON-NLS-1$
113                 // Ant View Labels
114                 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_PROJECT,
115                 // OBJECT + "file_obj.gif"); //$NON-NLS-1$
116                 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_PROJECT_ERROR,
117                 // LOCALTOOL + "ant_project_err.gif"); //$NON-NLS-1$
118                 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET,
119                 // LOCALTOOL + "ant_target.gif"); //$NON-NLS-1$
120                 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ERROR,
121                 // LOCALTOOL + "error.gif"); //$NON-NLS-1$
122                 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ELEMENTS,
123                 // LOCALTOOL + "elements.gif"); //$NON-NLS-1$
124                 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ELEMENT,
125                 // LOCALTOOL + "element.gif"); //$NON-NLS-1$
126                 // Wizards
127                 declareRegistryImage(IExternalToolConstants.IMG_WIZBAN_EXTERNAL_TOOLS,
128                                 WIZBAN + "ext_tools_wiz.gif"); //$NON-NLS-1$
129
130                 // Actions
131                 declareRegistryImage(IExternalToolConstants.IMG_ACTION_REFRESH,
132                                 LOCALTOOL + "refresh.gif"); //$NON-NLS-1$
133
134                 // Objects
135                 declareRegistryImage(IExternalToolConstants.IMG_TAB_MAIN, OBJECT
136                                 + "main_tab.gif"); //$NON-NLS-1$
137                 declareRegistryImage(IExternalToolConstants.IMG_TAB_OPTIONS, OBJECT
138                                 + "options_tab.gif"); //$NON-NLS-1$
139
140                 // ANT object
141                 declareRegistryImage(IExternalToolConstants.IMG_TAB_ANT_TARGETS,
142                                 LOCALTOOL + "ant_tsk_check.gif"); //$NON-NLS-1$
143         }
144
145         /**
146          * Declare an Image in the registry table.
147          * 
148          * @param key
149          *            The key to use when registering the image
150          * @param path
151          *            The path where the image can be found. This path is relative
152          *            to where this plugin class is found (i.e. typically the
153          *            packages directory)
154          */
155         private final static void declareRegistryImage(String key, String path) {
156                 ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
157                 try {
158                         desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
159                 } catch (MalformedURLException me) {
160                         // ExternalToolsPlugin.log(me);
161                 }
162                 imageRegistry.put(key, desc);
163                 imageDescriptors.put(key, desc);
164         }
165
166         /**
167          * Returns the ImageRegistry.
168          */
169         public static ImageRegistry getImageRegistry() {
170                 if (imageRegistry == null) {
171                         initializeImageRegistry();
172                 }
173                 return imageRegistry;
174         }
175
176         /**
177          * Initialize the image registry by declaring all of the required graphics.
178          * This involves creating JFace image descriptors describing how to
179          * create/find the image should it be needed. The image is not actually
180          * allocated until requested.
181          * 
182          * Prefix conventions Wizard Banners WIZBAN_ Preference Banners PREF_BAN_
183          * Property Page Banners PROPBAN_ Color toolbar CTOOL_ Enable toolbar ETOOL_
184          * Disable toolbar DTOOL_ Local enabled toolbar ELCL_ Local Disable toolbar
185          * DLCL_ Object large OBJL_ Object small OBJS_ View VIEW_ Product images
186          * PROD_ Misc images MISC_
187          * 
188          * Where are the images? The images (typically gifs) are found in the same
189          * location as this plugin class. This may mean the same package directory
190          * as the package holding this class. The images are declared using
191          * this.getClass() to ensure they are looked up via this plugin class.
192          * 
193          * @see JFace's ImageRegistry
194          */
195         public static ImageRegistry initializeImageRegistry() {
196                 imageRegistry = new ImageRegistry(ExternalToolsPlugin
197                                 .getStandardDisplay());
198                 imageDescriptors = new HashMap(30);
199                 declareImages();
200                 return imageRegistry;
201         }
202
203         /**
204          * Returns the <code>Image<code> identified by the given key,
205          * or <code>null</code> if it does not exist.
206          */
207         public static Image getImage(String key) {
208                 return getImageRegistry().get(key);
209         }
210
211         /**
212          * Returns the <code>ImageDescriptor<code> identified by the given key,
213          * or <code>null</code> if it does not exist.
214          */
215         public static ImageDescriptor getImageDescriptor(String key) {
216                 if (imageDescriptors == null) {
217                         initializeImageRegistry();
218                 }
219                 return (ImageDescriptor) imageDescriptors.get(key);
220         }
221
222         private static URL makeIconFileURL(String iconPath)
223                         throws MalformedURLException {
224                 if (ICON_BASE_URL == null) {
225                         throw new MalformedURLException();
226                 }
227
228                 return new URL(ICON_BASE_URL, iconPath);
229         }
230 }