source: trunk/org.modelica.mdt.ui/src/org/modelica/mdt/ui/ModelicaImages.java @ 254

Last change on this file since 254 was 254, checked in by boris, 19 years ago
  • fixed problem with images that fail to be loaded
File size: 5.7 KB
Line 
1/*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.modelica.mdt.ui;
12
13
14import java.net.MalformedURLException;
15import java.net.URL;
16
17import org.eclipse.jface.resource.ImageDescriptor;
18import org.eclipse.jface.resource.ImageRegistry;
19import org.eclipse.swt.graphics.Image;
20import org.modelica.mdt.ErrorManager;
21
22/**
23 * Bundle of most images used by the Mdt plug-in.
24 */
25public class ModelicaImages 
26{
27
28    /* Declare Common paths */
29    private static URL ICON_BASE_URL= null;
30
31    static 
32    {
33        String pathSuffix = "icons/"; //$NON-NLS-1$
34        ICON_BASE_URL= Plugin.getDefault().getBundle().getEntry(pathSuffix);
35    }
36   
37    // The plugin registry
38    private static ImageRegistry fgImageRegistry = null;
39
40    /*
41     * Available cached Images in the Mdt plug-in image registry.
42     */ 
43    public static final String IMG_OBJS_PACKAGE = "IMG_OBJS_EXCEPTION";
44    public static final String IMG_OBJS_CLASS = "IMG_OBJS_CLASS";
45    public static final String IMG_OBJS_MODEL = "IMG_OBJS_MODEL";
46    public static final String IMG_OBJS_FUNCTION = "IMG_OBJS_FUNCTION";
47    public static final String IMG_OBJS_RECORD = "IMG_OBJS_RECORD";
48    public static final String IMG_OBJS_CONNECTOR = "IMG_OBJS_CONNECTOR";
49    public static final String IMG_OBJS_BLOCK = "IMG_OBJS_BLOCK";   
50    public static final String IMG_OBJS_TYPE = "IMG_OBJS_TYPE";
51    public static final String IMG_OBJS_LIBRARY = "IMG_OBJS_LIBRARY";
52    public static final String IMG_OBJS_MO_FILE = "IMG_OBJS_MO_FILE";
53    public static final String IMG_OBJS_PROTECTED_COMPONENT
54            = "IMG_OBJS_PROTECTED_COMPONENT";
55    public static final String  IMG_OBJS_PUBLIC_COMPONENT
56            = "IMG_OBJS_PUBLIC_COMPONENT";
57   
58    public static final String IMG_WIZBAN_PACKAGE = "IMG_WIZBAN_PACKAGE";
59    public static final String IMG_WIZBAN_PROJECT = "IMG_WIZBAN_PROJECT";
60    public static final String IMG_WIZBAN_CLASS = "IMG_WIZBAN_CLASS";
61   
62   
63    /*
64     * Set of predefined Image Descriptors.
65     */
66    private static final String T_OBJ= "obj16/";        //$NON-NLS-1$
67//  private static final String T_OVR= "ovr16/";        //$NON-NLS-1$
68    private static final String T_WIZBAN= "wizban/";    //$NON-NLS-1$
69//  private static final String T_EVIEW= "eview16/";    //$NON-NLS-1$
70//  private static final String T_DLCL= "dtool16/";     //$NON-NLS-1$
71//  private static final String T_ELCL= "etool16/";     //$NON-NLS-1$
72
73
74   
75    /**
76     * Returns the image managed under the given key in this registry.
77     *
78     * @param key the image's key
79     * @return the image managed under the given key
80     */ 
81    public static Image get(String key) 
82    {
83        return getImageRegistry().get(key);
84    }
85   
86    /**
87     * Returns the <code>ImageDescriptor</code> identified by the given key,
88     * or <code>null</code> if it does not exist.
89     */
90    public static ImageDescriptor getImageDescriptor(String key) 
91    {
92        return getImageRegistry().getDescriptor(key);
93    }   
94   
95    /*
96     * Helper method to access the image registry from the JDIDebugUIPlugin class.
97     */
98    /* package */ static ImageRegistry getImageRegistry() 
99    {
100        if (fgImageRegistry == null) 
101        {
102            initializeImageRegistry();
103        }
104        return fgImageRegistry;
105    }
106   
107    private static void initializeImageRegistry() 
108    {
109        fgImageRegistry = new ImageRegistry(Plugin.getStandardDisplay());
110        declareImages();
111    }
112   
113    private static void declareImages() 
114    {
115        declareRegistryImage(IMG_OBJS_PACKAGE, T_OBJ + "package_obj.png"); //$NON-NLS-1$
116       
117        declareRegistryImage(IMG_OBJS_CLASS, T_OBJ + "class_obj.png");
118        declareRegistryImage(IMG_OBJS_MODEL, T_OBJ + "model_obj.png");
119        declareRegistryImage(IMG_OBJS_FUNCTION, T_OBJ + "function_obj.png");
120        declareRegistryImage(IMG_OBJS_RECORD, T_OBJ + "record_obj.png");
121        declareRegistryImage(IMG_OBJS_CONNECTOR, T_OBJ + "connector_obj.png");
122        declareRegistryImage(IMG_OBJS_BLOCK, T_OBJ + "block_obj.png");
123        declareRegistryImage(IMG_OBJS_TYPE, T_OBJ + "type_obj.png");
124        declareRegistryImage(IMG_OBJS_MO_FILE, T_OBJ + "mo_file.png");
125        declareRegistryImage(IMG_OBJS_LIBRARY, T_OBJ + "library_obj.png");
126        declareRegistryImage(IMG_OBJS_PROTECTED_COMPONENT, 
127                T_OBJ + "protected_component_obj.png");
128        declareRegistryImage(IMG_OBJS_PUBLIC_COMPONENT, 
129                T_OBJ + "public_component_obj.png");
130       
131        declareRegistryImage(IMG_WIZBAN_PACKAGE, T_WIZBAN + "package_wiz.png");
132        declareRegistryImage(IMG_WIZBAN_PROJECT, T_WIZBAN + "project_wiz.png");
133        declareRegistryImage(IMG_WIZBAN_CLASS, T_WIZBAN + "class_wiz.png");
134               
135    }
136   
137    /**
138     * Declare an Image in the registry table.
139     * @param key   The key to use when registering the image
140     * @param path  The path where the image can be found. This path is relative to where
141     *              this plugin class is found (i.e. typically the packages directory)
142     */
143    private final static void declareRegistryImage(String key, String path)
144    {
145        ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
146        try 
147        {
148            desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
149        }
150        catch (MalformedURLException me) 
151        {
152            ErrorManager.logError(me);
153        }
154        fgImageRegistry.put(key, desc);
155    }   
156   
157    private static URL makeIconFileURL(String iconPath) throws MalformedURLException
158    {
159        if (ICON_BASE_URL == null) 
160        {
161            throw new MalformedURLException();
162        }
163           
164        return new URL(ICON_BASE_URL, iconPath);
165    }   
166
167}
Note: See TracBrowser for help on using the repository browser.