Difference between revisions of "FAQ How do I create an image registry for my plug-in?"

From Eclipsepedia

Jump to: navigation, search
 
m
Line 8: Line 8:
 
overhead if you never use it. Here is an example of a plug-in that adds a  
 
overhead if you never use it. Here is an example of a plug-in that adds a  
 
<tt>sample.gif</tt> image to its image registry:
 
<tt>sample.gif</tt> image to its image registry:
 +
 
<pre>
 
<pre>
 
   public class ExamplesPlugin extends AbstractUIPlugin {
 
   public class ExamplesPlugin extends AbstractUIPlugin {
Line 25: Line 26:
 
   }
 
   }
 
</pre>
 
</pre>
 
  
 
== See Also: ==
 
== See Also: ==
[[FAQ_How_do_I_use_image_and_font_registries%3F]]
+
*[[FAQ_How_do_I_use_image_and_font_registries%3F]]
 
+
*[[FAQ_How_do_I_use_images_defined_by_other_plug-ins%3F]]
[[FAQ_How_do_I_use_images_defined_by_other_plug-ins%3F]]
+
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Revision as of 22:07, 29 May 2006

If you’re writing a plug-in with UI components, it should be a subclass of AbstractUIPlugin. This superclass already provides you with an empty image registry accessible by calling getImageRegistry. When the registry is first accessed, the hook method initializeImageRegistry will be called. You should override this method to populate your image registry with the image descriptors you need. You don’t have to use this registry if you don’t need it, and because it is created lazily on first access, there is no performance overhead if you never use it. Here is an example of a plug-in that adds a sample.gif image to its image registry:

   public class ExamplesPlugin extends AbstractUIPlugin {
      public static final String PLUGIN_ID = 
                                  "org.eclipse.faq.examples";
      public static final String IMAGE_ID = "sample.image";
      ...
      protected void initializeImageRegistry(
                                   ImageRegistry registry) {
         Bundle bundle = Platform.getBundle(PLUGIN_ID);
         IPath path = new Path("icons/sample.gif");
         URL url = Platform.find(bundle, path);
         ImageDescriptor desc = 
                      ImageDescriptor.createFromURL(url);
         registry.put(IMAGE_ID, desc);
      }
   }

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.