RSS news reader; initially copied from "all the news"
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.news / src / net / sourceforge / phpeclipse / news / IconManager.java
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
7  * 
8  * Contributors:
9  *     Jérôme Nègre - initial API and implementation
10  *******************************************************************************/
11
12 /*
13  * Created on 12 juin 2004
14  */
15 package net.sourceforge.phpeclipse.news;
16
17 import java.net.URL;
18
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.swt.graphics.Image;
22
23 /**
24  * @author Jérôme Nègre
25  */
26 public class IconManager {
27         //the root folder containing the icons
28         private static final String ICON_FOLDER = "icons/";
29         
30         //real file locations
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";
38
39         //list of all icon files to put in the ImageRegistry
40         private static final String[] LOCATIONS = new String[]{
41                         LOC_LED_DARK_GREEN,
42                         LOC_LED_LIGHT_GREEN,
43                         LOC_LED_RED,
44                         LOC_LED_YELLOW,
45                         LOC_LINK,
46                         LOC_REFRESH,
47                         LOC_EXTERNAL_BROWSER
48         };
49
50         //public names
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;
55         
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;
59         
60         /**
61          * Populates an image registry with all the locations
62          * @param registry
63          */
64         protected static void populateImageRegistry(ImageRegistry registry) {
65                 for(int i=0; i<LOCATIONS.length; i++) {
66                         registry.put(LOCATIONS[i],createImageDescriptor(LOCATIONS[i]));
67                 }
68         }
69
70         /**
71          * Creates the ImageDescriptor of a file given its path in the
72          * ICON_FOLDER.
73          * @param relativePath
74          * @return the ImageDescriptor
75          */
76     private static ImageDescriptor createImageDescriptor(String relativePath) {
77                 try {
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();
83                 }
84         }
85         
86         public static ImageDescriptor getImageDescriptor(String key) {
87                 return Plugin.getDefault().getImageRegistry().getDescriptor(key);
88         }
89         
90         public static Image getImage(String key) {
91                 return Plugin.getDefault().getImageRegistry().get(key);
92         }
93         
94         /**
95          * This class should not be instanciated
96          */
97         private IconManager() {
98                 //NOP
99         }
100 }