KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > utils > EclipseImageMap


1 /*
2  * Created on 2004-11-01 by max
3  *
4  */

5 package org.hibernate.eclipse.console.utils;
6
7 import java.net.MalformedURLException JavaDoc;
8 import java.net.URL JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11
12 import org.eclipse.jface.resource.ImageDescriptor;
13 import org.eclipse.jface.resource.ImageRegistry;
14 import org.eclipse.swt.graphics.Image;
15 import org.hibernate.console.ImageMap;
16 import org.hibernate.eclipse.console.HibernateConsolePlugin;
17
18 /**
19  * @author max
20  *
21  */

22 public class EclipseImageMap extends ImageMap {
23
24     public EclipseImageMap() {
25
26         declareImages();
27     }
28     
29     /** Declare Common paths */
30     protected static URL JavaDoc ICON_BASE_URL = null;
31
32     static {
33         String JavaDoc pathSuffix = "icons/";//$NON-NLS-1$
34

35         try {
36             ICON_BASE_URL = new URL JavaDoc(HibernateConsolePlugin.getDefault().getBundle().getEntry("/"), pathSuffix);//$NON-NLS-1$
37
} catch (MalformedURLException JavaDoc e) {
38             // do nothing
39
}
40     }
41
42     /** A table of all the <code>ImageDescriptor</code>s. */
43     Map JavaDoc imageDescriptors = new HashMap JavaDoc();
44     
45     /** The image registry containing <code>Image</code>s. */
46     ImageRegistry imageRegistry = new ImageRegistry();
47     
48     protected void declareRegistryImage(String JavaDoc key, String JavaDoc path) {
49         ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
50         try {
51             desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
52         } catch (MalformedURLException JavaDoc me) {
53             HibernateConsolePlugin.getDefault().log(me);
54         }
55         imageRegistry.put(key, desc);
56         imageDescriptors.put(key, desc);
57     }
58     
59     protected static URL JavaDoc makeIconFileURL(String JavaDoc iconPath)
60             throws MalformedURLException JavaDoc {
61         if (ICON_BASE_URL == null) {
62             throw new MalformedURLException JavaDoc();
63         }
64
65         return new URL JavaDoc(ICON_BASE_URL, iconPath);
66     }
67
68     public Image getImage(String JavaDoc key) {
69         return imageRegistry.get(key);
70     }
71
72     public ImageDescriptor getImageDescriptor(String JavaDoc key) {
73         
74         return (ImageDescriptor) imageDescriptors.get(key);
75     }
76
77 }
78
Popular Tags