View Javadoc

1   /*
2    * $Id: OWLImages.java,v 1.13 2005/05/31 21:57:12 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8   package com.bbn.swede.ui;
9   
10  
11  import java.net.MalformedURLException;
12  import java.net.URL;
13  
14  import org.eclipse.core.runtime.Platform;
15  import org.eclipse.jface.resource.ImageDescriptor;
16  import org.eclipse.jface.resource.ImageRegistry;
17  import org.eclipse.core.runtime.Path;
18  
19  import org.eclipse.swt.graphics.Image;
20  
21  /***
22   * Centralized image storage for SWeDE.  Provides access to icons included
23   * in the .ui plugin.
24   * @author jlerner
25   */
26  public final class OWLImages
27  {
28     private static final URL URL_BASIC =
29        Platform.find(Platform.getBundle("com.bbn.swede.ui"), new Path("/"));
30  
31     private static final String ICONS_PATH = "icons/"; //$NON-NLS-1$
32  
33     /***
34      * Image name string for OWL document object icon.
35      */
36     public static final String IMG_OWL_OBJ = "IMG_OWL_OBJ";
37     /***
38      * Image name string for external OWL document object icon.
39      */
40     public static final String IMG_OWL_EXT_OBJ = "IMG_OWL_EXT_OBJ";
41     /***
42      * Image name string for OWL class object icon.
43      */
44     public static final String IMG_CLASS_OBJ = "IMG_CLASS_OBJ";
45     /***
46      * Image name string for literal object icon.
47      */
48     public static final String IMG_LIT_OBJ = "IMG_LIT_OBJ";
49     /***
50      * Image name string for attribute object icon.
51      */
52     public static final String IMG_ATTRIB_OBJ = "IMG_ATTRIB_OBJ";
53     /***
54      * Image name string for OWL property object icon.
55      */
56     public static final String IMG_PROP_OBJ = "IMG_PROP_OBJ";
57     /***
58      * Image name string for OWL datatype property object icon.
59      */
60     public static final String IMG_DT_PROP_OBJ = "IMG_DT_PROP_OBJ";
61     /***
62      * Image name string for OWL object property object icon.
63      */
64     public static final String IMG_O_PROP_OBJ = "IMG_O_PROP_OBJ";
65     /***
66      * Image name string for OWL folder object icon.
67      */
68     public static final String IMG_OWLFOLD_OBJ = "IMG_OWLFOLD_OBJ";
69     /***
70      * Image name string for OWL project object icon.
71      */
72     public static final String IMG_OWLPROJ_OBJ = "IMG_OWLPROJ_OBJ";
73     /***
74      * Image name string for OWL individual object icon.
75      */
76     public static final String IMG_OWL_INST = "IMG_OWL_INST";
77     /***
78      * Image name string for OWL thing object icon.
79      */
80     public static final String IMG_THING = "IMG_THING";
81     /***
82      * Image name string for predicate object icon.
83      */
84     public static final String IMG_PREDICATE = "IMG_PREDICATE";
85     /***
86      * Image name string for unparseable object icon.
87      */
88     public static final String IMG_UNPARSEABLE = "IMG_UNPARSEABLE";
89     /***
90      * Image name string for Ontology object icon.
91      */
92     public static final String IMG_ONTOLOGY = "IMG_ONTOLOGY";
93  
94     private static OWLImages _owlImages = new OWLImages();
95     /***
96      * Provides access to the one and only instance of OWLImages.
97      * @return The singleton instance
98      */
99     public static OWLImages getOWLImages()
100    {
101       return _owlImages;
102    }
103    
104    /***
105     * Initializes the singleton instance of OWLImages.
106     */
107    private OWLImages()
108    {
109       _imageRegistry = new ImageRegistry();
110 
111       declareRegistryImage(IMG_OWL_OBJ, ICONS_PATH + "owl-document.gif");
112       declareRegistryImage(
113          IMG_OWL_EXT_OBJ,
114          ICONS_PATH + "owl-external-document.gif");
115       declareRegistryImage(IMG_CLASS_OBJ, ICONS_PATH + "owl-class.gif");
116       declareRegistryImage(IMG_LIT_OBJ, ICONS_PATH + "literal.gif");
117       declareRegistryImage(IMG_ATTRIB_OBJ, ICONS_PATH + "attribute.gif");
118       declareRegistryImage(IMG_PROP_OBJ, ICONS_PATH + "owl-property.gif");
119       declareRegistryImage(IMG_DT_PROP_OBJ, ICONS_PATH + "owl-dt-property.gif");
120       declareRegistryImage(IMG_O_PROP_OBJ, ICONS_PATH + "owl-o-property.gif");
121       declareRegistryImage(IMG_OWLFOLD_OBJ, ICONS_PATH + "owl-folder.gif");
122       declareRegistryImage(IMG_OWLPROJ_OBJ, ICONS_PATH + "owl-project.gif");
123       declareRegistryImage(IMG_OWL_INST, ICONS_PATH + "owl-instance.gif");
124       declareRegistryImage(IMG_THING, ICONS_PATH + "thing.gif");
125       declareRegistryImage(IMG_PREDICATE, ICONS_PATH + "predicate.gif");
126       declareRegistryImage(IMG_UNPARSEABLE, ICONS_PATH + "unparsable.gif");
127       declareRegistryImage(IMG_ONTOLOGY, ICONS_PATH + "ontology.gif");
128    }
129 
130    private ImageRegistry _imageRegistry;
131 
132    /***
133     * Adds a graphic to the image registry.
134     * @param key The name to associate with the image, which can be used later
135     *            to retrieve it
136     * @param path The location of the image on the filesystem
137     */
138    private void declareRegistryImage(String key, String path)
139    {
140       URL url = null;
141       try
142       {
143          url = new URL(URL_BASIC, path);
144       }
145       catch (MalformedURLException e)
146       {
147          //do nothing
148       }
149       ImageDescriptor desc = ImageDescriptor.createFromURL(url);
150       _imageRegistry.put(key, desc);
151    }
152 
153    /***
154     * Retrieves a shared image.
155     * @param sKey The name of the image to retrieve
156     * @return The image specified by <code>sKey</code>, or <code>null</code> if
157     *         no such image exists in the registry
158     */
159    public static Image getSharedImage(String sKey)
160    {
161       return getOWLImages()._imageRegistry.get(sKey);
162    }
163 }