KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > feature > messagebox > client > MessageBoxClient


1 /*
2  * MessageBoxClient.java
3  *
4  * Created on December 9, 2002, 2:54 AM
5  */

6
7 package com.quikj.application.web.talk.feature.messagebox.client;
8
9 import java.awt.*;
10 import java.util.*;
11 import com.quikj.client.beans.*;
12 import com.quikj.application.web.talk.client.*;
13 import com.quikj.application.web.talk.messaging.*;
14
15 /**
16  *
17  * @author amit
18  */

19 public class MessageBoxClient extends java.awt.Frame JavaDoc implements TalkSessionInterface
20 {
21     /** Creates new form MessageBoxClient */
22     public MessageBoxClient()
23     {
24         locale = TalkFrame.Instance().getLocale();
25         initComponents();
26         
27         // and center it
28

29         Rectangle pbounds = null;
30         if (TalkFrame.Instance().isShowing() == false)
31         {
32             Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
33             pbounds = new Rectangle(0, 0, dim.width, dim.height);
34         }
35         else
36         {
37             pbounds = TalkFrame.Instance().getBounds();
38         }
39         
40         Point mid = new Point(pbounds.x + (pbounds.width/2), pbounds.y + (pbounds.height/2));
41         Rectangle bounds = getBounds();
42         int x = mid.x - (bounds.width/2);
43         int y = mid.y - (bounds.height/2);
44         if (x < 0) x = pbounds.x;
45         if (y < 0) y = pbounds.y;
46         setBounds(x, y, bounds.width, bounds.height);
47     }
48     
49     /** This method is called from within the constructor to
50      * initialize the form.
51      * WARNING: Do NOT modify this code. The content of this method is
52      * always regenerated by the Form Editor.
53      */

54     private void initComponents()//GEN-BEGIN:initComponents
55
{
56         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
57
58         panel1 = new java.awt.Panel JavaDoc();
59         messageLabel = new java.awt.Label JavaDoc();
60         messageArea = new TextArea("", 10, 80, TextArea.SCROLLBARS_VERTICAL_ONLY);
61         panel2 = new java.awt.Panel JavaDoc();
62         sendButton = new java.awt.Button JavaDoc();
63         cancelButton = new java.awt.Button JavaDoc();
64
65         setLayout(new java.awt.GridBagLayout JavaDoc());
66
67         setBackground(java.awt.Color.white);
68         setTitle(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.feature.messagebox.client.language", locale).getString("Message_Box"));
69         addWindowListener(new java.awt.event.WindowAdapter JavaDoc()
70         {
71             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt)
72             {
73                 exitForm(evt);
74             }
75         });
76
77         panel1.setLayout(new java.awt.GridBagLayout JavaDoc());
78
79         panel1.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
80         messageLabel.setText(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.feature.messagebox.client.language", locale).getString("No_one_is_available_to_receive_your_session._Please_leave_a_message."));
81         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
82         gridBagConstraints.gridx = 0;
83         gridBagConstraints.gridy = 0;
84         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
85         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
86         panel1.add(messageLabel, gridBagConstraints);
87
88         messageArea.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
89         messageArea.setColumns(120);
90         messageArea.setRows(10);
91         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
92         gridBagConstraints.gridx = 0;
93         gridBagConstraints.gridy = 1;
94         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
95         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
96         gridBagConstraints.weightx = 100.0;
97         gridBagConstraints.weighty = 100.0;
98         panel1.add(messageArea, gridBagConstraints);
99
100         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.gridx = 0;
102         gridBagConstraints.gridy = 0;
103         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
105         gridBagConstraints.weightx = 100.0;
106         gridBagConstraints.weighty = 100.0;
107         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 10, 10, 10);
108         add(panel1, gridBagConstraints);
109
110         panel2.setLayout(new java.awt.GridBagLayout JavaDoc());
111
112         panel2.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
113         sendButton.setLabel(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.feature.messagebox.client.language", locale).getString("Send"));
114         sendButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
115         {
116             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
117             {
118                 sendButtonActionPerformed(evt);
119             }
120         });
121
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridx = 0;
124         gridBagConstraints.gridy = 0;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 10);
126         panel2.add(sendButton, gridBagConstraints);
127
128         cancelButton.setLabel(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.feature.messagebox.client.language", locale).getString("Cancel"));
129         cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
130         {
131             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
132             {
133                 cancelButtonActionPerformed(evt);
134             }
135         });
136
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.gridx = 1;
139         gridBagConstraints.gridy = 0;
140         panel2.add(cancelButton, gridBagConstraints);
141
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 0;
144         gridBagConstraints.gridy = 1;
145         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
147         gridBagConstraints.weightx = 100.0;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 10, 10);
149         add(panel2, gridBagConstraints);
150
151         pack();
152     }//GEN-END:initComponents
153

154     private void sendButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_sendButtonActionPerformed
155
{//GEN-HEADEREND:event_sendButtonActionPerformed
156
// Add your handling code here:
157
String JavaDoc message_text = messageArea.getText().trim();
158         if (message_text.length() > 0)
159         {
160             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
161             buffer.append("Name: "
162             + TalkFrame.Instance().getUserInformation().getUserName() + "\n");
163             
164             if (TalkFrame.Instance().getUserInformation().getFullName() != null)
165             {
166                 buffer.append("Full Name: "
167                 + TalkFrame.Instance().getUserInformation().getFullName() + "\n");
168             }
169             
170             if (TalkFrame.Instance().getUserInformation().getEmail() != null)
171             {
172                 buffer.append("E-mail: "
173                 + TalkFrame.Instance().getUserInformation().getEmail() + "\n");
174             }
175             
176             if (TalkFrame.Instance().getUserInformation().getComment() != null)
177             {
178                 buffer.append("Additional Information: "
179                 + TalkFrame.Instance().getUserInformation().getComment() + "\n");
180             }
181             
182             buffer.append("\n" + message_text);
183             
184             RTPMessage message = new RTPMessage();
185             message.setSessionId(callInfo.getSessionId());
186             message.setFrom(getFromName());
187             
188             MediaElements elements = new MediaElements();
189             TextElement telem = new TextElement();
190             telem.setMessage(buffer.toString());
191             elements.addMediaElement(telem);
192             message.setMediaElements(elements);
193             
194             TalkFrame.Instance().getCom().sendRequestMessage("text/xml",
195             message.format());
196         }
197         else // just close the window
198
{
199             dispose();
200         }
201     }//GEN-LAST:event_sendButtonActionPerformed
202

