Preferencedialog for "Mark Occurrences"
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / PHPUiImages.java
index abdb1f1..395ee76 100644 (file)
@@ -2,6 +2,8 @@ package net.sourceforge.phpdt.internal.ui;
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
 
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
@@ -16,35 +18,45 @@ public class PHPUiImages {
                "net.sourceforge.phpdt.internal.ui.";
        protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
 
-       protected static URL iconBaseURL;
-
+       protected static URL fgIconBaseURL=null;
+
+//     static {
+//             String pathSuffix = "icons/";
+//             try {
+//                     fgIconBaseURL =
+//                             new URL(
+//                                     PHPeclipsePlugin
+//                                             .getDefault()
+//                                             .getDescriptor()
+//                                             .getInstallURL(),
+//                                     pathSuffix);
+//             } catch (MalformedURLException e) {
+//                     PHPeclipsePlugin.log(e);
+//             }
+//     }
+
+//      Determine display depth. If depth > 4 then we use high color images. Otherwise low color
+       // images are used
        static {
-               String pathSuffix = "icons/";
-               try {
-                       iconBaseURL =
-                               new URL(
-                                       PHPeclipsePlugin
-                                               .getDefault()
-                                               .getDescriptor()
-                                               .getInstallURL(),
-                                       pathSuffix);
-               } catch (MalformedURLException e) {
-                       PHPeclipsePlugin.log(e);
-               }
+               fgIconBaseURL= PHPeclipsePlugin.getDefault().getBundle().getEntry("/icons/"); //$NON-NLS-1$
        }
-
-       protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
-
+       private static ImageRegistry fgImageRegistry= null;
+       private static HashMap fgAvoidSWTErrorMap= null;
+       
        protected static final String OBJ_PREFIX = "obj16";
        protected static final String OVR_PREFIX = "ovr16";
        protected static final String CTOOL_PREFIX = "ctool16";
 
-       public static final String IMG_CLASS = NAME_PREFIX + "class_obj.gif";
+       public static final String IMG_CLASS = NAME_PREFIX + "class_default_obj.gif";
        public static final String IMG_DEFINE = NAME_PREFIX + "define_obj.gif";
        public static final String IMG_BUILTIN = NAME_PREFIX + "builtin_obj.gif";
        public static final String IMG_FUN = NAME_PREFIX + "fun_obj.gif";
        public static final String IMG_INC = NAME_PREFIX + "impc_obj.gif";
        public static final String IMG_VAR = NAME_PREFIX + "var_obj.gif";
+       
+       public static final String IMG_TABLE = NAME_PREFIX + "table_obj.gif";
+       public static final String IMG_COLUMN = NAME_PREFIX + "column_obj.gif";
+       
        public static final String IMG_OBJS_WARNING =
                NAME_PREFIX + "warning_obj.gif";
        public static final String IMG_OBJS_INFO = NAME_PREFIX + "info_obj.gif";
@@ -66,6 +78,12 @@ public class PHPUiImages {
                createManaged(OBJ_PREFIX, IMG_INC);
        public static final ImageDescriptor DESC_VAR =
                createManaged(OBJ_PREFIX, IMG_VAR);
+       
+       public static final ImageDescriptor DESC_TABLE =
+               createManaged(OBJ_PREFIX, IMG_TABLE);
+       public static final ImageDescriptor DESC_COLUMN =
+               createManaged(OBJ_PREFIX, IMG_COLUMN);
+       
        public static final ImageDescriptor DESC_OBJS_WARNING =
                createManaged(OBJ_PREFIX, IMG_OBJS_WARNING);
        public static final ImageDescriptor DESC_OBJS_INFO =
@@ -87,11 +105,15 @@ public class PHPUiImages {
                private static final String T_WIZBAN= "wizban";         //$NON-NLS-1$
                private static final String T_CLCL= "clcl16";   //$NON-NLS-1$
                private static final String T_DLCL= "dlcl16";   //$NON-NLS-1$
+               private static final String T_ELCL= "elcl16";   //$NON-NLS-1$
                private static final String T_CTOOL= "ctool16";         //$NON-NLS-1$
                private static final String T_CVIEW= "cview16"; //$NON-NLS-1$
        
        public static final ImageDescriptor DESC_WIZBAN_NEWCLASS= create(T_WIZBAN, "newclass_wiz.gif");                         //$NON-NLS-1$
                
+       public static final ImageDescriptor DESC_ELCL_FILTER= create(T_ELCL, "filter_ps.gif"); //$NON-NLS-1$
+       public static final ImageDescriptor DESC_DLCL_FILTER= create(T_DLCL, "filter_ps.gif"); //$NON-NLS-1$
+
        /*
         * Available cached Images in the Java plugin image registry.
         */
@@ -120,7 +142,7 @@ public class PHPUiImages {
        public static final String IMG_OBJS_INTERFACE= NAME_PREFIX + "int_obj.gif";                     //$NON-NLS-1$
        public static final String IMG_OBJS_INTERFACEALT= NAME_PREFIX + "intf_obj.gif";                         //$NON-NLS-1$   
        public static final String IMG_OBJS_INTERFACE_DEFAULT= NAME_PREFIX + "int_default_obj.gif";             //$NON-NLS-1$
-       public static final String IMG_OBJS_CUNIT= NAME_PREFIX + "jcu_obj.gif";                                 //$NON-NLS-1$
+       public static final String IMG_OBJS_CUNIT= NAME_PREFIX + "phpedit.gif";                                 //$NON-NLS-1$
        public static final String IMG_OBJS_CUNIT_RESOURCE= NAME_PREFIX + "jcu_resource_obj.gif";                               //$NON-NLS-1$
        public static final String IMG_OBJS_CFILE= NAME_PREFIX + "classf_obj.gif";                      //$NON-NLS-1$
        public static final String IMG_OBJS_CFILECLASS= NAME_PREFIX + "class_obj.gif";                  //$NON-NLS-1$
@@ -349,21 +371,40 @@ public class PHPUiImages {
        public static final String IMG_CORRECTION_RENAME= NAME_PREFIX + "correction_rename.gif"; //$NON-NLS-1$
        public static final String IMG_CORRECTION_DELETE_IMPORT= NAME_PREFIX + "correction_delete_import.gif"; //$NON-NLS-1$
        public static final String IMG_CORRECTION_LOCAL= NAME_PREFIX + "localvariable_obj.gif"; //$NON-NLS-1$
+       public static final String IMG_CORRECTION_REMOVE= NAME_PREFIX + "remove_correction.gif"; //$NON-NLS-1$
+       public static final String IMG_CORRECTION_ADD= NAME_PREFIX + "add_correction.gif"; //$NON-NLS-1$
+
        static {
                createManaged(T_OBJ, IMG_CORRECTION_CHANGE);
                createManaged(T_OBJ, IMG_CORRECTION_MOVE);
                createManaged(T_OBJ, IMG_CORRECTION_RENAME);
                createManaged(T_OBJ, IMG_CORRECTION_DELETE_IMPORT);
                createManaged(T_OBJ, IMG_CORRECTION_LOCAL);
+               createManaged(T_OBJ, IMG_CORRECTION_REMOVE);
+               createManaged(T_OBJ, IMG_CORRECTION_ADD);
        }
+       
        /**
         * Returns the image managed under the given key in this registry.
         * 
         * @param key the image's key
         * @return the image managed under the given key
-        */
+        */ 
        public static Image get(String key) {
-               return IMAGE_REGISTRY.get(key);
+               return getImageRegistry().get(key);
+       }
+       
+       /**
+        * Returns the image descriptor for the given key in this registry. Might be called in a non-UI thread.
+        * 
+        * @param key the image's key
+        * @return the image descriptor for the given key
+        */ 
+       public static ImageDescriptor getDescriptor(String key) {
+               if (fgImageRegistry == null) {
+                       return (ImageDescriptor) fgAvoidSWTErrorMap.get(key);
+               }
+               return getImageRegistry().getDescriptor(key);
        }
 
        /**
@@ -386,8 +427,19 @@ public class PHPUiImages {
                setImageDescriptors(action, "lcl16", iconName);
        }
 
-       public static ImageRegistry getImageRegistry() {
-               return IMAGE_REGISTRY;
+       /*
+        * Helper method to access the image registry from the JavaPlugin class.
+        */
+       /* package */ static ImageRegistry getImageRegistry() {
+               if (fgImageRegistry == null) {
+                       fgImageRegistry= new ImageRegistry();
+                       for (Iterator iter= fgAvoidSWTErrorMap.keySet().iterator(); iter.hasNext();) {
+                               String key= (String) iter.next();
+                               fgImageRegistry.put(key, (ImageDescriptor) fgAvoidSWTErrorMap.get(key));
+                       }
+                       fgAvoidSWTErrorMap= null;
+               }
+               return fgImageRegistry;
        }
 
        //---- Helper methods to access icons on the file system --------------------------------------
@@ -418,16 +470,32 @@ public class PHPUiImages {
                action.setImageDescriptor(create("e" + type, relPath));
        }
 
-       protected static ImageDescriptor createManaged(
-               String prefix,
-               String name) {
+       private static ImageDescriptor createManaged(String prefix, String name) {
                try {
-                       ImageDescriptor result =
-                               ImageDescriptor.createFromURL(
-                                       makeIconFileURL(
-                                               prefix,
-                                               name.substring(NAME_PREFIX_LENGTH)));
-                       IMAGE_REGISTRY.put(name, result);
+                       ImageDescriptor result= ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
+                       if (fgAvoidSWTErrorMap == null) {
+                               fgAvoidSWTErrorMap= new HashMap();
+                       }
+                       fgAvoidSWTErrorMap.put(name, result);
+                       if (fgImageRegistry != null) {
+                               PHPeclipsePlugin.logErrorMessage("Image registry already defined"); //$NON-NLS-1$
+                       }
+                       return result;
+               } catch (MalformedURLException e) {
+                       return ImageDescriptor.getMissingImageDescriptor();
+               }
+       }
+       
+       private static ImageDescriptor createManaged(String prefix, String name, String key) {
+               try {
+                       ImageDescriptor result= ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
+                       if (fgAvoidSWTErrorMap == null) {
+                               fgAvoidSWTErrorMap= new HashMap();
+                       }
+                       fgAvoidSWTErrorMap.put(key, result);
+                       if (fgImageRegistry != null) {
+                               PHPeclipsePlugin.logErrorMessage("Image registry already defined"); //$NON-NLS-1$
+                       }
                        return result;
                } catch (MalformedURLException e) {
                        return ImageDescriptor.getMissingImageDescriptor();
@@ -444,12 +512,12 @@ public class PHPUiImages {
 
        protected static URL makeIconFileURL(String prefix, String name)
                throws MalformedURLException {
-               if (iconBaseURL == null)
+               if (fgIconBaseURL == null)
                        throw new MalformedURLException();
 
                StringBuffer buffer = new StringBuffer(prefix);
                buffer.append('/');
                buffer.append(name);
-               return new URL(iconBaseURL, buffer.toString());
+               return new URL(fgIconBaseURL, buffer.toString());
        }
 }
\ No newline at end of file