KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > 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.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.control.IllegalLifeCycleException;
43 import org.objectweb.fractal.api.control.LifeCycleController;
44 import org.objectweb.util.browser.api.Panel;
45 import org.objectweb.util.browser.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     /**
92      * Provides the panel to display.
93      * @return The panel to display.
94      */

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

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

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

146     /**
147      *
148      */

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

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

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