KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo2 > cif > 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.cif;
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  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
43  */

44
45 public class ProducerImpl
46      extends org.objectweb.ccm.demo2.ProducerSessionComposition.ComponentImpl
47   implements java.awt.event.ActionListener JavaDoc
48 {
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

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

70     /** The default constructor. */
71     public
72     ProducerImpl()
73     {
74     }
75
76     // ==================================================================
77
//
78
// Internal methods.
79
//
80
// ==================================================================
81

82     // ==================================================================
83
//
84
// Public methods.
85
//
86
// ==================================================================
87

88     // ==================================================================
89
//
90
// Methods for OMG IDL Components::EnterpriseComponent
91
//
92
// ==================================================================
93

94     /**
95      * Complete the component configuration.
96      *
97      * @exception org.omg.Components.InvalidConfiguration
98      * Thrown if the configuration is invalid.
99      */

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

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

144     /**
145      * Container callback to signal that the component is removed.
146      *
147      * @throw org.omg.Components.CCMException For any problems.
148      */

149     public void
150     ccm_remove()
151     throws org.omg.Components.CCMException
152     {
153         // Release the associated frame.
154
frame_.dispose();
155         frame_ = null;
156     }
157
158     // ==================================================================
159
//
160
// Methods for the OMG IDL demo2::CCM_Producer interface.
161
//
162
// ==================================================================
163

164     /**
165      * The mutator method for the attribute name.
166      *
167      * @param n The name.
168      */

169     public void
170     name(String JavaDoc n)
171     {
172         name_ = n;
173
174         if (frame_ != null)
175             frame_.setTitle(name_ + "'s Producer GUI");
176     }
177
178     /**
179      * The accessor method for the attribute name.
180      *
181      * @return The name.
182      */

183     public String JavaDoc
184     name()
185     {
186         return name_;
187     }
188
189     // ==================================================================
190
//
191
// Methods for the java.awt.event.ActionListener interface.
192
//
193
// ==================================================================
194

195     /**
196      * When the button is selectionned.
197      *
198      * @param e The associate ActionEvent.
199      */

200     public void
201     actionPerformed(java.awt.event.ActionEvent JavaDoc e)
202     {
203         if (list_.isSelectionEmpty())
204             return;
205
206         Object JavaDoc[] texts = list_.getSelectedValues();
207         for (int i=0; i<texts.length; i++)
208         {
209             get_context().push_crop(new FoodImpl( (String JavaDoc)texts[i] ));
210         }
211
212         list_.clearSelection();
213     }
214 }
215
Popular Tags