1 6 7 package com.quikj.application.web.talk.client.textboard; 8 9 import java.awt.*; 10 import java.util.*; 11 12 import com.quikj.application.web.talk.client.*; 13 import com.quikj.application.web.talk.messaging.*; 14 15 19 public class TextBoard extends java.awt.Frame 20 implements ApplicationMediaInterface 21 { 22 23 public TextBoard() 24 { 25 } 26 27 32 private void initComponents() { 34 java.awt.GridBagConstraints gridBagConstraints; 35 36 textLabel = new java.awt.Label (); 37 textBoard = new java.awt.TextArea (); 38 sendButton = new java.awt.Button (); 39 statusBar = new java.awt.TextField (); 40 41 setLayout(new java.awt.GridBagLayout ()); 42 43 setBackground(java.awt.Color.white); 44 setTitle(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.textboard.language", locale).getString("Text_Board")); 45 addWindowListener(new java.awt.event.WindowAdapter () 46 { 47 public void windowClosing(java.awt.event.WindowEvent evt) 48 { 49 exitForm(evt); 50 } 51 }); 52 53 textLabel.setText(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.textboard.language", locale).getString("Please_type_a_text_message_and_click_on_the_Send_button_to_send")); 54 gridBagConstraints = new java.awt.GridBagConstraints (); 55 gridBagConstraints.gridx = 0; 56 gridBagConstraints.gridy = 0; 57 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 58 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 10); 59 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 60 gridBagConstraints.weightx = 100.0; 61 add(textLabel, gridBagConstraints); 62 63 gridBagConstraints = new java.awt.GridBagConstraints (); 64 gridBagConstraints.gridx = 0; 65 gridBagConstraints.gridy = 1; 66 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 67 gridBagConstraints.insets = new java.awt.Insets (0, 10, 10, 10); 68 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 69 gridBagConstraints.weightx = 100.0; 70 gridBagConstraints.weighty = 100.0; 71 add(textBoard, gridBagConstraints); 72 73 sendButton.setLabel(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.textboard.language", locale).getString("Send")); 74 sendButton.addActionListener(new java.awt.event.ActionListener () 75 { 76 public void actionPerformed(java.awt.event.ActionEvent evt) 77 { 78 sendButtonActionPerformed(evt); 79 } 80 }); 81 82 gridBagConstraints = new java.awt.GridBagConstraints (); 83 gridBagConstraints.gridx = 0; 84 gridBagConstraints.gridy = 2; 85 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 86 gridBagConstraints.insets = new java.awt.Insets (10, 10, 10, 10); 87 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 88 gridBagConstraints.weightx = 100.0; 89 add(sendButton, gridBagConstraints); 90 91 statusBar.setBackground(new java.awt.Color (204, 204, 204)); 92 gridBagConstraints = new java.awt.GridBagConstraints (); 93 gridBagConstraints.gridx = 0; 94 gridBagConstraints.gridy = 3; 95 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 96 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 97 gridBagConstraints.weightx = 100.0; 98 add(statusBar, gridBagConstraints); 99 100 pack(); 101 } 103 private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) { if (textBoard.getText().trim().length() > 0) 107 { 108 RTPMessage rtp = new RTPMessage(); 109 rtp.setSessionId(parent.getCallInfo().getSessionId()); 110 rtp.setFrom(getFromName()); 111 112 MediaElements elements = new MediaElements(); 113 ApplicationElement aelem = new ApplicationElement(); 114 aelem.setInstance(instance); 115 aelem.setName(getClass().getName()); 116 aelem.setApplicationData(textBoard.getText()); 117 elements.addMediaElement(aelem); 118 rtp.setMediaElements(elements); 119 120 TalkFrame.Instance().getCom().sendRequestMessage("text/xml", 121 rtp.format()); 122 } 123 } 125 126 private void exitForm(java.awt.event.WindowEvent evt) 127 { if (instance != null) 129 { 130 parent.applicationMediaRemoved(instance); 131 } 132 super.dispose(); 133 } 135 138 public static void main(String args[]) 139 { 140 new TextBoard().show(); 141 } 142 143 public void applicationMessageReceived(String from, ApplicationElement element) 144 { 145 if (poppedUp == false) 146 { 147 show(); 148 poppedUp = true; 149 150 if ((parent instanceof TalkSession) == true) 152 { 153 Rectangle pbounds = ((TalkSession)parent).getBounds(); 154 Point mid = new Point(pbounds.x + (pbounds.width/2), 155 pbounds.y + (pbounds.height/2)); 156 Rectangle bounds = getBounds(); 157 int x = mid.x - (bounds.width/2); 158 int y = mid.y - (bounds.height/2); 159 if (x < 0) x = pbounds.x; 160 if (y < 0) y = pbounds.y; 161 setBounds(x, y, bounds.width, bounds.height); 162 } 163 } 164 165 processMessage(from, element); 166 } 167 168 private void processMessage(String from, ApplicationElement element) 169 { 170 String body = element.getApplicationData(); 171 if (body != null) 172 { 173 textBoard.setText(body); 174 } 175 } 176 177 public void init(Locale locale, TalkSessionInterface parent, String instance) 178 { 179 this.locale = locale; 180 this.parent = parent; 181 this.instance = instance; 182 183 initComponents(); 184 185 parent.applicationMediaAdded(instance, this); 186 } 187 188 public String menuItemName(Locale locale) 189 { 190 return java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.textboard.language", 191 locale).getString("Text_Board"); 192 } 193 194 public void menuItemSelected() 195 { 196 show(); 197 poppedUp = true; 198 199 if ((parent instanceof TalkSession) == true) 201 { 202 Rectangle pbounds = ((TalkSession)parent).getBounds(); 203 Point mid = new Point(pbounds.x + (pbounds.width/2), 204 pbounds.y + (pbounds.height/2)); 205 Rectangle bounds = getBounds(); 206 int x = mid.x - (bounds.width/2); 207 int y = mid.y - (bounds.height/2); 208 if (x < 0) x = pbounds.x; 209 if (y < 0) y = pbounds.y; 210 setBounds(x, y, bounds.width, bounds.height); 211 } 212 213 RTPMessage rtp = new RTPMessage(); 215 rtp.setSessionId(parent.getCallInfo().getSessionId()); 216 rtp.setFrom(getFromName()); 217 218 MediaElements elements = new MediaElements(); 219 ApplicationElement aelem = new ApplicationElement(); 220 aelem.setInstance(instance); 221 aelem.setName(getClass().getName()); 222 elements.addMediaElement(aelem); 223 rtp.setMediaElements(elements); 224 225 TalkFrame.Instance().getCom().sendRequestMessage("text/xml", 226 rtp.format()); 227 } 228 229 private String getFromName() 230 { 231 String from_name = TalkFrame.Instance().getUserInformation().getUserName(); 232 if (TalkFrame.Instance().getUserInformation().getFullName() != null) 233 { 234 if (TalkFrame.Instance().getUserInformation().getFullName().length() > 0) 235 { 236 from_name = TalkFrame.Instance().getUserInformation().getFullName(); 237 } 238 } 239 240 return from_name; 241 } 242 243 private java.awt.Button sendButton; 245 private java.awt.TextArea textBoard; 246 private java.awt.Label textLabel; 247 private java.awt.TextField statusBar; 248 private Locale locale; 250 private TalkSessionInterface parent; 251 private String instance; 252 private boolean poppedUp = false; 253 } 254 | Popular Tags |