KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > AnnotationImageProvider


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso;
5
6 import org.eclipse.jface.resource.ImageDescriptor;
7 import org.eclipse.jface.resource.ImageRegistry;
8 import org.eclipse.jface.text.source.Annotation;
9 import org.eclipse.swt.graphics.Image;
10 import org.eclipse.swt.widgets.Display;
11 import org.eclipse.ui.texteditor.IAnnotationImageProvider;
12
13 import java.net.URL JavaDoc;
14
15 /**
16  * A provider of images for our annotations.
17  *
18  * @see org.eclipse.ui.texteditor.IAnnotationImageProvider
19  */

20
21 public class AnnotationImageProvider implements IAnnotationImageProvider {
22   private ImageRegistry m_imageRegistry;
23   
24   private static final Object JavaDoc[] DEFAULT_IMAGES = {
25     new String JavaDoc[] {"org.terracotta.dso.adaptedTypeAnnotation",
26                   "/com/tc/admin/icons/installed_ovr.gif"},
27     new String JavaDoc[] {"org.terracotta.dso.adaptedTypeReferenceAnnotation",
28                   "/com/tc/admin/icons/blank.gif"},
29     new String JavaDoc[] {"org.terracotta.dso.bootJarTypeAnnotation",
30                   "/com/tc/admin/icons/blank.gif"},
31     new String JavaDoc[] {"org.terracotta.dso.excludedTypeAnnotation",
32                   "/com/tc/admin/icons/error_obj.gif"},
33     new String JavaDoc[] {"org.terracotta.dso.nameLockedAnnotation",
34                   "/com/tc/admin/icons/namelocked_view.gif"},
35     new String JavaDoc[] {"org.terracotta.dso.autolockedAnnotation",
36                   "/com/tc/admin/icons/autolocked_view.gif"},
37     new String JavaDoc[] {"org.terracotta.dso.rootAnnotation",
38                   "/com/tc/admin/icons/hierarchicalLayout.gif"},
39     new String JavaDoc[] {"org.terracotta.dso.distributedMethodAnnotation",
40                   "/com/tc/admin/icons/jspbrkpt_obj.gif"},
41     new String JavaDoc[] {"org.terracotta.dso.transientFieldAnnotation",
42                   "/com/tc/admin/icons/transient.gif"},
43   };
44   
45   public AnnotationImageProvider() {
46     m_imageRegistry = new ImageRegistry(Display.getDefault());
47
48     String JavaDoc[] mapping;
49     for(int i = 0; i < DEFAULT_IMAGES.length; i++) {
50       mapping = (String JavaDoc[])DEFAULT_IMAGES[i];
51       addDescriptor(mapping[0], mapping[1]);
52     }
53   }
54   
55   public Image getManagedImage(Annotation annotation) {
56     return null;
57   }
58
59   public String JavaDoc getImageDescriptorId(Annotation annotation) {
60     return annotation.getType();
61   }
62
63   public ImageDescriptor getImageDescriptor(String JavaDoc id) {
64     return m_imageRegistry.getDescriptor(id);
65   }
66   
67   public ImageDescriptor addDescriptor(String JavaDoc id, String JavaDoc uri) {
68     ImageDescriptor imageDesc = null;
69     URL JavaDoc url = getClass().getResource(uri);
70     
71     if(url != null) {
72       m_imageRegistry.put(id, imageDesc = ImageDescriptor.createFromURL(url));
73     }
74     else {
75       System.out.println("Unable to load image '"+id+"' from '"+url+"'");
76     }
77     
78     return imageDesc;
79   }
80 }
81
Popular Tags