KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > icon > InterfaceIconProvider


1 /*====================================================================
2  
3  Objectweb Browser Framework
4  Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5  Contact: openccm@objectweb.org
6  
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or any later version.
11  
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16  
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  USA
21  
22  Initial developer(s): Romain Rouvoy.
23  Contributor(s): ______________________________________.
24  
25  ---------------------------------------------------------------------
26  $Id: InterfaceIconProvider.java,v 1.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.fractal.explorer.icon;
30
31 import java.util.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import javax.swing.Icon JavaDoc;
35 import javax.swing.ImageIcon JavaDoc;
36
37 import org.objectweb.util.explorer.api.IconProvider;
38
39 /**
40  *
41  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
42  * @version 0.1
43  */

44 public abstract class InterfaceIconProvider
45            implements IconProvider
46 {
47     // ==================================================================
48
//
49
// Internal states.
50
//
51
// ==================================================================
52

53     /** The different icons. */
54
55     protected Map JavaDoc icons ;
56     
57     /**
58      * @return Returns the icons.
59      */

60     protected Map JavaDoc getIcons() {
61         return icons;
62     }
63     /**
64      * @param icons The icons to set.
65      */

66     protected void setIcons(Map JavaDoc icons) {
67         this.icons = icons;
68     }
69
70     /**
71      * Load a icon from the classpath.
72      * @param path the path for finding the requested icon.
73      * @return the instance of icon found (null if not found).
74      */

75     protected Icon JavaDoc load(String JavaDoc path) {
76         Icon JavaDoc icon = new ImageIcon JavaDoc(Thread.currentThread().getContextClassLoader().getResource(path));
77         if (icon == null)
78             System.err.println(path+" icon not found!");
79         return icon ;
80     }
81     
82     /**
83      * Load a couple of icons based on the Fc+name+(Started|Stopped) pattern.
84      * @param name the pattern to retrieve.
85      */

86     protected void loadFc(String JavaDoc name) {
87         getIcons().put(name, load("icons/Fc"+name+".png"));
88     }
89     
90     /**
91      * Default Icon provider constructor.
92      */

93     protected InterfaceIconProvider() {
94         setIcons(new HashMap JavaDoc());
95     }
96 }
97
Popular Tags