KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > Deployment > AssemblyIcon


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.explorer.Deployment;
27
28 import java.net.URL JavaDoc;
29
30 import javax.swing.ImageIcon JavaDoc;
31
32 import org.objectweb.util.explorer.api.IconProvider;
33 import org.omg.Components.Deployment.Assembly;
34
35 /**
36  * This class provides an icon depending on the Assembly status (inactive or inservice).
37  *
38  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
39  *
40  * @version 0.1
41  */

42 public class AssemblyIcon
43   implements IconProvider
44 {
45
46     //==================================================================
47
//
48
// No internal state.
49
//
50
//==================================================================
51

52     /** The associated icons. */
53     protected ImageIcon JavaDoc assemblyBuilt_, assemblyNotBuilt_;
54
55     //==================================================================
56
//
57
// No constructor.
58
//
59
//==================================================================
60

61     /**
62      * Default constructor.
63      */

64     public AssemblyIcon()
65     {
66         assemblyBuilt_ = createIcon("icons/assembly_built.png");
67         assemblyNotBuilt_ = createIcon("icons/assembly_tear_down.png");
68     }
69
70     //==================================================================
71
//
72
// Internal method.
73
//
74
//==================================================================
75

76     protected Assembly getAssembly(Object JavaDoc obj){
77         return (Assembly)obj;
78     }
79
80     /** Returns an ImageIcon, or null if the path is invalid. */
81     protected static ImageIcon JavaDoc createIcon(String JavaDoc imageName)
82     {
83         if (imageName != null) {
84             URL JavaDoc urlFile = null;
85             urlFile = Thread.currentThread().getContextClassLoader().getResource(imageName);
86             if(urlFile==null){
87                 try {
88                     urlFile = new URL JavaDoc(imageName);
89                 } catch (java.net.MalformedURLException JavaDoc e) {
90                     System.out.println(imageName + ": Malformed URL !");
91                 }
92             }
93             if(urlFile!=null){
94                 return new ImageIcon JavaDoc(urlFile);
95             }
96         }
97         return null;
98     }
99
100     //==================================================================
101
//
102
// Public methods for IconProvider interface.
103
//
104
//==================================================================
105

106     /**
107      * Returns a javax.swing.Icon according to the given object.
108      * Provides an icon representing the status of the Assembly
109      */

110     public Object JavaDoc newIcon(Object JavaDoc object)
111     {
112         Assembly assembly = getAssembly(object);
113         org.omg.Components.Deployment.AssemblyState state = assembly.get_state();
114         if(!state.equals(org.omg.Components.Deployment.AssemblyState.INACTIVE))
115             return assemblyBuilt_;
116         else
117             return assemblyNotBuilt_;
118     }
119     
120 }
Popular Tags