Prevents the location update and the display of the "location not found" dialog box
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / PHPUnitImages.java
1 /*************************************************************************
2  * @author Ali Echihabi (ali_echihabi@ieee.org, ali.echihabi@souss.ca)
3  *
4  * Plugin for PHP unit Testing.
5  * www.phpeclipse.de
6  * 
7  *************************************************************************/
8
9 package net.sourceforge.phpeclipse.phpunit;
10
11 import java.net.MalformedURLException;
12 import java.net.URL;
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.resource.ImageRegistry;
16 import org.eclipse.swt.graphics.Image;
17
18 public class PHPUnitImages {
19
20         protected static final String NAME_PREFIX = "net.sourceforge.phpeclipse.phpunit";
21
22         protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
23
24         protected static URL iconBaseURL;
25
26         static {
27                 String pathSuffix = "icons/";
28                 try {
29                         iconBaseURL = new URL(PHPUnitPlugin.getDefault().getDescriptor()
30                                         .getInstallURL(), pathSuffix);
31                 } catch (MalformedURLException e) {
32                         // PHPUnitPlugin.log(e);
33                         e.printStackTrace();
34                 }
35         }
36
37         protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
38
39         /*
40          * Available cached Images in the Java plugin image registry.
41          */
42
43         public static final String IMG_SELECT_TEST_SUITE = NAME_PREFIX
44                         + "tsuite.gif";
45
46         public static final String IMG_RUN_TEST_SUITE = NAME_PREFIX + "start.gif";
47
48         public static final String IMG_TEST_ERROR = NAME_PREFIX + "testerr.gif";
49
50         public static final String IMG_TEST_FAILURE = NAME_PREFIX + "testfail.gif";
51
52         public static final String IMG_TEST_PASS = NAME_PREFIX + "testok.gif";
53
54         public static final String IMG_TEST_SUITE_ERROR = NAME_PREFIX
55                         + "tsuiteerror.gif";
56
57         public static final String IMG_TEST_SUITE_PASS = NAME_PREFIX
58                         + "tsuiteok.gif";
59
60         public static final String IMG_TEST_SUITE_FAILURE = NAME_PREFIX
61                         + "tsuitefail.gif";
62
63         public static final String IMG_ERROR = NAME_PREFIX + "error.gif";
64
65         public static final String IMG_FAILURE = NAME_PREFIX + "failure.gif";
66
67         public static final ImageDescriptor DESC_SELECT_TEST_SUITE = createManaged(IMG_SELECT_TEST_SUITE);
68
69         public static final ImageDescriptor DESC_RUN_TEST_SUITE = createManaged(IMG_RUN_TEST_SUITE);
70
71         public static final ImageDescriptor DESC_TEST_ERROR = createManaged(IMG_TEST_ERROR);
72
73         public static final ImageDescriptor DESC_TEST_FAILURE = createManaged(IMG_TEST_FAILURE);
74
75         public static final ImageDescriptor DESC_TEST_PASS = createManaged(IMG_TEST_PASS);
76
77         public static final ImageDescriptor DESC_TEST_SUITE_ERROR = createManaged(IMG_TEST_SUITE_ERROR);
78
79         public static final ImageDescriptor DESC_TEST_SUITE_PASS = createManaged(IMG_TEST_SUITE_PASS);
80
81         public static final ImageDescriptor DESC_TEST_SUITE_FAILURE = createManaged(IMG_TEST_SUITE_FAILURE);
82
83         public static final ImageDescriptor DESC_ERROR = createManaged(IMG_ERROR);
84
85         public static final ImageDescriptor DESC_FAILURE = createManaged(IMG_FAILURE);
86
87         /**
88          * Returns the image managed under the given key in this registry.
89          * 
90          * @param key
91          *            the image's key
92          * @return the image managed under the given key
93          */
94         public static Image get(String key) {
95                 return IMAGE_REGISTRY.get(key);
96         }
97
98         public static ImageRegistry getImageRegistry() {
99                 return IMAGE_REGISTRY;
100         }
101
102         protected static ImageDescriptor createManaged(String name) {
103                 try {
104                         ImageDescriptor result = ImageDescriptor
105                                         .createFromURL(makeIconFileURL(name
106                                                         .substring(NAME_PREFIX_LENGTH)));
107                         IMAGE_REGISTRY.put(name, result);
108                         return result;
109                 } catch (MalformedURLException e) {
110                         return ImageDescriptor.getMissingImageDescriptor();
111                 }
112         }
113
114         protected static URL makeIconFileURL(String name)
115                         throws MalformedURLException {
116                 if (iconBaseURL == null)
117                         throw new MalformedURLException();
118
119                 return new URL(iconBaseURL, name);
120         }
121 }