KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > logdemo > ClientWithLogImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.logdemo;
31
32 /**
33  ** This is the ECM-aware implementation of the OMG IDL3 <tt>Client</tt> component type
34  ** which uses the simple log service.
35  **/

36 public class ClientWithLogImpl
37 extends Client_MainSegBase
38 implements java.io.Serializable JavaDoc, java.awt.event.ActionListener JavaDoc,
39            org.coach.ECM.ECMExecutor, org.objectweb.ccm.logservice.LogCallback
40 {
41     // client
42
private String JavaDoc _name;
43     private javax.swing.JFrame JavaDoc _frame;
44     private javax.swing.JTextField JavaDoc _text;
45
46     // default constructor
47
public
48     ClientWithLogImpl()
49     {
50         // client
51
_name = null;
52         _frame = null;
53         _text = null;
54     }
55
56     //
57
// overriden operations
58
//
59

60     final public void
61     configuration_complete()
62     throws org.omg.Components.InvalidConfiguration
63     {
64         // create a GUI
65
// NORTH: text field for user inputs
66
_text = new javax.swing.JTextField JavaDoc("", 1);
67
68         // CENTER: send button
69
javax.swing.JButton JavaDoc printb = new javax.swing.JButton JavaDoc("Send");
70         printb.addActionListener(this);
71
72         // MAIN panel
73
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(new java.awt.BorderLayout JavaDoc());
74         panel.add(new javax.swing.JScrollPane JavaDoc(_text), java.awt.BorderLayout.NORTH);
75         panel.add(printb, java.awt.BorderLayout.CENTER);
76         _frame = new javax.swing.JFrame JavaDoc(_name+" GUI");
77         _frame.setSize(400, 300);
78         _frame.getContentPane().add(panel);
79         _frame.pack();
80         _frame.show();
81     }
82         
83
84     //
85
// IDL:coach.org/ECM/ECMExecutor:1.0
86
//
87

88     final public org.omg.CORBA.Object JavaDoc
89     get_service_callback(String JavaDoc sid, String JavaDoc cid)
90     throws org.coach.ECM.UnknownService,
91            org.coach.ECM.UnknownServiceCallback
92     {
93         if (!sid.equals(org.objectweb.ccm.logservice.LOG_SERVICE_ID.value)) {
94             throw new org.coach.ECM.UnknownService();
95         }
96
97         if (!cid.equals(org.objectweb.ccm.logservice.LOG_SERVICE_CALLBACK_ID.value)) {
98             throw new org.coach.ECM.UnknownServiceCallback();
99         }
100
101         return this;
102     }
103
104     //
105
// IDL:org/objectweb/ccm/logservice/LogCallback:1.0
106
//
107

108     final public String JavaDoc
109     get_identity()
110     {
111         return "Client:"+name();
112     }
113
114     //
115
// IDL:objectweb.org/ecm/logdemo/Client:1.0
116
//
117

118     final public void
119     name(String JavaDoc n)
120     {
121         _name = n;
122
123         if (_frame!=null) {
124             _frame.setTitle(_name+" GUI");
125         }
126     }
127
128     final public String JavaDoc
129     name()
130     {
131         return _name;
132     }
133
134     //
135
// java.awt.event.ActionListener
136
//
137

138     final public void
139     actionPerformed(java.awt.event.ActionEvent JavaDoc e)
140     {
141         try {
142             // build message
143
Message msg = new Message();
144             msg.header = _name;
145             msg.content = _text.getText();
146
147             // build async message
148
AsyncMessage amsg = new AsyncMessageImpl(msg);
149
150             // push to emitter
151
org.omg.Components.LocalEvents levts = getCCM2Context().get_events();
152             int chid = levts.get_channel("async_display");
153             levts.push(amsg, chid);
154
155             // send to connected Display
156
org.omg.Components.LocalReceptacles lrecs = getCCM2Context().get_receptacles();
157             org.omg.CORBA.Object JavaDoc obj = lrecs.get_connections("display")[0].ref();
158             SynchronousDisplay dis = SynchronousDisplayHelper.narrow(obj);
159             // check if available.
160
if(dis!=null) {
161                 dis.print(msg);
162             }
163         } catch (Exception JavaDoc ex) {
164             ex.printStackTrace();
165         }
166     }
167 }
168
Popular Tags