69e97561ea69d1b0dc3bac8b99d88e5662470e87
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / PHPUnitImages.java
1 package net.sourceforge.phpeclipse.phpunit;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5
6 import org.eclipse.jface.resource.ImageDescriptor;
7 import org.eclipse.jface.resource.ImageRegistry;
8 import org.eclipse.swt.graphics.Image;
9
10 public class PHPUnitImages {
11
12         protected static final String NAME_PREFIX =
13                 "net.sourceforge.phpeclipse.phpunit";
14         protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
15
16         protected static URL iconBaseURL;
17
18         static {
19                 String pathSuffix = "icons/";
20                 try {
21                         iconBaseURL =
22                                 new URL(
23                                         PHPUnitPlugin.getDefault().getDescriptor().getInstallURL(),
24                                         pathSuffix);
25                 } catch (MalformedURLException e) {
26                         //PHPUnitPlugin.log(e);
27                         e.printStackTrace();
28                 }
29         }
30
31         protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
32
33         /*
34          * Available cached Images in the Java plugin image registry.
35          */
36
37         public static final String IMG_SELECT_TEST_SUITE = NAME_PREFIX + "tsuite.gif";
38         public static final String IMG_RUN_TEST_SUITE = NAME_PREFIX + "start.gif";
39         public static final String IMG_TEST_ERROR = NAME_PREFIX + "testerr.gif";
40         public static final String IMG_TEST_FAILURE = NAME_PREFIX + "testfail.gif";
41         public static final String IMG_TEST_PASS = NAME_PREFIX + "testok.gif";
42         public static final String IMG_TEST_SUITE_ERROR = NAME_PREFIX + "tsuiteerror.gif";
43         public static final String IMG_TEST_SUITE_PASS = NAME_PREFIX + "tsuiteok.gif";
44         public static final String IMG_TEST_SUITE_FAILURE = NAME_PREFIX + "tsuitefail.gif";
45         
46         public static final String IMG_ERROR = NAME_PREFIX + "error.gif";
47         public static final String IMG_FAILURE = NAME_PREFIX + "failure.gif";
48         
49
50
51         public static final ImageDescriptor DESC_SELECT_TEST_SUITE = createManaged(IMG_SELECT_TEST_SUITE);
52         public static final ImageDescriptor DESC_RUN_TEST_SUITE =createManaged(IMG_RUN_TEST_SUITE);
53         public static final ImageDescriptor DESC_TEST_ERROR = createManaged(IMG_TEST_ERROR);
54         public static final ImageDescriptor DESC_TEST_FAILURE = createManaged(IMG_TEST_FAILURE);
55         public static final ImageDescriptor DESC_TEST_PASS = createManaged(IMG_TEST_PASS);
56         public static final ImageDescriptor DESC_TEST_SUITE_ERROR = createManaged(IMG_TEST_SUITE_ERROR);
57         public static final ImageDescriptor DESC_TEST_SUITE_PASS = createManaged(IMG_TEST_SUITE_PASS);
58         public static final ImageDescriptor DESC_TEST_SUITE_FAILURE = createManaged(IMG_TEST_SUITE_FAILURE);
59         
60         public static final ImageDescriptor DESC_ERROR = createManaged(IMG_ERROR);
61         public static final ImageDescriptor DESC_FAILURE = createManaged(IMG_FAILURE);
62         /**
63          * Returns the image managed under the given key in this registry.
64          * 
65          * @param key the image's key
66          * @return the image managed under the given key
67          */
68         public static Image get(String key) {
69                 return IMAGE_REGISTRY.get(key);
70         }
71
72         public static ImageRegistry getImageRegistry() {
73                 return IMAGE_REGISTRY;
74         }
75
76         //---- Helper methods to access icons on the file system --------------------------------------
77
78         protected static ImageDescriptor createManaged(String name) {
79                 try {
80                         ImageDescriptor result =
81                                 ImageDescriptor.createFromURL(
82                                         makeIconFileURL(name.substring(NAME_PREFIX_LENGTH)));
83                         IMAGE_REGISTRY.put(name, result);
84                         return result;
85                 } catch (MalformedURLException e) {
86                         return ImageDescriptor.getMissingImageDescriptor();
87                 }
88         }
89
90         protected static URL makeIconFileURL(String name)
91                 throws MalformedURLException {
92                 if (iconBaseURL == null)
93                         throw new MalformedURLException();
94
95                 return new URL(iconBaseURL, name);
96         }
97 }