KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo3 > cif > ClientImpl


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): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.demo3.cif;
28
29 import org.objectweb.ccm.demo3.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 demo3::Client component type.
33  *
34  * This class inherits from the skeleton
35  * generated by the OpenCCM's CIF to Java 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 public class ClientImpl
45      extends org.objectweb.ccm.demo3.ClientSessionComposition.ComponentImpl
46   implements java.awt.event.ActionListener JavaDoc
47 {
48     // ==================================================================
49
//
50
// Internal state.
51
//
52
// ==================================================================
53

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

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

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

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

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

99     public void
100     configuration_complete()
101     throws org.omg.Components.InvalidConfiguration
102     {
103         // Checks if the configuration is completed.
104
if(name_ == null)
105             throw new org.omg.Components.InvalidConfiguration();
106
107         // Check if the connection to the server is set.
108
if(get_context().get_connection_the_service() == null)
109             throw new org.omg.Components.InvalidConfiguration();
110
111         // Instantiating the GUI.
112

113         // Creates a Swing Frame.
114
frame_ = new javax.swing.JFrame JavaDoc(name_ + "'s Client GUI");
115         // Sets its size.
116
frame_.setSize(400, 300);
117
118         // Creates a text field for user's inputs.
119
text_ = new javax.swing.JTextField JavaDoc("", 1);
120
121         // Creates a button to invoke the connected server component.
122
javax.swing.JButton JavaDoc button = new javax.swing.JButton JavaDoc("Print Text");
123         button.addActionListener(this);
124
125         // Constructs and shows the GUI.
126
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(
127                                        new java.awt.BorderLayout JavaDoc()
128                                    );
129         frame_.getContentPane().add(panel);
130         panel.add(new javax.swing.JScrollPane JavaDoc(text_),
131                   java.awt.BorderLayout.CENTER);
132         panel.add(button, java.awt.BorderLayout.SOUTH);
133         frame_.pack();
134         frame_.show();
135     }
136
137     // ==================================================================
138
//
139
// Methods for the OMG IDL org.omg.Components.SessionComponent
140
//
141
// ==================================================================
142

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

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

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

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

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

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

199     public void
200     actionPerformed(java.awt.event.ActionEvent JavaDoc e)
201     {
202         // Obtain the object reference associated to the
203
// 'the_service' receptacle.
204
Service service = get_context().get_connection_the_service();
205
206         // Check if the connection is available.
207
if(service == null)
208         {
209             System.err.println("The demo3::Client::the_service receptacle is not set!");
210             return;
211         }
212
213         // Calls the display service.
214
service.display(name_ + ":" + text_.getText());
215     }
216 }
217
Popular Tags