1 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 19 public class MessageBoxClient extends java.awt.Frame implements TalkSessionInterface 20 { 21 22 public MessageBoxClient() 23 { 24 locale = TalkFrame.Instance().getLocale(); 25 initComponents(); 26 27 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 54 private void initComponents() { 56 java.awt.GridBagConstraints gridBagConstraints; 57 58 panel1 = new java.awt.Panel (); 59 messageLabel = new java.awt.Label (); 60 messageArea = new TextArea("", 10, 80, TextArea.SCROLLBARS_VERTICAL_ONLY); 61 panel2 = new java.awt.Panel (); 62 sendButton = new java.awt.Button (); 63 cancelButton = new java.awt.Button (); 64 65 setLayout(new java.awt.GridBagLayout ()); 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 () 70 { 71 public void windowClosing(java.awt.event.WindowEvent evt) 72 { 73 exitForm(evt); 74 } 75 }); 76 77 panel1.setLayout(new java.awt.GridBagLayout ()); 78 79 panel1.setBackground(new java.awt.Color (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 (); 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 (255, 255, 255)); 89 messageArea.setColumns(120); 90 messageArea.setRows(10); 91 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (); 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 (10, 10, 10, 10); 108 add(panel1, gridBagConstraints); 109 110 panel2.setLayout(new java.awt.GridBagLayout ()); 111 112 panel2.setBackground(new java.awt.Color (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 () 115 { 116 public void actionPerformed(java.awt.event.ActionEvent evt) 117 { 118 sendButtonActionPerformed(evt); 119 } 120 }); 121 122 gridBagConstraints = new java.awt.GridBagConstraints (); 123 gridBagConstraints.gridx = 0; 124 gridBagConstraints.gridy = 0; 125 gridBagConstraints.insets = new java.awt.Insets (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 () 130 { 131 public void actionPerformed(java.awt.event.ActionEvent evt) 132 { 133 cancelButtonActionPerformed(evt); 134 } 135 }); 136 137 gridBagConstraints = new java.awt.GridBagConstraints (); 138 gridBagConstraints.gridx = 1; 139 gridBagConstraints.gridy = 0; 140 panel2.add(cancelButton, gridBagConstraints); 141 142 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 10, 10, 10); 149 add(panel2, gridBagConstraints); 150 151 pack(); 152 } 154 private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) { String message_text = messageArea.getText().trim(); 158 if (message_text.length() > 0) 159 { 160 StringBuffer buffer = new StringBuffer (); 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 { 199 dispose(); 200 } 201 } 203 private String getFromName() 204 { 205 String 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 evt) { dispose(); 221 } 223 224 private void exitForm(java.awt.event.WindowEvent evt) 225 { dispose(); 227 } 229 232 public static void main(String args[]) 233 { 234 new MessageBoxClient().show(); 235 } 236 237 public void appendToConversation(String text, Color color, int style) 238 { 239 } 240 241 public void applicationMediaAdded(String instance, ApplicationMediaInterface element) 242 { 243 } 244 245 public void applicationMediaRemoved(String 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 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 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 TalkFrame.Instance().sessionAdded(this); 322 323 if (media != null) 324 { 325 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 rcvd_msg = ((TextElement)element).getMessage(); 334 String message = rcvd_msg; 335 messageLabel.setText(message); 336 break; 337 } 338 } 340 } 341 342 show(); 343 return true; 344 } 345 346 public boolean makeCall(String called) 347 { 348 return false; } 350 351 public boolean receivedCall(int req_id, SetupRequestMessage setup, boolean auto_answer) 352 { 353 return false; } 355 356 public void rtpMessageReceived(RTPMessage rtp) 357 { 358 } 359 360 public void setCallInfo(CallInfo cinfo) 361 { 362 callInfo = cinfo; 363 } 364 365 private java.awt.Button cancelButton; 367 private java.awt.TextArea messageArea; 368 private java.awt.Label messageLabel; 369 private java.awt.Panel panel1; 370 private java.awt.Panel panel2; 371 private java.awt.Button sendButton; 372 374 private CallInfo callInfo; 375 private boolean callInProgress = false; 376 private Locale locale; 377 } 378 | Popular Tags |