KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > panel > LifeCycleControllerComponentPanel


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): ______________________________________.
24  
25  ---------------------------------------------------------------------
26  $Id: LifeCycleControllerComponentPanel.java,v 1.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.fractal.explorer.panel;
30
31 import java.awt.Color JavaDoc;
32 import java.awt.Component JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.awt.event.ActionEvent JavaDoc;
35
36 import javax.swing.AbstractAction JavaDoc;
37 import javax.swing.Box JavaDoc;
38 import javax.swing.JButton JavaDoc;
39 import javax.swing.JLabel JavaDoc;
40 import javax.swing.JPanel JavaDoc;
41
42 import org.objectweb.fractal.api.NoSuchInterfaceException;
43 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
44 import org.objectweb.fractal.api.control.LifeCycleController;
45 import org.objectweb.util.explorer.api.Panel;
46 import org.objectweb.util.explorer.api.TreeView;
47
48 /**
49  * This panel allows to start/stop the component.
50  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
51  * @version 0.1
52  */

53 public class LifeCycleControllerComponentPanel
54   implements Panel JavaDoc
55 {
56     // ==================================================================
57
//
58
// Internal states.
59
//
60
// ==================================================================
61

62     protected TreeView treeView_ = null;
63     
64     protected JPanel JavaDoc panel_ = null;
65     
66     // ==================================================================
67
//
68
// Constructors.
69
//
70
// ==================================================================
71

72     /**
73      * Empty constructor
74      */

75     public LifeCycleControllerComponentPanel() {
76         panel_ = new JPanel JavaDoc();
77         panel_.setBackground(Color.white);
78     }
79     
80     // ==================================================================
81
//
82
// No internal methods.
83
//
84
// ==================================================================
85

86     // ==================================================================
87
//
88
// Public methods for ViewPanel interface.
89
//
90
// ==================================================================
91

92     /* (non-Javadoc)
93      * @see org.objectweb.util.explorer.api.Panel#getPanel()
94      */

95     public Object JavaDoc getPanel(){
96         return panel_;
97     }
98     
99     /* (non-Javadoc)
100      * @see org.objectweb.util.explorer.api.Panel#selected(org.objectweb.util.explorer.api.TreeView)
101      */

102     public void selected(TreeView treeView) {
103         treeView_ = treeView;
104         org.objectweb.fractal.api.Component ci = (org.objectweb.fractal.api.Component)treeView.getSelectedObject();
105         try {
106             LifeCycleController lifeCycleController = (LifeCycleController)ci.getFcInterface("lifecycle-controller");
107             String JavaDoc value = null;
108             String JavaDoc status = lifeCycleController.getFcState();
109             
110             Box JavaDoc box_ = Box.createVerticalBox();
111             box_.add(Box.createVerticalStrut(10));
112             
113             Box JavaDoc labelBox = Box.createHorizontalBox();
114             labelBox.setAlignmentX(Component.CENTER_ALIGNMENT);
115             labelBox.add(Box.createHorizontalGlue());
116             JLabel JavaDoc labelValue = new JLabel JavaDoc("Component status : " + status);
117             labelBox.add(labelValue);
118             labelBox.add(Box.createHorizontalGlue());
119             box_.add(labelBox);
120             
121             if (status.equals(LifeCycleController.STARTED))
122                 value="Stop";
123             else if (status.equals(LifeCycleController.STOPPED))
124                 value="Start";
125             box_.add(Box.createVerticalStrut(10));
126             Box JavaDoc buttonBox = Box.createHorizontalBox();
127             buttonBox.add(Box.createHorizontalGlue());
128             JButton JavaDoc bt = new JButton JavaDoc(new StartStopAction(value,lifeCycleController));
129             bt.setPreferredSize(new Dimension JavaDoc(100,20));
130             buttonBox.add(bt);
131             buttonBox.add(Box.createHorizontalGlue());
132             box_.add(buttonBox);
133             box_.add(Box.createVerticalGlue());
134             panel_.add(box_);
135         } catch (NoSuchInterfaceException e) {
136             e.printStackTrace();
137         }
138     }
139     
140     /* (non-Javadoc)
141      * @see org.objectweb.util.explorer.api.Panel#unselected(org.objectweb.util.explorer.api.TreeView)
142      */

143     public void unselected(TreeView treeView) {
144     }
145     
146     // ==================================================================
147
//
148
// Internal classes.
149
//
150
// ==================================================================
151

152     /**
153      *
154      */

155     protected class StartStopAction extends AbstractAction JavaDoc {
156         
157         /** The associated LifeCycleController */
158         protected LifeCycleController lifeCycleController_;
159         
160         /** */
161         protected String JavaDoc value_;
162         
163         /**
164          * Default Constructor
165          */

166         public StartStopAction(String JavaDoc value, LifeCycleController lcc){
167             super(value);
168             value_ = value;
169             lifeCycleController_ = lcc;
170         }
171         
172         /**
173          * The action
174          */

175         public void actionPerformed(ActionEvent JavaDoc e){
176             try {
177                 if (value_.equals("Start"))
178                     lifeCycleController_.startFc();
179                 else if (value_.equals("Stop"))
180                     lifeCycleController_.stopFc();
181             } catch (IllegalLifeCycleException e1) {
182                 e1.printStackTrace();
183             }
184             LifeCycleControllerComponentPanel.this.treeView_.getTree().refreshAll();
185         }
186     }
187     
188 }
Popular Tags