KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > 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.1 2004/04/20 16:37:27 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.util.browser.plugins.fractal.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.browser.api.Panel;
46 import org.objectweb.util.browser.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     /**
93      * Provides the panel to display
94      * @return The panel to display
95      */

96     public JPanel JavaDoc getPanel(){
97         return panel_;
98     }
99     
100     /**
101      * Invokes just after instanciation
102      */

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

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

153     /**
154      *
155      */

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

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

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