BaseIconManager.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.common.ui;
00002 
00003 import org.eclipse.jface.resource.ImageDescriptor;
00004 import org.eclipse.jface.resource.ImageRegistry;
00005 import org.eclipse.swt.graphics.Image;
00006 import org.eclipse.ui.plugin.AbstractUIPlugin;
00007 
00008 import edu.rice.cs.hpc.common.plugin.Activator;
00009 
00010 /********************************************
00011  * 
00012  * Icon manager for registering to ImageRegistry
00013  *
00014  ********************************************/
00015 public abstract class BaseIconManager 
00016 {
00017     /********
00018      * get image from the registry
00019      * 
00020      * @param desc
00021      * @return Image if the key matches, null otherwise
00022      */
00023     static public Image getImage(AbstractUIPlugin plugin, final String desc) {
00024         final ImageRegistry registry = getRegistry(plugin);
00025         
00026         return registry.get(desc);
00027     }
00028     
00029     /********
00030      * get image descriptor from the registry
00031      * 
00032      * @param desc : the key descriptor
00033      * @return ImageRegistry if the key matches, null otherwise
00034      */
00035     static public ImageDescriptor getDescriptor(AbstractUIPlugin plugin, final String desc) {
00036         final ImageRegistry registry = getRegistry(plugin);
00037         
00038         return registry.getDescriptor(desc);
00039     }
00040 
00041     static protected ImageRegistry getRegistry(AbstractUIPlugin plugin) {
00042         // prepare the icon
00043         ImageRegistry imageRegistry = plugin.getImageRegistry();
00044         
00045         return imageRegistry;
00046     }
00047     
00048     protected void registerImage(ImageRegistry registry, Class<?> location, String key) {
00049         final ImageDescriptor desc = ImageDescriptor.createFromFile(location, key);
00050         registry.put(key, desc.createImage());
00051     }
00052 
00053     protected void registerDescriptor(ImageRegistry registry, Class<?> location, String key) {
00054         final ImageDescriptor desc = ImageDescriptor.createFromFile(location, key);
00055         registry.put(key, desc);
00056     }
00057 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1