1 /*******************************************************************************
2 * Copyright (c) 2004 Jérôme Nègre.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.jnegre.org/cpl1_0.html
9 * Jérôme Nègre - initial API and implementation
10 *******************************************************************************/
13 * Created on 12 juin 2004
15 package net.sourceforge.phpeclipse.news;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.swt.graphics.Image;
24 * @author Jérôme Nègre
26 public class IconManager {
27 //the root folder containing the icons
28 private static final String ICON_FOLDER = "icons/";
31 private static final String LOC_LED_DARK_GREEN = "led_dark_green.gif";
32 private static final String LOC_LED_LIGHT_GREEN = "led_light_green.gif";
33 private static final String LOC_LED_RED = "led_red.gif";
34 private static final String LOC_LED_YELLOW = "led_yellow.gif";
35 private static final String LOC_LINK = "link.gif";
36 private static final String LOC_REFRESH = "refresh.gif";
37 private static final String LOC_EXTERNAL_BROWSER = "external_browser.gif";
39 //list of all icon files to put in the ImageRegistry
40 private static final String[] LOCATIONS = new String[]{
51 public static final String ICON_STATUS_ERROR = LOC_LED_RED;
52 public static final String ICON_STATUS_UNREAD = LOC_LED_LIGHT_GREEN;
53 public static final String ICON_STATUS_READ = LOC_LED_DARK_GREEN;
54 public static final String ICON_STATUS_REFRESH = LOC_LED_YELLOW;
56 public static final String ICON_ACTION_REFRESH = LOC_REFRESH;
57 public static final String ICON_ACTION_LINK = LOC_LINK;
58 public static final String ICON_ACTION_EXTERNAL_BROWSER = LOC_EXTERNAL_BROWSER;
61 * Populates an image registry with all the locations
64 protected static void populateImageRegistry(ImageRegistry registry) {
65 for(int i=0; i<LOCATIONS.length; i++) {
66 registry.put(LOCATIONS[i],createImageDescriptor(LOCATIONS[i]));
71 * Creates the ImageDescriptor of a file given its path in the
74 * @return the ImageDescriptor
76 private static ImageDescriptor createImageDescriptor(String relativePath) {
78 URL url = new URL(Plugin.getDefault().getDescriptor().getInstallURL(),
79 ICON_FOLDER + relativePath);
80 return ImageDescriptor.createFromURL(url);
81 } catch (java.net.MalformedURLException e) {
82 return ImageDescriptor.getMissingImageDescriptor();
86 public static ImageDescriptor getImageDescriptor(String key) {
87 return Plugin.getDefault().getImageRegistry().getDescriptor(key);
90 public static Image getImage(String key) {
91 return Plugin.getDefault().getImageRegistry().get(key);
95 * This class should not be instanciated
97 private IconManager() {