KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo1 > 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): Romain Rouvoy, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.demo1.cif;
28
29 import org.objectweb.ccm.demo1.Display;
30
31 /**
32  * This is the implementation of the OMG IDL3 demo1::Client component type.
33  *
34  * This class inherits from the CIF generated skeleton class defined
35  * as ClientSessionComposition::ComponentImpl.
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:Romain.Rouvoy@lifl.fr">Romain Rouvoy</A>
43  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
44  */

45
46 public class ClientImpl
47      extends org.objectweb.ccm.demo1.ClientSessionComposition.ComponentImpl
48   implements 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 user's input field. */
63     private javax.swing.JTextField JavaDoc text_;
64
65     // ==================================================================
66
//
67
// Constructor.
68
//
69
// ==================================================================
70

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

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

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

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

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

115         // Creates a Swing Frame.
116
frame_ = new javax.swing.JFrame JavaDoc(name_ + "'s Client GUI");
117         // Sets its size.
118
frame_.setSize(400, 300);
119
120         // Creates a text field for user's inputs.
121
text_ = new javax.swing.JTextField JavaDoc("", 1);
122
123         // Creates a button to invoke the connected server component.
124
javax.swing.JButton JavaDoc button = new javax.swing.JButton JavaDoc("Print Text");
125         button.addActionListener(this);
126
127         // Constructs and shows the GUI.
128
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(
129                                            new java.awt.BorderLayout JavaDoc());
130         frame_.getContentPane().add(panel);
131         panel.add(new javax.swing.JScrollPane JavaDoc(text_),
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 demo1::CCM_Client_Executor
161
//
162
// ==================================================================
163

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

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

183     public String JavaDoc
184     the_name()
185     {
186         return name_;
187     }
188
189     // ==================================================================
190
//
191
// Methods for interface java.awt.event.ActionListener
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         // Obtain the object reference associated to the
204
// 'to_server' receptacle.
205
Display to_server = get_context().get_connection_to_server();
206
207         // Check if the connection is available.
208
if(to_server == null)
209         {
210             System.err.println("The demo1::Client::to_server receptacle is not set!");
211             return;
212         }
213
214         // Calls the print service.
215
to_server.print(name_ + ":" + text_.getText());
216     }
217 }
218
Popular Tags