203     private String JavaDoc getFromName()
204     {
205         String JavaDoc from_name = TalkFrame.Instance().getUserInformation().getUserName();
206         if (TalkFrame.Instance().getUserInformation().getFullName() != null)
207         {
208             if (TalkFrame.Instance().getUserInformation().getFullName().length() > 0)
209             {
210                 from_name = TalkFrame.Instance().getUserInformation().getFullName();
211             }
212         }
213         
214         return from_name;
215     }
216     
217     private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
218
{//GEN-HEADEREND:event_cancelButtonActionPerformed
219
// Add your handling code here:
220
dispose();
221     }//GEN-LAST:event_cancelButtonActionPerformed
222

223     /** Exit the Application */
224     private void exitForm(java.awt.event.WindowEvent JavaDoc evt)
225     {//GEN-FIRST:event_exitForm
226
dispose();
227     }//GEN-LAST:event_exitForm
228

229     /**
230      * @param args the command line arguments
231      */

232     public static void main(String JavaDoc args[])
233     {
234         new MessageBoxClient().show();
235     }
236     
237     public void appendToConversation(String JavaDoc text, Color color, int style)
238     {
239     }
240     
241     public void applicationMediaAdded(String JavaDoc instance, ApplicationMediaInterface element)
242     {
243     }
244     
245     public void applicationMediaRemoved(String JavaDoc instance)
246     {
247     }
248     
249     public void cleanupCall()
250     {
251         super.dispose();
252         
253         TalkFrame.Instance().sessionRemoved(this);
254         
255         callInProgress = false;
256     }
257     
258     public boolean disconnectReceived(DisconnectMessage disconnect)
259     {
260         String JavaDoc reason_s = null;
261         DisconnectReasonElement reason_element = disconnect.getDisconnectReason();
262         if (reason_element != null)
263         {
264             reason_s = reason_element.getReasonText();
265         }
266         
267         if (reason_s == null)
268         {
269             reason_s = java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.language",
270             locale).getString("Session_disconnected");
271         }
272         
273         InformationDialog info = new InformationDialog(this,
274         java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.language",
275         locale).getString("Disconnected"),
276         reason_s,
277         java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.language",
278                 locale).getString("Close"),
279         5000L);
280         
281         cleanupCall();
282         
283         return true;
284     }
285     
286     public void dispose()
287     {
288         if (callInProgress == true)
289         {
290             DisconnectMessage message = new DisconnectMessage();
291             message.setSessionId(callInfo.getSessionId());
292             DisconnectReasonElement reason = new DisconnectReasonElement();
293             reason.setReasonCode(0);
294             reason.setReasonText(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.language",
295             locale).getString("User_disconnected_the_session"));
296             message.setDisconnectReason(reason);
297             
298             // send the message
299
TalkFrame.Instance().getCom().sendRequestMessage("text/xml",
300             message.format());
301             
302             cleanupCall();
303         }
304         else
305         {
306             super.dispose();
307         }
308     }
309     
310     public CallInfo getCallInfo()
311     {
312         return callInfo;
313     }
314     
315     public boolean handoverCall(CallInfo cinfo, MediaElements media)
316     {
317         callInProgress = true;
318         callInfo = cinfo;
319         
320         // let TALKFRAME
321
TalkFrame.Instance().sessionAdded(this);
322         
323         if (media != null)
324         {
325             // process media request
326
int size = media.numMediaElements();
327             for (int i = 0; i < size; i++)
328             {
329                 MediaElementInterface element = media.elementAt(i);
330                 
331                 if ((element instanceof TextElement) == true)
332                 {
333                     String JavaDoc rcvd_msg = ((TextElement)element).getMessage();
334                     String JavaDoc message = rcvd_msg;
335                     messageLabel.setText(message);
336                     break;
337                 }
338                 // else, ignore
339
}
340         }
341         
342         show();
343         return true;
344     }
345     
346     public boolean makeCall(String JavaDoc called)
347     {
348         return false; // do not support make call
349
}
350     
351     public boolean receivedCall(int req_id, SetupRequestMessage setup, boolean auto_answer)
352     {
353         return false; // do not support received call
354
}
355     
356     public void rtpMessageReceived(RTPMessage rtp)
357     {
358     }
359     
360     public void setCallInfo(CallInfo cinfo)
361     {
362         callInfo = cinfo;
363     }
364     
365     // Variables declaration - do not modify//GEN-BEGIN:variables
366
private java.awt.Button JavaDoc cancelButton;
367     private java.awt.TextArea JavaDoc messageArea;
368     private java.awt.Label JavaDoc messageLabel;
369     private java.awt.Panel JavaDoc panel1;
370     private java.awt.Panel JavaDoc panel2;
371     private java.awt.Button JavaDoc sendButton;
372     // End of variables declaration//GEN-END:variables
373

374     private CallInfo callInfo;
375     private boolean callInProgress = false;
376     private Locale locale;
377 }
378
Popular Tags