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 | *******************************************************************************/ |
---|
11 | package org.modelica.mdt.ui; |
---|
12 | |
---|
13 | |
---|
14 | import java.net.MalformedURLException; |
---|
15 | import java.net.URL; |
---|
16 | |
---|
17 | import org.eclipse.jface.resource.ImageDescriptor; |
---|
18 | import org.eclipse.jface.resource.ImageRegistry; |
---|
19 | import org.eclipse.swt.graphics.Image; |
---|
20 | import org.modelica.mdt.MdtPlugin; |
---|
21 | |
---|
22 | /** |
---|
23 | * Bundle of most images used by the Mdt plug-in. |
---|
24 | */ |
---|
25 | public 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= MdtPlugin.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_MO_FILE = "IMG_OBJS_MO_FILE"; |
---|
52 | public static final String IMG_OBJS_LIBRARY = "IMG_OBJS_LIBRARY"; |
---|
53 | |
---|
54 | public static final String IMG_WIZBAN_PACKAGE = "IMG_WIZBAN_PACKAGE"; |
---|
55 | |
---|
56 | |
---|
57 | /* |
---|
58 | * Set of predefined Image Descriptors. |
---|
59 | */ |
---|
60 | private static final String T_OBJ= "obj16/"; //$NON-NLS-1$ |
---|
61 | // private static final String T_OVR= "ovr16/"; //$NON-NLS-1$ |
---|
62 | private static final String T_WIZBAN= "wizban/"; //$NON-NLS-1$ |
---|
63 | // private static final String T_EVIEW= "eview16/"; //$NON-NLS-1$ |
---|
64 | // private static final String T_DLCL= "dtool16/"; //$NON-NLS-1$ |
---|
65 | // private static final String T_ELCL= "etool16/"; //$NON-NLS-1$ |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | /** |
---|
70 | * Returns the image managed under the given key in this registry. |
---|
71 | * |
---|
72 | * @param key the image's key |
---|
73 | * @return the image managed under the given key |
---|
74 | */ |
---|
75 | public static Image get(String key) |
---|
76 | { |
---|
77 | return getImageRegistry().get(key); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Returns the <code>ImageDescriptor</code> identified by the given key, |
---|
82 | * or <code>null</code> if it does not exist. |
---|
83 | */ |
---|
84 | public static ImageDescriptor getImageDescriptor(String key) |
---|
85 | { |
---|
86 | return getImageRegistry().getDescriptor(key); |
---|
87 | } |
---|
88 | |
---|
89 | /* |
---|
90 | * Helper method to access the image registry from the JDIDebugUIPlugin class. |
---|
91 | */ |
---|
92 | /* package */ static ImageRegistry getImageRegistry() |
---|
93 | { |
---|
94 | if (fgImageRegistry == null) |
---|
95 | { |
---|
96 | initializeImageRegistry(); |
---|
97 | } |
---|
98 | return fgImageRegistry; |
---|
99 | } |
---|
100 | |
---|
101 | private static void initializeImageRegistry() |
---|
102 | { |
---|
103 | fgImageRegistry= new ImageRegistry(MdtPlugin.getStandardDisplay()); |
---|
104 | declareImages(); |
---|
105 | } |
---|
106 | |
---|
107 | private static void declareImages() |
---|
108 | { |
---|
109 | declareRegistryImage(IMG_OBJS_PACKAGE, T_OBJ + "package_obj.gif"); //$NON-NLS-1$ |
---|
110 | |
---|
111 | declareRegistryImage(IMG_OBJS_CLASS, T_OBJ + "class_obj.png"); |
---|
112 | declareRegistryImage(IMG_OBJS_MODEL, T_OBJ + "model_obj.png"); |
---|
113 | declareRegistryImage(IMG_OBJS_FUNCTION, T_OBJ + "function_obj.png"); |
---|
114 | declareRegistryImage(IMG_OBJS_RECORD, T_OBJ + "record_obj.png"); |
---|
115 | declareRegistryImage(IMG_OBJS_CONNECTOR, T_OBJ + "connector_obj.png"); |
---|
116 | declareRegistryImage(IMG_OBJS_BLOCK, T_OBJ + "block_obj.png"); |
---|
117 | declareRegistryImage(IMG_OBJS_TYPE, T_OBJ + "type_obj.png"); |
---|
118 | declareRegistryImage(IMG_OBJS_MO_FILE, T_OBJ + "mo_file.png"); |
---|
119 | declareRegistryImage(IMG_OBJS_LIBRARY, T_OBJ + "library_obj.gif"); |
---|
120 | |
---|
121 | declareRegistryImage(IMG_WIZBAN_PACKAGE, T_WIZBAN + "package_wiz.gif"); |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | /** |
---|
126 | * Declare an Image in the registry table. |
---|
127 | * @param key The key to use when registering the image |
---|
128 | * @param path The path where the image can be found. This path is relative to where |
---|
129 | * this plugin class is found (i.e. typically the packages directory) |
---|
130 | */ |
---|
131 | private final static void declareRegistryImage(String key, String path) |
---|
132 | { |
---|
133 | ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor(); |
---|
134 | try |
---|
135 | { |
---|
136 | desc = ImageDescriptor.createFromURL(makeIconFileURL(path)); |
---|
137 | } |
---|
138 | catch (MalformedURLException me) |
---|
139 | { |
---|
140 | MdtPlugin.log(me); |
---|
141 | } |
---|
142 | fgImageRegistry.put(key, desc); |
---|
143 | } |
---|
144 | |
---|
145 | private static URL makeIconFileURL(String iconPath) throws MalformedURLException |
---|
146 | { |
---|
147 | if (ICON_BASE_URL == null) |
---|
148 | { |
---|
149 | throw new MalformedURLException(); |
---|
150 | } |
---|
151 | |
---|
152 | return new URL(ICON_BASE_URL, iconPath); |
---|
153 | } |
---|
154 | |
---|
155 | } |
---|