KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > icon > DefaultFileIconProvider


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@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): Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.icon;
28
29 /** To use the SimpleContextFactory interface */
30 import org.objectweb.util.browser.core.api.FileIconProvider;
31 import org.objectweb.util.browser.core.common.ClassResolver;
32
33 /** To use the ImageIcon class */
34 import javax.swing.ImageIcon JavaDoc;
35
36 /** To use the Icon interface */
37 import javax.swing.Icon JavaDoc;
38
39 /** To use the URL class */
40 import java.net.MalformedURLException JavaDoc;
41 import java.net.URL JavaDoc;
42
43 /**
44  * Basic implementation for Icon factories.
45  *
46  *
47  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
48  * @version 0.1
49  *
50  */

51 public class DefaultFileIconProvider implements FileIconProvider {
52
53     /** The Associated ImageIcon */
54     protected Icon JavaDoc icon_ = null;
55
56     /**
57      * Return an ImageIcon associated to the param's object.
58      *
59      * @param object The contextual view on the tree.
60      * @return The associated icon.
61      */

62     public Icon JavaDoc newIcon(Object JavaDoc object) {
63         return icon_;
64     }
65
66     /**
67      * Fix the url of the icon file to display
68      *
69      * @param url The url of the file to display
70      */

71     public void setUrl(String JavaDoc url) {
72         if (url != null) {
73             URL JavaDoc urlFile = null;
74             urlFile = ClassResolver.getResource(url);
75             if(urlFile==null){
76                 try {
77                     urlFile = new URL JavaDoc(url);
78                 } catch (MalformedURLException JavaDoc e) {
79                     System.out.println(getClass().getName() + url + ": Malformed URL !");
80                 }
81             }
82             if(urlFile!=null){
83                 icon_ = new ImageIcon JavaDoc(urlFile);
84             }
85         }
86     }
87
88 }
89
Popular Tags