KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > client > textboard > TextBoard


1 /*
2  * TextBoard.java
3  *
4  * Created on June 9, 2003, 1:51 PM
5  */

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 /**
16  *
17  * @author amit
18  */

19 public class TextBoard extends java.awt.Frame JavaDoc
20 implements ApplicationMediaInterface
21 {
22     /** Creates new form TextBoard */
23     public TextBoard()
24     {
25     }
26     
27     /** This method is called from within the constructor to
28      * initialize the form.
29      * WARNING: Do NOT modify this code. The content of this method is
30      * always regenerated by the Form Editor.
31      */

32     private void initComponents()//GEN-BEGIN:initComponents
33
{
34         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
35
36         textLabel = new java.awt.Label JavaDoc();
37         textBoard = new java.awt.TextArea JavaDoc();
38         sendButton = new java.awt.Button JavaDoc();
39         statusBar = new java.awt.TextField JavaDoc();
40
41         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc()
46         {
47             public void windowClosing(java.awt.event.WindowEvent JavaDoc 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 JavaDoc();
55         gridBagConstraints.gridx = 0;
56         gridBagConstraints.gridy = 0;
57         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
58         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
64         gridBagConstraints.gridx = 0;
65         gridBagConstraints.gridy = 1;
66         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
67         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc()
75         {
76             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
77             {
78                 sendButtonActionPerformed(evt);
79             }
80         });
81
82         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
83         gridBagConstraints.gridx = 0;
84         gridBagConstraints.gridy = 2;
85         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
86         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc(204, 204, 204));
92         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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     }//GEN-END:initComponents
102

103     private void sendButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_sendButtonActionPerformed
104
{//GEN-HEADEREND:event_sendButtonActionPerformed
105
// Add your handling code here:
106
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     }//GEN-LAST:event_sendButtonActionPerformed
124

125     /** Exit the Application */
126     private void exitForm(java.awt.event.WindowEvent JavaDoc evt)
127     {//GEN-FIRST:event_exitForm
128
if (instance != null)
129         {
130             parent.applicationMediaRemoved(instance);
131         }
132         super.dispose();
133     }//GEN-LAST:event_exitForm
134

135     /**
136      * @param args the command line arguments
137      */

138     public static void main(String JavaDoc args[])
139     {
140         new TextBoard().show();
141     }
142     
143     public void applicationMessageReceived(String JavaDoc from, ApplicationElement element)
144     {
145         if (poppedUp == false)
146         {
147             show();
148             poppedUp = true;
149             
150             // and center it
151
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 JavaDoc from, ApplicationElement element)
169     {
170         String JavaDoc body = element.getApplicationData();
171         if (body != null)
172         {
173             textBoard.setText(body);
174         }
175     }
176     
177     public void init(Locale locale, TalkSessionInterface parent, String JavaDoc 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 JavaDoc 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         // and center it
200
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         // next, send a message to the other side(s) to pop-up the window
214
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 JavaDoc getFromName()
230     {
231         String JavaDoc 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     // Variables declaration - do not modify//GEN-BEGIN:variables
244
private java.awt.Button JavaDoc sendButton;
245     private java.awt.TextArea JavaDoc textBoard;
246     private java.awt.Label JavaDoc textLabel;
247     private java.awt.TextField JavaDoc statusBar;
248     // End of variables declaration//GEN-END:variables
249
private Locale locale;
250     private TalkSessionInterface parent;
251     private String JavaDoc instance;
252     private boolean poppedUp = false;
253 }
254
Popular Tags