KickJava   Java API By Example, From Geeks To Geeks.

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


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): Jerome Moroy.
23  Contributor(s): Romain Rouvoy______________________________________.
24  
25  ---------------------------------------------------------------------
26  $Id: LifeCycleComponentIconProvider.java,v 1.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.fractal.explorer.icon;
30
31 import javax.swing.Icon JavaDoc;
32
33 import org.objectweb.fractal.api.Component;
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.fractal.api.control.LifeCycleController;
36 import org.objectweb.fractal.api.control.SuperController;
37 import org.objectweb.fractal.explorer.FcExplorer;
38
39 /**
40  * Provides a specific icon depending on the status of the component.
41  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
42  * @version 0.2
43  */

44 public class LifeCycleComponentIconProvider
45      extends InterfaceIconProvider
46 {
47     /**
48      * Load a couple of icons based on the Fc+name+(Started|Stopped) pattern.
49      * @param name the pattern to retrieve.
50      */

51     protected void loadFc(String JavaDoc name) {
52         getIcons().put(name,
53                        new Icon JavaDoc[] {load("icons/Fc"+name+"Started.png"),
54                                    load("icons/Fc"+name+"Stopped.png")});
55     }
56     
57     /** Empty constructor. */
58     public LifeCycleComponentIconProvider() {
59         super();
60         loadFc("Primitive");
61         loadFc("Composite");
62         loadFc("Shared");
63     }
64     
65     //==================================================================
66
//
67
// No internal method.
68
//
69
//==================================================================
70

71     /**
72      * Provides the couple of icons for a type of component (Primitive, Composite or Shared).
73      * @param cpt the component to introspect.
74      * @return the couple of icons associated to the component.
75      */

76     protected Icon JavaDoc[] loadIcon(Component cpt) {
77         try {
78             SuperController sc = FcExplorer.getSuperController(cpt);
79             if (sc.getFcSuperComponents().length > 1)
80                 return (Icon JavaDoc[]) getIcons().get("Shared");
81         } catch (NoSuchInterfaceException e) {}
82         try {
83             FcExplorer.getContentController(cpt);
84             return (Icon JavaDoc[]) getIcons().get("Composite");
85         } catch (NoSuchInterfaceException e) {}
86         return (Icon JavaDoc[]) getIcons().get("Primitive");
87     }
88     
89     //==================================================================
90
//
91
// Public methods for IconProvider interface.
92
//
93
//==================================================================
94

95     /**
96      * Provides the appropriate icon.
97      * @param object the component to represent.
98      * @return the associated icon.
99      */

100     public Object JavaDoc newIcon(Object JavaDoc object) {
101         Component ci = (Component)object;
102         Icon JavaDoc[] icons = loadIcon(ci);
103         if (icons == null) return null;
104         LifeCycleController lcc=null;
105         try {
106             lcc = FcExplorer.getLifeCycleController(ci);
107         } catch (NoSuchInterfaceException e) {
108             return icons[0];
109         }
110         String JavaDoc status = lcc.getFcState();
111         if (status.equals(LifeCycleController.STARTED))
112             return icons[0];
113         else if (status.equals(LifeCycleController.STOPPED))
114             return icons[1];
115         else
116             return null;
117     }
118 }
Popular Tags