Merged "Open PHP Declaration" and "Open Include File" into one action "Open Declarati...
[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
19 public class PHPUnitImages {
20
21         protected static final String NAME_PREFIX =
22                 "net.sourceforge.phpeclipse.phpunit";
23         protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
24
25         protected static URL iconBaseURL;
26
27         static {
28                 String pathSuffix = "icons/";
29                 try {
30                         iconBaseURL =
31                                 new URL(
32                                         PHPUnitPlugin.getDefault().getDescriptor().getInstallURL(),
33                                         pathSuffix);
34                 } catch (MalformedURLException e) {
35                         //PHPUnitPlugin.log(e);
36                         e.printStackTrace();
37                 }
38         }
39
40         protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
41
42         /*
43          * Available cached Images in the Java plugin image registry.
44          */
45
46         public static final String IMG_SELECT_TEST_SUITE =
47                 NAME_PREFIX + "tsuite.gif";
48         public static final String IMG_RUN_TEST_SUITE = NAME_PREFIX + "start.gif";
49         public static final String IMG_TEST_ERROR = NAME_PREFIX + "testerr.gif";
50         public static final String IMG_TEST_FAILURE = NAME_PREFIX + "testfail.gif";
51         public static final String IMG_TEST_PASS = NAME_PREFIX + "testok.gif";
52         public static final String IMG_TEST_SUITE_ERROR =
53                 NAME_PREFIX + "tsuiteerror.gif";
54         public static final String IMG_TEST_SUITE_PASS =
55                 NAME_PREFIX + "tsuiteok.gif";
56         public static final String IMG_TEST_SUITE_FAILURE =
57                 NAME_PREFIX + "tsuitefail.gif";
58
59         public static final String IMG_ERROR = NAME_PREFIX + "error.gif";
60         public static final String IMG_FAILURE = NAME_PREFIX + "failure.gif";
61
62         public static final ImageDescriptor DESC_SELECT_TEST_SUITE =
63                 createManaged(IMG_SELECT_TEST_SUITE);
64         public static final ImageDescriptor DESC_RUN_TEST_SUITE =
65                 createManaged(IMG_RUN_TEST_SUITE);
66         public static final ImageDescriptor DESC_TEST_ERROR =
67                 createManaged(IMG_TEST_ERROR);
68         public static final ImageDescriptor DESC_TEST_FAILURE =
69                 createManaged(IMG_TEST_FAILURE);
70         public static final ImageDescriptor DESC_TEST_PASS =
71                 createManaged(IMG_TEST_PASS);
72         public static final ImageDescriptor DESC_TEST_SUITE_ERROR =
73                 createManaged(IMG_TEST_SUITE_ERROR);
74         public static final ImageDescriptor DESC_TEST_SUITE_PASS =
75                 createManaged(IMG_TEST_SUITE_PASS);
76         public static final ImageDescriptor DESC_TEST_SUITE_FAILURE =
77                 createManaged(IMG_TEST_SUITE_FAILURE);
78
79         public static final ImageDescriptor DESC_ERROR = createManaged(IMG_ERROR);
80         public static final ImageDescriptor DESC_FAILURE =
81                 createManaged(IMG_FAILURE);
82         /**
83          * Returns the image managed under the given key in this registry.
84          * 
85          * @param key the image's key
86          * @return the image managed under the given key
87          */
88         public static Image get(String key) {
89                 return IMAGE_REGISTRY.get(key);
90         }
91
92         public static ImageRegistry getImageRegistry() {
93                 return IMAGE_REGISTRY;
94         }
95
96
97         protected static ImageDescriptor createManaged(String name) {
98                 try {
99                         ImageDescriptor result =
100                                 ImageDescriptor.createFromURL(
101                                         makeIconFileURL(name.substring(NAME_PREFIX_LENGTH)));
102                         IMAGE_REGISTRY.put(name, result);
103                         return result;
104                 } catch (MalformedURLException e) {
105                         return ImageDescriptor.getMissingImageDescriptor();
106                 }
107         }
108
109         protected static URL makeIconFileURL(String name)
110                 throws MalformedURLException {
111                 if (iconBaseURL == null)
112                         throw new MalformedURLException();
113
114                 return new URL(iconBaseURL, name);
115         }
116 }