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;
18 public class PHPUnitImages {
20 protected static final String NAME_PREFIX = "net.sourceforge.phpeclipse.phpunit";
22 protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
24 protected static URL iconBaseURL;
27 String pathSuffix = "icons/";
29 iconBaseURL = new URL(PHPUnitPlugin.getDefault().getDescriptor()
30 .getInstallURL(), pathSuffix);
31 } catch (MalformedURLException e) {
32 // PHPUnitPlugin.log(e);
37 protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
40 * Available cached Images in the Java plugin image registry.
43 public static final String IMG_SELECT_TEST_SUITE = NAME_PREFIX
46 public static final String IMG_RUN_TEST_SUITE = NAME_PREFIX + "start.gif";
48 public static final String IMG_TEST_ERROR = NAME_PREFIX + "testerr.gif";
50 public static final String IMG_TEST_FAILURE = NAME_PREFIX + "testfail.gif";
52 public static final String IMG_TEST_PASS = NAME_PREFIX + "testok.gif";
54 public static final String IMG_TEST_SUITE_ERROR = NAME_PREFIX
57 public static final String IMG_TEST_SUITE_PASS = NAME_PREFIX
60 public static final String IMG_TEST_SUITE_FAILURE = NAME_PREFIX
63 public static final String IMG_ERROR = NAME_PREFIX + "error.gif";
65 public static final String IMG_FAILURE = NAME_PREFIX + "failure.gif";
67 public static final ImageDescriptor DESC_SELECT_TEST_SUITE = createManaged(IMG_SELECT_TEST_SUITE);
69 public static final ImageDescriptor DESC_RUN_TEST_SUITE = createManaged(IMG_RUN_TEST_SUITE);
71 public static final ImageDescriptor DESC_TEST_ERROR = createManaged(IMG_TEST_ERROR);
73 public static final ImageDescriptor DESC_TEST_FAILURE = createManaged(IMG_TEST_FAILURE);
75 public static final ImageDescriptor DESC_TEST_PASS = createManaged(IMG_TEST_PASS);
77 public static final ImageDescriptor DESC_TEST_SUITE_ERROR = createManaged(IMG_TEST_SUITE_ERROR);
79 public static final ImageDescriptor DESC_TEST_SUITE_PASS = createManaged(IMG_TEST_SUITE_PASS);
81 public static final ImageDescriptor DESC_TEST_SUITE_FAILURE = createManaged(IMG_TEST_SUITE_FAILURE);
83 public static final ImageDescriptor DESC_ERROR = createManaged(IMG_ERROR);
85 public static final ImageDescriptor DESC_FAILURE = createManaged(IMG_FAILURE);
88 * Returns the image managed under the given key in this registry.
92 * @return the image managed under the given key
94 public static Image get(String key) {
95 return IMAGE_REGISTRY.get(key);
98 public static ImageRegistry getImageRegistry() {
99 return IMAGE_REGISTRY;
102 protected static ImageDescriptor createManaged(String name) {
104 ImageDescriptor result = ImageDescriptor
105 .createFromURL(makeIconFileURL(name
106 .substring(NAME_PREFIX_LENGTH)));
107 IMAGE_REGISTRY.put(name, result);
109 } catch (MalformedURLException e) {
110 return ImageDescriptor.getMissingImageDescriptor();
114 protected static URL makeIconFileURL(String name)
115 throws MalformedURLException {
116 if (iconBaseURL == null)
117 throw new MalformedURLException();
119 return new URL(iconBaseURL, name);