KickJava   Java API By Example, From Geeks To Geeks.

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


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: LifeCycleControllerPanel.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.control.IllegalLifeCycleException;
43 import org.objectweb.fractal.api.control.LifeCycleController;
44 import org.objectweb.util.explorer.api.Panel;
45 import org.objectweb.util.explorer.api.TreeView;
46
47 /**
48  * This panel allows to start/stop the component.
49  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
50  * @version 0.1
51  */

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

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

71     /**
72      * Empty constructor.
73      */

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

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

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

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

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

136     public void unselected(TreeView treeView) {
137     }
138     
139     // ==================================================================
140
//
141
// Internal classes.
142
//
143
// ==================================================================
144

145     /**
146      *
147      */

148     protected class StartStopAction extends AbstractAction JavaDoc {
149         
150         /** The associated LifeCycleController */
151         protected LifeCycleController lifeCycleController_;
152         
153         /** */
154         protected String JavaDoc value_;
155         
156         /**
157          * Default Constructor
158          */

159         public StartStopAction(String JavaDoc value, LifeCycleController lcc){
160             super(value);
161             value_ = value;
162             lifeCycleController_ = lcc;
163         }
164         
165         /**
166          * The action
167          */

168         public void actionPerformed(ActionEvent JavaDoc e){
169             try {
170                 if (value_.equals("Start"))
171                     lifeCycleController_.startFc();
172                 else if (value_.equals("Stop"))
173                     lifeCycleController_.stopFc();
174             } catch (IllegalLifeCycleException e1) {
175                 e1.printStackTrace();
176             }
177             LifeCycleControllerPanel.this.treeView_.getTree().refreshAll();
178         }
179     }
180     
181 }
Popular Tags