1 /*************************************************************************
2 * @author Ali Echihabi (ali_echihabi@ieee.org, ali.echihabi@souss.ca)
4 * Plugin for PHP unit Testing.
7 *************************************************************************/
9 package net.sourceforge.phpeclipse.phpunit;
11 import java.net.MalformedURLException;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.resource.ImageRegistry;
16 import org.eclipse.swt.graphics.Image;
19 public class PHPUnitImages {
21 protected static final String NAME_PREFIX =
22 "net.sourceforge.phpeclipse.phpunit";
23 protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
25 protected static URL iconBaseURL;
28 String pathSuffix = "icons/";
32 PHPUnitPlugin.getDefault().getDescriptor().getInstallURL(),
34 } catch (MalformedURLException e) {
35 //PHPUnitPlugin.log(e);
40 protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
43 * Available cached Images in the Java plugin image registry.
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";
59 public static final String IMG_ERROR = NAME_PREFIX + "error.gif";
60 public static final String IMG_FAILURE = NAME_PREFIX + "failure.gif";
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);
79 public static final ImageDescriptor DESC_ERROR = createManaged(IMG_ERROR);
80 public static final ImageDescriptor DESC_FAILURE =
81 createManaged(IMG_FAILURE);
83 * Returns the image managed under the given key in this registry.
85 * @param key the image's key
86 * @return the image managed under the given key
88 public static Image get(String key) {
89 return IMAGE_REGISTRY.get(key);
92 public static ImageRegistry getImageRegistry() {
93 return IMAGE_REGISTRY;
97 protected static ImageDescriptor createManaged(String name) {
99 ImageDescriptor result =
100 ImageDescriptor.createFromURL(
101 makeIconFileURL(name.substring(NAME_PREFIX_LENGTH)));
102 IMAGE_REGISTRY.put(name, result);
104 } catch (MalformedURLException e) {
105 return ImageDescriptor.getMissingImageDescriptor();
109 protected static URL makeIconFileURL(String name)
110 throws MalformedURLException {
111 if (iconBaseURL == null)
112 throw new MalformedURLException();
114 return new URL(iconBaseURL, name);