KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo2 > monolithic > ProducerImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): Philippe Merle, Mathieu Vadet.
23 Contributor(s): Romain Rouvoy, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.demo2.monolithic;
28
29 import org.objectweb.ccm.demo2.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 demo2::Producer component type.
33  *
34  * This class inherits from the local CCM_Producer interface
35  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
36  *
37  * This class also implements the java.awt.event.ActionListener to manage
38  * users' interactions on the Swing GUI associated to this component.
39  *
40  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</A>
41  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</A>
42  */

43
44 public class ProducerImpl
45      extends org.omg.CORBA.LocalObject JavaDoc
46   implements CCM_Producer,
47              org.omg.Components.SessionComponent,
48              java.awt.event.ActionListener JavaDoc
49 {
50     // ==================================================================
51
//
52
// Internal state.
53
//
54
// ==================================================================
55

56     /** The name of the component. */
57     private String JavaDoc name_;
58
59     /** To refer to the GUI frame. */
60     private javax.swing.JFrame JavaDoc frame_;
61
62     /** To refer to the GUI user input area. */
63     private javax.swing.JList JavaDoc list_;
64
65     /** To refer to the component context. */
66     private CCM_Producer_Context the_context_;
67
68     // ==================================================================
69
//
70
// Constructor.
71
//
72
// ==================================================================
73

74     /** The default constructor. */
75     public
76     ProducerImpl()
77     {
78     }
79
80     // ==================================================================
81
//
82
// Internal methods.
83
//
84
// ==================================================================
85

86     // ==================================================================
87
//
88
// Public methods.
89
//
90
// ==================================================================
91

92     // ==================================================================
93
//
94
// Methods for OMG IDL Components::EnterpriseComponent
95
//
96
// ==================================================================
97

98     /**
99      * Complete the component configuration.
100      *
101      * @exception org.omg.Components.InvalidConfiguration
102      * Thrown if the configuration is invalid.
103      */

104     public void
105     configuration_complete ()
106     throws org.omg.Components.InvalidConfiguration
107     {
108         // Checks if the configuration is not completed.
109
if(name_ == null)
110             throw new org.omg.Components.InvalidConfiguration();
111
112         // Instantiating the GUI.
113

114         // Creates a Swing Frame.
115
frame_ = new javax.swing.JFrame JavaDoc(name_ + "'s Producer GUI");
116         // Sets its size.
117
frame_.setSize(400, 300);
118
119         // Creates a JList for user's inputs.
120
String JavaDoc[] data = {
121             "apple", "pear", "carrot", "corn", "milk", "orange" , "beer",
122             "radish", "beans", "pumpkin", "salad", "worm", "potato", "nothing"
123         };
124         list_ = new javax.swing.JList JavaDoc(data);
125
126         // Creates a button to publishe Food events.
127
javax.swing.JButton JavaDoc button = new javax.swing.JButton JavaDoc("Do crop");
128         button.addActionListener(this);
129
130         // Constructs and shows the GUI.
131
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(
132                                        new java.awt.BorderLayout JavaDoc()
133                                    );
134         frame_.getContentPane().add(panel);
135         panel.add(new javax.swing.JScrollPane JavaDoc(list_),
136                   java.awt.BorderLayout.CENTER);
137         panel.add(button, java.awt.BorderLayout.SOUTH);
138         frame_.pack();
139         frame_.show();
140     }
141
142     // ==================================================================
143
//
144
// Methods for the OMG IDL org.omg.Components.SessionComponent
145
//
146
// ==================================================================
147

148     /**
149      * Set the session component context.
150      *
151      * @param context The session component context.
152      *
153      * @throw org.omg.Components.CCMException For any problems.
154      */

155     public void
156     set_session_context(org.omg.Components.SessionContext context)
157     throws org.omg.Components.CCMException
158     {
159         the_context_ = (CCM_Producer_Context)context;
160     }
161
162     /**
163      * Container callback to signal that the component is activated.
164      *
165      * @throw org.omg.Components.CCMException For any problems.
166      */

167     public void
168     ccm_activate()
169     throws org.omg.Components.CCMException
170     {
171         // Nothing to do currently.
172
}
173
174     /**
175      * Container callback to signal that the component is activated.
176      *
177      * @throw org.omg.Components.CCMException For any problems.
178      */

179     public void
180     ccm_passivate()
181     throws org.omg.Components.CCMException
182     {
183         // Nothing to do currently.
184
}
185
186     /**
187      * Container callback to signal that the component is removed.
188      *
189      * @throw org.omg.Components.CCMException For any problems.
190      */

191     public void
192     ccm_remove()
193     throws org.omg.Components.CCMException
194     {
195         // Release the associated frame.
196
frame_.dispose();
197         frame_ = null;
198     }
199
200     // ==================================================================
201
//
202
// Methods for the OMG IDL demo2::CCM_Producer interface.
203
//
204
// ==================================================================
205

206     /**
207      * The mutator method for the attribute name.
208      *
209      * @param n The name.
210      */

211     public void
212     name(String JavaDoc n)
213     {
214         name_ = n;
215
216         if (frame_ != null)
217             frame_.setTitle(name_ + "'s Producer GUI");
218     }
219
220     /**
221      * The accessor method for the attribute name.
222      *
223      * @return The name.
224      */

225     public String JavaDoc
226     name()
227     {
228         return name_;
229     }
230
231     // ==================================================================
232
//
233
// Methods for the java.awt.event.ActionListener interface.
234
//
235
// ==================================================================
236

237     /**
238      * When the button is selectionned.
239      *
240      * @param e The associate ActionEvent.
241      */

242     public void
243     actionPerformed(java.awt.event.ActionEvent JavaDoc e)
244     {
245         if (list_.isSelectionEmpty())
246             return;
247
248         Object JavaDoc[] texts = list_.getSelectedValues();
249         for (int i=0; i<texts.length; i++)
250         {
251             the_context_.push_crop(new FoodImpl( (String JavaDoc)texts[i] ));
252         }
253
254         list_.clearSelection();
255     }
256 }
257
Popular Tags